From contropinion at gmail.com Sat Sep 1 00:15:04 2012 From: contropinion at gmail.com (contro opinion) Date: Sat, 1 Sep 2012 00:15:04 -0400 Subject: to know binary Message-ID: there is a only line in the file nanmed test: 1234 when i open it whit xxd xxd test what i get is : 0000000: 3132 3334 0a 1234. can you explain it ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Sep 1 00:18:02 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Sep 2012 14:18:02 +1000 Subject: to know binary In-Reply-To: References: Message-ID: On Sat, Sep 1, 2012 at 2:15 PM, contro opinion wrote: > there is a only line in the file nanmed test: > 1234 > when i open it whit xxd > xxd test > what i get is : > 0000000: 3132 3334 0a 1234. > can you explain it ? I would explain it as a file with one line named test: 1234 I would further explain that this uses Unix-style line endings. Any further explanations will require a much clearer question. Try this: http://www.catb.org/~esr/faqs/smart-questions.html ChrisA From gandalf at shopzeus.com Sat Sep 1 00:21:35 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sat, 01 Sep 2012 06:21:35 +0200 Subject: to know binary In-Reply-To: References: Message-ID: <50418D4F.2010603@shopzeus.com> On 2012-09-01 06:15, contro opinion wrote: > there is a only line in the file nanmed test: > 1234 > when i open it whit xxd > xxd test > what i get is : > 0000000: 3132 3334 0a 1234. > can you explain it ? At offset zero (000000): chr(0x31) + chr(0x32)+ chr(0x33)+ chr(0x33)+ chr(0x0a) = '1'+'2'+'3'+'4'+'.' = '1234.' Does it have to do ANYTHING with Python? If I were you, and it was something that must be explained, then I would rather start books about programming before asking questions on a mailing list that is not related to my question. From d at davea.name Sat Sep 1 00:40:52 2012 From: d at davea.name (Dave Angel) Date: Sat, 01 Sep 2012 00:40:52 -0400 Subject: to know binary In-Reply-To: References: Message-ID: <504191D4.8010300@davea.name> On 09/01/2012 12:15 AM, contro opinion wrote: > there is a only line in the file nanmed test: > 1234 > when i open it whit xxd > xxd test > what i get is : > 0000000: 3132 3334 0a 1234. > can you explain it ? > > > Explain what, exactly? Explain why you were able to run xxd without first installing Mumps? What is it you don't understand? Do you know hex? Are you familiar with the hex codes for common ASCII characters and control characters? Does the period at the end of the line bother you? Are you expecting some different number of zeroes in the address field? Since you're apparently running Linux/Unix, you can find xxd executable by using where xxd. And you can tell what kind of file it is by running file on it. xxd is evidently not written in Python. So why again are you asking here? -- DaveA From dihedral88888 at googlemail.com Sat Sep 1 01:08:56 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 31 Aug 2012 22:08:56 -0700 (PDT) Subject: Unittest - testing for filenames and filesize In-Reply-To: References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> Message-ID: On Saturday, September 1, 2012 12:19:10 AM UTC+8, Chris Withers wrote: > On 23/08/2012 12:25, Tigerstyle wrote: > > > class FileTest(unittest.TestCase): > > > > > > def setUp(self): > > > self.origdir = os.getcwd() > > > self.dirname = tempfile.mkdtemp("testdir") > > > os.chdir(self.dirname) > > > > I wouldn't change directories like this, it's pretty fragile, just use > > absolute paths. > > > > > def test_1(self): > > > "Verify creation of files is possible" > > > for filename in ("this.txt", "that.txt", "the_other.txt"): > > > f = open(filename, "w") > > > f.write("Some text\n") > > > f.close() > > > self.assertTrue(f.closed) > > > > > > def test_2(self): > > > "Verify that current directory is empty" > > > self.assertEqual(glob.glob("*"), [], "Directory not empty") > > > > > > def tearDown(self): > > > os.chdir(self.origdir) > > > shutil.rmtree(self.dirname) > > > > Seeing this, you might find the following tools useful: > > > > http://packages.python.org/testfixtures/files.html > > > > cheers, > > > > Chris > > > > -- > > Simplistix - Content Management, Batch Processing & Python Consulting > > - http://www.simplistix.co.uk Well, I am thinking that the directory tree listing services or daemons supported by the OS by some iterators could be better than the stack based model. From dihedral88888 at googlemail.com Sat Sep 1 01:08:56 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 31 Aug 2012 22:08:56 -0700 (PDT) Subject: Unittest - testing for filenames and filesize In-Reply-To: References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> Message-ID: On Saturday, September 1, 2012 12:19:10 AM UTC+8, Chris Withers wrote: > On 23/08/2012 12:25, Tigerstyle wrote: > > > class FileTest(unittest.TestCase): > > > > > > def setUp(self): > > > self.origdir = os.getcwd() > > > self.dirname = tempfile.mkdtemp("testdir") > > > os.chdir(self.dirname) > > > > I wouldn't change directories like this, it's pretty fragile, just use > > absolute paths. > > > > > def test_1(self): > > > "Verify creation of files is possible" > > > for filename in ("this.txt", "that.txt", "the_other.txt"): > > > f = open(filename, "w") > > > f.write("Some text\n") > > > f.close() > > > self.assertTrue(f.closed) > > > > > > def test_2(self): > > > "Verify that current directory is empty" > > > self.assertEqual(glob.glob("*"), [], "Directory not empty") > > > > > > def tearDown(self): > > > os.chdir(self.origdir) > > > shutil.rmtree(self.dirname) > > > > Seeing this, you might find the following tools useful: > > > > http://packages.python.org/testfixtures/files.html > > > > cheers, > > > > Chris > > > > -- > > Simplistix - Content Management, Batch Processing & Python Consulting > > - http://www.simplistix.co.uk Well, I am thinking that the directory tree listing services or daemons supported by the OS by some iterators could be better than the stack based model. From gandalf at shopzeus.com Sat Sep 1 01:17:09 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sat, 01 Sep 2012 07:17:09 +0200 Subject: Async client for PostgreSQL? Message-ID: <50419A55.3080904@shopzeus.com> Is there any extension for Python that can do async I/O for PostgreSQL with tornadoweb's ioloop? Something like: class MainHandler(tornado.web.RequestHandler): @tornado.web.asynchronous def get(self): pg_connection.(long_taking_query_sql,params,callback=self.on_query_opened) def on_query_opened(self, query): self.write(process_rows(query)) self.finish() What would be an alternative? The theoretical problem: suppose there are 100 clients (web browsers) connected to the server with keep alive connections. They are doing long-polls and they are also sending/receiving events (with short response times). Each web browser has an associated state stored on the server side, in the memory (as an object tree). The state is bound to the client with a session id. Most requests will have to be responded with small amounts of data, calculated from the session state, or queried from the database. Most database queries are simple, running for about 100msec. But a few of them will run for 1sec or more. Number of requests ending in database queries is relatively low (10/sec). Other requests can be responded must faster. but they are much more frequent (100/sec, that is. 1 request/sec/client). There is a big global cache full of (Python) objects. Their purpose is to reduce the number of database queries. These objects in the global cache are emitting events to other objects found in the client sessions. Generally, it is not possible to tell what request will end in a database query. Multi-threading is not an option because number of clients is too high (running 100 threads is not good). This is why I decided to use anyc I/O. Tornadoweb looks good for most requirements: async i/o, store session state in objects etc. The biggest problem is that psycopg is not compatible with this model. If I use blocking I/O calls inside a request handler, then they will block all other requests most of the time, resulting in slow response times. What would be a good solution for this? Thanks, Laszlo From d at davea.name Sat Sep 1 01:29:26 2012 From: d at davea.name (Dave Angel) Date: Sat, 01 Sep 2012 01:29:26 -0400 Subject: to know binary In-Reply-To: References: <504191D4.8010300@davea.name> Message-ID: <50419D36.1080306@davea.name> On 09/01/2012 12:59 AM, contro opinion wrote: 1) you top-posted 2) you replied privately, excluding the list from your query > the file is utf-8 format, >>>> str='/0x31/0x32/0x33/0x34' 3) No idea what that value is supposed to mean. Perhaps you intended to use backslashes here? And perhaps you meant to omit the zeroes? >>>> > why unicode(str,"utf-8").encode("utf-8") can not get 1234? > It gets a string, not an integer. And the string will be "1234" once you fix the problems in the earlier line. While you're at it, you should pick a better name for your string. str already has a meaning in Python, and you're hiding that. No real harm other than readability, but it'll be embarrassing when you actually need to use the str() function and you end up trying to call your string. Still not sure how to interpret your original message. You said nothing about unicode, or conversions. And I've been assuming you're using Python 2.x, but all this will be different for 3.x -- DaveA From __peter__ at web.de Sat Sep 1 02:10:40 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 01 Sep 2012 08:10:40 +0200 Subject: why i can't set locale? References: Message-ID: contro opinion wrote: >>>> locale.setlocale(locale.LC_ALL, 'gbk') > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/locale.py", line 513, in setlocale > return _setlocale(category, locale) > locale.Error: unsupported locale setting Try picking one of the locales listed by $ locale -a (Goggle suggests that you may be looking for "zh_CN.GBK") From __peter__ at web.de Sat Sep 1 02:37:00 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 01 Sep 2012 08:37 +0200 Subject: how to get character hex number? References: <50417631.1080508@tim.thechases.com> <50418609.8030902@tim.thechases.com> Message-ID: Tim Chase wrote: > On 08/31/12 22:41, contro opinion wrote: >>>>>>> u"english".encode("utf-8") >>>> 'english' >>>>>>> u"english".encode("ascii") >>>> 'english' >>>> >>>> how can i get 656e676c697368 in encode method? >>> >>> At least in 2.x, you can do: >>> >>> >>> u"english".encode("hex") >>> '656e676c697368' >> >> how about in python3.0? > > Well, in 3.1.3 at least, using the u"..." notation dies on me with > an invalid syntax. However, as Ian suggests, you can do > > my_str = "english" > "".join("%02x" % c for c in my_str.encode("ascii")) > > or whatever other encoding you want instead of "ascii". Another option: >>> binascii.hexlify("english".encode()).decode() '656e676c697368' From breamoreboy at yahoo.co.uk Sat Sep 1 04:49:39 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 01 Sep 2012 09:49:39 +0100 Subject: how to get character hex number? In-Reply-To: <50418609.8030902@tim.thechases.com> References: <50417631.1080508@tim.thechases.com> <50418609.8030902@tim.thechases.com> Message-ID: On 01/09/2012 04:50, Tim Chase wrote: > > Well, in 3.1.3 at least, using the u"..." notation dies on me with > an invalid syntax. However, as Ian suggests, you can do > > my_str = "english" > "".join("%02x" % c for c in my_str.encode("ascii")) > > or whatever other encoding you want instead of "ascii". > > -tkc > > The u"..." notation has been reintroducd for Python 3.3 see http://docs.python.org/dev/whatsnew/3.3.html#pep-414-explicit-unicode-literals -- Cheers. Mark Lawrence. From arnodel at gmail.com Sat Sep 1 05:55:15 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 1 Sep 2012 10:55:15 +0100 Subject: Tkinter bug in Entry widgets on OS X In-Reply-To: <624248hoth2ih6bu6jvnvehokbenn0a555@invalid.netcom.com> References: <624248hoth2ih6bu6jvnvehokbenn0a555@invalid.netcom.com> Message-ID: On Friday, 31 August 2012, Dennis Lee Bieber wrote: > On Fri, 31 Aug 2012 15:41:01 GMT, Alister > > > declaimed the following in gmane.comp.python.general: > > > I agree that it is unexpected in a single line entry box but isn't the > 1st > > rule of user interface design to assume the user is a moron & will do > > things they are not supposed to do? > > > > Therefore invalid inputs should be handled gracefully (not just insert > > random characters) which is what I think the original poster is > > suggesting. > > To which I'd suggest the programmer (vs the user), probably needs > to > code some sort of per-character validation check... After all, there may > be situations where accepting pretty much any key-code is desired, and > if the widget filters characters before they get to the programmer level > that becomes impossible. > > It would be good if I could intercept the key press event and cancel its action on the Entry widget. It's easy to intercept the key event, but I haven't found out how to prevent the funny characters from being inserted into the Entry widget input area. I've struggled to find good tkinter docs on the web. > caveat -- I've only written one simple form using Tkinter, so what > do I know... It's about as much as I've done! -- Arnaud -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sat Sep 1 06:30:43 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 01 Sep 2012 12:30:43 +0200 Subject: Tkinter bug in Entry widgets on OS X References: <624248hoth2ih6bu6jvnvehokbenn0a555@invalid.netcom.com> Message-ID: Arnaud Delobelle wrote: > On Friday, 31 August 2012, Dennis Lee Bieber wrote: > >> On Fri, 31 Aug 2012 15:41:01 GMT, Alister >> >> > >> declaimed the following in gmane.comp.python.general: >> >> > I agree that it is unexpected in a single line entry box but isn't the >> 1st >> > rule of user interface design to assume the user is a moron & will do >> > things they are not supposed to do? >> > >> > Therefore invalid inputs should be handled gracefully (not just insert >> > random characters) which is what I think the original poster is >> > suggesting. >> >> To which I'd suggest the programmer (vs the user), probably needs >> to >> code some sort of per-character validation check... After all, there may >> be situations where accepting pretty much any key-code is desired, and >> if the widget filters characters before they get to the programmer level >> that becomes impossible. >> >> > It would be good if I could intercept the key press event and cancel its > action on the Entry widget. It's easy to intercept the key event, but I > haven't found out how to prevent the funny characters from being inserted > into the Entry widget input area. Untested as I have no Mac: import Tkinter as tk def suppress(event): if event.keycode in {111, 116}: print "ignoring", event.keycode return "break" print event.keycode, "accepted" root = tk.Tk() entry = tk.Entry(root) entry.bind("", suppress) entry.pack() root.mainloop() > I've struggled to find good tkinter > docs on the web. For my (basic) needs I keep coming back to http://infohost.nmt.edu/tcc/help/pubs/tkinter/ From python.list at tim.thechases.com Sat Sep 1 07:48:51 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 01 Sep 2012 06:48:51 -0500 Subject: how to get character hex number? In-Reply-To: References: <50417631.1080508@tim.thechases.com> <50418609.8030902@tim.thechases.com> Message-ID: <5041F623.8080208@tim.thechases.com> On 09/01/12 03:49, Mark Lawrence wrote: > On 01/09/2012 04:50, Tim Chase wrote: >> Well, in 3.1.3 at least, using the u"..." notation dies on me with >> an invalid syntax. > > The u"..." notation has been reintroducd for Python 3.3 Nice to know--it makes writing backwards compat. code just a bit easier, even if it is a NOOP. I'll catch it when Debian Stable makes it there (currently at 3.1). -tkc From feliphil at gmx.net Sat Sep 1 08:55:35 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Sat, 1 Sep 2012 14:55:35 +0200 Subject: Looking for an IPC solution References: Message-ID: <20120901145535.53fd8d7d2e71b880d107266b@gmx.net> > There are just so many IPC modules out there. I'm looking for a > solution for developing a new a multi-tier application. The core > application will be running on a single computer, so the IPC should > be using shared memory (or mmap) and have very short response times. Probably the fastest I/RPC implementation for Python should be OmniOrbpy: http://omniorb.sourceforge.net/ It's cross-platform, language-independent and standard-(Corba-) compliant. > I have seen a stand alone cross platform IPC server before that could > serve "channels", and send/receive messages using these channels. But > I don't remember its name and now I cannot find it. Can somebody > please help? If it's just for "messaging", Spread should be interesting: http://www.spread.org/ Also cross-platform & language-independent. Sincerely, Wolfgang From arnodel at gmail.com Sat Sep 1 08:56:32 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 1 Sep 2012 13:56:32 +0100 Subject: Tkinter bug in Entry widgets on OS X In-Reply-To: References: <624248hoth2ih6bu6jvnvehokbenn0a555@invalid.netcom.com> Message-ID: On 1 September 2012 11:30, Peter Otten <__peter__ at web.de> wrote: > Arnaud Delobelle wrote: >> It would be good if I could intercept the key press event and cancel its >> action on the Entry widget. It's easy to intercept the key event, but I >> haven't found out how to prevent the funny characters from being inserted >> into the Entry widget input area. > > Untested as I have no Mac: > > import Tkinter as tk > > def suppress(event): > if event.keycode in {111, 116}: > print "ignoring", event.keycode > return "break" > print event.keycode, "accepted" > > root = tk.Tk() > entry = tk.Entry(root) > entry.bind("", suppress) > entry.pack() > > root.mainloop() This works fine! return "break" is the piece of knowledge that I was missing. Thanks a lot! In fact I lied a bit in my original message - I do use the UP and DOWN arrows on one Entry widget for navigating its command history. To do this I was binding the "" and "" events to a function, which simply has to return "break" to work around the bug. On other Entry widgets, I just bind "" and "" to a suppress function which simply returns "break". >> I've struggled to find good tkinter >> docs on the web. > > For my (basic) needs I keep coming back to > > http://infohost.nmt.edu/tcc/help/pubs/tkinter/ Thanks for the link. I was using the docs on effbot which are nice but probably incomplete (and old). I guess I should flag up this bug but I don't even know if it's a Python or Tk problem and have little time or expertise to investigate. -- Arnaud From ashwini.oruganti at gmail.com Sat Sep 1 09:47:05 2012 From: ashwini.oruganti at gmail.com (Ashwini Oruganti) Date: Sat, 1 Sep 2012 19:17:05 +0530 Subject: Twisted 12.2.0 released Message-ID: On behalf of Twisted Matrix Laboratories, I am honored to announce the release of Twisted 12.2. Highlights for this release include: * To be able to work on Python3 support, Python 2.5 is no longer supported. * twisted.mail.imap4 now serves BODYSTRUCTURE responses which provide more information and conform to the IMAP4 RFC more closely. * twisted.conch now supports commercial SSH implementations which don't comply with the IETF standard. * twisted.internet.endpoints now provides several new endpoints, including a TCP client endpoint that resolves hostnames to IPv6 host addresses. * IReactorSocket.adoptStreamConnection, implemented by some reactors, allows adding an existing established connection to the reactor. Starting with the release after 12.2, Twisted will begin requiring zope.interface 3.6 (as part of Python 3 support). This is the last Twisted release supporting Python 2.6 on Windows. For more information, see the NEWS file here: http://twistedmatrix.com/Releases/Twisted/12.2/NEWS.txt Download it now from: http://pypi.python.org/packages/source/T/Twisted/Twisted-12.2.0.tar.bz2 or http://pypi.python.org/packages/2.6/T/Twisted/Twisted-12.2.0.win32-py2.6.exe or http://pypi.python.org/packages/2.6/T/Twisted/Twisted-12.2.0.win32-py2.6.msi or http://pypi.python.org/packages/2.7/T/Twisted/Twisted-12.2.0.win32-py2.7.exe or http://pypi.python.org/packages/2.7/T/Twisted/Twisted-12.2.0.win32-py2.7.msi Thanks to the supporters of Twisted and to the many contributors for this release. -- Ashwini Oruganti -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Sat Sep 1 11:27:18 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 1 Sep 2012 08:27:18 -0700 (PDT) Subject: interfacing with x86_64 assembler In-Reply-To: References: Message-ID: <33ae97d9-b49d-4163-80b3-1a5b2233bd41@googlegroups.com> On Friday, 31 August 2012 19:28:11 UTC+5:30, Grant Edwards wrote: > On 2012-08-31, Mark Lawrence wrote: > > > On 31/08/2012 14:40, lipska the kat wrote: > > > > >> I was hacking away at some x86_64 assembler today > > >> when I found myself obsessively indenting my code > > >> by EXACTLY 4 spaces or (multiples thereof) > > > > > What's wrong with structured assembler? :) > > > > Nothing -- it's called "C". > > > > -- > > Grant Edwards grant.b.edwards Yow! Not SENSUOUS ... only > > at "FROLICSOME" ... and in > > gmail.com need of DENTAL WORK ... in > > PAIN!!! Very much true. In fact C is by definition assembly (as the creators just added whatever features the machine supported to C) From maniandram01 at gmail.com Sat Sep 1 11:32:32 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 1 Sep 2012 08:32:32 -0700 (PDT) Subject: PipeController v0.1 - experimental tool to simulate simple UNIX-style pipes in Python In-Reply-To: <229067cc-dee6-4f0c-bcf2-c30f20b4a9be@googlegroups.com> References: <229067cc-dee6-4f0c-bcf2-c30f20b4a9be@googlegroups.com> Message-ID: <58eb1290-dbdc-4b89-b03f-d4efd125a132@googlegroups.com> On Friday, 31 August 2012 03:27:54 UTC+5:30, vasudevram wrote: > I wrote PipeController recently to experiment with doing UNIX-style pipes in Python. > > > > Blog post about it: > > > > http://jugad2.blogspot.in/2012/08/pipecontroller-v01-released-simulating.html > > > > The blog post has a link to the downloadable PipeController source code. > > > > It will be released under the New BSD License, which means you can use it for any purpose, commercial or otherwise, subject to the terms of the license. > > > > - Vasudev Ram > > www.dancingbison.com > > jugad2.blogspot.com > > twitter.com/vasudevram Doesn't the pipes module already do this? From raipervaiz786 at gmail.com Sat Sep 1 12:08:01 2012 From: raipervaiz786 at gmail.com (raipervaiz786 at gmail.com) Date: Sat, 1 Sep 2012 09:08:01 -0700 (PDT) Subject: KAJOL SEX VIDEOS''''''''''''''''''' In-Reply-To: References: Message-ID: <6478da06-0d3f-40e3-807c-edd72cd1f7cb@googlegroups.com> On Thursday, August 2, 2012 9:35:25 PM UTC+5, devi wrote: > KAJAL SEX VIDEOS > > http://maxworkerds.co.cc From werner at thieprojects.ch Sat Sep 1 13:18:03 2012 From: werner at thieprojects.ch (Werner Thie) Date: Sat, 01 Sep 2012 07:18:03 -1000 Subject: Async client for PostgreSQL? In-Reply-To: <50419A55.3080904@shopzeus.com> References: <50419A55.3080904@shopzeus.com> Message-ID: <5042434B.3010201@thieprojects.ch> On 8/31/12 7:17 PM, Laszlo Nagy wrote: > Is there any extension for Python that can do async I/O for PostgreSQL > with tornadoweb's ioloop? > > Something like: > > class MainHandler(tornado.web.RequestHandler): > @tornado.web.asynchronous > def get(self): > pg_connection.(long_taking_query_sql,params,callback=self.on_query_opened) > > def on_query_opened(self, query): > self.write(process_rows(query)) > self.finish() > > > > What would be an alternative? > > The theoretical problem: suppose there are 100 clients (web browsers) > connected to the server with keep alive connections. They are doing > long-polls and they are also sending/receiving events (with short > response times). Each web browser has an associated state stored on the > server side, in the memory (as an object tree). The state is bound to > the client with a session id. Most requests will have to be responded > with small amounts of data, calculated from the session state, or > queried from the database. Most database queries are simple, running for > about 100msec. But a few of them will run for 1sec or more. Number of > requests ending in database queries is relatively low (10/sec). Other > requests can be responded must faster. but they are much more frequent > (100/sec, that is. 1 request/sec/client). There is a big global cache > full of (Python) objects. Their purpose is to reduce the number of > database queries. These objects in the global cache are emitting events > to other objects found in the client sessions. Generally, it is not > possible to tell what request will end in a database query. > > Multi-threading is not an option because number of clients is too high > (running 100 threads is not good). This is why I decided to use anyc > I/O. Tornadoweb looks good for most requirements: async i/o, store > session state in objects etc. The biggest problem is that psycopg is not > compatible with this model. If I use blocking I/O calls inside a request > handler, then they will block all other requests most of the time, > resulting in slow response times. > > What would be a good solution for this? > > Thanks, > > Laszlo > Hi does running on tornado imply that you would not consider twisted http://twistedmatrix.com ? If not, twisted has exactly this capability hiding long running queries on whatever db's behind deferToThread(). Brute force I would pack the db access into a twisted run web-service, forking work out in twisted either with deferToThread() or if you want to take advantage of using processes instead of threads thus being able to tap all cores, then have a look at ampoule at https://launchpad.net/ampoule - be aware though that ampoule has a 64k limit on what can be passed around. Werner From ian.g.kelly at gmail.com Sat Sep 1 14:20:35 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 1 Sep 2012 12:20:35 -0600 Subject: PipeController v0.1 - experimental tool to simulate simple UNIX-style pipes in Python In-Reply-To: References: <229067cc-dee6-4f0c-bcf2-c30f20b4a9be@googlegroups.com> <58eb1290-dbdc-4b89-b03f-d4efd125a132@googlegroups.com> Message-ID: Resending to the list... On Sep 1, 2012 12:19 PM, "Ian Kelly" wrote: > On Sep 1, 2012 9:37 AM, "Ramchandra Apte" wrote: > > Doesn't the pipes module already do this? > > No, that deals with actual Unix pipes. This appears to be about pipelined > processing within a single program and not IPC; the description "Unix-like" > is a bit misleading, IMO. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Sat Sep 1 15:28:34 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sat, 01 Sep 2012 21:28:34 +0200 Subject: Async client for PostgreSQL? In-Reply-To: <5042434B.3010201@thieprojects.ch> References: <50419A55.3080904@shopzeus.com> <5042434B.3010201@thieprojects.ch> Message-ID: <504261E2.5030305@shopzeus.com> > Hi > > does running on tornado imply that you would not consider twisted > http://twistedmatrix.com ? > > If not, twisted has exactly this capability hiding long running > queries on whatever db's behind deferToThread(). All right, I was reading its documentation http://twistedmatrix.com/documents/10.1.0/api/twisted.internet.threads.deferToThread.html It doesn't tell too much about it: "Run a function in a thread and return the result as a Deferred.". Run a function but in what thread? Does it create a new thread for every invocation? In that case, I don't want to use this. My example case: 10% from 100 requests/second deal with a database. But it does not mean that one db-related request will do a single db API call only. They will almost always do more: start transaction, parse and open query, fetch with cursor, close query, open another query etc. then commit transaction. 8 API calls to do a quick fetch + update (usually under 100msec, but it might be blocked by another transaction for a while...) So we are talking about 80 database API calls per seconds at least. It would be insane to initialize a new thread for each invocation. And wrapping these API calls into a single closure function is not useful either, because that function would not be able to safely access the state that is stored in the main thread. Unless you protet it with locks. But it is whole point of async I/O server: to avoid using slow locks, expensive threads and context switching. Maybe, deferToThread uses a thread pool? But it doesn't say much about it. (Am I reading the wrong documentation?) BTW I could try a version that uses a thread pool. It is sad, by the way. We have async I/O servers for Python that can be used for large number of clients, but most external modules/extensions do not support their I/O loops. Including the extension modules of the most popular databases. So yes, you can use Twisted or torandoweb until you do not want to call *some* API functions that are blocking. (By *some* I mean: much less blocking than non-blocking, but quite a few.) We also have synchronous Python servers, but we cannot get rid of the GIL, Python threads are expensive and slow, so they cannot be used for a large number of clients. And finally, we have messaging services/IPC like zeromq. They are probably the most expensive, but they scale very well. But you need more money to operate the underlying hardware. I'm starting to think that I did not get a quick answer because my use case (100 clients) fall into to the "heavy weight" category, and the solution is to invest more in the hardware. :-) Thanks, Laszlo From vinay_sajip at yahoo.co.uk Sat Sep 1 17:59:52 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sat, 1 Sep 2012 14:59:52 -0700 (PDT) Subject: ANN: A new version (0.3.1) of the Python module which wraps GnuPG has been released. Message-ID: A new version of the Python module which wraps GnuPG has been released. What Changed? ============= This is a minor enhancement and bug-fix release. See the project website ( http://code.google.com/p/python-gnupg/ ) for more information. Summary: Better support for status messages from GnuPG. Support for additional arguments to be passed to GnuPG. Bugs in tests which used Latin-1 encoded data have been fixed by specifying that encoding. On verification (including after decryption), the signer trust level is returned in integer and text formats. The current version passes all tests on Windows (CPython 2.4, 2.5, 2.6, 2.7, 3.1 and Jython 2.5.1), Mac OS X (Python 2.5) and Ubuntu (CPython 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2). On Windows, GnuPG 1.4.11 has been used for the tests. What Does It Do? ================ The gnupg module allows Python programs to make use of the functionality provided by the Gnu Privacy Guard (abbreviated GPG or GnuPG). Using this module, Python programs can encrypt and decrypt data, digitally sign documents and verify digital signatures, manage (generate, list and delete) encryption keys, using proven Public Key Infrastructure (PKI) encryption technology based on OpenPGP. This module is expected to be used with Python versions >= 2.4, as it makes use of the subprocess module which appeared in that version of Python. This module is a newer version derived from earlier work by Andrew Kuchling, Richard Jones and Steve Traugott. A test suite using unittest is included with the source distribution. Simple usage: >>> import gnupg >>> gpg = gnupg.GPG(gnupghome='/path/to/keyring/directory') >>> gpg.list_keys() [{ ... 'fingerprint': 'F819EE7705497D73E3CCEE65197D5DAC68F1AAB2', 'keyid': '197D5DAC68F1AAB2', 'length': '1024', 'type': 'pub', 'uids': ['', 'Gary Gross (A test user) ']}, { ... 'fingerprint': '37F24DD4B918CC264D4F31D60C5FEFA7A921FC4A', 'keyid': '0C5FEFA7A921FC4A', 'length': '1024', ... 'uids': ['', 'Danny Davis (A test user) ']}] >>> encrypted = gpg.encrypt("Hello, world!", ['0C5FEFA7A921FC4A']) >>> str(encrypted) '-----BEGIN PGP MESSAGE-----\nVersion: GnuPG v1.4.9 (GNU/Linux)\n \nhQIOA/6NHMDTXUwcEAf ... -----END PGP MESSAGE-----\n' >>> decrypted = gpg.decrypt(str(encrypted), passphrase='secret') >>> str(decrypted) 'Hello, world!' >>> signed = gpg.sign("Goodbye, world!", passphrase='secret') >>> verified = gpg.verify(str(signed)) >>> print "Verified" if verified else "Not verified" 'Verified' For more information, visit http://code.google.com/p/python-gnupg/ - as always, your feedback is most welcome (especially bug reports, patches and suggestions for improvement). Enjoy! Cheers Vinay Sajip Red Dove Consultants Ltd. From werner at thieprojects.ch Sat Sep 1 18:24:10 2012 From: werner at thieprojects.ch (Werner Thie) Date: Sat, 01 Sep 2012 12:24:10 -1000 Subject: Async client for PostgreSQL? In-Reply-To: <504261E2.5030305@shopzeus.com> References: <50419A55.3080904@shopzeus.com> <5042434B.3010201@thieprojects.ch> <504261E2.5030305@shopzeus.com> Message-ID: <50428B0A.3030403@thieprojects.ch> On 9/1/12 9:28 AM, Laszlo Nagy wrote: > >> Hi >> >> does running on tornado imply that you would not consider twisted >> http://twistedmatrix.com ? >> >> If not, twisted has exactly this capability hiding long running >> queries on whatever db's behind deferToThread(). > All right, I was reading its documentation > > http://twistedmatrix.com/documents/10.1.0/api/twisted.internet.threads.deferToThread.html > > > It doesn't tell too much about it: "Run a function in a thread and > return the result as a Deferred.". > > Run a function but in what thread? Does it create a new thread for every > invocation? In that case, I don't want to use this. My example case: 10% > from 100 requests/second deal with a database. But it does not mean that > one db-related request will do a single db API call only. They will > almost always do more: start transaction, parse and open query, fetch > with cursor, close query, open another query etc. then commit > transaction. 8 API calls to do a quick fetch + update (usually under > 100msec, but it might be blocked by another transaction for a while...) > So we are talking about 80 database API calls per seconds at least. It > would be insane to initialize a new thread for each invocation. And > wrapping these API calls into a single closure function is not useful > either, because that function would not be able to safely access the > state that is stored in the main thread. Unless you protet it with > locks. But it is whole point of async I/O server: to avoid using slow > locks, expensive threads and context switching. > > Maybe, deferToThread uses a thread pool? But it doesn't say much about > it. (Am I reading the wrong documentation?) BTW I could try a version > that uses a thread pool. > > It is sad, by the way. We have async I/O servers for Python that can be > used for large number of clients, but most external modules/extensions > do not support their I/O loops. Including the extension modules of the > most popular databases. So yes, you can use Twisted or torandoweb until > you do not want to call *some* API functions that are blocking. (By > *some* I mean: much less blocking than non-blocking, but quite a few.) > We also have synchronous Python servers, but we cannot get rid of the > GIL, Python threads are expensive and slow, so they cannot be used for a > large number of clients. And finally, we have messaging services/IPC > like zeromq. They are probably the most expensive, but they scale very > well. But you need more money to operate the underlying hardware. I'm > starting to think that I did not get a quick answer because my use case > (100 clients) fall into to the "heavy weight" category, and the solution > is to invest more in the hardware. :-) > > Thanks, > > Laszlo > Laszlo: Hmm, I was suggesting that you could replace the whole DB driver with a webservice implemented with twisted, if you rule out threads then with ampoule doing it with a process pool and consume this webservice with the tornado side asynchronously. production level example thread pool based DB API: Just to give you some ballpark figures, I'm running a game server with a daily peak of about 1500 parallel permanent connections and 50k games played every day (avg game duration 13min, peak request frequency close to 100req/sec) with a lot of statistics going into a MySQL DB on US$2k worth of hardware. Twisted as basis sitting atop FreeBSD, started the latest version in March, its running since then, no restarts, no reboots, no problems. production level example process pool based PDF production: Or for another implementation I'm running a webservice based PDF production (probably as blocking as services can come) for a Java based business app with twisted/ampoule, this is as stable as the game server. HTH, Werner From steve+comp.lang.python at pearwood.info Sat Sep 1 18:41:04 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Sep 2012 22:41:04 GMT Subject: Curses unicode support Message-ID: <50428f00$0$29978$c3e8da3$5496439d@news.astraweb.com> Thanks to Victor Stinner, the curses module now has improved Unicode support. http://mail.python.org/pipermail/python-dev/2012-September/121569.html Victor has asked for testers to report any bugs in the module before Python 3.3 goes live: [quote] So please try to test the curses module before Python 3.3 final with your favorite application! [end quote] -- Steven From james.pye at gmail.com Sat Sep 1 19:57:13 2012 From: james.pye at gmail.com (jwp) Date: Sat, 1 Sep 2012 16:57:13 -0700 (PDT) Subject: Async client for PostgreSQL? In-Reply-To: References: Message-ID: On Friday, August 31, 2012 10:17:18 PM UTC-7, Laszlo Nagy wrote: > Is there any extension for Python that can do async I/O for PostgreSQL As others point out, the easiest route is using one of the blocking drivers with threads and "emulate" async operations. However, the low-level parts of py-postgresql (python.projects.postgresql.org) were designed with arbitrary modes in mind. That is, the protocol code is independent of the transport so that it could be used with frameworks like twisted given some effort. Much of the work that will go into py-postgresql over the next couple years will be to make it easier to integrate into arbitrary frameworks. Currently, I suspect it would require some "heavy lifting".. =\ cheers, github.com/jwp From james.pye at gmail.com Sat Sep 1 19:57:13 2012 From: james.pye at gmail.com (jwp) Date: Sat, 1 Sep 2012 16:57:13 -0700 (PDT) Subject: Async client for PostgreSQL? In-Reply-To: References: Message-ID: On Friday, August 31, 2012 10:17:18 PM UTC-7, Laszlo Nagy wrote: > Is there any extension for Python that can do async I/O for PostgreSQL As others point out, the easiest route is using one of the blocking drivers with threads and "emulate" async operations. However, the low-level parts of py-postgresql (python.projects.postgresql.org) were designed with arbitrary modes in mind. That is, the protocol code is independent of the transport so that it could be used with frameworks like twisted given some effort. Much of the work that will go into py-postgresql over the next couple years will be to make it easier to integrate into arbitrary frameworks. Currently, I suspect it would require some "heavy lifting".. =\ cheers, github.com/jwp From john_ladasky at sbcglobal.net Sat Sep 1 20:10:08 2012 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sat, 1 Sep 2012 17:10:08 -0700 (PDT) Subject: interfacing with x86_64 assembler In-Reply-To: <33ae97d9-b49d-4163-80b3-1a5b2233bd41@googlegroups.com> References: <33ae97d9-b49d-4163-80b3-1a5b2233bd41@googlegroups.com> Message-ID: <9f3dcb98-ad0c-4acf-82a7-c10767327f4a@googlegroups.com> I haven't seen this joke on the Net in years, does anyone still remember it? "C combines the power of assembly language with the readability and maintainability of assembly language." From rosuav at gmail.com Sat Sep 1 20:36:03 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Sep 2012 10:36:03 +1000 Subject: interfacing with x86_64 assembler In-Reply-To: <9f3dcb98-ad0c-4acf-82a7-c10767327f4a@googlegroups.com> References: <33ae97d9-b49d-4163-80b3-1a5b2233bd41@googlegroups.com> <9f3dcb98-ad0c-4acf-82a7-c10767327f4a@googlegroups.com> Message-ID: On Sun, Sep 2, 2012 at 10:10 AM, John Ladasky wrote: > I haven't seen this joke on the Net in years, does anyone still remember it? > > "C combines the power of assembly language with the readability and maintainability of assembly language." Seen it, and it has validity. But I'd rather work with C than actual assembly any day. And these days, C code is just a bunch of directives specifying how a compiler should build a program; optimizing compilers add, remove, reorder, whatever they think fit. It's a pretty high level language now. ChrisA From castironpi at gmail.com Sat Sep 1 22:10:43 2012 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 1 Sep 2012 19:10:43 -0700 (PDT) Subject: Looking for an IPC solution In-Reply-To: References: Message-ID: <40ab9c6f-737e-47e3-950b-558472ad4a09@googlegroups.com> On Friday, August 31, 2012 2:22:00 PM UTC-5, Laszlo Nagy wrote: > There are just so many IPC modules out there. I'm looking for a solution > > for developing a new a multi-tier application. The core application will > > be running on a single computer, so the IPC should be using shared > > memory (or mmap) and have very short response times. But there will be a > > tier that will hold application state for clients, and there will be > > lots of clients. So that tier needs to go to different computers. E.g. > > the same IPC should also be accessed over TCP/IP. Most messages will be > > simple data structures, nothing complicated. The ability to run on PyPy > > would, and also to run on both Windows and Linux would be a plus. > > > > I have seen a stand alone cross platform IPC server before that could > > serve "channels", and send/receive messages using these channels. But I > > don't remember its name and now I cannot find it. Can somebody please help? > > > > Thanks, > > > > Laszlo Hi Laszlo, There aren't a lot of ways to create a Python object in an "mmap" buffer. "mmap" is conducive to arrays of arrays. For variable-length structures like strings and lists, you need "dynamic allocation". The C functions "malloc" and "free" allocate memory space, and file creation and deletion routines operate on disk space. However "malloc" doesn't allow you to allocate memory space within memory that's already allocated. Operating systems don't provide that capability, and doing it yourself amounts to creating your own file system. If you did, you still might not be able to use existing libraries like the STL or Python, because one address might refer to different locations in different processes. One solution is to keep a linked list of free blocks within your "mmap" buffer. It is prone to slow access times and segment fragmentation. Another solution is to create many small files with fixed-length names. The minimum file size on your system might become prohibitive depending on your constraints, since a 4-byte integer could occupy 4096 bytes on disk or more. Or you can serialize the arguments and return values of your functions, and make requests to a central process. From castironpi at gmail.com Sat Sep 1 22:10:43 2012 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 1 Sep 2012 19:10:43 -0700 (PDT) Subject: Looking for an IPC solution In-Reply-To: References: Message-ID: <40ab9c6f-737e-47e3-950b-558472ad4a09@googlegroups.com> On Friday, August 31, 2012 2:22:00 PM UTC-5, Laszlo Nagy wrote: > There are just so many IPC modules out there. I'm looking for a solution > > for developing a new a multi-tier application. The core application will > > be running on a single computer, so the IPC should be using shared > > memory (or mmap) and have very short response times. But there will be a > > tier that will hold application state for clients, and there will be > > lots of clients. So that tier needs to go to different computers. E.g. > > the same IPC should also be accessed over TCP/IP. Most messages will be > > simple data structures, nothing complicated. The ability to run on PyPy > > would, and also to run on both Windows and Linux would be a plus. > > > > I have seen a stand alone cross platform IPC server before that could > > serve "channels", and send/receive messages using these channels. But I > > don't remember its name and now I cannot find it. Can somebody please help? > > > > Thanks, > > > > Laszlo Hi Laszlo, There aren't a lot of ways to create a Python object in an "mmap" buffer. "mmap" is conducive to arrays of arrays. For variable-length structures like strings and lists, you need "dynamic allocation". The C functions "malloc" and "free" allocate memory space, and file creation and deletion routines operate on disk space. However "malloc" doesn't allow you to allocate memory space within memory that's already allocated. Operating systems don't provide that capability, and doing it yourself amounts to creating your own file system. If you did, you still might not be able to use existing libraries like the STL or Python, because one address might refer to different locations in different processes. One solution is to keep a linked list of free blocks within your "mmap" buffer. It is prone to slow access times and segment fragmentation. Another solution is to create many small files with fixed-length names. The minimum file size on your system might become prohibitive depending on your constraints, since a 4-byte integer could occupy 4096 bytes on disk or more. Or you can serialize the arguments and return values of your functions, and make requests to a central process. From alessandromoura35 at googlemail.com Sat Sep 1 22:30:59 2012 From: alessandromoura35 at googlemail.com (alessandromoura35 at googlemail.com) Date: Sat, 1 Sep 2012 19:30:59 -0700 (PDT) Subject: Accessing AST at runtime Message-ID: <8b41b8a9-b3b8-485a-8e5d-34d28c2d6d66@googlegroups.com> Hi, I would like to access the AST of a python object at runtime. I mean, if I have this: def f(x): return x*x/2 Is there any way to interrogate the object f to find out the AST of the expression x*x/2 ? Of course if the definition of f were in a file, I could use the ast module to parse it; but what I want is to do this from within the code. The closest thing I was able to find was f.__code__, and more specifically f.__code__.co_code, but that is a byte-string which seems to be the bytecode (?) for the function. This may not be possible at all; maybe after the def statement is processed by the Python interpreter the AST information is discarded. But I wanted to check here if someone knows one way or another. Many thanks. From maniandram01 at gmail.com Sat Sep 1 22:48:51 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 1 Sep 2012 19:48:51 -0700 (PDT) Subject: Accessing AST at runtime In-Reply-To: <8b41b8a9-b3b8-485a-8e5d-34d28c2d6d66@googlegroups.com> References: <8b41b8a9-b3b8-485a-8e5d-34d28c2d6d66@googlegroups.com> Message-ID: <90dd585c-360b-461d-b306-493ae170974a@googlegroups.com> On Sunday, 2 September 2012 08:00:59 UTC+5:30, (unknown) wrote: > Hi, > > > > I would like to access the AST of a python object at runtime. I mean, if I have this: > > > > def f(x): return x*x/2 > > > > Is there any way to interrogate the object f to find out the AST of the expression x*x/2 ? Of course if the definition of f were in a file, I could use the ast module to parse it; but what I want is to do this from within the code. > > > > The closest thing I was able to find was f.__code__, and more specifically f.__code__.co_code, but that is a byte-string which seems to be the bytecode (?) for the function. > > > > This may not be possible at all; maybe after the def statement is processed by the Python interpreter the AST information is discarded. But I wanted to check here if someone knows one way or another. > > > > Many thanks. You could scan the text for code and then ast.parse() it. Then you know how... From maniandram01 at gmail.com Sat Sep 1 22:50:34 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 1 Sep 2012 19:50:34 -0700 (PDT) Subject: interfacing with x86_64 assembler In-Reply-To: References: <33ae97d9-b49d-4163-80b3-1a5b2233bd41@googlegroups.com> <9f3dcb98-ad0c-4acf-82a7-c10767327f4a@googlegroups.com> Message-ID: <67e68826-7217-4d49-80ec-fc1cf5be26e7@googlegroups.com> On Sunday, 2 September 2012 06:06:06 UTC+5:30, Chris Angelico wrote: > On Sun, Sep 2, 2012 at 10:10 AM, John Ladasky > > wrote: > > > I haven't seen this joke on the Net in years, does anyone still remember it? > > > > > > "C combines the power of assembly language with the readability and maintainability of assembly language." > > > > Seen it, and it has validity. But I'd rather work with C than actual > > assembly any day. And these days, C code is just a bunch of directives > > specifying how a compiler should build a program; optimizing compilers > > add, remove, reorder, whatever they think fit. It's a pretty high > > level language now. > > > > ChrisA I thought it was like this: assembly a low level language C a medium level language Java a high level language Python a very-high level language From maniandram01 at gmail.com Sat Sep 1 22:50:34 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 1 Sep 2012 19:50:34 -0700 (PDT) Subject: interfacing with x86_64 assembler In-Reply-To: References: <33ae97d9-b49d-4163-80b3-1a5b2233bd41@googlegroups.com> <9f3dcb98-ad0c-4acf-82a7-c10767327f4a@googlegroups.com> Message-ID: <67e68826-7217-4d49-80ec-fc1cf5be26e7@googlegroups.com> On Sunday, 2 September 2012 06:06:06 UTC+5:30, Chris Angelico wrote: > On Sun, Sep 2, 2012 at 10:10 AM, John Ladasky > > wrote: > > > I haven't seen this joke on the Net in years, does anyone still remember it? > > > > > > "C combines the power of assembly language with the readability and maintainability of assembly language." > > > > Seen it, and it has validity. But I'd rather work with C than actual > > assembly any day. And these days, C code is just a bunch of directives > > specifying how a compiler should build a program; optimizing compilers > > add, remove, reorder, whatever they think fit. It's a pretty high > > level language now. > > > > ChrisA I thought it was like this: assembly a low level language C a medium level language Java a high level language Python a very-high level language From maniandram01 at gmail.com Sat Sep 1 23:15:19 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 1 Sep 2012 20:15:19 -0700 (PDT) Subject: py2c - an open source Python to C/C++ is looking for developers In-Reply-To: References: <16816fd5-c6b4-49df-baf0-e0bfb0d999df@googlegroups.com> <1409e6f3-b265-4329-9618-c06f8098fef3@t1g2000pbl.googlegroups.com> Message-ID: <9cf4820c-25a2-45a7-af47-cb3e06d30707@googlegroups.com> On Tuesday, 31 July 2012 18:16:27 UTC+5:30, Stefan Behnel wrote: > Stefan Behnel, 31.07.2012 07:23: > > > From a look at the source code, it seems hard to bring it together with > > > anything. It looks very monolithic. > > > > Hmm, sorry, I mixed it up with "2c.py", which is yet another of those > > Python-to-C compilers with an all too similar name. > > > > https://code.google.com/p/2c-python/ > > > > There are a couple of others here: > > > > http://wiki.python.org/moin/PythonImplementations > > > > Seeing the number of those compilers, almost none of which is commonly used > > and/or still alive as a project, the question really is: why another one? > > > > I mean, it's totally fine as a hobby educational project, sure, and I > > really don't want to discourage anyone from going through this to have fun. > > > > But apart from "just for fun", what is the goal that would make this > > particular compiler different from the others? And also different enough to > > merit its own source base, instead of basing it on one of the existing > > projects? I don't consider "source is harder to read than to write" a good > > answer to this in general. > > > Stefan It converts to *pure* C/C++ *without* using Python or its API so that it can be the same speed as C/C++ From maniandram01 at gmail.com Sat Sep 1 23:15:19 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 1 Sep 2012 20:15:19 -0700 (PDT) Subject: py2c - an open source Python to C/C++ is looking for developers In-Reply-To: References: <16816fd5-c6b4-49df-baf0-e0bfb0d999df@googlegroups.com> <1409e6f3-b265-4329-9618-c06f8098fef3@t1g2000pbl.googlegroups.com> Message-ID: <9cf4820c-25a2-45a7-af47-cb3e06d30707@googlegroups.com> On Tuesday, 31 July 2012 18:16:27 UTC+5:30, Stefan Behnel wrote: > Stefan Behnel, 31.07.2012 07:23: > > > From a look at the source code, it seems hard to bring it together with > > > anything. It looks very monolithic. > > > > Hmm, sorry, I mixed it up with "2c.py", which is yet another of those > > Python-to-C compilers with an all too similar name. > > > > https://code.google.com/p/2c-python/ > > > > There are a couple of others here: > > > > http://wiki.python.org/moin/PythonImplementations > > > > Seeing the number of those compilers, almost none of which is commonly used > > and/or still alive as a project, the question really is: why another one? > > > > I mean, it's totally fine as a hobby educational project, sure, and I > > really don't want to discourage anyone from going through this to have fun. > > > > But apart from "just for fun", what is the goal that would make this > > particular compiler different from the others? And also different enough to > > merit its own source base, instead of basing it on one of the existing > > projects? I don't consider "source is harder to read than to write" a good > > answer to this in general. > > > Stefan It converts to *pure* C/C++ *without* using Python or its API so that it can be the same speed as C/C++ From cjgohlke at gmail.com Sat Sep 1 23:28:30 2012 From: cjgohlke at gmail.com (cjgohlke at gmail.com) Date: Sat, 1 Sep 2012 20:28:30 -0700 (PDT) Subject: Curses unicode support In-Reply-To: <50428f00$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <50428f00$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <30764d09-c9e8-4c72-afd0-609e2fbe690b@googlegroups.com> On Saturday, September 1, 2012 3:41:04 PM UTC-7, Steven D'Aprano wrote: > Thanks to Victor Stinner, the curses module now has improved Unicode > > support. > > > > http://mail.python.org/pipermail/python-dev/2012-September/121569.html > > > > Victor has asked for testers to report any bugs in the module before > > Python 3.3 goes live: > > > > [quote] > > So please try to test the curses module before Python 3.3 final with > > your favorite application! > > [end quote] > > > > > > -- > > Steven It might be worth mentioning here that there is no _curses module, with or without Unicode support, in any CPython version for the Windows operating system (http://bugs.python.org/issue2889). Christoph From torriem at gmail.com Sun Sep 2 01:27:58 2012 From: torriem at gmail.com (Michael Torrie) Date: Sat, 01 Sep 2012 23:27:58 -0600 Subject: py2c - an open source Python to C/C++ is looking for developers In-Reply-To: <9cf4820c-25a2-45a7-af47-cb3e06d30707@googlegroups.com> References: <16816fd5-c6b4-49df-baf0-e0bfb0d999df@googlegroups.com> <1409e6f3-b265-4329-9618-c06f8098fef3@t1g2000pbl.googlegroups.com> <9cf4820c-25a2-45a7-af47-cb3e06d30707@googlegroups.com> Message-ID: <5042EE5E.1080408@gmail.com> On 09/01/2012 09:15 PM, Ramchandra Apte wrote: > It converts to *pure* C/C++ *without* using Python or its API so that it can be the same speed as C/C++ Sounds like a fun project for you. I hope you learn a lot doing it. That's reason enough for it. Do you plan to port all the standard python modules as well, though? Because Python modules, both in the standard library and third-party, are the main reasons that I use python. For example, PyGTK. Python is a great glue language. Since it can seamlessly interact with C and be extended in C, speed has never really been an issue for me. From tjreedy at udel.edu Sun Sep 2 02:05:32 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 02 Sep 2012 02:05:32 -0400 Subject: Accessing AST at runtime In-Reply-To: <8b41b8a9-b3b8-485a-8e5d-34d28c2d6d66@googlegroups.com> References: <8b41b8a9-b3b8-485a-8e5d-34d28c2d6d66@googlegroups.com> Message-ID: On 9/1/2012 10:30 PM, alessandromoura35 at googlemail.com wrote: > Hi, > > I would like to access the AST of a python object at runtime. I mean, > if I have this: > > def f(x): return x*x/2 > > Is there any way to interrogate the object f to find out the AST of > the expression x*x/2 ? Of course if the definition of f were in a > file, I could use the ast module to parse it; but what I want is to > do this from within the code. > > The closest thing I was able to find was f.__code__, and more > specifically f.__code__.co_code, but that is a byte-string which > seems to be the bytecode (?) for the function. > > This may not be possible at all; maybe after the def statement is > processed by the Python interpreter the AST information is discarded. Yes, it is. -- Terry Jan Reedy From maniandram01 at gmail.com Sun Sep 2 02:10:59 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 1 Sep 2012 23:10:59 -0700 (PDT) Subject: py2c - an open source Python to C/C++ is looking for developers In-Reply-To: References: <16816fd5-c6b4-49df-baf0-e0bfb0d999df@googlegroups.com> <1409e6f3-b265-4329-9618-c06f8098fef3@t1g2000pbl.googlegroups.com> <9cf4820c-25a2-45a7-af47-cb3e06d30707@googlegroups.com> Message-ID: <6b2b2379-c382-4338-9a10-18e1a63cfbee@googlegroups.com> >That's reason enough for it. Do you plan to port all the standard python modules as well, though? Well, it should be quite easy because most of the _modules are either C accelerator (which there is no need to port) or a C wrapper (which should be trivial to port) From maniandram01 at gmail.com Sun Sep 2 02:10:59 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 1 Sep 2012 23:10:59 -0700 (PDT) Subject: py2c - an open source Python to C/C++ is looking for developers In-Reply-To: References: <16816fd5-c6b4-49df-baf0-e0bfb0d999df@googlegroups.com> <1409e6f3-b265-4329-9618-c06f8098fef3@t1g2000pbl.googlegroups.com> <9cf4820c-25a2-45a7-af47-cb3e06d30707@googlegroups.com> Message-ID: <6b2b2379-c382-4338-9a10-18e1a63cfbee@googlegroups.com> >That's reason enough for it. Do you plan to port all the standard python modules as well, though? Well, it should be quite easy because most of the _modules are either C accelerator (which there is no need to port) or a C wrapper (which should be trivial to port) From maniandram01 at gmail.com Sun Sep 2 02:16:15 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 1 Sep 2012 23:16:15 -0700 (PDT) Subject: py2c - an open source Python to C/C++ is looking for developers In-Reply-To: References: <16816fd5-c6b4-49df-baf0-e0bfb0d999df@googlegroups.com> <1409e6f3-b265-4329-9618-c06f8098fef3@t1g2000pbl.googlegroups.com> <9cf4820c-25a2-45a7-af47-cb3e06d30707@googlegroups.com> Message-ID: <33c248e3-06fe-4929-b617-392d7122d6e0@googlegroups.com> On Sunday, 2 September 2012 11:18:38 UTC+5:30, Michael Torrie wrote: > On 09/01/2012 09:15 PM, Ramchandra Apte wrote: > > > It converts to *pure* C/C++ *without* using Python or its API so that it can be the same speed as C/C++ > > > > Sounds like a fun project for you. I hope you learn a lot doing it. > > That's reason enough for it. Do you plan to port all the standard > > python modules as well, though? Because Python modules, both in the > > standard library and third-party, are the main reasons that I use > > python. For example, PyGTK. Python is a great glue language. Since it > > can seamlessly interact with C and be extended in C, speed has never > > really been an issue for me. I am writing py2c for my OS written in Python (planned) . >Sounds like a fun project for you. More fun with more developers. (I need developers) From maniandram01 at gmail.com Sun Sep 2 02:16:15 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 1 Sep 2012 23:16:15 -0700 (PDT) Subject: py2c - an open source Python to C/C++ is looking for developers In-Reply-To: References: <16816fd5-c6b4-49df-baf0-e0bfb0d999df@googlegroups.com> <1409e6f3-b265-4329-9618-c06f8098fef3@t1g2000pbl.googlegroups.com> <9cf4820c-25a2-45a7-af47-cb3e06d30707@googlegroups.com> Message-ID: <33c248e3-06fe-4929-b617-392d7122d6e0@googlegroups.com> On Sunday, 2 September 2012 11:18:38 UTC+5:30, Michael Torrie wrote: > On 09/01/2012 09:15 PM, Ramchandra Apte wrote: > > > It converts to *pure* C/C++ *without* using Python or its API so that it can be the same speed as C/C++ > > > > Sounds like a fun project for you. I hope you learn a lot doing it. > > That's reason enough for it. Do you plan to port all the standard > > python modules as well, though? Because Python modules, both in the > > standard library and third-party, are the main reasons that I use > > python. For example, PyGTK. Python is a great glue language. Since it > > can seamlessly interact with C and be extended in C, speed has never > > really been an issue for me. I am writing py2c for my OS written in Python (planned) . >Sounds like a fun project for you. More fun with more developers. (I need developers) From stefan_ml at behnel.de Sun Sep 2 02:21:29 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 02 Sep 2012 08:21:29 +0200 Subject: Cython 0.17 released Message-ID: Hello everyone, on behalf of the Cython project team, I'm proud to announce the final release of Cython 0.17. This is a major step forward in the development of the Cython programming language that will make life easier for a lot of users, rounds up some rough edges of the compiler and adds (preliminary) support for CPython 3.3 and PyPy. With this release, the Cython compiler successfully passes over 14,000 regression tests of the CPython 3.3 test suite and almost 13,000 tests of the CPython 2.7 suite, with only some 300 and 200 failures respectively. This makes it a serious alternative to interpreted Python execution that integrates natively with the complete CPython ecosystem. It is also the first final release of an implementation of PEP 380 (generator delegation), before it will eventually appear in CPython 3.3. === Download and Documentation === Download: http://cython.org/release/Cython-0.17.tar.gz Release notes: http://wiki.cython.org/ReleaseNotes-0.17 Homepage: http://cython.org/ Documentation: http://docs.cython.org/ === Major features of this release === * vastly improved integration with the C++ STL containers http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html#standard-library http://docs.cython.org/src/tutorial/strings.html#c-strings * "yield from" delegation between generators (PEP 380) http://www.python.org/dev/peps/pep-0380/ * alpha quality support for PyPy (via cpyext) http://docs.cython.org/src/userguide/pypy.html === What is Cython ? === Cython is a language with an optimising compiler that makes writing C extensions for the Python language as easy as Python itself. The Cython language is a superset of the Python language that additionally supports calling C functions and declaring C types on variables and class attributes. This allows the compiler to generate very efficient C code from Cython code. The C code is generated once and then compiles with all major C/C++ compilers in CPython 2.4 and later, including Python 3.x. PyPy support is work in progress (on both sides) and is considered mostly usable in Cython 0.17. All of this makes Cython the ideal language for wrapping external C libraries, embedding CPython into existing applications, and for fast C modules that speed up the execution of Python code. Have fun, Stefan From stefan_ml at behnel.de Sun Sep 2 02:27:14 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 02 Sep 2012 08:27:14 +0200 Subject: py2c - an open source Python to C/C++ is looking for developers In-Reply-To: <6b2b2379-c382-4338-9a10-18e1a63cfbee@googlegroups.com> References: <16816fd5-c6b4-49df-baf0-e0bfb0d999df@googlegroups.com> <1409e6f3-b265-4329-9618-c06f8098fef3@t1g2000pbl.googlegroups.com> <9cf4820c-25a2-45a7-af47-cb3e06d30707@googlegroups.com> <6b2b2379-c382-4338-9a10-18e1a63cfbee@googlegroups.com> Message-ID: Ramchandra Apte, 02.09.2012 08:10: >> That's reason enough for it. Do you plan to port all the standard > python modules as well, though? > > Well, it should be quite easy because most of the _modules are either C accelerator (which there is no need to port) or a C wrapper (which should be trivial to port) Nope, not at all. They use the CPython C-API internally, so in order to port them, you'll have to reimplement that first. That's a huge amount of work, as proven by the incompleteness of all other Python implementations in that regard. If you think you can do better here then IronPython or PyPy, please go ahead. Stefan From storchaka at gmail.com Sun Sep 2 03:23:15 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sun, 02 Sep 2012 10:23:15 +0300 Subject: py2c - an open source Python to C/C++ is looking for developers In-Reply-To: <9cf4820c-25a2-45a7-af47-cb3e06d30707@googlegroups.com> References: <16816fd5-c6b4-49df-baf0-e0bfb0d999df@googlegroups.com> <1409e6f3-b265-4329-9618-c06f8098fef3@t1g2000pbl.googlegroups.com> <9cf4820c-25a2-45a7-af47-cb3e06d30707@googlegroups.com> Message-ID: On 02.09.12 06:15, Ramchandra Apte wrote: > It converts to *pure* C/C++ *without* using Python or its API so that it can be the same speed as C/C++ How is it implemented long integers? From wxjmfauth at gmail.com Sun Sep 2 03:36:50 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 2 Sep 2012 00:36:50 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> Message-ID: <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Le jeudi 30 ao?t 2012 17:01:50 UTC+2, Antoine Pitrou a ?crit?: > > > I honestly suggest you shut up until you have a clue. > D?sol? Antoine, I have not the knowledge to dive in the Python code, but I know what is a character. The coding of the characters is a domain per se, independent from the os, from the computer languages. Before spending time to implement a new algorithm, maybe it is better to ask, if there is something better than the actual schemes. I still remember my thoughts when I read the PEP 393 discussion: "this is not logical", "they do no understand typography", "atomic character ???", ... Real world exemples. >>> import libfrancais >>> li = ['no?l', 'noir', 'n?ud', 'noduleux', \ ... 'no?tique', 'no?se', 'noir?tre'] >>> r = libfrancais.sortfr(li) >>> r ['noduleux', 'no?l', 'no?se', 'no?tique', 'n?ud', 'noir', 'noir?tre'] (cf "Le Petit Robert") or The *letters* satisfying the requirements of the "Imprimerie nationale". jmf From wxjmfauth at gmail.com Sun Sep 2 03:36:50 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 2 Sep 2012 00:36:50 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> Message-ID: <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Le jeudi 30 ao?t 2012 17:01:50 UTC+2, Antoine Pitrou a ?crit?: > > > I honestly suggest you shut up until you have a clue. > D?sol? Antoine, I have not the knowledge to dive in the Python code, but I know what is a character. The coding of the characters is a domain per se, independent from the os, from the computer languages. Before spending time to implement a new algorithm, maybe it is better to ask, if there is something better than the actual schemes. I still remember my thoughts when I read the PEP 393 discussion: "this is not logical", "they do no understand typography", "atomic character ???", ... Real world exemples. >>> import libfrancais >>> li = ['no?l', 'noir', 'n?ud', 'noduleux', \ ... 'no?tique', 'no?se', 'noir?tre'] >>> r = libfrancais.sortfr(li) >>> r ['noduleux', 'no?l', 'no?se', 'no?tique', 'n?ud', 'noir', 'noir?tre'] (cf "Le Petit Robert") or The *letters* satisfying the requirements of the "Imprimerie nationale". jmf From gandalf at shopzeus.com Sun Sep 2 03:56:28 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sun, 02 Sep 2012 09:56:28 +0200 Subject: Async client for PostgreSQL? In-Reply-To: <50428B0A.3030403@thieprojects.ch> References: <50419A55.3080904@shopzeus.com> <5042434B.3010201@thieprojects.ch> <504261E2.5030305@shopzeus.com> <50428B0A.3030403@thieprojects.ch> Message-ID: <5043112C.1010005@shopzeus.com> > Hmm, I was suggesting that you could replace the whole DB driver with > a webservice implemented with twisted, if you rule out threads then > with ampoule doing it with a process pool and consume this webservice > with the tornado side asynchronously. I see. I'm sorry, I misunderstood. So this would be a wrapper around PostgreSQL. Very interesting idea. (In this case, I'm not sure how to safely manage transactions.) > > production level example thread pool based DB API: > Just to give you some ballpark figures, I'm running a game server with > a daily peak of about 1500 parallel permanent connections and 50k > games played every day (avg game duration 13min, peak request > frequency close to 100req/sec) with a lot of statistics going into a > MySQL DB on US$2k worth of hardware. Twisted as basis sitting atop > FreeBSD, started the latest version in March, its running since then, > no restarts, no reboots, no problems. Thank you. From breamoreboy at yahoo.co.uk Sun Sep 2 04:43:31 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Sep 2012 09:43:31 +0100 Subject: py2c - an open source Python to C/C++ is looking for developers In-Reply-To: <33c248e3-06fe-4929-b617-392d7122d6e0@googlegroups.com> References: <16816fd5-c6b4-49df-baf0-e0bfb0d999df@googlegroups.com> <1409e6f3-b265-4329-9618-c06f8098fef3@t1g2000pbl.googlegroups.com> <9cf4820c-25a2-45a7-af47-cb3e06d30707@googlegroups.com> <33c248e3-06fe-4929-b617-392d7122d6e0@googlegroups.com> Message-ID: On 02/09/2012 07:16, Ramchandra Apte wrote: > On Sunday, 2 September 2012 11:18:38 UTC+5:30, Michael Torrie wrote: >> On 09/01/2012 09:15 PM, Ramchandra Apte wrote: >> >>> It converts to *pure* C/C++ *without* using Python or its API so that it can be the same speed as C/C++ >> >> >> >> Sounds like a fun project for you. I hope you learn a lot doing it. >> >> That's reason enough for it. Do you plan to port all the standard >> >> python modules as well, though? Because Python modules, both in the >> >> standard library and third-party, are the main reasons that I use >> >> python. For example, PyGTK. Python is a great glue language. Since it >> >> can seamlessly interact with C and be extended in C, speed has never >> >> really been an issue for me. > > I am writing py2c for my OS written in Python (planned) . >> Sounds like a fun project for you. > More fun with more developers. (I need developers) > Your earlier quote "Well, it should be quite easy because most of the _modules are either C accelerator (which there is no need to port) or a C wrapper (which should be trivial to port)" means that I won't be touching the project with a 10 foot long disinfected barge pole. -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Sun Sep 2 04:58:14 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Sep 2012 09:58:14 +0100 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: On 02/09/2012 08:36, wxjmfauth at gmail.com wrote: > Le jeudi 30 ao?t 2012 17:01:50 UTC+2, Antoine Pitrou a ?crit : >> >> >> I honestly suggest you shut up until you have a clue. >> > D?sol? Antoine, > > I have not the knowledge to dive in the Python code, > but I know what is a character. You're a character, and from my observations on this thread you're very humorous. YMMV. > > The coding of the characters is a domain per se, > independent from the os, from the computer languages. > > Before spending time to implement a new algorithm, > maybe it is better to ask, if there is something > better than the actual schemes. Please write a new PEP indicating how you would correct your perceived deficiencies with PEP 393 and its implementation. > > I still remember my thoughts when I read the PEP 393 > discussion: "this is not logical", "they do no understand > typography", "atomic character ???", ... When PEP 393 was first drafted how much input did you give during the acceptance process, if any? > > Real world exemples. > >>>> import libfrancais >>>> li = ['no?l', 'noir', 'n?ud', 'noduleux', \ Why the unneeded continuation character, fancy wasting storage space? > ... 'no?tique', 'no?se', 'noir?tre'] >>>> r = libfrancais.sortfr(li) >>>> r > ['noduleux', 'no?l', 'no?se', 'no?tique', 'n?ud', 'noir', > 'noir?tre'] What has sorting foreign words got to do with the internal representaion of the individual characters? > > (cf "Le Petit Robert") > > or > > The *letters* satisfying the requirements of the > "Imprimerie nationale". > > jmf > I've just rechecked my calendar and it's definitly not 1st April today. Poor old me I'm baffled as always. -- Cheers. Mark Lawrence. From arnodel at gmail.com Sun Sep 2 05:04:12 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 2 Sep 2012 10:04:12 +0100 Subject: running Lua in Python Message-ID: Hi all, I'm looking for a way to run Lua scripts in Python, and also send and receive data between the two. Something like lunatic-python [1] would be ideal. However, so far I haven't been able to build it on the machines it's supposed to run on (macs with OS X Lion) and it seems to be dormant. My requirements are stock OS X Python (which is 2.7) and Lua 5.2. I'm looking for either a way to make lunatic-python work or another tool that would do the job. Thanks in advance. -- Arnaud [1] http://labix.org/lunatic-python From ian.g.kelly at gmail.com Sun Sep 2 05:06:16 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 2 Sep 2012 03:06:16 -0600 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: On Sun, Sep 2, 2012 at 1:36 AM, wrote: > I still remember my thoughts when I read the PEP 393 > discussion: "this is not logical", "they do no understand > typography", "atomic character ???", ... That would indicate one of two possibilities. Either: 1) Everybody in the PEP 393 discussion except for you is clueless about how to implement a Unicode type; or 2) You are clueless about how to implement a Unicode type. Taking into account Occam's razor, and also that you seem to be unable or unwilling to offer a solid rationale for those thoughts, I have to say that I'm currently leaning toward the second possibility. > Real world exemples. > >>>> import libfrancais >>>> li = ['no?l', 'noir', 'n?ud', 'noduleux', \ > ... 'no?tique', 'no?se', 'noir?tre'] >>>> r = libfrancais.sortfr(li) >>>> r > ['noduleux', 'no?l', 'no?se', 'no?tique', 'n?ud', 'noir', > 'noir?tre'] libfrancais does not appear to be publicly available. It's not listed in PyPI, and googling for "python libfrancais" turns up nothing relevant. Rewriting the example to use locale.strcoll instead: >>> li = ['no?l', 'noir', 'n?ud', 'noduleux', 'no?tique', 'no?se', 'noir?tre'] >>> import locale >>> locale.setlocale(locale.LC_ALL, 'French_France') 'French_France.1252' >>> import functools >>> sorted(li, key=functools.cmp_to_key(locale.strcoll)) ['noduleux', 'no?l', 'no?se', 'no?tique', 'n?ud', 'noir', 'noir?tre'] # Python 3.2 >>> import timeit >>> timeit.repeat("sorted(li, key=functools.cmp_to_key(locale.strcoll))", "import functools; import locale; li = ['no?l', 'noir', 'n?ud', 'noduleux', 'no?tique', 'no?se', 'noir?tre']", number=10000) [0.5544277025009592, 0.5370117249557325, 0.5551836677925053] # Python 3.3 >>> import timeit >>> timeit.repeat("sorted(li, key=functools.cmp_to_key(locale.strcoll))", "import functools; import locale; li = ['no?l', 'noir', 'n?ud', 'noduleux', 'no?tique', 'no?se', 'noir?tre']", number=10000) [0.1421166788364303, 0.12389078130001963, 0.13184190553613462] As you can see, Python 3.3 is about 77% faster than Python 3.2 on this example. If this was intended to show that the Python 3.3 Unicode representation is a regression over the Python 3.2 implementation, then it's a complete failure as an example. From ian.g.kelly at gmail.com Sun Sep 2 05:24:58 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 2 Sep 2012 03:24:58 -0600 Subject: running Lua in Python In-Reply-To: References: Message-ID: On Sun, Sep 2, 2012 at 3:04 AM, Arnaud Delobelle wrote: > Hi all, > > I'm looking for a way to run Lua scripts in Python, and also send and > receive data between the two. Something like lunatic-python [1] would > be ideal. However, so far I haven't been able to build it on the > machines it's supposed to run on (macs with OS X Lion) and it seems to > be dormant. > > My requirements are stock OS X Python (which is 2.7) and Lua 5.2. I'm > looking for either a way to make lunatic-python work or another tool > that would do the job. The simple approach would be to run the Lua scripts with the subprocess module, using JSON (or something equally accessible) as an interchange format. If you need to embed the Lua interpreter in the Python process, and you can't get an existing third-party module to work, consider rolling your own C module for the purpose. My recollection of working with Lua is that it's a very easy language to embed. From typetoken at gmail.com Sun Sep 2 05:39:15 2012 From: typetoken at gmail.com (Token Type) Date: Sun, 2 Sep 2012 02:39:15 -0700 (PDT) Subject: =?UTF-8?Q?The_method_of_insert_doesn=27t_work_with_nltk_texts=3A?= =?UTF-8?Q?=E3=80=80AttributeError=3A_=27ConcatenatedCorpusView=27_object_has_no_at?= =?UTF-8?Q?tribute_=27insert=27?= Message-ID: <58dd6730-9c37-4b90-9dbc-2724300ff5f4@googlegroups.com> I wrote codes to add 'like' at the end of every 3 word in a nltk text as follows: >>> text = nltk.corpus.brown.words(categories = 'news') >>> def hedge(text): for i in range(3,len(text),4): new_text = text.insert(i, 'like') return new_text[:50] >>> hedge(text) Traceback (most recent call last): File "", line 1, in hedge(text) File "", line 3, in hedge new_text = text.insert(i, 'like') AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' Isn't text in the brown corpus above a list? why doesn't it has attribute 'insert'? Thanks much for your hints. From alec.taylor6 at gmail.com Sun Sep 2 05:39:25 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 2 Sep 2012 19:39:25 +1000 Subject: running Lua in Python In-Reply-To: References: Message-ID: Or you can use a module made for this task: http://labix.org/lunatic-python http://pypi.python.org/pypi/lupa On Sun, Sep 2, 2012 at 7:24 PM, Ian Kelly wrote: > > On Sun, Sep 2, 2012 at 3:04 AM, Arnaud Delobelle wrote: > > Hi all, > > > > I'm looking for a way to run Lua scripts in Python, and also send and > > receive data between the two. Something like lunatic-python [1] would > > be ideal. However, so far I haven't been able to build it on the > > machines it's supposed to run on (macs with OS X Lion) and it seems to > > be dormant. > > > > My requirements are stock OS X Python (which is 2.7) and Lua 5.2. I'm > > looking for either a way to make lunatic-python work or another tool > > that would do the job. > > The simple approach would be to run the Lua scripts with the > subprocess module, using JSON (or something equally accessible) as an > interchange format. > > If you need to embed the Lua interpreter in the Python process, and > you can't get an existing third-party module to work, consider rolling > your own C module for the purpose. My recollection of working with > Lua is that it's a very easy language to embed. > -- > http://mail.python.org/mailman/listinfo/python-list From rishabhdixit11 at gmail.com Sun Sep 2 05:44:15 2012 From: rishabhdixit11 at gmail.com (Rishabh Dixit) Date: Sun, 2 Sep 2012 15:14:15 +0530 Subject: Changing a Value in List of lists Message-ID: Hi all, I have a doubt regarding how the list work in following case- >>> ls=[[0]*5]*5 >>> ls[1][1]+=1 >>> ls [[0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 0, 0, 0]] Here, according to me only one value in ls should be incremented but it is increasing 1 value in all the lists of ls. Why?? -- Regards, Rishabh Dixit MSc.(Tech) Information Systems, BITS Pilani -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Sun Sep 2 05:45:50 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 02 Sep 2012 11:45:50 +0200 Subject: running Lua in Python In-Reply-To: References: Message-ID: Arnaud Delobelle, 02.09.2012 11:04: > I'm looking for a way to run Lua scripts in Python, and also send and > receive data between the two. Something like lunatic-python [1] would > be ideal. However, so far I haven't been able to build it on the > machines it's supposed to run on (macs with OS X Lion) and it seems to > be dormant. > > My requirements are stock OS X Python (which is 2.7) and Lua 5.2. I'm > looking for either a way to make lunatic-python work or another tool > that would do the job. Try Lupa: http://pypi.python.org/pypi/lupa Stefan From arnodel at gmail.com Sun Sep 2 05:49:31 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 2 Sep 2012 10:49:31 +0100 Subject: running Lua in Python In-Reply-To: References: Message-ID: On 2 September 2012 10:39, Alec Taylor wrote: > Or you can use a module made for this task: > > http://labix.org/lunatic-python As I said in my original message, I couldn't get this to work. > http://pypi.python.org/pypi/lupa I'll check this out, thanks. -- Arnaud From __peter__ at web.de Sun Sep 2 05:52:14 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 02 Sep 2012 11:52:14 +0200 Subject: Flexible string representation, unicode, typography, ... References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: Ian Kelly wrote: > Rewriting the example to use locale.strcoll instead: >>>> sorted(li, key=functools.cmp_to_key(locale.strcoll)) There is also locale.strxfrm() which you can use directly: sorted(li, key=locale.strxfrm) From rosuav at gmail.com Sun Sep 2 05:57:37 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Sep 2012 19:57:37 +1000 Subject: Changing a Value in List of lists In-Reply-To: References: Message-ID: On Sun, Sep 2, 2012 at 7:44 PM, Rishabh Dixit wrote: > > Hi all, > > I have a doubt regarding how the list work in following case- > >>>> ls=[[0]*5]*5 >>>> ls[1][1]+=1 >>>> ls > [[0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, > 0, 0, 0]] > > > Here, according to me only one value in ls should be incremented but it is > increasing 1 value in all the lists of ls. Why?? When you take the list [[0,0,0,0,0]] and multiply it by 5, you get a list with five references to the same inner list. That's where the confusion is coming from. Then when you change one of them, it changes all five displayed versions, since they're all still the same list. ChrisA From nospam at nospam.com Sun Sep 2 06:19:02 2012 From: nospam at nospam.com (Gilles) Date: Sun, 02 Sep 2012 12:19:02 +0200 Subject: [2.5.1] Read each line from txt file, replace, and save? Message-ID: Hello This is a newbie question. I need to read a text file into a variable, loop through each line and use a regex to substitute some items within the line, and save the whole variable into a new text file. This triggers an error when I save the modified variable that contains all the lines: ================== import re,sys f = open("C:\\input.txt", "r") textlines = f.readlines() f.close() for line in textlines: #edit each line line = "just a test" #rewrite data to new file log = open('output.sub','w') #ERROR: argument 1 must be string or read-only character buffer, not list log.write(textlines) log.close() ================== Should I use another way to read the file, edit each line, and save the data into a new file? Thank you. From breamoreboy at yahoo.co.uk Sun Sep 2 06:36:35 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Sep 2012 11:36:35 +0100 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: I've found the white paper which gives the technical basis for the claims made by jmf so thought I'd better share in order to explain his rationale. http://www.montypython.net/scripts/right-think.php -- Cheers. Mark Lawrence. From nospam at nospam.com Sun Sep 2 06:36:48 2012 From: nospam at nospam.com (Gilles) Date: Sun, 02 Sep 2012 12:36:48 +0200 Subject: [2.5.1] Read each line from txt file, replace, and save? References: Message-ID: On Sun, 02 Sep 2012 12:19:02 +0200, Gilles wrote: (snip) Found it: #rewrite lines to new file output = open('output.txt','w') for line in textlines: #edit each line line = "just a test" output.write("%s" % line) output.close() From rishabhdixit11 at gmail.com Sun Sep 2 07:00:28 2012 From: rishabhdixit11 at gmail.com (Rishabh Dixit) Date: Sun, 2 Sep 2012 16:30:28 +0530 Subject: Changing a Value in List of lists In-Reply-To: References: Message-ID: Hi Chris, Thanks for your reply. I tried this - >>> ls=[0 for i in range(5)] >>> mat=[ls for i in range(5)] >>> mat[1][2]+=1 >>> mat [[0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0]] I guess here also the same issue is there as ls refers to one list that is being repeated through mat and change in one causes change in others also. Is there any solution to change all elements independently. On Sun, Sep 2, 2012 at 3:14 PM, Rishabh Dixit wrote: > > Hi all, > > I have a doubt regarding how the list work in following case- > > >>> ls=[[0]*5]*5 > >>> ls[1][1]+=1 > >>> ls > [[0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, > 1, 0, 0, 0]] > > > Here, according to me only one value in ls should be incremented but it is > increasing 1 value in all the lists of ls. Why?? > -- > Regards, > Rishabh Dixit > MSc.(Tech) Information Systems, > BITS Pilani > > -- Regards, Rishabh Dixit MSc.(Tech) Information Systems, BITS Pilani -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Sun Sep 2 07:02:02 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Sep 2012 12:02:02 +0100 Subject: [2.5.1] Read each line from txt file, replace, and save? In-Reply-To: References: Message-ID: On 02/09/2012 11:36, Gilles wrote: > On Sun, 02 Sep 2012 12:19:02 +0200, Gilles wrote: > (snip) > > Found it: > > #rewrite lines to new file > output = open('output.txt','w') > > for line in textlines: > #edit each line > line = "just a test" > output.write("%s" % line) > > output.close() > IMHO better practice to use the with statement. See http://docs.python.org/reference/compound_stmts.html#the-with-statement -- Cheers. Mark Lawrence. From rishabhdixit11 at gmail.com Sun Sep 2 07:05:45 2012 From: rishabhdixit11 at gmail.com (Rishabh Dixit) Date: Sun, 2 Sep 2012 16:35:45 +0530 Subject: Changing a Value in List of lists In-Reply-To: References: Message-ID: Hi, I got it :). We should create a new list every time before adding to a list of list so that instead repeating the reference a new reference generated every time. >>> mat=[[0]*5 for i in range(5)] >>> mat[1][2]+=1 >>> mat [[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] This worked for me!! Thanx :) On Sun, Sep 2, 2012 at 4:30 PM, Rishabh Dixit wrote: > Hi Chris, > > Thanks for your reply. I tried this - > > >>> ls=[0 for i in range(5)] > >>> mat=[ls for i in range(5)] > >>> mat[1][2]+=1 > >>> mat > [[0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, > 0, 1, 0, 0]] > > I guess here also the same issue is there as ls refers to one list that is > being repeated through mat and change in one causes change in others also. > > Is there any solution to change all elements independently. > > > > On Sun, Sep 2, 2012 at 3:14 PM, Rishabh Dixit wrote: > >> >> Hi all, >> >> I have a doubt regarding how the list work in following case- >> >> >>> ls=[[0]*5]*5 >> >>> ls[1][1]+=1 >> >>> ls >> [[0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, >> 1, 0, 0, 0]] >> >> >> Here, according to me only one value in ls should be incremented but it >> is increasing 1 value in all the lists of ls. Why?? >> -- >> Regards, >> Rishabh Dixit >> MSc.(Tech) Information Systems, >> BITS Pilani >> >> > > > -- > Regards, > Rishabh Dixit > MSc.(Tech) Information Systems, > BITS Pilani > > -- Regards, Rishabh Dixit MSc.(Tech) Information Systems, BITS Pilani -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Sun Sep 2 07:10:29 2012 From: d at davea.name (Dave Angel) Date: Sun, 02 Sep 2012 07:10:29 -0400 Subject: =?UTF-8?B?UmU6IFRoZSBtZXRob2Qgb2YgaW5zZXJ0IGRvZXNuJ3Qgd29yayB3aXQ=?= =?UTF-8?B?aCBubHRrIHRleHRzOuOAgEF0dHJpYnV0ZUVycm9yOiAnQ29uY2F0ZW5hdGVkQ28=?= =?UTF-8?B?cnB1c1ZpZXcnIG9iamVjdCBoYXMgbm8gYXR0cmlidXRlICdpbnNlcnQn?= In-Reply-To: <58dd6730-9c37-4b90-9dbc-2724300ff5f4@googlegroups.com> References: <58dd6730-9c37-4b90-9dbc-2724300ff5f4@googlegroups.com> Message-ID: <50433EA5.9090302@davea.name> On 09/02/2012 05:39 AM, Token Type wrote: > I wrote codes to add 'like' at the end of every 3 word in a nltk text as follows: > >>>> text = nltk.corpus.brown.words(categories = 'news') >>>> def hedge(text): > for i in range(3,len(text),4): > new_text = text.insert(i, 'like') > return new_text[:50] > >>>> hedge(text) > Traceback (most recent call last): > File "", line 1, in > hedge(text) > File "", line 3, in hedge > new_text = text.insert(i, 'like') > AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' > > Isn't text in the brown corpus above a list? why doesn't it has attribute 'insert'? > I tried to find online documentation for nltk, and although I found the mention of a free online book, I didn't see it. So, some generic comments. The error message is telling you that the object 'text' is not a list, but a "ConcatenatedCorpusView". Perhaps you can look that up in your docs for nltk. But there's quite a bit you can do just with the interpreter. try print type(text) to see the type of text. try dir(text) to see what attributes it has try help(text) to see what docstrings might be built in. Incidentally, if you really think it's a list of words (or that it acts like a list), then 'text' might not be the best name for it. Any reason you didn't just call it words ? -- DaveA From mailinglists at xgm.de Sun Sep 2 07:12:34 2012 From: mailinglists at xgm.de (Florian Lindner) Date: Sun, 02 Sep 2012 13:12:34 +0200 Subject: Logging handler: No output Message-ID: <3165391.mTzesgFQhr@horus> Hello, I have a class method that executes a subprocess. There are two loggers in the class, self.logger for general logging and proclog for process output (stdout & stderr) logging which should go to stdout and a file: def start_process(self, command, no_shlex=False, raise_excpt=True, print_output = True, **kwargs): cmd = command if no_shlex else shlex.split(command) # Use an additional logger without formatting for process output. proclog = logging.getLogger(self.config.tag) proclog.propagate = False # Process output should not propage to the main logger logfile = self._logfilename() if logfile: proclog.addHandler(logging.FileHandler(logfile)) if print_output: proclog.addHandler(logging.StreamHandler(sys.stdout)) self.popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=0, **kwargs) while True: output = self.popen.stdout.readline().decode() if output == "" and self.popen.poll() != None: break proclog.info(output.rstrip("\n")) ret_code = self.popen.returncode self.logger.debug("%s returned with %i", command, ret_code) But neither the FileHandler nor the StreamHandler produce any actual output. The file is being created but stays empty. If I use a print output in the while loop it works, so output is catched and the applications stdout in working. But why the logger proclog catching nothing? Thanks, Florian From breamoreboy at yahoo.co.uk Sun Sep 2 07:17:35 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Sep 2012 12:17:35 +0100 Subject: Changing a Value in List of lists In-Reply-To: References: Message-ID: On 02/09/2012 12:05, Rishabh Dixit wrote: > Hi, > > I got it :). We should create a new list every time before adding to a list > of list so that instead repeating the reference a new reference generated > every time. > Please don't top post on this list as it often destroys the context, thanks. -- Cheers. Mark Lawrence. From no.email at nospam.invalid Sun Sep 2 07:30:40 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 02 Sep 2012 04:30:40 -0700 Subject: Logging handler: No output References: Message-ID: <7xzk58fyqn.fsf@ruckus.brouhaha.com> Florian Lindner writes: > The file is being created but stays empty. If I use a print output in the > while loop it works, so output is catched and the applications stdout in > working. But why the logger proclog catching nothing? I don't see you setting the log level anyplace in that sample, and you are logging at INFO and DEBUG levels. By default, only WARNING and above only actually produce output. If you want INFO and DEBUG to log, you have to request it. From storchaka at gmail.com Sun Sep 2 08:00:59 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sun, 02 Sep 2012 15:00:59 +0300 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: On 02.09.12 12:52, Peter Otten wrote: > Ian Kelly wrote: > >> Rewriting the example to use locale.strcoll instead: > >>>>> sorted(li, key=functools.cmp_to_key(locale.strcoll)) > > There is also locale.strxfrm() which you can use directly: > > sorted(li, key=locale.strxfrm) Hmm, and with locale.strxfrm Python 3.3 20% slower than 3.2. From breamoreboy at yahoo.co.uk Sun Sep 2 08:23:53 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Sep 2012 13:23:53 +0100 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: On 02/09/2012 13:00, Serhiy Storchaka wrote: > On 02.09.12 12:52, Peter Otten wrote: >> Ian Kelly wrote: >> >>> Rewriting the example to use locale.strcoll instead: >> >>>>>> sorted(li, key=functools.cmp_to_key(locale.strcoll)) >> >> There is also locale.strxfrm() which you can use directly: >> >> sorted(li, key=locale.strxfrm) > > Hmm, and with locale.strxfrm Python 3.3 20% slower than 3.2. > > That's it then I'm giving up with Python. In future I'll be writing everything in machine code to ensure that I get the fastest possible run times. -- Cheers. Mark Lawrence. From roy at panix.com Sun Sep 2 08:35:13 2012 From: roy at panix.com (Roy Smith) Date: Sun, 02 Sep 2012 08:35:13 -0400 Subject: Flexible string representation, unicode, typography, ... References: <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: In article , Mark Lawrence wrote: > On 02/09/2012 13:00, Serhiy Storchaka wrote: > > On 02.09.12 12:52, Peter Otten wrote: > >> Ian Kelly wrote: > >> > >>> Rewriting the example to use locale.strcoll instead: > >> > >>>>>> sorted(li, key=functools.cmp_to_key(locale.strcoll)) > >> > >> There is also locale.strxfrm() which you can use directly: > >> > >> sorted(li, key=locale.strxfrm) > > > > Hmm, and with locale.strxfrm Python 3.3 20% slower than 3.2. > > > > > > That's it then I'm giving up with Python. In future I'll be writing > everything in machine code to ensure that I get the fastest possible run > times. Feh. You software guys are always too willing to sacrifice performance for convenience. If you really want speed, grab yourself a handful of chips and a soldering iron. From typetoken at gmail.com Sun Sep 2 09:06:11 2012 From: typetoken at gmail.com (John H. Li) Date: Sun, 2 Sep 2012 21:06:11 +0800 Subject: Fwd: The method of insert doesn't work with nltk texts: AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' In-Reply-To: References: <58dd6730-9c37-4b90-9dbc-2724300ff5f4@googlegroups.com> <50433EA5.9090302@davea.name> Message-ID: First, thanks very much for your kind help. 1)Further more, I test the function of insert. It did work as follows: >>> text = ['The', 'Fulton', 'County', 'Grand'] >>> text.insert(3,'like') >>> text ['The', 'Fulton', 'County', 'like', 'Grand'] >>> 2) I tested the text from nltk. It is list actually. See the following: >>> text = nltk.corpus.brown.words(categories = 'news') >>> text[:10] ['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', 'Friday', 'an', 'investigation', 'of'] How come python tells me that it is not a list by prompting "AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'"? I am confused. Since we doubt text is not a list, I have to add one more line of code there as follows. Then it seems working. >>> text = nltk.corpus.brown.words(categories = 'news') >>> def hedge(text): text = list(text) for i in range(3,len(text),4): text.insert(i, 'like') return text[:50] >>> hedge(text) ['The', 'Fulton', 'County', 'like', 'Grand', 'Jury', 'said', 'like', 'Friday', 'an', 'investigation', 'like', 'of', "Atlanta's", 'recent', 'like', 'primary', 'election', 'produced', 'like', '``', 'no', 'evidence', 'like', "''", 'that', 'any', 'like', 'irregularities', 'took', 'place', 'like', '.', 'The', 'jury', 'like', 'further', 'said', 'in', 'like', 'term-end', 'presentments', 'that', 'like', 'the', 'City', 'Executive', 'like', 'Committee', ','] Isn't it odd? -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Sun Sep 2 09:46:36 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sun, 2 Sep 2012 06:46:36 -0700 (PDT) Subject: py2c - an open source Python to C/C++ is looking for developers In-Reply-To: References: <16816fd5-c6b4-49df-baf0-e0bfb0d999df@googlegroups.com> <1409e6f3-b265-4329-9618-c06f8098fef3@t1g2000pbl.googlegroups.com> <9cf4820c-25a2-45a7-af47-cb3e06d30707@googlegroups.com> Message-ID: On Sunday, 2 September 2012 12:53:35 UTC+5:30, Serhiy Storchaka wrote: > On 02.09.12 06:15, Ramchandra Apte wrote: > > > It converts to *pure* C/C++ *without* using Python or its API so that it can be the same speed as C/C++ > > > > How is it implemented long integers? py2c has been just started (long integer multiplacation might use the Python internal multiplication code) (it uses the karatsuba algorithm) From maniandram01 at gmail.com Sun Sep 2 09:46:36 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sun, 2 Sep 2012 06:46:36 -0700 (PDT) Subject: py2c - an open source Python to C/C++ is looking for developers In-Reply-To: References: <16816fd5-c6b4-49df-baf0-e0bfb0d999df@googlegroups.com> <1409e6f3-b265-4329-9618-c06f8098fef3@t1g2000pbl.googlegroups.com> <9cf4820c-25a2-45a7-af47-cb3e06d30707@googlegroups.com> Message-ID: On Sunday, 2 September 2012 12:53:35 UTC+5:30, Serhiy Storchaka wrote: > On 02.09.12 06:15, Ramchandra Apte wrote: > > > It converts to *pure* C/C++ *without* using Python or its API so that it can be the same speed as C/C++ > > > > How is it implemented long integers? py2c has been just started (long integer multiplacation might use the Python internal multiplication code) (it uses the karatsuba algorithm) From maniandram01 at gmail.com Sun Sep 2 09:48:59 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sun, 2 Sep 2012 06:48:59 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: <5c453ede-33dd-4b7f-aa53-9424224ec6c7@googlegroups.com> On Sunday, 2 September 2012 17:53:16 UTC+5:30, Mark Lawrence wrote: > On 02/09/2012 13:00, Serhiy Storchaka wrote: > > > On 02.09.12 12:52, Peter Otten wrote: > > >> Ian Kelly wrote: > > >> > > >>> Rewriting the example to use locale.strcoll instead: > > >> > > >>>>>> sorted(li, key=functools.cmp_to_key(locale.strcoll)) > > >> > > >> There is also locale.strxfrm() which you can use directly: > > >> > > >> sorted(li, key=locale.strxfrm) > > > > > > Hmm, and with locale.strxfrm Python 3.3 20% slower than 3.2. > > > > > > > > > > That's it then I'm giving up with Python. In future I'll be writing > > everything in machine code to ensure that I get the fastest possible run > > times. > > > > -- > > Cheers. > > > > Mark Lawrence. please make it *heavily optimized* machine code From maniandram01 at gmail.com Sun Sep 2 09:48:59 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sun, 2 Sep 2012 06:48:59 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: <5c453ede-33dd-4b7f-aa53-9424224ec6c7@googlegroups.com> On Sunday, 2 September 2012 17:53:16 UTC+5:30, Mark Lawrence wrote: > On 02/09/2012 13:00, Serhiy Storchaka wrote: > > > On 02.09.12 12:52, Peter Otten wrote: > > >> Ian Kelly wrote: > > >> > > >>> Rewriting the example to use locale.strcoll instead: > > >> > > >>>>>> sorted(li, key=functools.cmp_to_key(locale.strcoll)) > > >> > > >> There is also locale.strxfrm() which you can use directly: > > >> > > >> sorted(li, key=locale.strxfrm) > > > > > > Hmm, and with locale.strxfrm Python 3.3 20% slower than 3.2. > > > > > > > > > > That's it then I'm giving up with Python. In future I'll be writing > > everything in machine code to ensure that I get the fastest possible run > > times. > > > > -- > > Cheers. > > > > Mark Lawrence. please make it *heavily optimized* machine code From d at davea.name Sun Sep 2 09:51:15 2012 From: d at davea.name (Dave Angel) Date: Sun, 02 Sep 2012 09:51:15 -0400 Subject: Fwd: The method of insert doesn't work with nltk texts: AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' In-Reply-To: References: <58dd6730-9c37-4b90-9dbc-2724300ff5f4@googlegroups.com> <50433EA5.9090302@davea.name> Message-ID: <50436453.3030503@davea.name> On 09/02/2012 09:06 AM, John H. Li wrote: > First, thanks very much for your kind help. > > 1)Further more, I test the function of insert. It did work as follows: > >>>> text = ['The', 'Fulton', 'County', 'Grand'] >>>> text.insert(3,'like') >>>> text > ['The', 'Fulton', 'County', 'like', 'Grand'] > 2) I tested the text from nltk. It is list actually. See the following: >>>> text = nltk.corpus.brown.words(categories = 'news') >>>> text[:10] > ['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', 'Friday', 'an', > 'investigation', 'of'] > > How come python tells me that it is not a list by prompting "AttributeError: > 'ConcatenatedCorpusView' object has no attribute 'insert'"? I am confused. > > Since we doubt text is not a list, I have to add one more line of code > there as follows. Then it seems working. >>>> text = nltk.corpus.brown.words(categories = 'news') >>>> def hedge(text): > text = list(text) > for i in range(3,len(text),4): > text.insert(i, 'like') > return text[:50] > >>>> hedge(text) > ['The', 'Fulton', 'County', 'like', 'Grand', 'Jury', 'said', 'like', > 'Friday', 'an', 'investigation', 'like', 'of', "Atlanta's", 'recent', > 'like', 'primary', 'election', 'produced', 'like', '``', 'no', 'evidence', > 'like', "''", 'that', 'any', 'like', 'irregularities', 'took', 'place', > 'like', '.', 'The', 'jury', 'like', 'further', 'said', 'in', 'like', > 'term-end', 'presentments', 'that', 'like', 'the', 'City', 'Executive', > 'like', 'Committee', ','] > > Isn't it odd? > > Without reading the documentation, or at least the help(), I can't figure it to be odd. If a class wants to support slicing semantics, all it has to do is implement special methods like __getslice__ and __setslice__. If it doesn't document .insert(), then you shouldn't try to call it. Duck-typing. What did you get when you tried type(), dir() and help() ? Did they help. -- DaveA From __peter__ at web.de Sun Sep 2 10:12:02 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 02 Sep 2012 16:12:02 +0200 Subject: The method of insert doesn't work with nltk =?UTF-8?B?dGV4dHM644CAQXR0cmlidXRlRXJyb3I6?= 'ConcatenatedCorpusView' object has no attribute 'insert' References: <58dd6730-9c37-4b90-9dbc-2724300ff5f4@googlegroups.com> Message-ID: Token Type wrote: > I wrote codes to add 'like' at the end of every 3 word in a nltk text as follows: > > >>> text = nltk.corpus.brown.words(categories = 'news') > >>> def hedge(text): > for i in range(3,len(text),4): > new_text = text.insert(i, 'like') > return new_text[:50] > > >>> hedge(text) > > Traceback (most recent call last): > File "", line 1, in > hedge(text) > File "", line 3, in hedge > new_text = text.insert(i, 'like') > AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' > > Isn't text in the brown corpus above a list? why doesn't it has attribute 'insert'? > > Thanks much for your hints. The error message shows that text is not a list. It looks like a list, >>> text = nltk.corpus.brown.words(categories="news") >>> text ['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', ...] but it is actually a nltk.corpus.reader.util.ConcatenatedCorpusView: >>> type(text) The implementer of a class is free to decide what methods he wants to implement. You can get a first impression of the available ones with dir(): >>> dir(text) ['_MAX_REPR_SIZE', '__add__', '__class__', '__cmp__', '__contains__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__iter__', '__len__', '__module__', '__mul__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_offsets', '_open_piece', '_pieces', 'close', 'count', 'index', 'iterate_from'] As you can see insert() is not among these methods. However, __iter__() is a hint that you can convert the ConcatenatedCorpusView to a list, and that does provide an insert() method. Let's try: >>> text = list(text) >>> type(text) >>> text.insert(0, "yadda") >>> text[:5] ['yadda', 'The', 'Fulton', 'County', 'Grand'] Note that your hedge() function may still not work as you expect: >>> text = ["-"] * 20 >>> text ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'] >>> for i in range(0, len(text), 3): ... text.insert(i, "X") ... >>> text ['X', '-', '-', 'X', '-', '-', 'X', '-', '-', 'X', '-', '-', 'X', '-', '-', 'X', '-', '-', 'X', '-', '-', '-', '-', '-', '-', '-', '-'] That is because the list is growing with every insert() call. One workaround is to start inserting items at the end of the list: >>> text = ["-"] * 20 >>> for i in reversed(range(0, len(text), 3)): ... text.insert(i, "X") ... >>> text ['X', '-', '-', '-', 'X', '-', '-', '-', 'X', '-', '-', '-', 'X', '-', '-', '-', 'X', '-', '-', '-', 'X', '-', '-', '-', 'X', '-', '-'] From breamoreboy at yahoo.co.uk Sun Sep 2 10:46:00 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Sep 2012 15:46:00 +0100 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <5c453ede-33dd-4b7f-aa53-9424224ec6c7@googlegroups.com> References: <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> <5c453ede-33dd-4b7f-aa53-9424224ec6c7@googlegroups.com> Message-ID: On 02/09/2012 14:48, Ramchandra Apte wrote: > > please make it *heavily optimized* machine code > Goes without saying. First thing I'll concentrate on is removing superfluous newlines sent by crappy mail clients or similar. -- Cheers. Mark Lawrence. From _ at lvh.cc Sun Sep 2 12:36:27 2012 From: _ at lvh.cc (Laurens Van Houtven) Date: Sun, 2 Sep 2012 18:36:27 +0200 Subject: [Twisted-Python] Twisted 12.2.0 released In-Reply-To: References: Message-ID: Congratulations to the entire team, particularly Ashwini, and thank you for an awesome release manager job well done, Ashwini :) On Sat, Sep 1, 2012 at 3:47 PM, Ashwini Oruganti wrote: > On behalf of Twisted Matrix Laboratories, I am honored to announce the > release of Twisted 12.2. > > Highlights for this release include: > > * To be able to work on Python3 support, Python 2.5 is no longer > supported. > > * twisted.mail.imap4 now serves BODYSTRUCTURE responses which provide > more information and conform to the IMAP4 RFC more closely. > > * twisted.conch now supports commercial SSH implementations which don't > comply with the IETF standard. > > * twisted.internet.endpoints now provides several new endpoints, > including a > TCP client endpoint that resolves hostnames to IPv6 host addresses. > > * IReactorSocket.adoptStreamConnection, implemented by some reactors, > allows adding an existing established connection to the reactor. > > Starting with the release after 12.2, Twisted will begin requiring > zope.interface 3.6 (as part of Python 3 support). > > This is the last Twisted release supporting Python 2.6 on Windows. > > For more information, see the NEWS file here: > > http://twistedmatrix.com/Releases/Twisted/12.2/NEWS.txt > > > Download it now from: > > http://pypi.python.org/packages/source/T/Twisted/Twisted-12.2.0.tar.bz2 > or > > > http://pypi.python.org/packages/2.6/T/Twisted/Twisted-12.2.0.win32-py2.6.exe > or > > > http://pypi.python.org/packages/2.6/T/Twisted/Twisted-12.2.0.win32-py2.6.msi > or > > > http://pypi.python.org/packages/2.7/T/Twisted/Twisted-12.2.0.win32-py2.7.exe > or > > > http://pypi.python.org/packages/2.7/T/Twisted/Twisted-12.2.0.win32-py2.7.msi > > > Thanks to the supporters of Twisted and to the many contributors for this > release. > > > -- > Ashwini Oruganti > > _______________________________________________ > Twisted-Python mailing list > Twisted-Python at twistedmatrix.com > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python > > -- cheers lvh -------------- next part -------------- An HTML attachment was scrubbed... URL: From vinay_sajip at yahoo.co.uk Sun Sep 2 13:02:11 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 2 Sep 2012 17:02:11 +0000 (UTC) Subject: Logging handler: No output References: <3165391.mTzesgFQhr@horus> Message-ID: Florian Lindner xgm.de> writes: > But neither the FileHandler nor the StreamHandler produce any actual output. > The file is being created but stays empty. If I use a print output in the > while loop it works, so output is catched and the applications stdout in > working. But why the logger proclog catching nothing? > Paul Rubin's answer looks correct. In addition, you should note that every call to start_process will add a new handler to the logger (I can't tell if the logger could be the same on multiple calls, but it seems likely) and that may produce multiple messages. The rule of thumb is: most code should get loggers and log to them, but adding handlers, setting levels etc. should be only done in one place (typically invoked from a "if __name__ == '__main__'" clause. Regards, Vinay Sajip From gwhite at ti.com Sun Sep 2 13:23:53 2012 From: gwhite at ti.com (gwhite) Date: Sun, 2 Sep 2012 10:23:53 -0700 (PDT) Subject: newbie ``print`` question Message-ID: I can't figure out how to stop the "add a space at the beginning" behavior of the print function. >>> print 1,;print 2, 1 2 See the space in between the 1 and the 2 at the output print to the command console? The help for print is: "A space is written before each object is (converted and) written, unless the output system believes it is positioned at the beginning of a line." So it is apparently doing what it is supposed to do. Is there a way to stop this? Or is there a different function that will only print what you have in the formatted string? For example, in MATLAB I only had to do: >> fprintf('1');fprintf('2') 12 fprintf works the same way if printing to a file. It only puts in what you explicitly tell it to put in. From breamoreboy at yahoo.co.uk Sun Sep 2 13:41:23 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Sep 2012 18:41:23 +0100 Subject: newbie ``print`` question In-Reply-To: References: Message-ID: On 02/09/2012 18:23, gwhite wrote: > I can't figure out how to stop the "add a space at the beginning" > behavior of the print function. > >>>> print 1,;print 2, > 1 2 > > See the space in between the 1 and the 2 at the output print to the > command console? > > The help for print is: > > "A space is written before each object is (converted and) written, > unless the output system believes it is positioned at the beginning of > a line." > > So it is apparently doing what it is supposed to do. > > Is there a way to stop this? Or is there a different function that > will only print what you have in the formatted string? > > For example, in MATLAB I only had to do: > >>> fprintf('1');fprintf('2') > 12 > > fprintf works the same way if printing to a file. It only puts in > what you explicitly tell it to put in. > I'd settle for print 12, YMMV. -- Cheers. Mark Lawrence. From castironpi at gmail.com Sun Sep 2 13:43:20 2012 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 2 Sep 2012 10:43:20 -0700 (PDT) Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1567e8c7-a2bb-41f4-9be8-18e9f4d063cb@googlegroups.com> On Monday, August 27, 2012 2:17:45 PM UTC-5, Ian wrote: > On Thu, Aug 23, 2012 at 10:49 AM, Aaron Brady wrote: > > > The patch for the above is only 40-60 lines. However it introduces two new concepts. > > > > Is there a link to the patch? Please see below. It grew somewhat during development. > > The first is a "linked list". SNIP. > > The second is "uncounted references". The uncounted references are references to "set iterators" exclusively, exist only internally to "set" objects, and are invisible to the rest of the program. The reason for the exception is that iterators are unique in the Python Data Model; iterators consist of a single immutable reference, unlike both immutable types such as strings and numbers, as well as container types. Counted references could be used instead, but would be consistently wasted work for the garbage collector, though the benefit to programmers' peace of mind could be significant. > > > > > > Please share your opinion! Do you agree that the internal list resolves the inconsistency? Do you agree with the strategy? Do you agree that uncounted references are justified to introduce, or are counted references preferable? > > > > This feature is a hard sell as it is; I think that adding uncounted > > references into the mix is only going to make that worse. May I > > suggest an alternate approach? Internally tag each set or dict with a > > "version", which is just a C int. Every time the hash table is > > modified, increment the version. When an iterator is created, store > > the current version on the iterator. When the iterator is advanced, > > check that the iterator version matches the dict/set version. If > > they're not equal, raise an error. > > > > This should add less overhead than the linked list without any > > concerns about reference counting. It does introduce a small bug in > > that an error condition could be "missed", if the version is > > incremented a multiple of 2**32 or 2**64 times between iterations -- > > but how often is that really likely to occur? Bearing in mind that > > this error is meant for debugging and not production error handling, > > you could even make the version a single byte and I'd still be fine > > with that. > > > > Cheers, > > Ian Hi Ian, We could use a Python long object for the version index to prevent overflow. Combined with P. Rubin's idea to count the number of open iterators, most use cases still wouldn't exceed a single word comparison; we could reset the counter when there weren't any. Using the linked list collection, modification operations are expensive in rare cases. Using the version index, iteration is expensive in rare cases. I was more interested in the linked list for conceptual reasons, so I developed it further. Changelog, diff file, test suite, and links are below. The devs should be aware that a competing patch might be developed. I would be pleased to hear what everybody thinks of it! Linked list with uncounted references implementation for Win32. Added: - 'set_clear_ex' and 'set_clear_internal_ex' methods, differ in invalidation and conditional invalidation behavior and return type.. The 'set.clear()' method and 'tp_clear' type field both called the same method. - 'set_invalidate_iter_linked' method. Iterate over the iterators of a set, mark them invalid, and clear the list. - 'setiter_unlink_internal' method. Remove the iterator from the set's linked list of iterators. - 'IterationError', global. - New fields: -- PySetObject: setiterobject *iter_linked. Pointer to the first element of the linked list of the iterators of the set. -- setiterobject: setiterobject *linked_pred, *linked_succ. Predecessor and successor nodes in the linked list of iterators of the same set. -- setiterobject: char ob_valid. Validation status of the iterator. - Result is compared with original in 'set_intersection_update' and '_multi' to determine whether to invalidate the list of iterators. Asymptotic running time is unchanged. - Pending: add 'tp_clear' field to 'PySetIter_Type'? - Test script included, 'large numbers' test pending. 6 files changed: { setobject.h, setobject.c, exceptions.c, pyerrors.h, python3.def, python33stub.def }. Test script 'set_iterator_test.py' new. Linked list interface and pseudocode 'patch_pseudocode.txt'. Zip file: http://home.comcast.net/~castironpi-misc/clpy-0062-set_iterator_patch.zip Diff file of 3.3.0b2: http://home.comcast.net/~castironpi-misc/clpy-0062-set_iterator_diff.txt From castironpi at gmail.com Sun Sep 2 13:43:20 2012 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 2 Sep 2012 10:43:20 -0700 (PDT) Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1567e8c7-a2bb-41f4-9be8-18e9f4d063cb@googlegroups.com> On Monday, August 27, 2012 2:17:45 PM UTC-5, Ian wrote: > On Thu, Aug 23, 2012 at 10:49 AM, Aaron Brady wrote: > > > The patch for the above is only 40-60 lines. However it introduces two new concepts. > > > > Is there a link to the patch? Please see below. It grew somewhat during development. > > The first is a "linked list". SNIP. > > The second is "uncounted references". The uncounted references are references to "set iterators" exclusively, exist only internally to "set" objects, and are invisible to the rest of the program. The reason for the exception is that iterators are unique in the Python Data Model; iterators consist of a single immutable reference, unlike both immutable types such as strings and numbers, as well as container types. Counted references could be used instead, but would be consistently wasted work for the garbage collector, though the benefit to programmers' peace of mind could be significant. > > > > > > Please share your opinion! Do you agree that the internal list resolves the inconsistency? Do you agree with the strategy? Do you agree that uncounted references are justified to introduce, or are counted references preferable? > > > > This feature is a hard sell as it is; I think that adding uncounted > > references into the mix is only going to make that worse. May I > > suggest an alternate approach? Internally tag each set or dict with a > > "version", which is just a C int. Every time the hash table is > > modified, increment the version. When an iterator is created, store > > the current version on the iterator. When the iterator is advanced, > > check that the iterator version matches the dict/set version. If > > they're not equal, raise an error. > > > > This should add less overhead than the linked list without any > > concerns about reference counting. It does introduce a small bug in > > that an error condition could be "missed", if the version is > > incremented a multiple of 2**32 or 2**64 times between iterations -- > > but how often is that really likely to occur? Bearing in mind that > > this error is meant for debugging and not production error handling, > > you could even make the version a single byte and I'd still be fine > > with that. > > > > Cheers, > > Ian Hi Ian, We could use a Python long object for the version index to prevent overflow. Combined with P. Rubin's idea to count the number of open iterators, most use cases still wouldn't exceed a single word comparison; we could reset the counter when there weren't any. Using the linked list collection, modification operations are expensive in rare cases. Using the version index, iteration is expensive in rare cases. I was more interested in the linked list for conceptual reasons, so I developed it further. Changelog, diff file, test suite, and links are below. The devs should be aware that a competing patch might be developed. I would be pleased to hear what everybody thinks of it! Linked list with uncounted references implementation for Win32. Added: - 'set_clear_ex' and 'set_clear_internal_ex' methods, differ in invalidation and conditional invalidation behavior and return type.. The 'set.clear()' method and 'tp_clear' type field both called the same method. - 'set_invalidate_iter_linked' method. Iterate over the iterators of a set, mark them invalid, and clear the list. - 'setiter_unlink_internal' method. Remove the iterator from the set's linked list of iterators. - 'IterationError', global. - New fields: -- PySetObject: setiterobject *iter_linked. Pointer to the first element of the linked list of the iterators of the set. -- setiterobject: setiterobject *linked_pred, *linked_succ. Predecessor and successor nodes in the linked list of iterators of the same set. -- setiterobject: char ob_valid. Validation status of the iterator. - Result is compared with original in 'set_intersection_update' and '_multi' to determine whether to invalidate the list of iterators. Asymptotic running time is unchanged. - Pending: add 'tp_clear' field to 'PySetIter_Type'? - Test script included, 'large numbers' test pending. 6 files changed: { setobject.h, setobject.c, exceptions.c, pyerrors.h, python3.def, python33stub.def }. Test script 'set_iterator_test.py' new. Linked list interface and pseudocode 'patch_pseudocode.txt'. Zip file: http://home.comcast.net/~castironpi-misc/clpy-0062-set_iterator_patch.zip Diff file of 3.3.0b2: http://home.comcast.net/~castironpi-misc/clpy-0062-set_iterator_diff.txt From joel.goldstick at gmail.com Sun Sep 2 13:44:58 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 2 Sep 2012 13:44:58 -0400 Subject: newbie ``print`` question In-Reply-To: References: Message-ID: On Sun, Sep 2, 2012 at 1:23 PM, gwhite wrote: > I can't figure out how to stop the "add a space at the beginning" > behavior of the print function. > >>>> print 1,;print 2, > 1 2 > > See the space in between the 1 and the 2 at the output print to the > command console? > > The help for print is: > > "A space is written before each object is (converted and) written, > unless the output system believes it is positioned at the beginning of > a line." > > So it is apparently doing what it is supposed to do. > > Is there a way to stop this? Or is there a different function that > will only print what you have in the formatted string? You can do it with string formatting. My example shows 'old style' string formatting syntax. There is a newer style. You can learn about both from the online python docs. >>> print "%d%d" % (1,2) 12 >>> -- Joel Goldstick From foobar at invalid.invalid Sun Sep 2 13:49:10 2012 From: foobar at invalid.invalid (mblume) Date: Sun, 2 Sep 2012 17:49:10 +0000 (UTC) Subject: newbie ``print`` question References: Message-ID: Am Sun, 02 Sep 2012 10:23:53 -0700 schrieb gwhite: > I can't figure out how to stop the "add a space at the beginning" > behavior of the print function. > >>>> print 1,;print 2, > 1 2 > > See the space in between the 1 and the 2 at the output print to the > command console? > > The help for print is: > > "A space is written before each object is (converted and) written, > unless the output system believes it is positioned at the beginning of a > line." > > So it is apparently doing what it is supposed to do. > > Is there a way to stop this? Or is there a different function that will > only print what you have in the formatted string? > > For example, in MATLAB I only had to do: > >>> fprintf('1');fprintf('2') > 12 > > fprintf works the same way if printing to a file. It only puts in > what you explicitly tell it to put in. import sys sys.stdout.write("1"); sys.stdout.write("2") HTH Martin From clp2 at rebertia.com Sun Sep 2 13:55:40 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 2 Sep 2012 10:55:40 -0700 Subject: newbie ``print`` question In-Reply-To: References: Message-ID: On Sun, Sep 2, 2012 at 10:23 AM, gwhite wrote: > I can't figure out how to stop the "add a space at the beginning" > behavior of the print function. > >>>> print 1,;print 2, > 1 2 > > See the space in between the 1 and the 2 at the output print to the > command console? > > The help for print is: > > "A space is written before each object is (converted and) written, > unless the output system believes it is positioned at the beginning of > a line." > > So it is apparently doing what it is supposed to do. > > Is there a way to stop this? If you were to use Python 3.x, yes. Otherwise, no. > Or is there a different function that > will only print what you have in the formatted string? Use the .write() method of the sys.stdout file object. http://docs.python.org/library/sys.html#sys.stdout Alternatively, you can stick with `print` and rework your code so that it outputs an entire line at a time (thus, there'd only be 1 argument passed to `print`, so its "spaces between arguments" feature wouldn't come into play). Cheers, Chris From tjreedy at udel.edu Sun Sep 2 14:04:29 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 02 Sep 2012 14:04:29 -0400 Subject: [2.5.1] Read each line from txt file, replace, and save? In-Reply-To: References: Message-ID: On 9/2/2012 6:36 AM, Gilles wrote: > On Sun, 02 Sep 2012 12:19:02 +0200, Gilles wrote: > (snip) > > Found it: > > #rewrite lines to new file > output = open('output.txt','w') > > for line in textlines: > #edit each line > line = "just a test" > output.write("%s" % line) > > output.close() If you process each line separately, there is no reason to read them all at once. Use the file as an iterator directly. Since line is already a string, there is no reason to copy it into a new string. Combining these two changes with Mark's suggestion to use with and we have the following simple code: with open('input.txt', 'r') as inp, open('output.txt', 'w') as out: for line in inp: out.write(process(line)) where for your example, process(line) == 'just a test\n' (you need explicit line ending for .write()) -- Terry Jan Reedy From tjreedy at udel.edu Sun Sep 2 14:07:47 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 02 Sep 2012 14:07:47 -0400 Subject: Changing a Value in List of lists In-Reply-To: References: Message-ID: On 9/2/2012 7:17 AM, Mark Lawrence wrote: > On 02/09/2012 12:05, Rishabh Dixit wrote: >> Hi, >> >> I got it :). We should create a new list every time before adding to a >> list >> of list so that instead repeating the reference a new reference generated >> every time. >> > > Please don't top post on this list as it often destroys the context, > thanks. In this particular case, OP could and should have trimmed off everything other than the top post, as it stands alone. Then it would not have been a top post ;-). -- Terry Jan Reedy From tjreedy at udel.edu Sun Sep 2 14:33:08 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 02 Sep 2012 14:33:08 -0400 Subject: newbie ``print`` question In-Reply-To: References: Message-ID: On 9/2/2012 1:23 PM, gwhite wrote: > I can't figure out how to stop the "add a space at the beginning" > behavior of the print function. > >>>> print 1,;print 2, > 1 2 You have discovered why print is a function in 3.x. >>> print(1, 2, sep='') 12 >>> print(1, end=''); print(2, end='') 12 In 2.6 or 2.7, you can add from __future__ import print_function but I recommend using 3.2 or 3.3 unless you have a reason to use older Python. -- Terry Jan Reedy From arnodel at gmail.com Sun Sep 2 14:34:58 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 2 Sep 2012 19:34:58 +0100 Subject: running Lua in Python In-Reply-To: References: Message-ID: On 2 September 2012 10:49, Arnaud Delobelle wrote: > On 2 September 2012 10:39, Alec Taylor wrote: >> http://pypi.python.org/pypi/lupa > > I'll check this out, thanks. Mmh it seems to be lua 5.1 and more importantly it seems to require a custom build of Python, which I don't want. So it seems the simplest solution is to run Lua in a child process... -- Arnaud From stefan_ml at behnel.de Sun Sep 2 14:42:28 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 02 Sep 2012 20:42:28 +0200 Subject: running Lua in Python In-Reply-To: References: Message-ID: Arnaud Delobelle, 02.09.2012 20:34: > On 2 September 2012 10:49, Arnaud Delobelle wrote: >> On 2 September 2012 10:39, Alec Taylor wrote: >>> http://pypi.python.org/pypi/lupa >> >> I'll check this out, thanks. > > Mmh it seems to be lua 5.1 and more importantly it seems to require a > custom build of Python, which I don't want. I have no idea why you say that, for neither of the two. Stefan From gwhite at ti.com Sun Sep 2 14:51:13 2012 From: gwhite at ti.com (gwhite) Date: Sun, 2 Sep 2012 11:51:13 -0700 (PDT) Subject: newbie ``print`` question References: Message-ID: <4951e202-da4d-4a02-a1c7-b1322fc3b268@kr6g2000pbb.googlegroups.com> On Sep 2, 10:49?am, mblume wrote: > Am Sun, 02 Sep 2012 10:23:53 -0700 schrieb gwhite: > > > > > > > > > > > I can't figure out how to stop the "add a space at the beginning" > > behavior of the print function. > > >>>> print 1,;print 2, > > 1 2 > > > See the space in between the 1 and the 2 at the output print to the > > command console? > > > The help for print is: > > > "A space is written before each object is (converted and) written, > > unless the output system believes it is positioned at the beginning of a > > line." > > > So it is apparently doing what it is supposed to do. > > > Is there a way to stop this? ?Or is there a different function that will > > only print what you have in the formatted string? > > > For example, in MATLAB I only had to do: > > >>> fprintf('1');fprintf('2') > > 12 > > > ?fprintf works the same way if printing to a file. ?It only puts in > > what you explicitly tell it to put in. > > import sys > > sys.stdout.write("1"); sys.stdout.write("2") > > HTH > Martin Thanks. From gwhite at ti.com Sun Sep 2 14:51:20 2012 From: gwhite at ti.com (gwhite) Date: Sun, 2 Sep 2012 11:51:20 -0700 (PDT) Subject: newbie ``print`` question References: Message-ID: <91179238-6050-422b-8a7d-ed0a0cebc3cd@qa3g2000pbc.googlegroups.com> On Sep 2, 10:55?am, Chris Rebert wrote: > On Sun, Sep 2, 2012 at 10:23 AM, gwhite wrote: > > I can't figure out how to stop the "add a space at the beginning" > > behavior of the print function. > > >>>> print 1,;print 2, > > 1 2 > > > See the space in between the 1 and the 2 at the output print to the > > command console? > > > The help for print is: > > > "A space is written before each object is (converted and) written, > > unless the output system believes it is positioned at the beginning of > > a line." > > > So it is apparently doing what it is supposed to do. > > > Is there a way to stop this? > > If you were to use Python 3.x, yes. Otherwise, no. > > > Or is there a different function that > > will only print what you have in the formatted string? > > Use the .write() method of the sys.stdout file object.http://docs.python.org/library/sys.html#sys.stdout > > Alternatively, you can stick with `print` and rework your code so that > it outputs an entire line at a time (thus, there'd only be 1 argument > passed to `print`, so its "spaces between arguments" feature wouldn't > come into play). > > Cheers, > Chris Thanks. From wxjmfauth at gmail.com Sun Sep 2 14:58:08 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 2 Sep 2012 11:58:08 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: Le dimanche 2 septembre 2012 11:07:35 UTC+2, Ian a ?crit?: > On Sun, Sep 2, 2012 at 1:36 AM, wrote: > > > I still remember my thoughts when I read the PEP 393 > > > discussion: "this is not logical", "they do no understand > > > typography", "atomic character ???", ... > > > > That would indicate one of two possibilities. Either: > > > > 1) Everybody in the PEP 393 discussion except for you is clueless > > about how to implement a Unicode type; or > > > > 2) You are clueless about how to implement a Unicode type. > > > > Taking into account Occam's razor, and also that you seem to be unable > > or unwilling to offer a solid rationale for those thoughts, I have to > > say that I'm currently leaning toward the second possibility. > > > > > > > Real world exemples. > > > > > >>>> import libfrancais > > >>>> li = ['no?l', 'noir', 'n?ud', 'noduleux', \ > > > ... 'no?tique', 'no?se', 'noir?tre'] > > >>>> r = libfrancais.sortfr(li) > > >>>> r > > > ['noduleux', 'no?l', 'no?se', 'no?tique', 'n?ud', 'noir', > > > 'noir?tre'] > > > > libfrancais does not appear to be publicly available. It's not listed > > in PyPI, and googling for "python libfrancais" turns up nothing > > relevant. > > > > Rewriting the example to use locale.strcoll instead: > > > > >>> li = ['no?l', 'noir', 'n?ud', 'noduleux', 'no?tique', 'no?se', 'noir?tre'] > > >>> import locale > > >>> locale.setlocale(locale.LC_ALL, 'French_France') > > 'French_France.1252' > > >>> import functools > > >>> sorted(li, key=functools.cmp_to_key(locale.strcoll)) > > ['noduleux', 'no?l', 'no?se', 'no?tique', 'n?ud', 'noir', 'noir?tre'] > > > > # Python 3.2 > > >>> import timeit > > >>> timeit.repeat("sorted(li, key=functools.cmp_to_key(locale.strcoll))", "import functools; import locale; li = ['no?l', 'noir', 'n?ud', 'noduleux', 'no?tique', 'no?se', 'noir?tre']", number=10000) > > [0.5544277025009592, 0.5370117249557325, 0.5551836677925053] > > > > # Python 3.3 > > >>> import timeit > > >>> timeit.repeat("sorted(li, key=functools.cmp_to_key(locale.strcoll))", "import functools; import locale; li = ['no?l', 'noir', 'n?ud', 'noduleux', 'no?tique', 'no?se', 'noir?tre']", number=10000) > > [0.1421166788364303, 0.12389078130001963, 0.13184190553613462] > > > As you can see, Python 3.3 is about 77% faster than Python 3.2 on this > > example. If this was intended to show that the Python 3.3 Unicode > > representation is a regression over the Python 3.2 implementation, > > then it's a complete failure as an example. - Unfortunately, I got opposite and even much worst results on my win box, considering - libfrancais is one of my module and it does a little bit more than the std sorting tools. My rationale: very simple. 1) I never heard about something better than sticking with one of the Unicode coding scheme. (genreral theory) 2) I am not at all convinced by the "new" Py 3.3 algorithm. I'm not the only one guy, who noticed problems. Arguing, "it is fast enough", is not a correct answer. jmf From wxjmfauth at gmail.com Sun Sep 2 14:58:08 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 2 Sep 2012 11:58:08 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: Le dimanche 2 septembre 2012 11:07:35 UTC+2, Ian a ?crit?: > On Sun, Sep 2, 2012 at 1:36 AM, wrote: > > > I still remember my thoughts when I read the PEP 393 > > > discussion: "this is not logical", "they do no understand > > > typography", "atomic character ???", ... > > > > That would indicate one of two possibilities. Either: > > > > 1) Everybody in the PEP 393 discussion except for you is clueless > > about how to implement a Unicode type; or > > > > 2) You are clueless about how to implement a Unicode type. > > > > Taking into account Occam's razor, and also that you seem to be unable > > or unwilling to offer a solid rationale for those thoughts, I have to > > say that I'm currently leaning toward the second possibility. > > > > > > > Real world exemples. > > > > > >>>> import libfrancais > > >>>> li = ['no?l', 'noir', 'n?ud', 'noduleux', \ > > > ... 'no?tique', 'no?se', 'noir?tre'] > > >>>> r = libfrancais.sortfr(li) > > >>>> r > > > ['noduleux', 'no?l', 'no?se', 'no?tique', 'n?ud', 'noir', > > > 'noir?tre'] > > > > libfrancais does not appear to be publicly available. It's not listed > > in PyPI, and googling for "python libfrancais" turns up nothing > > relevant. > > > > Rewriting the example to use locale.strcoll instead: > > > > >>> li = ['no?l', 'noir', 'n?ud', 'noduleux', 'no?tique', 'no?se', 'noir?tre'] > > >>> import locale > > >>> locale.setlocale(locale.LC_ALL, 'French_France') > > 'French_France.1252' > > >>> import functools > > >>> sorted(li, key=functools.cmp_to_key(locale.strcoll)) > > ['noduleux', 'no?l', 'no?se', 'no?tique', 'n?ud', 'noir', 'noir?tre'] > > > > # Python 3.2 > > >>> import timeit > > >>> timeit.repeat("sorted(li, key=functools.cmp_to_key(locale.strcoll))", "import functools; import locale; li = ['no?l', 'noir', 'n?ud', 'noduleux', 'no?tique', 'no?se', 'noir?tre']", number=10000) > > [0.5544277025009592, 0.5370117249557325, 0.5551836677925053] > > > > # Python 3.3 > > >>> import timeit > > >>> timeit.repeat("sorted(li, key=functools.cmp_to_key(locale.strcoll))", "import functools; import locale; li = ['no?l', 'noir', 'n?ud', 'noduleux', 'no?tique', 'no?se', 'noir?tre']", number=10000) > > [0.1421166788364303, 0.12389078130001963, 0.13184190553613462] > > > As you can see, Python 3.3 is about 77% faster than Python 3.2 on this > > example. If this was intended to show that the Python 3.3 Unicode > > representation is a regression over the Python 3.2 implementation, > > then it's a complete failure as an example. - Unfortunately, I got opposite and even much worst results on my win box, considering - libfrancais is one of my module and it does a little bit more than the std sorting tools. My rationale: very simple. 1) I never heard about something better than sticking with one of the Unicode coding scheme. (genreral theory) 2) I am not at all convinced by the "new" Py 3.3 algorithm. I'm not the only one guy, who noticed problems. Arguing, "it is fast enough", is not a correct answer. jmf From arnodel at gmail.com Sun Sep 2 15:17:04 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 2 Sep 2012 20:17:04 +0100 Subject: running Lua in Python In-Reply-To: References: Message-ID: On 2 September 2012 19:42, Stefan Behnel wrote: > Arnaud Delobelle, 02.09.2012 20:34: >> On 2 September 2012 10:49, Arnaud Delobelle wrote: >>> On 2 September 2012 10:39, Alec Taylor wrote: >>>> http://pypi.python.org/pypi/lupa >>> >>> I'll check this out, thanks. >> >> Mmh it seems to be lua 5.1 and more importantly it seems to require a >> custom build of Python, which I don't want. > > I have no idea why you say that, for neither of the two. * For the custom build of Python on OS X, this blog post: http://t-p-j.blogspot.co.uk/2010/11/lupa-on-os-x-with-macports-python-26.html which is actually linked to in lupa's own INSTALL.rst file * For Lua 5.1, the official LuaJIT page: http://luajit.org/luajit.html where I quote: """ LuaJIT implements the full set of language features defined by Lua 5.1. """ Of course I'd be glad to be proved wrong on both counts. -- Arnaud From gwhite at ti.com Sun Sep 2 15:18:00 2012 From: gwhite at ti.com (gwhite) Date: Sun, 2 Sep 2012 12:18:00 -0700 (PDT) Subject: newbie ``print`` question References: Message-ID: <7e3de84a-6704-4a16-a887-04fb22b7f159@v9g2000pbu.googlegroups.com> On Sep 2, 11:33?am, Terry Reedy wrote: > On 9/2/2012 1:23 PM, gwhite wrote: > > > I can't figure out how to stop the "add a space at the beginning" > > behavior of the print function. > > >>>> print 1,;print 2, > > 1 2 > > You have discovered why print is a function in 3.x. > ?>>> print(1, 2, sep='') > 12 > ?>>> print(1, end=''); print(2, end='') > 12 > > In 2.6 or 2.7, you can add > ? ?from __future__ import print_function > but I recommend using 3.2 or 3.3 unless you have a reason to use older > Python. > > -- > Terry Jan Reedy Thanks. I would use 3.2 or 3.3, but I am actually using pythonxy, which hasn't quite gotten there yet, as the bundle of packages has to all play nice together. Or so I am guessing. I have been considering the __future__ technique. From me at joshmk.com Sun Sep 2 15:24:25 2012 From: me at joshmk.com (me) Date: 02 Sep 2012 19:24:25 GMT Subject: how to interact with Windows cmd? Message-ID: <5043b268$0$44362$c3e8da3$f017e9df@news.astraweb.com> Not sure but have you tried using functions from the os library? For example you could use execl() to execute your commands and pipe the output somewhere-stdin in your case. From gwhite at ti.com Sun Sep 2 15:26:44 2012 From: gwhite at ti.com (gwhite) Date: Sun, 2 Sep 2012 12:26:44 -0700 (PDT) Subject: newbie ``print`` question References: Message-ID: On Sep 2, 10:55?am, Chris Rebert wrote: > On Sun, Sep 2, 2012 at 10:23 AM, gwhite wrote: > > I can't figure out how to stop the "add a space at the beginning" > > behavior of the print function. > > >>>> print 1,;print 2, > > 1 2 > > > See the space in between the 1 and the 2 at the output print to the > > command console? > > > The help for print is: > > > "A space is written before each object is (converted and) written, > > unless the output system believes it is positioned at the beginning of > > a line." > > > So it is apparently doing what it is supposed to do. > > > Is there a way to stop this? > > If you were to use Python 3.x, yes. Otherwise, no. > > > Or is there a different function that > > will only print what you have in the formatted string? > > Use the .write() method of the sys.stdout file object.http://docs.python.org/library/sys.html#sys.stdout > > Alternatively, you can stick with `print` and rework your code so that > it outputs an entire line at a time (thus, there'd only be 1 argument > passed to `print`, so its "spaces between arguments" feature wouldn't > come into play). On the "rework" thing, yes, I suppose I could construct the line as a single string prior to print. There would be things like `for` loops and conditionals to do so. That isn't so unusual. I was actually doing some simple tests of other things -- you know, newbie stuff to make sure I understood what the various ops were doing. I wasn't even thinking about `print` Then I got sidetracked with this item, which I thought was very odd, since it is "deciding for you" to stuff a space in. From stefan_ml at behnel.de Sun Sep 2 15:26:54 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 02 Sep 2012 21:26:54 +0200 Subject: running Lua in Python In-Reply-To: References: Message-ID: Arnaud Delobelle, 02.09.2012 21:17: > On 2 September 2012 19:42, Stefan Behnel wrote: >> Arnaud Delobelle, 02.09.2012 20:34: >>> On 2 September 2012 10:49, Arnaud Delobelle wrote: >>>> On 2 September 2012 10:39, Alec Taylor wrote: >>>>> http://pypi.python.org/pypi/lupa >>>> >>>> I'll check this out, thanks. >>> >>> Mmh it seems to be lua 5.1 and more importantly it seems to require a >>> custom build of Python, which I don't want. >> >> I have no idea why you say that, for neither of the two. > > * For the custom build of Python on OS X, this blog post: > > http://t-p-j.blogspot.co.uk/2010/11/lupa-on-os-x-with-macports-python-26.html > > which is actually linked to in lupa's own INSTALL.rst file Ah, ok, but that's a) a rather old blog post and it b) refers to LuaJIT, not plain Lua. Just because LuaJIT requires special build flags doesn't mean that Lupa or Lua do. > * For Lua 5.1, the official LuaJIT page: > > http://luajit.org/luajit.html > > where I quote: > > """ > LuaJIT implements the full set of language features defined by Lua 5.1. > """ > > Of course I'd be glad to be proved wrong on both counts. I was told that it works with Lua 5.1 and didn't try it with Lua 5.2 myself. But I think you should, if that's what you want to use. Stefan From gwhite at ti.com Sun Sep 2 15:34:48 2012 From: gwhite at ti.com (gwhite) Date: Sun, 2 Sep 2012 12:34:48 -0700 (PDT) Subject: newbie ``print`` question References: Message-ID: <23e8e5c4-fb47-4753-b936-e1d546702387@pz10g2000pbb.googlegroups.com> On Sep 2, 12:26?pm, gwhite wrote: > On Sep 2, 10:55?am, Chris Rebert wrote: > > > > > > > > > > > On Sun, Sep 2, 2012 at 10:23 AM, gwhite wrote: > > > I can't figure out how to stop the "add a space at the beginning" > > > behavior of the print function. > > > >>>> print 1,;print 2, > > > 1 2 > > > > See the space in between the 1 and the 2 at the output print to the > > > command console? > > > > The help for print is: > > > > "A space is written before each object is (converted and) written, > > > unless the output system believes it is positioned at the beginning of > > > a line." > > > > So it is apparently doing what it is supposed to do. > > > > Is there a way to stop this? > > > If you were to use Python 3.x, yes. Otherwise, no. > > > > Or is there a different function that > > > will only print what you have in the formatted string? > > > Use the .write() method of the sys.stdout file object.http://docs.python.org/library/sys.html#sys.stdout > > > Alternatively, you can stick with `print` and rework your code so that > > it outputs an entire line at a time (thus, there'd only be 1 argument > > passed to `print`, so its "spaces between arguments" feature wouldn't > > come into play). > > On the "rework" thing, yes, I suppose I could construct the line as a > single string prior to print. ? ?There would be things like `for` > loops and conditionals to do so. ?That isn't so unusual. > > I was actually doing some simple tests of other things -- you know, > newbie stuff to make sure I understood what the various ops were > doing. ?I wasn't even thinking about `print` Then I got sidetracked > with this item, which I thought was very odd, since it is "deciding > for you" to stuff a space in. btw, I also thought the default "add a CR LF" to the end was odd too. But at least that one had a simple way out. From vasudevram at gmail.com Sun Sep 2 15:35:02 2012 From: vasudevram at gmail.com (vasudevram) Date: Sun, 2 Sep 2012 12:35:02 -0700 (PDT) Subject: PipeController v0.1 - experimental tool to simulate simple UNIX-style pipes in Python In-Reply-To: <58eb1290-dbdc-4b89-b03f-d4efd125a132@googlegroups.com> References: <229067cc-dee6-4f0c-bcf2-c30f20b4a9be@googlegroups.com> <58eb1290-dbdc-4b89-b03f-d4efd125a132@googlegroups.com> Message-ID: <97cb2e8e-1b62-4096-a0af-6aa8fae2d1e8@googlegroups.com> On Saturday, September 1, 2012 9:02:33 PM UTC+5:30, Ramchandra Apte wrote: > On Friday, 31 August 2012 03:27:54 UTC+5:30, vasudevram wrote: > > > I wrote PipeController recently to experiment with doing UNIX-style pipes in Python. > > > Doesn't the pipes module already do this? Yes. As Ian Kelly points out here: http://www.mail-archive.com/python-list at python.org/msg335943.html the pipes module of Python does deal with actual UNIX pipes. But I had mentioned this - Python's pipes module - in my first post, some months ago, about doing UNIX-pipes in Python ( on my blog, here: http://jugad2.blogspot.in/2011/09/some-ways-of-doing-unix-style-pipes-in.html ), and that first post was in turn linked to, in the current post under discussion ( i.e. this one: http://jugad2.blogspot.in/2012/08/pipecontroller-v01-released-simulating.html ). To Ian Kelly: > No, that deals with actual Unix pipes. This appears to be about pipelined > processing within a single program and not IPC; the description "Unix-like" > is a bit misleading, IMO. I guess it can be interpreted as a bit misleading, but it was not intentionally so. The way I meant it was that PipeController tries to achieve _roughly_ similar functionality, of composing a program out of components, as UNIX pipes do. (That too, only a small subset, as I mention in my blog post). In the case of UNIX the components are commands, in the case of my Python approach the components are functions. Also, I used the term "UNIX-style pipes", not "UNIX pipes", to stress that it was the overall concept of a pipeline that was being simulated, not the exact design / implementation details, and you can also notice that my first post has links to many different third-party ways of simulating UNIX-pipes in Python, some of which are not like actual UNIX pipes at all, in their implementation. But I agree that your description of PipeController as "pipelined processing within a single program" is more accurate. I could have used a better choice of words but there was no intention to mislead. - Vasudev Ram www.dancingbison.com jugad2.blogspot.com From me at joshmk.com Sun Sep 2 15:36:05 2012 From: me at joshmk.com (me) Date: 02 Sep 2012 19:36:05 GMT Subject: stuck in files!! Message-ID: <5043b524$0$1844$c3e8da3$dbd57e7@news.astraweb.com> The best you can do is pipe a string to a .txt document then pipe it again to a wordpad document. You should be able to do that easily with file and open() From d at davea.name Sun Sep 2 15:41:58 2012 From: d at davea.name (Dave Angel) Date: Sun, 02 Sep 2012 15:41:58 -0400 Subject: newbie ``print`` question In-Reply-To: <23e8e5c4-fb47-4753-b936-e1d546702387@pz10g2000pbb.googlegroups.com> References: <23e8e5c4-fb47-4753-b936-e1d546702387@pz10g2000pbb.googlegroups.com> Message-ID: <5043B686.9090402@davea.name> On 09/02/2012 03:34 PM, gwhite wrote: > > > btw, I also thought the default "add a CR LF" to the end was odd too. > But at least that one had a simple way out. But it (print on Python 2.x) doesn't, unless you're stuck on Windows. And even then, you can prevent it by using a 'b' in the mode. -- DaveA From torriem at gmail.com Sun Sep 2 15:45:03 2012 From: torriem at gmail.com (Michael Torrie) Date: Sun, 02 Sep 2012 13:45:03 -0600 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: <5043B73F.4020908@gmail.com> On 09/02/2012 12:58 PM, wxjmfauth at gmail.com wrote: > My rationale: very simple. > > 1) I never heard about something better than sticking with one > of the Unicode coding scheme. (genreral theory) > 2) I am not at all convinced by the "new" Py 3.3 algorithm. I'm not the > only one guy, who noticed problems. Arguing, "it is fast enough", is not > a correct answer. If this is true, why were you holding ho Google Go as an example of doing it right? Certainly Google Go doesn't line up with your rational. Go has both Strings and Runes. But strings are UTF-8-encoded bytes strings and Runes are 32-bit integers. They are not interchangeable without a costly encoding and decoding process. Even worse, indexing a Go string to get a "Rune" involves some very costly decoding that has to be done starting at the beginning of the string each time. In the worst case, Python's strings are as slow as Go because Python does the exact same thing as Go, but chooses between three encodings instead of just one. Best case scenario, Python's strings could be much faster than Go's because indexing through 2 of the 3 encodings is O(1) because they are constant-width encodings. If as you say, the latin-1 subset of UTF-8 is used, then UTF-8 indexing is O(1) too, otherwise it's probably O(n). From gwhite at ti.com Sun Sep 2 15:46:18 2012 From: gwhite at ti.com (gwhite) Date: Sun, 2 Sep 2012 12:46:18 -0700 (PDT) Subject: newbie ``print`` question References: Message-ID: <80660748-d3a1-4878-b506-9415cb8191a2@xd1g2000pbc.googlegroups.com> On Sep 2, 10:45?am, Joel Goldstick wrote: > On Sun, Sep 2, 2012 at 1:23 PM, gwhite wrote: > > I can't figure out how to stop the "add a space at the beginning" > > behavior of the print function. > > >>>> print 1,;print 2, > > 1 2 > > > See the space in between the 1 and the 2 at the output print to the > > command console? > > > The help for print is: > > > "A space is written before each object is (converted and) written, > > unless the output system believes it is positioned at the beginning of > > a line." > > > So it is apparently doing what it is supposed to do. > > > Is there a way to stop this? ?Or is there a different function that > > will only print what you have in the formatted string? > > You can do it with string formatting. ?My example shows 'old style' > string formatting syntax. ?There is a newer style. ?You can learn > about both from the online python docs. > > > > >>> print "%d%d" % (1,2) > 12 For "real" stuff, I've been trying to use that. I saw it in Beazley's latest Essential text. You're right, I can construct a single string and then write it. In fact, it looks like it is a must unless using the 3.2/3.3 version of `print`. From me at joshmk.com Sun Sep 2 15:48:08 2012 From: me at joshmk.com (me) Date: 02 Sep 2012 19:48:08 GMT Subject: How to print a number as if in the python interpreter? Message-ID: <5043b7f7$0$1288$c3e8da3$eb767761@news.astraweb.com> Use repr() print(repr(sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1]))) From gwhite at ti.com Sun Sep 2 15:50:12 2012 From: gwhite at ti.com (gwhite) Date: Sun, 2 Sep 2012 12:50:12 -0700 (PDT) Subject: newbie ``print`` question References: <23e8e5c4-fb47-4753-b936-e1d546702387@pz10g2000pbb.googlegroups.com> Message-ID: <09a119ef-4374-4740-808f-69f8df555f40@f4g2000pbq.googlegroups.com> On Sep 2, 12:43?pm, Dave Angel wrote: > On 09/02/2012 03:34 PM, gwhite wrote: > > > > > > btw, I also thought the default "add a CR LF" to the end was odd too. > > But at least that one had a simple way out. > > But it (print on Python 2.x) doesn't, unless you're stuck on Windows. > And even then, you can prevent it by using a 'b' in the mode. Yes, I'm using windows. What is "'b' in the mode?" The help for print says: A ``'\n'`` character is written at the end, unless the ``print`` statement ends with a comma. This is the only action if the statement contains just the keyword ``print``. So I followed with a comma to stop the default CR LF insertion. From d at davea.name Sun Sep 2 15:51:58 2012 From: d at davea.name (Dave Angel) Date: Sun, 02 Sep 2012 15:51:58 -0400 Subject: stuck in files!! In-Reply-To: <5043b524$0$1844$c3e8da3$dbd57e7@news.astraweb.com> References: <5043b524$0$1844$c3e8da3$dbd57e7@news.astraweb.com> Message-ID: <5043B8DE.20606@davea.name> On 09/02/2012 03:36 PM, me wrote: > The best you can do is pipe a string to a .txt document then pipe it again to a wordpad document. You should be able to do that easily with file and open() > If your reply is going to break the thread, and if the thread has been stale almost a month, then it seems the least you could do would be to quote some portion of the message you're replying to. As it stands, your message refers to piping a string to two documents, which is patently impractical in Bash. Better switch to Frod. -- DaveA From me at joshmk.com Sun Sep 2 15:58:03 2012 From: me at joshmk.com (me) Date: 02 Sep 2012 19:58:03 GMT Subject: newbie ``print`` question Message-ID: <5043ba4a$0$13161$c3e8da3$14a0410e@news.astraweb.com> Well you can convert the ints to str then concatenate them. print "1" + "2" From me at joshmk.com Sun Sep 2 16:07:06 2012 From: me at joshmk.com (me) Date: 02 Sep 2012 20:07:06 GMT Subject: stuck in files!! Message-ID: <5043bc69$0$1736$c3e8da3$3a1a2348@news.astraweb.com> Didn't see the post date on my reader haha. Sorry about that. From d at davea.name Sun Sep 2 16:07:35 2012 From: d at davea.name (Dave Angel) Date: Sun, 02 Sep 2012 16:07:35 -0400 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <5043B73F.4020908@gmail.com> References: <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> <5043B73F.4020908@gmail.com> Message-ID: <5043BC87.2090301@davea.name> On 09/02/2012 03:45 PM, Michael Torrie wrote: > : > In the worst case, Python's strings are as slow as Go because Python > does the exact same thing as Go, but chooses between three encodings > instead of just one. Best case scenario, Python's strings could be > much faster than Go's because indexing through 2 of the 3 encodings is > O(1) because they are constant-width encodings. If as you say, the > latin-1 subset of UTF-8 is used, then UTF-8 indexing is O(1) too, > otherwise it's probably O(n). I'm afraid you have it backwards. the Utf-8 version of the latin-1-compatible characters would be variable length. But my understanding of the pep is that the internal one-byte format is simply the lowest order byte of each code point, after assuring that all code points in the particular string are less than 256. That's going to coincidentally resemble latin-1's encoding, but since it's an internal form, the resemblance is irrelevant. Anyway, those one-byte values are going to be O(1), naturally. No encoding involved, and no searching nor expanding. -- DaveA From gwhite at ti.com Sun Sep 2 16:11:24 2012 From: gwhite at ti.com (gwhite) Date: Sun, 2 Sep 2012 13:11:24 -0700 (PDT) Subject: newbie ``print`` question References: Message-ID: <83b01510-4912-43d8-a9fb-c8c0d376937f@rg9g2000pbc.googlegroups.com> On Sep 2, 11:33?am, Terry Reedy wrote: > On 9/2/2012 1:23 PM, gwhite wrote: > > > I can't figure out how to stop the "add a space at the beginning" > > behavior of the print function. > > >>>> print 1,;print 2, > > 1 2 > > You have discovered why print is a function in 3.x. > ?>>> print(1, 2, sep='') > 12 > ?>>> print(1, end=''); print(2, end='') > 12 > > In 2.6 or 2.7, you can add > ? ?from __future__ import print_function > but I recommend using 3.2 or 3.3 unless you have a reason to use older > Python. It looks like one can avoid pre-construction of the total line with 3.x. >>> from __future__ import print_function >>> print('a=%.1f,' % 1.0, end='');print('b=%.1f' % 2.0, end='') a=1.0,b=2.0 Thanks. It isn't that hard to pre-construct, but regardless, there is better control in 3.x. From d at davea.name Sun Sep 2 16:15:42 2012 From: d at davea.name (Dave Angel) Date: Sun, 02 Sep 2012 16:15:42 -0400 Subject: newbie ``print`` question In-Reply-To: <09a119ef-4374-4740-808f-69f8df555f40@f4g2000pbq.googlegroups.com> References: <23e8e5c4-fb47-4753-b936-e1d546702387@pz10g2000pbb.googlegroups.com> <09a119ef-4374-4740-808f-69f8df555f40@f4g2000pbq.googlegroups.com> Message-ID: <5043BE6E.9020300@davea.name> On 09/02/2012 03:50 PM, gwhite wrote: > On Sep 2, 12:43 pm, Dave Angel wrote: >> On 09/02/2012 03:34 PM, gwhite wrote: >> >>> >>> btw, I also thought the default "add a CR LF" to the end was odd too. >>> But at least that one had a simple way out. >> But it (print on Python 2.x) doesn't, unless you're stuck on Windows. >> And even then, you can prevent it by using a 'b' in the mode. > Yes, I'm using windows. What is "'b' in the mode?" The help for > print says: > > A ``'\n'`` character is written at the end, unless the ``print`` > statement ends with a comma. This is the only action if the statement > contains just the keyword ``print``. > > So I followed with a comma to stop the default CR LF insertion. > You're correct; the best way to suppress the newline at the end of print is to use the trailing comma. But since print is for lines, it usually is a good default. If you don't want to get any extra characters, just use write(). It takes a string, and outputs exactly what it's given. I assumed you were complaining about the conversion of newline to carriage-return-newline, which is done by default on Windows, and can be suppressed by opening the file with "b" as the mode parameter. -- DaveA From breamoreboy at yahoo.co.uk Sun Sep 2 16:24:34 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Sep 2012 21:24:34 +0100 Subject: newbie ``print`` question In-Reply-To: <5043ba4a$0$13161$c3e8da3$14a0410e@news.astraweb.com> References: <5043ba4a$0$13161$c3e8da3$14a0410e@news.astraweb.com> Message-ID: On 02/09/2012 20:58, me wrote: > Well you can convert the ints to str then concatenate them. > > print "1" + "2" > Please post other parts of the thread so people can get the context or don't bother posting at all, thanks. -- Cheers. Mark Lawrence. From clp2 at rebertia.com Sun Sep 2 16:33:47 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 2 Sep 2012 13:33:47 -0700 Subject: newbie ``print`` question In-Reply-To: References: <5043ba4a$0$13161$c3e8da3$14a0410e@news.astraweb.com> Message-ID: On Sun, Sep 2, 2012 at 1:24 PM, Mark Lawrence wrote: > On 02/09/2012 20:58, me wrote: >> >> Well you can convert the ints to str then concatenate them. >> >> print "1" + "2" >> > > Please post other parts of the thread so people can get the context or don't > bother posting at all, thanks. Please also adjust your mail client so that your "From" is more informative and less confusing than simply "me". Regards, Chris From d at davea.name Sun Sep 2 16:38:22 2012 From: d at davea.name (Dave Angel) Date: Sun, 02 Sep 2012 16:38:22 -0400 Subject: stuck in files!! In-Reply-To: <5043bc69$0$1736$c3e8da3$3a1a2348@news.astraweb.com> References: <5043bc69$0$1736$c3e8da3$3a1a2348@news.astraweb.com> Message-ID: <5043C3BE.1050001@davea.name> On 09/02/2012 04:07 PM, me wrote: > Didn't see the post date on my reader haha. Sorry about that. > Well, i see you're also posting responses to recent messages. Great. But please use reply with a proper mail program; your messages are all brand new threads. And could you fix your email address? You're apparently hijacking someone else's domain. If you want to stay anonymous, use the invalid domain, as it's reserved for such purposes. Try me at invalid -- DaveA From tjreedy at udel.edu Sun Sep 2 16:38:34 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 02 Sep 2012 16:38:34 -0400 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <5043B73F.4020908@gmail.com> References: <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> <5043B73F.4020908@gmail.com> Message-ID: On 9/2/2012 3:45 PM, Michael Torrie wrote: > In the worst case, Python's strings are as slow as Go because Python > does the exact same thing as Go, but chooses between three encodings > instead of just one. Best case scenario, Python's strings could be much > faster than Go's because indexing through 2 of the 3 encodings is O(1) In CPython 3.3, indexing of str text string objects is always O(1) and it is always indexes and counts code points rather than code units. It was the latter for narrow builds in 3.2 and before. As a result, single character (code point) strings had a length of 2 rather than 1 for extended plane characters. 3.3 corrects this. -- Terry Jan Reedy From storchaka at gmail.com Sun Sep 2 16:38:49 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sun, 02 Sep 2012 23:38:49 +0300 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> Message-ID: On 30.08.12 09:55, Steven D'Aprano wrote: > And Python's solution uses those: UCS-2, UCS-4, and UTF-8. I see that this misconception widely spread. In fact Python 3.3 uses four kinds of ready strings. * ASCII. All codes <= U+007F. * UCS1. All codes <= U+00FF, at least one code > U+007F. * UCS2. All codes <= U+FFFF, at least one code > U+00FF. * UCS4. All codes <= U+0010FFFF, at least one code > U+FFFF. Indexing is O(0) for any string. Also the string can optionally cache UTF-8 and wchar_t* representation. From tjreedy at udel.edu Sun Sep 2 16:49:05 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 02 Sep 2012 16:49:05 -0400 Subject: newbie ``print`` question In-Reply-To: References: Message-ID: On 9/2/2012 3:26 PM, gwhite wrote: > On the "rework" thing, yes, I suppose I could construct the line as a > single string prior to print. There would be things like `for` > loops and conditionals to do so. That isn't so unusual. The usual idiom is to construct a list of pieces and then join with ''. >>> print(''.join(['1', '2'])) 12 Or map str to a list of objects. >>> print(''.join(map(str, [1, 2]))) 12 You can do either of these in 2.x. If you use .write, include '\n' at the end of the list (when needed). Print was designed as a quick and easy way to put lines of text on the screen. Then people asked for a way to use with with other streams, hence the >> hack. Then people wanted ways to control the separator and terminator. As that point, Guido realized that it needed to be a function, not a statement, with all the options requested. -- Terry Jan Reedy From vasudevram at gmail.com Sun Sep 2 16:56:37 2012 From: vasudevram at gmail.com (vasudevram) Date: Sun, 2 Sep 2012 13:56:37 -0700 (PDT) Subject: PipeController v0.1 - experimental tool to simulate simple UNIX-style pipes in Python In-Reply-To: <97cb2e8e-1b62-4096-a0af-6aa8fae2d1e8@googlegroups.com> References: <229067cc-dee6-4f0c-bcf2-c30f20b4a9be@googlegroups.com> <58eb1290-dbdc-4b89-b03f-d4efd125a132@googlegroups.com> <97cb2e8e-1b62-4096-a0af-6aa8fae2d1e8@googlegroups.com> Message-ID: On Monday, September 3, 2012 1:05:03 AM UTC+5:30, vasudevram wrote: > > To Ian Kelly: > > No, that deals with actual Unix pipes. This appears to be about pipelined > > processing within a single program and not IPC; the description "Unix-like" > > is a bit misleading, IMO. > I guess it can be interpreted as a bit misleading, but it was not intentionally so. The way I meant it was that PipeController tries to achieve _roughly_ similar functionality, of composing a program out of components, as UNIX pipes do. To Ian again: Also, I used the word "synchronous" somewhat deliberately (see in my blog post: "PipeController is a tool to experiment with a simple, sequential, synchronous simulation of UNIX-style pipes in Python."). I used the word synchronous to indicate that my PipeController implementation runs the functions one after another (for each item in the input), in contrast to actual Unix pipes, where the different commands in a pipeline can, and IIRC, do, run in parallel / asynchronously, with their IPC being coordinated / managed by the kernel and shell. From gwhite at ti.com Sun Sep 2 16:58:25 2012 From: gwhite at ti.com (gwhite) Date: Sun, 2 Sep 2012 13:58:25 -0700 (PDT) Subject: newbie ``print`` question References: <23e8e5c4-fb47-4753-b936-e1d546702387@pz10g2000pbb.googlegroups.com> <09a119ef-4374-4740-808f-69f8df555f40@f4g2000pbq.googlegroups.com> Message-ID: <18639409-7989-454d-91bc-b7b7b7f3528b@s9g2000pbh.googlegroups.com> On Sep 2, 1:16?pm, Dave Angel wrote: > On 09/02/2012 03:50 PM, gwhite wrote: > > > > > > > > > > > On Sep 2, 12:43 pm, Dave Angel wrote: > >> On 09/02/2012 03:34 PM, gwhite wrote: > > >>> > >>> btw, I also thought the default "add a CR LF" to the end was odd too. > >>> But at least that one had a simple way out. > >> But it (print on Python 2.x) doesn't, unless you're stuck on Windows. > >> And even then, you can prevent it by using a 'b' in the mode. > > Yes, I'm using windows. ?What is "'b' in the mode?" ?The help for > > print says: > > > A ``'\n'`` character is written at the end, unless the ``print`` > > statement ends with a comma. ?This is the only action if the statement > > contains just the keyword ``print``. > > > So I followed with a comma to stop the default CR LF insertion. > > You're correct; ?the best way to suppress the newline at the end of > print is to use the trailing comma. ?But since print is for lines, it > usually is a good default. ?If you don't want to get any extra > characters, just use write(). ?It takes a string, and outputs exactly > what it's given. > > I assumed you were complaining about the conversion of newline to > carriage-return-newline, which is done by default on Windows, and can be > suppressed by opening the file with "b" as the mode parameter. Sorry, I was a little vague on the newline stuff. In any case, I've learned I should probably avoid the comma, if looking at 3.x: >>> from __future__ import print_function >>> print('a=%.1f,' % 1.0),;print('b=%.1f' % 2.0) a=1.0, (None,) b=2.0 Given the input of several posters, I feel like I should probably be using the `write` function anyway. (I don't have a problem pre- constructing strings either.) But I am a newbie, and "all" the show-and-tell examples/tutorials use `print`. But this little thread has helped me a lot. From gwhite at ti.com Sun Sep 2 17:04:40 2012 From: gwhite at ti.com (gwhite) Date: Sun, 2 Sep 2012 14:04:40 -0700 (PDT) Subject: newbie ``print`` question References: Message-ID: <34d3b3b3-e65d-40a0-8b33-17c6b51b13a8@f4g2000pbq.googlegroups.com> On Sep 2, 1:37?pm, Dennis Lee Bieber wrote: > On Sun, 2 Sep 2012 10:23:53 -0700 (PDT), gwhite > declaimed the following in gmane.comp.python.general: > > > > > "A space is written before each object is (converted and) written, > > unless the output system believes it is positioned at the beginning of > > a line." > > > So it is apparently doing what it is supposed to do. > > > Is there a way to stop this? ?Or is there a different function that > > will only print what you have in the formatted string? > > E:\UserData\Wulfraed\My Documents>python > ActivePython 2.7.2.5 (ActiveState Software Inc.) based on > Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > > >>> import sys > >>> print "1",;sys.stdout.softspace=0;print "2" > 12 > > >>> sys.stdout.write("1");sys.stdout.write("2");print > 12 > > ? ? ? ? In Python 2.x, the equivalent of fprint/fprintf is NOT print but > sys.stdout.write/file_object.write > > ? ? ? ? "print" is just a convenience function that is designed to translate > its arguments into a textual representation, and then drop it to the > screen. Part of the convenience is to separate output items by a space > and to emit a newline at the end. > > ? ? ? ? .write(), OTOH, does no formatting -- not even new lines. You have > to provide all conversion to text, and line endings. Thanks. I am starting to get it. From gwhite at ti.com Sun Sep 2 17:18:20 2012 From: gwhite at ti.com (gwhite) Date: Sun, 2 Sep 2012 14:18:20 -0700 (PDT) Subject: newbie ``print`` question References: Message-ID: <680feff1-8d8e-4f6d-8521-1e875479d1f7@k9g2000pbr.googlegroups.com> On Sep 2, 1:49?pm, Terry Reedy wrote: > On 9/2/2012 3:26 PM, gwhite wrote: > > > On the "rework" thing, yes, I suppose I could construct the line as a > > single string prior to print. ? ?There would be things like `for` > > loops and conditionals to do so. ?That isn't so unusual. > > The usual idiom is to construct a list of pieces and then join with ''. > > ?>>> print(''.join(['1', '2'])) > 12 > > Or map str to a list of objects. > > ?>>> print(''.join(map(str, [1, 2]))) > 12 > > You can do either of these in 2.x. > If you use .write, include '\n' at the end of the list (when needed). > > Print was designed as a quick and easy way to put lines of text on the > screen. Then people asked for a way to use with with other streams, > hence the >> hack. Then people wanted ways to control the separator and > terminator. As that point, Guido realized that it needed to be a > function, not a statement, with all the options requested. Thanks again, Terry. There is a lot to the language, I am finding out. I am a HW engineer, not really a programmer. Python seems a lot more sophisticated than MATLAB. I'm kinda thinking `write` is likely to be a little more "stable" than `print` (if that is the right characterization) when my eventual switch from 2.7 to 3.x happens. You think? From storchaka at gmail.com Sun Sep 2 17:45:37 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Mon, 03 Sep 2012 00:45:37 +0300 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> Message-ID: On 02.09.12 23:38, Serhiy Storchaka wrote: > Indexing is O(0) for any string. Typo. O(1) From rosuav at gmail.com Sun Sep 2 17:47:47 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Sep 2012 07:47:47 +1000 Subject: newbie ``print`` question In-Reply-To: <680feff1-8d8e-4f6d-8521-1e875479d1f7@k9g2000pbr.googlegroups.com> References: <680feff1-8d8e-4f6d-8521-1e875479d1f7@k9g2000pbr.googlegroups.com> Message-ID: On Mon, Sep 3, 2012 at 7:18 AM, gwhite wrote: > Thanks again, Terry. There is a lot to the language, I am finding > out. I am a HW engineer, not really a programmer. Python seems a lot > more sophisticated than MATLAB. > > I'm kinda thinking `write` is likely to be a little more "stable" than > `print` (if that is the right characterization) when my eventual > switch from 2.7 to 3.x happens. You think? If you're planning to switch, make use of __future__. It's specifically to make that job easier. Once you have a future declaration at the top, print() will be stable across 2.7 and 3.x. ChrisA From python at mrabarnett.plus.com Sun Sep 2 18:43:42 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 02 Sep 2012 23:43:42 +0100 Subject: newbie ``print`` question In-Reply-To: <18639409-7989-454d-91bc-b7b7b7f3528b@s9g2000pbh.googlegroups.com> References: <23e8e5c4-fb47-4753-b936-e1d546702387@pz10g2000pbb.googlegroups.com> <09a119ef-4374-4740-808f-69f8df555f40@f4g2000pbq.googlegroups.com> <18639409-7989-454d-91bc-b7b7b7f3528b@s9g2000pbh.googlegroups.com> Message-ID: <5043E11E.9030001@mrabarnett.plus.com> On 02/09/2012 21:58, gwhite wrote: > On Sep 2, 1:16 pm, Dave Angel wrote: >> On 09/02/2012 03:50 PM, gwhite wrote: >> >> >> >> >> >> >> >> >> >> > On Sep 2, 12:43 pm, Dave Angel wrote: >> >> On 09/02/2012 03:34 PM, gwhite wrote: >> >> >>> >> >>> btw, I also thought the default "add a CR LF" to the end was odd too. >> >>> But at least that one had a simple way out. >> >> But it (print on Python 2.x) doesn't, unless you're stuck on Windows. >> >> And even then, you can prevent it by using a 'b' in the mode. >> > Yes, I'm using windows. What is "'b' in the mode?" The help for >> > print says: >> >> > A ``'\n'`` character is written at the end, unless the ``print`` >> > statement ends with a comma. This is the only action if the statement >> > contains just the keyword ``print``. >> >> > So I followed with a comma to stop the default CR LF insertion. >> >> You're correct; the best way to suppress the newline at the end of >> print is to use the trailing comma. But since print is for lines, it >> usually is a good default. If you don't want to get any extra >> characters, just use write(). It takes a string, and outputs exactly >> what it's given. >> >> I assumed you were complaining about the conversion of newline to >> carriage-return-newline, which is done by default on Windows, and can be >> suppressed by opening the file with "b" as the mode parameter. > > > Sorry, I was a little vague on the newline stuff. > > In any case, I've learned I should probably avoid the comma, if > looking at 3.x: > >>>> from __future__ import print_function >>>> print('a=%.1f,' % 1.0),;print('b=%.1f' % 2.0) > a=1.0, > (None,) > b=2.0 > Explanation: With 'print' as a function, the first 'print' prints the result of "'a=%.1f,' % 1.0" and then returns None. The trailing comma makes that into a tuple (None,), which is printed by the interactive interpreter as such. In other words: >>> None, (None,) >>> The second prints the result of "'b=%.1f' % 2.0" and then returns None. The interactive interpreter, recognising that it's only None, doesn't bother to print it. In other words: >>> None >>> > Given the input of several posters, I feel like I should probably be > using the `write` function anyway. (I don't have a problem pre- > constructing strings either.) > > But I am a newbie, and "all" the show-and-tell examples/tutorials use > `print`. But this little thread has helped me a lot. > From gwhite at ti.com Sun Sep 2 19:20:42 2012 From: gwhite at ti.com (gwhite) Date: Sun, 2 Sep 2012 16:20:42 -0700 (PDT) Subject: newbie ``print`` question References: <680feff1-8d8e-4f6d-8521-1e875479d1f7@k9g2000pbr.googlegroups.com> Message-ID: <63ca5a36-04d4-489a-b82e-9bb8e86bdc5e@v19g2000pbt.googlegroups.com> On Sep 2, 2:47?pm, Chris Angelico wrote: > On Mon, Sep 3, 2012 at 7:18 AM, gwhite wrote: > > Thanks again, Terry. ?There is a lot to the language, I am finding > > out. ?I am a HW engineer, not really a programmer. ?Python seems a lot > > more sophisticated than MATLAB. > > > I'm kinda thinking `write` is likely to be a little more "stable" than > > `print` (if that is the right characterization) when my eventual > > switch from 2.7 to 3.x happens. ?You think? > > If you're planning to switch, make use of __future__. It's > specifically to make that job easier. Once you have a future > declaration at the top, print() will be stable across 2.7 and 3.x. I guess you're saying 3.x will just ignore: from __future__ import print_function I'll risk being silly, and thus ask: but what if when I get to 3.x there is no __future__, as it is now "present?" Do I need to strip out the line? What would happen when I finally started running 3.3, and a new __future__ was made that broke the old syntax? Do I need to strip out the line? I'm probably over thinking it. I don't know what I am doing. lol! From rosuav at gmail.com Sun Sep 2 19:28:17 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Sep 2012 09:28:17 +1000 Subject: newbie ``print`` question In-Reply-To: <63ca5a36-04d4-489a-b82e-9bb8e86bdc5e@v19g2000pbt.googlegroups.com> References: <680feff1-8d8e-4f6d-8521-1e875479d1f7@k9g2000pbr.googlegroups.com> <63ca5a36-04d4-489a-b82e-9bb8e86bdc5e@v19g2000pbt.googlegroups.com> Message-ID: On Mon, Sep 3, 2012 at 9:20 AM, gwhite wrote: > I guess you're saying 3.x will just ignore: > > from __future__ import print_function > > I'll risk being silly, and thus ask: but what if when I get to 3.x > there is no __future__, as it is now "present?" Do I need to strip > out the line? > > What would happen when I finally started running 3.3, and a new > __future__ was made that broke the old syntax? Do I need to strip out > the line? > > I'm probably over thinking it. I don't know what I am doing. lol! The __future__ statement is guaranteed to be supported forever afterwards. And new ones won't do anything unless you explicitly put them into your code. It's quite a good system, imo. ChrisA From gwhite at ti.com Sun Sep 2 19:33:37 2012 From: gwhite at ti.com (gwhite) Date: Sun, 2 Sep 2012 16:33:37 -0700 (PDT) Subject: newbie ``print`` question References: <23e8e5c4-fb47-4753-b936-e1d546702387@pz10g2000pbb.googlegroups.com> <09a119ef-4374-4740-808f-69f8df555f40@f4g2000pbq.googlegroups.com> <18639409-7989-454d-91bc-b7b7b7f3528b@s9g2000pbh.googlegroups.com> Message-ID: <36dc2a2b-3326-417e-8b7d-2d8f8fc6fe03@r1g2000pbq.googlegroups.com> On Sep 2, 3:43?pm, MRAB wrote: > On 02/09/2012 21:58, gwhite wrote: > > > > > > > > > On Sep 2, 1:16 pm, Dave Angel wrote: > >> On 09/02/2012 03:50 PM, gwhite wrote: > > >> > On Sep 2, 12:43 pm, Dave Angel wrote: > >> >> On 09/02/2012 03:34 PM, gwhite wrote: > > >> >>> > >> >>> btw, I also thought the default "add a CR LF" to the end was odd too. > >> >>> But at least that one had a simple way out. > >> >> But it (print on Python 2.x) doesn't, unless you're stuck on Windows. > >> >> And even then, you can prevent it by using a 'b' in the mode. > >> > Yes, I'm using windows. ?What is "'b' in the mode?" ?The help for > >> > print says: > > >> > A ``'\n'`` character is written at the end, unless the ``print`` > >> > statement ends with a comma. ?This is the only action if the statement > >> > contains just the keyword ``print``. > > >> > So I followed with a comma to stop the default CR LF insertion. > > >> You're correct; ?the best way to suppress the newline at the end of > >> print is to use the trailing comma. ?But since print is for lines, it > >> usually is a good default. ?If you don't want to get any extra > >> characters, just use write(). ?It takes a string, and outputs exactly > >> what it's given. > > >> I assumed you were complaining about the conversion of newline to > >> carriage-return-newline, which is done by default on Windows, and can be > >> suppressed by opening the file with "b" as the mode parameter. > > > Sorry, I was a little vague on the newline stuff. > > > In any case, I've learned I should probably avoid the comma, if > > looking at 3.x: > > >>>> from __future__ import print_function > >>>> print('a=%.1f,' % 1.0),;print('b=%.1f' % 2.0) > > a=1.0, > > (None,) > > b=2.0 > > Explanation: > > With 'print' as a function, the first 'print' prints the result of > "'a=%.1f,' % 1.0" and then returns None. The trailing comma makes that > into a tuple (None,), which is printed by the interactive interpreter > as such. > > In other words: > > ?>>> None, > (None,) > ?>>> > > The second prints the result of "'b=%.1f' % 2.0" and then returns None. > The interactive interpreter, recognising that it's only None, doesn't > bother to print it. > > In other words: > > ?>>> None Thanks, that makes sense. It does look like 2.7 & 3.3 don't parse the comma the same way. Just to repeat, since I didn't give the exact same line to both versions of Python: 2.7 >>> print('a=%.1f,' % 1.0),;print('b=%.1f' % 2.0) a=1.0, b=2.0 This has been more informative than I thought it was going to be. From python at mrabarnett.plus.com Sun Sep 2 20:12:33 2012 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 03 Sep 2012 01:12:33 +0100 Subject: newbie ``print`` question In-Reply-To: <36dc2a2b-3326-417e-8b7d-2d8f8fc6fe03@r1g2000pbq.googlegroups.com> References: <23e8e5c4-fb47-4753-b936-e1d546702387@pz10g2000pbb.googlegroups.com> <09a119ef-4374-4740-808f-69f8df555f40@f4g2000pbq.googlegroups.com> <18639409-7989-454d-91bc-b7b7b7f3528b@s9g2000pbh.googlegroups.com> <36dc2a2b-3326-417e-8b7d-2d8f8fc6fe03@r1g2000pbq.googlegroups.com> Message-ID: <5043F5F1.4010104@mrabarnett.plus.com> On 03/09/2012 00:33, gwhite wrote: > On Sep 2, 3:43 pm, MRAB wrote: >> On 02/09/2012 21:58, gwhite wrote: >> >> >> >> >> >> >> >> > On Sep 2, 1:16 pm, Dave Angel wrote: >> >> On 09/02/2012 03:50 PM, gwhite wrote: >> >> >> > On Sep 2, 12:43 pm, Dave Angel wrote: >> >> >> On 09/02/2012 03:34 PM, gwhite wrote: >> >> >> >>> >> >> >>> btw, I also thought the default "add a CR LF" to the end was odd too. >> >> >>> But at least that one had a simple way out. >> >> >> But it (print on Python 2.x) doesn't, unless you're stuck on Windows. >> >> >> And even then, you can prevent it by using a 'b' in the mode. >> >> > Yes, I'm using windows. What is "'b' in the mode?" The help for >> >> > print says: >> >> >> > A ``'\n'`` character is written at the end, unless the ``print`` >> >> > statement ends with a comma. This is the only action if the statement >> >> > contains just the keyword ``print``. >> >> >> > So I followed with a comma to stop the default CR LF insertion. >> >> >> You're correct; the best way to suppress the newline at the end of >> >> print is to use the trailing comma. But since print is for lines, it >> >> usually is a good default. If you don't want to get any extra >> >> characters, just use write(). It takes a string, and outputs exactly >> >> what it's given. >> >> >> I assumed you were complaining about the conversion of newline to >> >> carriage-return-newline, which is done by default on Windows, and can be >> >> suppressed by opening the file with "b" as the mode parameter. >> >> > Sorry, I was a little vague on the newline stuff. >> >> > In any case, I've learned I should probably avoid the comma, if >> > looking at 3.x: >> >> >>>> from __future__ import print_function >> >>>> print('a=%.1f,' % 1.0),;print('b=%.1f' % 2.0) >> > a=1.0, >> > (None,) >> > b=2.0 >> >> Explanation: >> >> With 'print' as a function, the first 'print' prints the result of >> "'a=%.1f,' % 1.0" and then returns None. The trailing comma makes that >> into a tuple (None,), which is printed by the interactive interpreter >> as such. >> >> In other words: >> >> >>> None, >> (None,) >> >>> >> >> The second prints the result of "'b=%.1f' % 2.0" and then returns None. >> The interactive interpreter, recognising that it's only None, doesn't >> bother to print it. >> >> In other words: >> >> >>> None > > Thanks, that makes sense. > > It does look like 2.7 & 3.3 don't parse the comma the same way. Just > to repeat, since I didn't give the exact same line to both versions of > Python: > > 2.7 >>>> print('a=%.1f,' % 1.0),;print('b=%.1f' % 2.0) > a=1.0, b=2.0 > > This has been more informative than I thought it was going to be. > Basically: In Python 2, 'print' is a statement. In Python 3, 'print' is a function. so they _would_ be parsed differently, because they _are_ different. However, in later versions of Python 2, such as 2.7, adding "from __future__ import print_function" will make 'print' a function like in Python 3. (It has no effect in Python 3 because 'print' is already a function, of course, so if you've converted a Python 2 script which contains it to Python 3 and just happened to leave it in, it won't complain either.) From python-excel at raf.org Sun Sep 2 20:18:34 2012 From: python-excel at raf.org (python-excel at raf.org) Date: Mon, 3 Sep 2012 10:18:34 +1000 Subject: [pyxl] xlrd-0.8.0 .xlsx formatting_info=True not implemented In-Reply-To: <1346443978.955.YahooMailNeo@web110708.mail.gq1.yahoo.com> References: <501944E4.2090902@simplistix.co.uk> <5c84fd3b-c899-4703-867d-ddbc5d1746de@googlegroups.com> <20120829021646.GA8163@raf.org> <20120830025758.GA26856@raf.org> <1346443978.955.YahooMailNeo@web110708.mail.gq1.yahoo.com> Message-ID: <20120903001834.GA30530@raf.org> Albert-Jan Roskam wrote: > Hi, > > As a work-around, you could use the CRAN R package XLConnect, using > RPy or RPy2, to do what you want. IIRC it's based on Java, so it's not > extremely fast. > http://cran.r-project.org/web/packages/XLConnect/vignettes/XLConnect.pdf > This is another package I just saw for the first time > > http://cran.r-project.org/web/packages/xlsx/xlsx.pdf > > Regards, > Albert-Jan hi, many thanks for the suggestions but i've already implemented an alternative using perl and its Spreadsheet::XLSX module. cheers, raf From jiangwen365 at gmail.com Sun Sep 2 21:01:33 2012 From: jiangwen365 at gmail.com (=?GB2312?B?va3OxA==?=) Date: Mon, 3 Sep 2012 09:01:33 +0800 Subject: PyPyODBC 0.8.3 released with improved performance and SQLAlchemy support Message-ID: PyPyODBC - A Pure Python ctypes ODBC module Features - Pure Python, compatible with IronPython and PyPy (tested on Win32) - Almost totally same usage as pyodbc You can simply try pypyodbc in your existing pyodbc powered script with the following changes: #import pyodbc <-- The original pyodbc importing line import pypyodbc as pyodbc # Let pypyodbc "pretend" the pyodbc pyodbc.connect(...) # pypyodbc is now doing pyodbc's job with same APIs! History Version 0.8.3 Sep 1 2012 sql_longvarchar handling fix; performance optimization; Version 0.8.2 Aug 27 2012 Differentiate sql_varchar and sql_longvarchar; Initial support for SQLAlchemy; Version 0.8.1 Aug 26 2012 Fixed the long type parameter issue; Added support for IronPython; Version 0.8 Aug 25 2012 Added getinfo method; Version 0.7 Jul 28 2012 Fixed nchar/ntext/nvarchar string truncat problem ; Version 0.6 Jul 4 2012 Added Cursor.commit() and Cursor.rollback(); Added readonly keyword to connect; Version 0.5 Jun 23 2012 Initial release; From steve+comp.lang.python at pearwood.info Sun Sep 2 21:42:08 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Sep 2012 01:42:08 GMT Subject: Flexible string representation, unicode, typography, ... References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: <50440af0$0$29967$c3e8da3$5496439d@news.astraweb.com> On Sun, 02 Sep 2012 11:58:08 -0700, wxjmfauth wrote: > - Unfortunately, I got opposite and even much worst results on my win > box, considering > - libfrancais is one of my module and it does a little bit more than the > std sorting tools. How do we know that the problem isn't in your module? > My rationale: very simple. > > 1) I never heard about something better than sticking with one of the > Unicode coding scheme. (genreral theory) Your ignorance is not a good reason for abandoning a powerful software technique. 2) I am not at all convinced by > the "new" Py 3.3 algorithm. I'm not the only one guy, who noticed > problems. That's nice. Nobody has yet displayed genuine performance problems, only artificial and platform-dependent slowdowns that are insignificant in practice. If you can demonstrate genuine problems, people will be interested in fixing them. Let me be frank: nobody gives a damn if, for some rare circumstances, some_string.replace(another_string) takes 0.3?s instead of 0.1?s. Overall, considering multiple platforms and dozens of different string operations, PEP 393 is a big win: - many operations are faster - a few operations are a LOT faster - but a very few operations are sometimes slower - many strings will use less memory - sometimes a LOT less memory - no more distinction between wide and narrow builds - characters in the supplementary planes are now, for the first time in Python, treated correctly by default That's six wins versus one loss. > Arguing, "it is fast enough", is not a correct answer. It is *exactly* the correct answer. Nobody is going to revert this just because your script now runs in 5.7ms instead of 5.2ms. Who cares? If you are *seriously* interested in debugging why string code is slower for you, you can start by running the full suite of Python string benchmarks: see the stringbench benchmark in the Tools directory of source installations, or see here: http://hg.python.org/cpython/file/8ff2f4634ed8/Tools/stringbench -- Steven From steve+comp.lang.python at pearwood.info Sun Sep 2 21:54:42 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Sep 2012 01:54:42 GMT Subject: Flexible string representation, unicode, typography, ... References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> Message-ID: <50440de2$0$29967$c3e8da3$5496439d@news.astraweb.com> On Sun, 02 Sep 2012 23:38:49 +0300, Serhiy Storchaka wrote: > On 30.08.12 09:55, Steven D'Aprano wrote: >> And Python's solution uses those: UCS-2, UCS-4, and UTF-8. > > I see that this misconception widely spread. I am not familiar enough with the C implementation to tell what Python 3.3 actually does, and the PEP assumes a fair amount of familiarity with the CPython source. So I welcome corrections. > In fact Python 3.3 uses four kinds of ready strings. > > * ASCII. All codes <= U+007F. > * UCS1. All codes <= U+00FF, at least one code > U+007F. > * UCS2. All codes <= U+FFFF, at least one code > U+00FF. > * UCS4. All codes <= U+0010FFFF, at least one code > U+FFFF. Where UCS1 is equivalent to Latin-1, correct? UCS2 is what Python 3.2 narrow builds uses for all strings, including codes > U+FFFF using surrogate pairs. UCS4 is what Python 3.2 wide builds uses for all strings. This means that Python 3.3 will no longer have surrogate pairs. Am I right? > Indexing is O(0) for any string. I think you mean O(1) for constant-time lookups. > Also the string can optionally cache UTF-8 and wchar_t* representation. Right, that's the bit that wasn't clear -- the UTF-8 data is a cache, not the canonical representation. -- Steven From tjreedy at udel.edu Sun Sep 2 22:33:55 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 02 Sep 2012 22:33:55 -0400 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <50440de2$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <50440de2$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/2/2012 9:54 PM, Steven D'Aprano wrote: > On Sun, 02 Sep 2012 23:38:49 +0300, Serhiy Storchaka wrote: > >> On 30.08.12 09:55, Steven D'Aprano wrote: >>> And Python's solution uses those: UCS-2, UCS-4, and UTF-8. >> >> I see that this misconception widely spread. > > I am not familiar enough with the C implementation to tell what Python > 3.3 actually does, and the PEP assumes a fair amount of familiarity with > the CPython source. So I welcome corrections. > > >> In fact Python 3.3 uses four kinds of ready strings. >> >> * ASCII. All codes <= U+007F. >> * UCS1. All codes <= U+00FF, at least one code > U+007F. >> * UCS2. All codes <= U+FFFF, at least one code > U+00FF. >> * UCS4. All codes <= U+0010FFFF, at least one code > U+FFFF. > > Where UCS1 is equivalent to Latin-1, correct? > > UCS2 is what Python 3.2 narrow builds uses for all strings, including > codes > U+FFFF using surrogate pairs. > > UCS4 is what Python 3.2 wide builds uses for all strings. > > This means that Python 3.3 will no longer have surrogate pairs. Basically, yes. I believe CPython will only use surrogate code points if one requests errors=surrogate-escape on decoding or explicitly puts them in a literal (\unnnn or \Ummmmmmmm). The consequences fall under the 'consenting adults' policy. -- Terry Jan Reedy From rishabhdixit11 at gmail.com Mon Sep 3 01:05:02 2012 From: rishabhdixit11 at gmail.com (Rishabh Dixit) Date: Sun, 2 Sep 2012 22:05:02 -0700 (PDT) Subject: Changing a Value in List of lists In-Reply-To: References: Message-ID: <5c3e1037-0d6b-4bca-86cc-eb0520321a41@googlegroups.com> On Sunday, 2 September 2012 23:40:32 UTC+5:30, Terry Reedy wrote: > On 9/2/2012 7:17 AM, Mark Lawrence wrote: > > > On 02/09/2012 12:05, Rishabh Dixit wrote: > > >> Hi, > > >> > > >> I got it :). We should create a new list every time before adding to a > > >> list > > >> of list so that instead repeating the reference a new reference generated > > >> every time. > > >> > > > > > > Please don't top post on this list as it often destroys the context, > > > thanks. > > > > In this particular case, OP could and should have trimmed off everything > > other than the top post, as it stands alone. Then it would not have been > > a top post ;-). > > > > -- > > Terry Jan Reedy Sorry for the inconvenience. I would not do it again. From rishabhdixit11 at gmail.com Mon Sep 3 01:05:02 2012 From: rishabhdixit11 at gmail.com (Rishabh Dixit) Date: Sun, 2 Sep 2012 22:05:02 -0700 (PDT) Subject: Changing a Value in List of lists In-Reply-To: References: Message-ID: <5c3e1037-0d6b-4bca-86cc-eb0520321a41@googlegroups.com> On Sunday, 2 September 2012 23:40:32 UTC+5:30, Terry Reedy wrote: > On 9/2/2012 7:17 AM, Mark Lawrence wrote: > > > On 02/09/2012 12:05, Rishabh Dixit wrote: > > >> Hi, > > >> > > >> I got it :). We should create a new list every time before adding to a > > >> list > > >> of list so that instead repeating the reference a new reference generated > > >> every time. > > >> > > > > > > Please don't top post on this list as it often destroys the context, > > > thanks. > > > > In this particular case, OP could and should have trimmed off everything > > other than the top post, as it stands alone. Then it would not have been > > a top post ;-). > > > > -- > > Terry Jan Reedy Sorry for the inconvenience. I would not do it again. From wxjmfauth at gmail.com Mon Sep 3 01:39:44 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 2 Sep 2012 22:39:44 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: Le dimanche 2 septembre 2012 14:01:18 UTC+2, Serhiy Storchaka a ?crit?: > On 02.09.12 12:52, Peter Otten wrote: > > > Ian Kelly wrote: > > > > > >> Rewriting the example to use locale.strcoll instead: > > > > > >>>>> sorted(li, key=functools.cmp_to_key(locale.strcoll)) > > > > > > There is also locale.strxfrm() which you can use directly: > > > > > > sorted(li, key=locale.strxfrm) > > > > Hmm, and with locale.strxfrm Python 3.3 20% slower than 3.2. With a memory gain = 0 since my text contains non-latin-1 characters! jmf From wxjmfauth at gmail.com Mon Sep 3 01:39:44 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 2 Sep 2012 22:39:44 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: Le dimanche 2 septembre 2012 14:01:18 UTC+2, Serhiy Storchaka a ?crit?: > On 02.09.12 12:52, Peter Otten wrote: > > > Ian Kelly wrote: > > > > > >> Rewriting the example to use locale.strcoll instead: > > > > > >>>>> sorted(li, key=functools.cmp_to_key(locale.strcoll)) > > > > > > There is also locale.strxfrm() which you can use directly: > > > > > > sorted(li, key=locale.strxfrm) > > > > Hmm, and with locale.strxfrm Python 3.3 20% slower than 3.2. With a memory gain = 0 since my text contains non-latin-1 characters! jmf From breamoreboy at yahoo.co.uk Mon Sep 3 02:11:06 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 03 Sep 2012 07:11:06 +0100 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: On 03/09/2012 06:39, wxjmfauth at gmail.com wrote: > Le dimanche 2 septembre 2012 14:01:18 UTC+2, Serhiy Storchaka a ?crit : >> On 02.09.12 12:52, Peter Otten wrote: >> >>> Ian Kelly wrote: >> >>> >> >>>> Rewriting the example to use locale.strcoll instead: >> >>> >> >>>>>>> sorted(li, key=functools.cmp_to_key(locale.strcoll)) >> >>> >> >>> There is also locale.strxfrm() which you can use directly: >> >>> >> >>> sorted(li, key=locale.strxfrm) >> >> >> >> Hmm, and with locale.strxfrm Python 3.3 20% slower than 3.2. > > With a memory gain = 0 since my text contains non-latin-1 characters! > > jmf > This is getting really funny. Do you make a living writing comedy for big film or TV studios? Your response to Steven D'Aprano's "That's six wins versus one loss." should be hilarious. Or do you not respond to fact based posts? -- Cheers. Mark Lawrence. From __peter__ at web.de Mon Sep 3 02:15:30 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 03 Sep 2012 08:15:30 +0200 Subject: Flexible string representation, unicode, typography, ... References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: wxjmfauth at gmail.com wrote: > Le dimanche 2 septembre 2012 14:01:18 UTC+2, Serhiy Storchaka a ?crit : >> Hmm, and with locale.strxfrm Python 3.3 20% slower than 3.2. > > With a memory gain = 0 since my text contains non-latin-1 characters! I can't confirm this. At least users of wide builds will see a decrease in memory use: $ cat strxfrm_getsize.py import locale import sys print("maxunicode:", sys.maxunicode) locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8") words = [ 'no?l', 'noir', 'n?ud', 'noduleux', 'no?tique', 'no?se', 'noir?tre'] print("total size of original strings:", sum(sys.getsizeof(s) for s in words)) print( "total size of transformed strings:", sum(sys.getsizeof(locale.strxfrm(s)) for s in words)) $ python3.2 strxfrm_getsize.py maxunicode: 1114111 total size of original strings: 584 total size of transformed strings: 980 $ python3.3 strxfrm_getsize.py maxunicode: 1114111 total size of original strings: 509 total size of transformed strings: 483 The situation is more complex than you suppose -- you need less dogma and more experiments ;) From gandalf at shopzeus.com Mon Sep 3 02:31:43 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 03 Sep 2012 08:31:43 +0200 Subject: tornado.web ioloop add_timeout eats CPU Message-ID: <50444ECF.2000504@shopzeus.com> JavaScript clients (browsers) do long poll requests. Each request can take up to 10 seconds before the server responds. On the server side, every client has a queue of messages that needs to be sent to the client. When the long poll request comes in, the server checks if there are messages to be sent out. If there are no outgoing messages, then it does not finish the response, but calls ioloop's add_timeout method for doing further checks. After 10 seconds (if there are no new messages) the server returns 304/not modified. If there is a message, then it is sent back to the client as fast as possible, and the client comes back with another long poll immediately. These message queues are used for UI updates and also for instant messaging. UI must be responsive. For this reason, any message in the outgoing queue should be sent out to the client within 0.1 seconds. Sometimes (rarely) lots of messages arrive quickly, and in those cases it would be good to send them out even faster. What I did is that in the first 0.1 seconds, I call add_timeout with 0.01 seconds. So if the outgoing queue is full of messages, then they are delivered quickly. After 0.1 seconds lapsed, add_timeout is called with 0.1 sec parameter. So the server load is reduced because most clients are inactive, and they are going to get callbacks in every 0.1 sec. Here are the two most important methods of my request handler: @tornado.web.asynchronous def post(self): """Handle POST requests.""" # Disable caching self.set_header("Cache-Control","no-cache, must-revalidate") self.set_header("Expires","Mon, 26 Jul 1997 05:00:00 GMT") self.poll_start = time.time() action = self.get_argument("action") if action=="poll": self.poll() elif action=="message": self.process_incoming(self.get_argument("message")) else: self.set_status(400) self.finish() def poll(self): """Handle POLL request for the browser's message loop. This method monitors the outgoing message queue, and sends new messages to the browser when they come in (or until self.poll_interval seconds elapsed).""" poll_elapsed = time.time() - self.poll_start if poll_elapsed<0.1: poll_step = 0.01 else: poll_step = 0.1 if poll_elapsed:1() 1135775 832.283 0.001 832.283 0.001 {method 'poll' of 'select.epoll' objects} I have copied out the two relevant rows only. As you can see, total runtime was 845 seconds, and 832 seconds were spent in "epoll". Apparently, CPU load goes up linearly as I connect more clients. It means that 50 connected clients would do 20% CPU load. Which is ridiculous, because they don't do anything but wait for messages to be processed. Something terribly wrong, but I cannot figure out what? Actually I could not try this with 50 clients. If I open 15 clients, then the server starts dropping connections. (Tried from Firefox and Chrome too.) If I change the poll() method this way: else: print "No messages after %.2f seconds"%poll_elapsed self.set_status(304) self.finish() then I see this in the log: No messages after 10.01 seconds ERROR:root:Uncaught exception POST /client (127.0.0.1) HTTPRequest(protocol='http', host='127.0.0.1:8888', method='POST', uri='/client', version='HTTP/1.1', remote_ip='127.0.0.1', body='_xsrf=df157469a62142d7b28c5a4880dd8478&action=poll', headers={'Referer': 'http://127.0.0.1:8888/', 'Content-Length': '50', 'Accept-Language': 'en-us;q=0.8,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'Host': '127.0.0.1:8888', 'Accept': '*/*', 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0', 'Connection': 'keep-alive', 'X-Requested-With': 'XMLHttpRequest', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache', 'Cookie': 'sid="MS1acHd5b3V1WHFOQU1BbTVmSXJEeVhkLys=|1346652787|e045d786fdb89b73220a2c77ef89572d0c16901e"; _xsrf=df157469a62142d7b28c5a4880dd8478; xsfr=df157469a62142d7b28c5a4880dd8478', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}) Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/tornado/stack_context.py", line 183, in wrapped callback(*args, **kwargs) File "/home/gandalf/Python/Projects/test/client.py", line 67, in poll self.finish() File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 641, in finish self.request.finish() File "/usr/lib/python2.7/dist-packages/tornado/httpserver.py", line 411, in finish self.connection.finish() File "/usr/lib/python2.7/dist-packages/tornado/httpserver.py", line 186, in finish self._finish_request() File "/usr/lib/python2.7/dist-packages/tornado/httpserver.py", line 213, in _finish_request self.stream.read_until(b("\r\n\r\n"), self._header_callback) File "/usr/lib/python2.7/dist-packages/tornado/iostream.py", line 151, in read_until self._check_closed() File "/usr/lib/python2.7/dist-packages/tornado/iostream.py", line 493, in _check_closed raise IOError("Stream is closed") IOError: Stream is closed What is even more interesting is that on the client side, Firebug tells me that the connection was dropped after 15 seconds. The JavaScript message loop is operated by a jQuery AJAX call, that has timeout=15000 parameter given: that.messageLoop = function () { var xsfr = that.readCookie("xsfr"); $.ajax({ url: '/client', type: "POST", data: {"_xsrf":xsfr,"action":"poll"}, async: true, cache: false, timeout: 15000, error: function (data) { setTimeout( that.messageLoop , 1000); console.log(data); }, success: function (data) { if (data) { try { eval(data); } catch(err) { $().toastmessage('showErrorToast', err.message); } } setTimeout( that.messageLoop , 10); } }); }; But on the server side, I see that the connection was dropped after 10.01 seconds. If I start 20 clients, then about every second poll request gets dropped. Thanks, Laszlo From godson.g at gmail.com Mon Sep 3 03:08:16 2012 From: godson.g at gmail.com (Godson Gera) Date: Mon, 3 Sep 2012 12:38:16 +0530 Subject: Twisted 12.2.0 released In-Reply-To: References: Message-ID: On Sat, Sep 1, 2012 at 7:17 PM, Ashwini Oruganti wrote: > On behalf of Twisted Matrix Laboratories, I am honored to announce the > release of Twisted 12.2. > > Congrats, Ashwini. adoptStreamConnection is much needed feature, happy to see that added to this release. -- Thanks & Regards, Godson Gera http://godson.in -------------- next part -------------- An HTML attachment was scrubbed... URL: From contropinion at gmail.com Mon Sep 3 04:18:45 2012 From: contropinion at gmail.com (contro opinion) Date: Mon, 3 Sep 2012 04:18:45 -0400 Subject: get the matched regular expression position in string. Message-ID: Here is a string : str1="ha,hihi,aaaaa,ok" I want to get the position of "," in the str1,Which can count 3,8,14. how can I get it in python ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Sep 3 04:33:57 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 03 Sep 2012 09:33:57 +0100 Subject: get the matched regular expression position in string. In-Reply-To: References: Message-ID: On 03/09/2012 09:18, contro opinion wrote: > Here is a string : > > str1="ha,hihi,aaaaa,ok" > > I want to get the position of "," in the str1,Which can count 3,8,14. > > how can I get it in python ? > Write some code using an appropriate string method. If it doesn't work put the minimum piece of code here that demonstrates the problem, what you expect to happen, what actually happened, and if appropriate the complete traceback. -- Cheers. Mark Lawrence. From clp2 at rebertia.com Mon Sep 3 04:36:12 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 3 Sep 2012 01:36:12 -0700 Subject: get the matched regular expression position in string. In-Reply-To: References: Message-ID: On Mon, Sep 3, 2012 at 1:18 AM, contro opinion wrote: > Subject: get the matched regular expression position in string. As is often the case in Python, string methods suffice. Particularly for something so simple, regexes aren't necessary. > Here is a string : > > str1="ha,hihi,aaaaa,ok" > > I want to get the position of "," in the str1,Which can count 3,8,14. Note that Python's indices start at 0. Your example output uses 1-based indices. > how can I get it in python ? def find_all(string, substr): start = 0 while True: try: pos = string.index(substr, start) except ValueError: break else: yield pos start = pos + 1 str1 = "ha,hihi,aaaaa,ok" print list(find_all(str1, ",")) #===> [2, 7, 13] In the future, I recommend reading the documentation for Python's string type: http://docs.python.org/library/stdtypes.html#string-methods What opinion are you contrary ("contro") to anyway? Regards, Chris From tjreedy at udel.edu Mon Sep 3 04:38:26 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 03 Sep 2012 04:38:26 -0400 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: On 9/3/2012 2:15 AM, Peter Otten wrote: > At least users of wide builds will see a decrease in memory use: Everyone saves because everyone uses large parts of the stdlib. When 3.3 start up in a Windows console, there are 56 modules in sys.modules. With Idle, there are over 130. All the identifiers, all the global, local, and attribute names are present as ascii-only strings. Now multiply that by some reasonable average, keeping in mind that __builtins__ alone has 148 names. Former narrow build users gain less space but also gain the elimination of buggy behavior. -- Terry Jan Reedy From jeanmichel at sequans.com Mon Sep 3 04:54:47 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 03 Sep 2012 10:54:47 +0200 Subject: Looking for an IPC solution In-Reply-To: <50410AD6.7080003@shopzeus.com> References: <50410AD6.7080003@shopzeus.com> Message-ID: <50447057.4030405@sequans.com> Laszlo Nagy wrote: > There are just so many IPC modules out there. I'm looking for a > solution for developing a new a multi-tier application. The core > application will be running on a single computer, so the IPC should be > using shared memory (or mmap) and have very short response times. But > there will be a tier that will hold application state for clients, and > there will be lots of clients. So that tier needs to go to different > computers. E.g. the same IPC should also be accessed over TCP/IP. Most > messages will be simple data structures, nothing complicated. The > ability to run on PyPy would, and also to run on both Windows and > Linux would be a plus. > > I have seen a stand alone cross platform IPC server before that could > serve "channels", and send/receive messages using these channels. But > I don't remember its name and now I cannot find it. Can somebody > please help? > > Thanks, > > Laszlo > http://pypi.python.org/pypi/execnet ? It sends/receives messages through channels, probably not the only one though. It requires only python installed on the remote machines. JM From vikas.choudhary at yahoo.co.in Mon Sep 3 06:01:21 2012 From: vikas.choudhary at yahoo.co.in (Vikas Kumar Choudhary) Date: Mon, 3 Sep 2012 18:01:21 +0800 (SGT) Subject: Time Bound Input in python Message-ID: <1346666481.56139.YahooMailNeo@web193102.mail.sg3.yahoo.com> Hi I though of taking time bound input from user in python using "input" command. it waits fro infinite time , but I want to limit the time after that user input should expire with none. Please help. ? Thanks & Regard's Vikas Kumar Choudhary Mobile:91-7838594971/9886793145 http://in.linkedin.com/pub/vikas-kumar-choudhary/b/890/9aa http://www.facebook.com/vikaskchoudhary (Yahoo,MSN-Hotmail,Skype) Messenger = vikas.choudhary Please?Add Me in Your Messenger List for Better Communication P??Please consider the environment before printing this e-mail Do not print this email unless it is absolutely necessary. Save papers, Save tree. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Note: This e-mail is confidential and may also be privileged, this is for the intended recipients only. If you are not the intended recipient, please delete the message and notify me immediately; you should not copy or use it for any purpose, nor disclose its contents to any other person. Notice:? All email and instant messages (including attachments) sent to or from This E-mail id , may be retained, monitored and/or reviewed, or authorized law enforcement personnel, without further notice or consent. ---------------------------------------------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From vlastimil.brom at gmail.com Mon Sep 3 07:36:01 2012 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 3 Sep 2012 13:36:01 +0200 Subject: get the matched regular expression position in string. In-Reply-To: References: Message-ID: 2012/9/3 contro opinion : > Here is a string : > str1="ha,hihi,aaaaa,ok" > I want to get the position of "," in the str1,Which can count 3,8,14. > how can I get it in python ? > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, you can use re.finditer to match all "," and the start() method of the respective matches; cf.: http://docs.python.org/library/re.html#match-objects >>> import re >>> [m.start() for m in re.finditer(r",", "ha,hihi,aaaaa,ok")] [2, 7, 13] >>> [The obtained indices are zero-based, as has already been mentioned.] hth, vbr From marco_u at nsgmail.com Mon Sep 3 08:32:15 2012 From: marco_u at nsgmail.com (Marco) Date: Mon, 03 Sep 2012 14:32:15 +0200 Subject: The opener parameter of Python 3 open() built-in Message-ID: Does anyone have an example of utilisation? From d at davea.name Mon Sep 3 09:05:42 2012 From: d at davea.name (Dave Angel) Date: Mon, 03 Sep 2012 09:05:42 -0400 Subject: The opener parameter of Python 3 open() built-in In-Reply-To: References: Message-ID: <5044AB26.7010200@davea.name> On 09/03/2012 08:32 AM, Marco wrote: > Does anyone have an example of utilisation? As of Python 3.2.3, there is no "opener" parameter in the open() function. http://docs.python.org/py3k/library/functions.html I don't know of any such parameter in earlier or later versions, but I could be wrong there. -- DaveA From lists at cheimes.de Mon Sep 3 09:29:05 2012 From: lists at cheimes.de (Christian Heimes) Date: Mon, 03 Sep 2012 15:29:05 +0200 Subject: The opener parameter of Python 3 open() built-in In-Reply-To: References: Message-ID: Am 03.09.2012 14:32, schrieb Marco: > Does anyone have an example of utilisation? The opener argument is a new 3.3 feature. For example you can use the feature to implement exclusive creation of a file to avoid symlink attacks. import os def opener(file, flags): return os.open(file, flags | os.O_EXCL) open("newfile", "w", opener=opener) From marco.buttu at gmail.com Mon Sep 3 09:33:23 2012 From: marco.buttu at gmail.com (Marco) Date: Mon, 03 Sep 2012 15:33:23 +0200 Subject: The opener parameter of Python 3 open() built-in In-Reply-To: References: Message-ID: <5044B1A3.7040300@nsgmail.com> On 09/03/2012 03:05 PM, Dave Angel wrote: >> Does anyone have an example of utilisation? > As of Python 3.2.3, there is no "opener" parameter in the open() function. > http://docs.python.org/py3k/library/functions.html > > I don't know of any such parameter in earlier or later versions, but I > could be wrong there. It's new in Python 3.3: http://docs.python.org/dev/library/functions.html#open From marco_u at nsgmail.com Mon Sep 3 09:33:23 2012 From: marco_u at nsgmail.com (Marco) Date: Mon, 03 Sep 2012 15:33:23 +0200 Subject: The opener parameter of Python 3 open() built-in References: Message-ID: <5044B1A3.7040300@nsgmail.com> On 09/03/2012 03:05 PM, Dave Angel wrote: >> Does anyone have an example of utilisation? > As of Python 3.2.3, there is no "opener" parameter in the open() function. > http://docs.python.org/py3k/library/functions.html > > I don't know of any such parameter in earlier or later versions, but I > could be wrong there. It's new in Python 3.3: http://docs.python.org/dev/library/functions.html#open From markrrivet at aol.com Mon Sep 3 10:12:11 2012 From: markrrivet at aol.com (Mark R Rivet) Date: Mon, 03 Sep 2012 10:12:11 -0400 Subject: simple client data base Message-ID: Hello all, I am learning to program in python. I have a need to make a program that can store, retrieve, add, and delete client data such as name, address, social, telephone number and similar information. This would be a small client database for my wife who has a home accounting business. I have been reading about lists, tuples, and dictionary data structures in python and I am confused as to which would be more appropriate for a simple database. I know that python has real database capabilities but I'm not there yet and would like to proceed with as simple a structure as possible. Can anyone give me some idea's or tell me which structure would be best to use? Maybe its a combination of structures? I need some help. Thanks for your help. From laureote-loic at hotmail.fr Mon Sep 3 10:21:52 2012 From: laureote-loic at hotmail.fr (=?iso-8859-1?B?bG/vYyBMYXVy6W90ZQ==?=) Date: Mon, 3 Sep 2012 16:21:52 +0200 Subject: simple client data base In-Reply-To: References: Message-ID: Hi, You can try gadfly ! This system is based on SQL. Lo?c > From: markrrivet at aol.com > Subject: simple client data base > Date: Mon, 3 Sep 2012 10:12:11 -0400 > To: python-list at python.org > > Hello all, I am learning to program in python. I have a need to make a > program that can store, retrieve, add, and delete client data such as > name, address, social, telephone number and similar information. This > would be a small client database for my wife who has a home accounting > business. > > I have been reading about lists, tuples, and dictionary data > structures in python and I am confused as to which would be more > appropriate for a simple database. > > I know that python has real database capabilities but I'm not there > yet and would like to proceed with as simple a structure as possible. > > Can anyone give me some idea's or tell me which structure would be > best to use? > > Maybe its a combination of structures? I need some help. > > Thanks for your help. > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.hellwig at gmail.com Mon Sep 3 10:27:14 2012 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Mon, 3 Sep 2012 07:27:14 -0700 (PDT) Subject: simple client data base In-Reply-To: References: Message-ID: <0ca44b62-6308-45ed-93ed-681978298ef7@googlegroups.com> On Monday, 3 September 2012 15:12:21 UTC+1, Manatee wrote: > Hello all, I am learning to program in python. I have a need to make a > > program that can store, retrieve, add, and delete client data such as > > name, address, social, telephone number and similar information. This > > would be a small client database for my wife who has a home accounting > > business. > > > > I have been reading about lists, tuples, and dictionary data > > structures in python and I am confused as to which would be more > > appropriate for a simple database. > > > > I know that python has real database capabilities but I'm not there > > yet and would like to proceed with as simple a structure as possible. > > > > Can anyone give me some idea's or tell me which structure would be > > best to use? > > > > Maybe its a combination of structures? I need some help. > > > > Thanks for your help. How about the half-way house, sqlite3 which comes with python? hth -- mph From rosuav at gmail.com Mon Sep 3 10:28:50 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Sep 2012 00:28:50 +1000 Subject: simple client data base In-Reply-To: References: Message-ID: On Tue, Sep 4, 2012 at 12:12 AM, Mark R Rivet wrote: > I have been reading about lists, tuples, and dictionary data > structures in python and I am confused as to which would be more > appropriate for a simple database. I think you're looking at this backwards. A database is for storing information on disk, but lists/tuples/dicts are for manipulating it in memory. You may also be needlessly reinventing the wheel. Aren't there already several million basic contact databases around? Why roll your own? ChrisA From atmb4u at gmail.com Mon Sep 3 10:29:46 2012 From: atmb4u at gmail.com (Anoop Thomas Mathew) Date: Mon, 3 Sep 2012 19:59:46 +0530 Subject: simple client data base In-Reply-To: References: Message-ID: Hi, You can make use of sqlite database also. And for the structure, you can create a single table and different columns for the fields like name, number etc. You can get more details over here. http://docs.python.org/library/sqlite3.html Thanks, Anoop Thomas Mathew atm ___ Life is short, Live it hard. On 3 September 2012 19:51, lo?c Laur?ote wrote: > > Hi, > > You can try gadfly ! > This system is based on SQL. > > Lo?c > * > *** > > > > > From: markrrivet at aol.com > > Subject: simple client data base > > Date: Mon, 3 Sep 2012 10:12:11 -0400 > > To: python-list at python.org > > > > > Hello all, I am learning to program in python. I have a need to make a > > program that can store, retrieve, add, and delete client data such as > > name, address, social, telephone number and similar information. This > > would be a small client database for my wife who has a home accounting > > business. > > > > I have been reading about lists, tuples, and dictionary data > > structures in python and I am confused as to which would be more > > appropriate for a simple database. > > > > I know that python has real database capabilities but I'm not there > > yet and would like to proceed with as simple a structure as possible. > > > > Can anyone give me some idea's or tell me which structure would be > > best to use? > > > > Maybe its a combination of structures? I need some help. > > > > Thanks for your help. > > -- > > http://mail.python.org/mailman/listinfo/python-list > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Sep 3 10:37:16 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 03 Sep 2012 15:37:16 +0100 Subject: simple client data base In-Reply-To: References: Message-ID: On 03/09/2012 15:12, Mark R Rivet wrote: > Hello all, I am learning to program in python. I have a need to make a > program that can store, retrieve, add, and delete client data such as > name, address, social, telephone number and similar information. This > would be a small client database for my wife who has a home accounting > business. > > I have been reading about lists, tuples, and dictionary data > structures in python and I am confused as to which would be more > appropriate for a simple database. > > I know that python has real database capabilities but I'm not there > yet and would like to proceed with as simple a structure as possible. > > Can anyone give me some idea's or tell me which structure would be > best to use? > > Maybe its a combination of structures? I need some help. > > Thanks for your help. > If you stick with the simple data structures at some point you're going to have to save them to disk with a module like pickle or shelve. IMHO using sqlite is a better option as it comes with Python. -- Cheers. Mark Lawrence. From __peter__ at web.de Mon Sep 3 10:50:14 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 03 Sep 2012 16:50:14 +0200 Subject: simple client data base References: Message-ID: Chris Angelico wrote: > You may also be needlessly reinventing the wheel. Aren't there already > several million basic contact databases around? Why roll your own? To learn a thing or two, and to stick it to the defeatists ;) From roy at panix.com Mon Sep 3 11:24:56 2012 From: roy at panix.com (Roy Smith) Date: Mon, 03 Sep 2012 11:24:56 -0400 Subject: Flexible string representation, unicode, typography, ... References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <50440de2$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <50440de2$0$29967$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > > Indexing is O(0) for any string. > > I think you mean O(1) for constant-time lookups. Why settle for constant-time, when you can have zero-time instead :-) From storchaka at gmail.com Mon Sep 3 11:26:02 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Mon, 03 Sep 2012 18:26:02 +0300 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <50440af0$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> <50440af0$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03.09.12 04:42, Steven D'Aprano wrote: > If you are *seriously* interested in debugging why string code is slower > for you, you can start by running the full suite of Python string > benchmarks: see the stringbench benchmark in the Tools directory of > source installations, or see here: > > http://hg.python.org/cpython/file/8ff2f4634ed8/Tools/stringbench http://hg.python.org/cpython/file/default/Tools/stringbench However, stringbench is not good tool to measure the effectiveness of new string representation, because it focuses mainly on ASCII strings and comparing strings with bytes. From emile at fenx.com Mon Sep 3 11:27:26 2012 From: emile at fenx.com (Emile van Sebille) Date: Mon, 03 Sep 2012 08:27:26 -0700 Subject: Time Bound Input in python In-Reply-To: <1346666481.56139.YahooMailNeo@web193102.mail.sg3.yahoo.com> References: <1346666481.56139.YahooMailNeo@web193102.mail.sg3.yahoo.com> Message-ID: On 9/3/2012 3:01 AM Vikas Kumar Choudhary said... > Hi > > I though of taking time bound input from user in python using "input" > command. > it waits fro infinite time , but I want to limit the time after that > user input should expire with none. > Please help. > Googling yields http://stackoverflow.com/questions/1335507/keyboard-input-with-timeout-in-python among others. Emile From oscar.j.benjamin at gmail.com Mon Sep 3 11:32:19 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 3 Sep 2012 16:32:19 +0100 Subject: simple client data base In-Reply-To: References: Message-ID: On 3 September 2012 15:12, Mark R Rivet wrote: > Hello all, I am learning to program in python. I have a need to make a > program that can store, retrieve, add, and delete client data such as > name, address, social, telephone number and similar information. This > would be a small client database for my wife who has a home accounting > business. > I would use the sqlite3 module for this (if I wasn't using gmail contacts). > I have been reading about lists, tuples, and dictionary data > structures in python and I am confused as to which would be more > appropriate for a simple database. > As already said by Chris these are the types that Python uses to represent data in memory, rather than on disk. There are a number of ways that you can use these to represent the information from your database. For example, you could use a dict of dicts: >>> contact_db = {} # empty dict >>> contact_db['john'] = {'alias':'john', 'name':'John Doe', 'email': ' john at example.com'} >>> contact_db['dave'] = {'alias':'dave', 'name':'Dave Doe', 'email': ' dave at example.com'} >>> contact_db {'dave': {'alias': 'dave', 'name': 'Dave Doe', 'email': 'dave at example.com'}, 'john': {'alias': 'john', 'name': 'John Doe', 'email': 'john at example.com'}} >>> contact_db['dave'] {'alias': 'dave', 'name': 'Dave Doe', 'email': 'dave at example.com'} >>> contact_db['dave']['email'] 'dave at example.com' I know that python has real database capabilities but I'm not there > yet and would like to proceed with as simple a structure as possible. > If you don't want to use real database capabilities you could save the data above into a csv file using the csv module: >>> import csv >>> with open('contacts.csv', 'wb') as f: ... writer = csv.DictWriter(f) ... writer.writelines(contact_db.values()) You can then reload the data with: >>> with open('contacts.csv', 'rb') as f: ... reader = csv.DictReader(f, ['alias', 'name', 'email']) ... new_contact_db = {} ... for row in reader: ... new_contact_db[row['alias']] = row ... >>> new_contact_db {'dave': {'alias': 'dave', 'name': 'Dave Doe', 'email': 'dave at example.com'}, 'john': {'alias': 'john', 'name': 'John Doe', 'email': 'john at example.com'}} >>> contact_db == new_contact_db True > > Can anyone give me some idea's or tell me which structure would be > best to use? > The above method for storing the data on disk is simple but not very safe. If you use it for your wife's business make sure that you are always keeping backups of the file. Preferably don't overwrite the file directly but write the data out to a separate file first and then rename the file (to avoid loss of data if the program has an error while writing). The obvious way to improve on the above is to use the sqlite3 module to store the data in an sqlite3 file instead of a csv file. There is one advantage to using the above over using an sqlite3 database which is that the data can be edited manually as a text file or using standard spreadsheet software if necessary. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From storchaka at gmail.com Mon Sep 3 11:41:50 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Mon, 03 Sep 2012 18:41:50 +0300 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <50440de2$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <50440de2$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03.09.12 04:54, Steven D'Aprano wrote: > This means that Python 3.3 will no longer have surrogate pairs. > > Am I right? As Terry said, basically, yes. Python 3.3 does not need in surrogate pairs, but does not prevent their creation. You can create a surrogate code (U+D800..U+DFFF) intentionally (as you can create a single accent modifier or other senseless alone charcode), but less likely that you will get them unintentionally. From storchaka at gmail.com Mon Sep 3 11:56:50 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Mon, 03 Sep 2012 18:56:50 +0300 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: On 03.09.12 09:15, Peter Otten wrote: > wxjmfauth at gmail.com wrote: >> Le dimanche 2 septembre 2012 14:01:18 UTC+2, Serhiy Storchaka a ?crit : > >>> Hmm, and with locale.strxfrm Python 3.3 20% slower than 3.2. >> >> With a memory gain = 0 since my text contains non-latin-1 characters! > > I can't confirm this. At least users of wide builds will see a decrease in > memory use: And only users of wide builds will see a 20% decrease in speed for this data (with longer strings Python 3.3 will outstrip Python 3.2). This happens because of the inevitable transformation UCS2 -> wchar_t and wchar_t -> UCS2 on platform with 4-bytes wchar_t. On Windows there should be no slowing down. From feliphil at gmx.net Mon Sep 3 12:03:27 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Mon, 3 Sep 2012 18:03:27 +0200 Subject: simple client data base References: Message-ID: <20120903180327.94ba442a44e4f26803de0747@gmx.net> > Hello all, I am learning to program in python. I have a need to make a > program that can store, retrieve, add, and delete client data such as > name, address, social, telephone number and similar information. This > would be a small client database for my wife who has a home accounting > business. Python imho would be in need of a really good accounting application as a "demonstrator" for its capabilities. ;-) > I have been reading about lists, tuples, and dictionary data > structures in python and I am confused as to which would be more > appropriate for a simple database. > > I know that python has real database capabilities but I'm not there > yet and would like to proceed with as simple a structure as possible. The list of Python frameworks for rapid development of desktop (i.e. non-Web) database applications currently contains: using PyQt (& Sqlalchemy): Pypapi: www.pypapi.org Camelot: www.python-camelot.com Qtalchemy: www.qtalchemy.org using PyGTK: Sqlkit: sqlkit.argolinux.org (also uses Sqlalchemy) Kiwi: www.async.com.br/projects/kiwi using wxPython: Dabo: www.dabodev.com Defis: sourceforge.net/projects/defis (Russian only) GNUe: www.gnuenterprise.org Pypapi, Camelot, Sqlkit and Dabo seem to be the most active and best documented/supported ones. Sqlalchemy (www.sqlalchemy.org) seems to be "quite useful" for working with databases. Those of the above mentioned frameworks that don't use it do so for historic reasons, because the corresponding project started before Sqlalchemy became known. If you want to rely on not losing your data, you might want to use PostgreSQL (www.postgresql.org) as a storage backend with any of these. Sincerely, Wolfgang P.S.: If anyone knows of frameworks not listed here, thanks for mailing me. From storchaka at gmail.com Mon Sep 3 12:06:14 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Mon, 03 Sep 2012 19:06:14 +0300 Subject: The opener parameter of Python 3 open() built-in In-Reply-To: References: Message-ID: On 03.09.12 16:29, Christian Heimes wrote: > Am 03.09.2012 14:32, schrieb Marco: >> Does anyone have an example of utilisation? > > The opener argument is a new 3.3 feature. For example you can use the > feature to implement exclusive creation of a file to avoid symlink attacks. Or you can use new dir_fd argument for same reason (or for performance). for root, dirs, files, rootfd in os.fwalk(topdir): def opener(file, flags): return os.open(file, flags, dir_fd=rootfd) for name in files: with open(name, "r", opener=opener) as f: ... From ian.g.kelly at gmail.com Mon Sep 3 14:33:29 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 3 Sep 2012 12:33:29 -0600 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> Message-ID: On Sun, Sep 2, 2012 at 6:00 AM, Serhiy Storchaka wrote: > On 02.09.12 12:52, Peter Otten wrote: >> >> Ian Kelly wrote: >> >>> Rewriting the example to use locale.strcoll instead: >> >> >>>>>> sorted(li, key=functools.cmp_to_key(locale.strcoll)) >> >> >> There is also locale.strxfrm() which you can use directly: >> >> sorted(li, key=locale.strxfrm) > > > Hmm, and with locale.strxfrm Python 3.3 20% slower than 3.2. Doh! In Python 3.3, strcoll and strxfrm are the same speed, so I guess that the actual optimization I'm seeing here is that in Python 3.3, cmp_to_key(strcoll) has been optimized to return strxfrm. From walterhurry at lavabit.com Mon Sep 3 15:02:08 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Mon, 3 Sep 2012 19:02:08 +0000 (UTC) Subject: simple client data base References: <20120903180327.94ba442a44e4f26803de0747@gmx.net> Message-ID: On Mon, 03 Sep 2012 18:03:27 +0200, Wolfgang Keller wrote: >> Hello all, I am learning to program in python. I have a need to make a >> program that can store, retrieve, add, and delete client data such as >> name, address, social, telephone number and similar information. This >> would be a small client database for my wife who has a home accounting >> business. > > > > Python imho would be in need of a really good accounting application as > a "demonstrator" for its capabilities. ;-) > > > >> I have been reading about lists, tuples, and dictionary data structures >> in python and I am confused as to which would be more appropriate for a >> simple database. >> >> I know that python has real database capabilities but I'm not there yet >> and would like to proceed with as simple a structure as possible. > > The list of Python frameworks for rapid development of desktop (i.e. > non-Web) database applications currently contains: > > using PyQt (& Sqlalchemy): > Pypapi: www.pypapi.org Camelot: www.python-camelot.com Qtalchemy: > www.qtalchemy.org > > using PyGTK: > Sqlkit: sqlkit.argolinux.org (also uses Sqlalchemy) > Kiwi: www.async.com.br/projects/kiwi > > using wxPython: > Dabo: www.dabodev.com Defis: sourceforge.net/projects/defis (Russian > only) > GNUe: www.gnuenterprise.org > > Pypapi, Camelot, Sqlkit and Dabo seem to be the most active and best > documented/supported ones. > > Sqlalchemy (www.sqlalchemy.org) seems to be "quite useful" for working > with databases. Those of the above mentioned frameworks that don't use > it do so for historic reasons, because the corresponding project started > before Sqlalchemy became known. > > If you want to rely on not losing your data, you might want to use > PostgreSQL (www.postgresql.org) as a storage backend with any of these. Personally, I wouldn't bother with SQLAlchemy for this. I'd just use Python as the front end, PostgreSQL for the database, and psycopg2 for the interface. From ian.g.kelly at gmail.com Mon Sep 3 15:29:35 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 3 Sep 2012 13:29:35 -0600 Subject: set and dict iteration In-Reply-To: <1567e8c7-a2bb-41f4-9be8-18e9f4d063cb@googlegroups.com> References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> <1567e8c7-a2bb-41f4-9be8-18e9f4d063cb@googlegroups.com> Message-ID: On Sun, Sep 2, 2012 at 11:43 AM, Aaron Brady wrote: > We could use a Python long object for the version index to prevent overflow. Combined with P. Rubin's idea to count the number of open iterators, most use cases still wouldn't exceed a single word comparison; we could reset the counter when there weren't any. We could use a Python long; I just don't think the extra overhead is justified in a data structure that is already highly optimized for speed. Incrementing and testing a C int is *much* faster than doing the same with a Python long. From bryanjugglercryptographer at yahoo.com Mon Sep 3 15:47:46 2012 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Mon, 3 Sep 2012 12:47:46 -0700 (PDT) Subject: tornado.web ioloop add_timeout eats CPU References: Message-ID: Laszlo Nagy wrote: [...] > And here is my problem. If I point 5 browsers to the server, then I get > 2% CPU load (Intel i5 2.8GHz on amd64 Linux). But why? Most of the time, > the server should be sleeping. cProfile tells this: > > ncalls tottime percall cumtime percall filename:lineno(function) > 1 0.000 0.000 845.146 845.146 :1() > 1135775 832.283 0.001 832.283 0.001 {method 'poll' of > 'select.epoll' objects} > > I have copied out the two relevant rows only. As you can see, total > runtime was 845 seconds, and 832 seconds were spent in "epoll". > Apparently, CPU load goes up linearly as I connect more clients. It > means that 50 connected clients would do 20% CPU load. Which is > ridiculous, because they don't do anything but wait for messages to be > processed. Something terribly wrong, but I cannot figure out what? What's wrong is the 1,135,775 calls to "method 'poll' of 'select.epoll' objects". With five browsers waiting for messages over 845 seconds, that works out to each waiting browser inducing 269 epolls per second. Almost equally important is what the problem is *not*. The problem is *not* spending the vast majority of time in epoll; that's *good* news. The problem is *not* that CPU load goes up linearly as we connect more clients. This is an efficiency problem, not a scaling problem. So what's the fix? I'm not a Tornado user; I don't have a patch. Obviously Laszlo's polling strategy is not performing, and the solution is to adopt the event-driven approach that epoll and Tornado do well. -Bryan From castironpi at gmail.com Mon Sep 3 16:04:23 2012 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 3 Sep 2012 13:04:23 -0700 (PDT) Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> <1567e8c7-a2bb-41f4-9be8-18e9f4d063cb@googlegroups.com> Message-ID: On Monday, September 3, 2012 2:30:24 PM UTC-5, Ian wrote: > On Sun, Sep 2, 2012 at 11:43 AM, Aaron Brady wrote: > > > We could use a Python long object for the version index to prevent overflow. Combined with P. Rubin's idea to count the number of open iterators, most use cases still wouldn't exceed a single word comparison; we could reset the counter when there weren't any. > > > > We could use a Python long; I just don't think the extra overhead is > > justified in a data structure that is already highly optimized for > > speed. Incrementing and testing a C int is *much* faster than doing > > the same with a Python long. I think the technique would require two python longs and a bool in the set, and a python long in the iterator. One long counts the number of existing (open) iterators. Another counts the version. The bool keeps track of whether an iterator has been created since the last modification, in which case the next modification requires incrementing the version and resetting the flag. From castironpi at gmail.com Mon Sep 3 16:04:23 2012 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 3 Sep 2012 13:04:23 -0700 (PDT) Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> <1567e8c7-a2bb-41f4-9be8-18e9f4d063cb@googlegroups.com> Message-ID: On Monday, September 3, 2012 2:30:24 PM UTC-5, Ian wrote: > On Sun, Sep 2, 2012 at 11:43 AM, Aaron Brady wrote: > > > We could use a Python long object for the version index to prevent overflow. Combined with P. Rubin's idea to count the number of open iterators, most use cases still wouldn't exceed a single word comparison; we could reset the counter when there weren't any. > > > > We could use a Python long; I just don't think the extra overhead is > > justified in a data structure that is already highly optimized for > > speed. Incrementing and testing a C int is *much* faster than doing > > the same with a Python long. I think the technique would require two python longs and a bool in the set, and a python long in the iterator. One long counts the number of existing (open) iterators. Another counts the version. The bool keeps track of whether an iterator has been created since the last modification, in which case the next modification requires incrementing the version and resetting the flag. From d at davea.name Mon Sep 3 16:27:38 2012 From: d at davea.name (Dave Angel) Date: Mon, 03 Sep 2012 16:27:38 -0400 Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> <1567e8c7-a2bb-41f4-9be8-18e9f4d063cb@googlegroups.com> Message-ID: <504512BA.5010809@davea.name> On 09/03/2012 04:04 PM, Aaron Brady wrote: > On Monday, September 3, 2012 2:30:24 PM UTC-5, Ian wrote: >> On Sun, Sep 2, 2012 at 11:43 AM, Aaron Brady wrote: >> >>> We could use a Python long object for the version index to prevent overflow. Combined with P. Rubin's idea to count the number of open iterators, most use cases still wouldn't exceed a single word comparison; we could reset the counter when there weren't any. >> >> >> We could use a Python long; I just don't think the extra overhead is >> >> justified in a data structure that is already highly optimized for >> >> speed. Incrementing and testing a C int is *much* faster than doing >> >> the same with a Python long. > I think the technique would require two python longs and a bool in the set, and a python long in the iterator. > > One long counts the number of existing (open) iterators. Another counts the version. The bool keeps track of whether an iterator has been created since the last modification, in which case the next modification requires incrementing the version and resetting the flag. I think you're over-engineering the problem. it's a bug if an iterator is used after some change is made to the set it's iterating over. We don't need to catch every possible instance of the bug, that's what testing is for. The point is to "probably" detect it, and for that, all we need is a counter in the set and a counter in the open iterator. Whenever changing the set, increment its count. And whenever iterating, check the two counters. if they don't agree, throw an exception, and destroy the iterator. i suppose that could be done with a flag, but it could just as easily be done by zeroing the pointer to the set. I'd figure a byte or two would be good enough for the counts, but a C uint would be somewhat faster, and wouldn't wrap as quickly. -- DaveA From dwightdhutto at gmail.com Mon Sep 3 17:25:49 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 3 Sep 2012 17:25:49 -0400 Subject: simple client data base In-Reply-To: References: <20120903180327.94ba442a44e4f26803de0747@gmx.net> Message-ID: If you're just starting to learn python/computer science, why not try setting up section fields in a file that you can parse, with your own database. Then you can parse through, append, delete, etc and this will show you the 'higher' level of db's. Plus, I don't think anyone has mentioned RDBM: http://en.wikipedia.org/wiki/Relational_database_management_system or these from python: www.python.org/dev/peps/pep-0249/ http://wiki.python.org/moin/DatabaseProgramming/ -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From vasudevram at gmail.com Mon Sep 3 17:43:19 2012 From: vasudevram at gmail.com (vasudevram) Date: Mon, 3 Sep 2012 14:43:19 -0700 (PDT) Subject: Looking for an IPC solution In-Reply-To: <20120901145535.53fd8d7d2e71b880d107266b@gmx.net> References: <20120901145535.53fd8d7d2e71b880d107266b@gmx.net> Message-ID: <5e9d5f7b-f96e-4670-9b49-1996b4ad5a1c@googlegroups.com> On Saturday, September 1, 2012 6:25:36 PM UTC+5:30, Wolfgang Keller wrote: > > There are just so many IPC modules out there. I'm looking for a > > > solution for developing a new a multi-tier application. The core > > > application will be running on a single computer, so the IPC should > > > be using shared memory (or mmap) and have very short response times. > > > > Probably the fastest I/RPC implementation for Python should be > > OmniOrbpy: > > > > http://omniorb.sourceforge.net/ > > > > It's cross-platform, language-independent and standard-(Corba-) > > compliant. > > > > > I have seen a stand alone cross platform IPC server before that could > > > serve "channels", and send/receive messages using these channels. But > > > I don't remember its name and now I cannot find it. Can somebody > > > please help? > > > > If it's just for "messaging", Spread should be interesting: > > > > http://www.spread.org/ > > > > Also cross-platform & language-independent. > > > > Sincerely, > > > > Wolfgang Though I'm not the OP, thanks for the info. Will put Spread on my stack to check out ... From storchaka at gmail.com Mon Sep 3 17:46:31 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Tue, 04 Sep 2012 00:46:31 +0300 Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27.08.12 22:17, Ian Kelly wrote: > May I > suggest an alternate approach? Internally tag each set or dict with a > "version", which is just a C int. Every time the hash table is > modified, increment the version. When an iterator is created, store > the current version on the iterator. When the iterator is advanced, > check that the iterator version matches the dict/set version. If > they're not equal, raise an error. Oh, I'm surprised that this strategy is not used yet. I was sure that it is used. From calderone.jeanpaul at gmail.com Mon Sep 3 18:09:26 2012 From: calderone.jeanpaul at gmail.com (calderone.jeanpaul at gmail.com) Date: Mon, 3 Sep 2012 15:09:26 -0700 (PDT) Subject: Async client for PostgreSQL? In-Reply-To: References: <50419A55.3080904@shopzeus.com> <5042434B.3010201@thieprojects.ch> Message-ID: <6cf8b825-8f94-4b82-9079-a55900f5f058@googlegroups.com> On Saturday, September 1, 2012 3:28:52 PM UTC-4, Laszlo Nagy wrote: > > Hi > > > > > > does running on tornado imply that you would not consider twisted > > > http://twistedmatrix.com ? > > > > > > If not, twisted has exactly this capability hiding long running > > > queries on whatever db's behind deferToThread(). > > All right, I was reading its documentation > > > > http://twistedmatrix.com/documents/10.1.0/api/twisted.internet.threads.deferToThread.html > > > > It doesn't tell too much about it: "Run a function in a thread and > > return the result as a Deferred.". > You can find more documentation here: http://twistedmatrix.com/documents/current/core/howto/threading.html Also, Twisted has dedicated APIs for interacting with databases asynchronously: http://twistedmatrix.com/documents/current/core/howto/rdbms.html Additionally, there is a non-blocking (rather than thread-based) implementation of the above API available for PostgreSQL: http://pypi.python.org/pypi/txpostgres > > > Run a function but in what thread? Does it create a new thread for every > > invocation? In that case, I don't want to use this. My example case: 10% > > from 100 requests/second deal with a database. But it does not mean that > > one db-related request will do a single db API call only. They will > > almost always do more: start transaction, parse and open query, fetch > > with cursor, close query, open another query etc. then commit > > transaction. 8 API calls to do a quick fetch + update (usually under > > 100msec, but it might be blocked by another transaction for a while...) > > So we are talking about 80 database API calls per seconds at least. It > > would be insane to initialize a new thread for each invocation. And > > wrapping these API calls into a single closure function is not useful > > either, because that function would not be able to safely access the > > state that is stored in the main thread. Unless you protet it with > > locks. But it is whole point of async I/O server: to avoid using slow > > locks, expensive threads and context switching. > > > > Maybe, deferToThread uses a thread pool? But it doesn't say much about > > it. (Am I reading the wrong documentation?) BTW I could try a version > > that uses a thread pool. > > > > It is sad, by the way. We have async I/O servers for Python that can be > > used for large number of clients, but most external modules/extensions > > do not support their I/O loops. Including the extension modules of the > > most popular databases. So yes, you can use Twisted or torandoweb until > > you do not want to call *some* API functions that are blocking. (By > > *some* I mean: much less blocking than non-blocking, but quite a few.) > > We also have synchronous Python servers, but we cannot get rid of the > > GIL, Python threads are expensive and slow, so they cannot be used for a > > large number of clients. And finally, we have messaging services/IPC > > like zeromq. They are probably the most expensive, but they scale very > > well. But you need more money to operate the underlying hardware. I'm > > starting to think that I did not get a quick answer because my use case > > (100 clients) fall into to the "heavy weight" category, and the solution > > is to invest more in the hardware. :-) > > > > Thanks, > > > > Laszlo From calderone.jeanpaul at gmail.com Mon Sep 3 18:09:26 2012 From: calderone.jeanpaul at gmail.com (calderone.jeanpaul at gmail.com) Date: Mon, 3 Sep 2012 15:09:26 -0700 (PDT) Subject: Async client for PostgreSQL? In-Reply-To: References: <50419A55.3080904@shopzeus.com> <5042434B.3010201@thieprojects.ch> Message-ID: <6cf8b825-8f94-4b82-9079-a55900f5f058@googlegroups.com> On Saturday, September 1, 2012 3:28:52 PM UTC-4, Laszlo Nagy wrote: > > Hi > > > > > > does running on tornado imply that you would not consider twisted > > > http://twistedmatrix.com ? > > > > > > If not, twisted has exactly this capability hiding long running > > > queries on whatever db's behind deferToThread(). > > All right, I was reading its documentation > > > > http://twistedmatrix.com/documents/10.1.0/api/twisted.internet.threads.deferToThread.html > > > > It doesn't tell too much about it: "Run a function in a thread and > > return the result as a Deferred.". > You can find more documentation here: http://twistedmatrix.com/documents/current/core/howto/threading.html Also, Twisted has dedicated APIs for interacting with databases asynchronously: http://twistedmatrix.com/documents/current/core/howto/rdbms.html Additionally, there is a non-blocking (rather than thread-based) implementation of the above API available for PostgreSQL: http://pypi.python.org/pypi/txpostgres > > > Run a function but in what thread? Does it create a new thread for every > > invocation? In that case, I don't want to use this. My example case: 10% > > from 100 requests/second deal with a database. But it does not mean that > > one db-related request will do a single db API call only. They will > > almost always do more: start transaction, parse and open query, fetch > > with cursor, close query, open another query etc. then commit > > transaction. 8 API calls to do a quick fetch + update (usually under > > 100msec, but it might be blocked by another transaction for a while...) > > So we are talking about 80 database API calls per seconds at least. It > > would be insane to initialize a new thread for each invocation. And > > wrapping these API calls into a single closure function is not useful > > either, because that function would not be able to safely access the > > state that is stored in the main thread. Unless you protet it with > > locks. But it is whole point of async I/O server: to avoid using slow > > locks, expensive threads and context switching. > > > > Maybe, deferToThread uses a thread pool? But it doesn't say much about > > it. (Am I reading the wrong documentation?) BTW I could try a version > > that uses a thread pool. > > > > It is sad, by the way. We have async I/O servers for Python that can be > > used for large number of clients, but most external modules/extensions > > do not support their I/O loops. Including the extension modules of the > > most popular databases. So yes, you can use Twisted or torandoweb until > > you do not want to call *some* API functions that are blocking. (By > > *some* I mean: much less blocking than non-blocking, but quite a few.) > > We also have synchronous Python servers, but we cannot get rid of the > > GIL, Python threads are expensive and slow, so they cannot be used for a > > large number of clients. And finally, we have messaging services/IPC > > like zeromq. They are probably the most expensive, but they scale very > > well. But you need more money to operate the underlying hardware. I'm > > starting to think that I did not get a quick answer because my use case > > (100 clients) fall into to the "heavy weight" category, and the solution > > is to invest more in the hardware. :-) > > > > Thanks, > > > > Laszlo From castironpi at gmail.com Mon Sep 3 20:24:02 2012 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 3 Sep 2012 17:24:02 -0700 (PDT) Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> <1567e8c7-a2bb-41f4-9be8-18e9f4d063cb@googlegroups.com> Message-ID: On Monday, September 3, 2012 3:28:28 PM UTC-5, Dave Angel wrote: > On 09/03/2012 04:04 PM, Aaron Brady wrote: > > > On Monday, September 3, 2012 2:30:24 PM UTC-5, Ian wrote: > > >> On Sun, Sep 2, 2012 at 11:43 AM, Aaron Brady wrote: > > >> > > >>> We could use a Python long object for the version index to prevent overflow. Combined with P. Rubin's idea to count the number of open iterators, most use cases still wouldn't exceed a single word comparison; we could reset the counter when there weren't any. > > >> > > >> > > >> We could use a Python long; I just don't think the extra overhead is > > >> > > >> justified in a data structure that is already highly optimized for > > >> > > >> speed. Incrementing and testing a C int is *much* faster than doing > > >> > > >> the same with a Python long. > > > I think the technique would require two python longs and a bool in the set, and a python long in the iterator. > > > > > > One long counts the number of existing (open) iterators. Another counts the version. The bool keeps track of whether an iterator has been created since the last modification, in which case the next modification requires incrementing the version and resetting the flag. > > > > I think you're over-engineering the problem. it's a bug if an iterator > > is used after some change is made to the set it's iterating over. We > > don't need to catch every possible instance of the bug, that's what > > testing is for. The point is to "probably" detect it, and for that, all > > we need is a counter in the set and a counter in the open iterator. > > Whenever changing the set, increment its count. And whenever iterating, > > check the two counters. if they don't agree, throw an exception, and > > destroy the iterator. i suppose that could be done with a flag, but it > > could just as easily be done by zeroing the pointer to the set. > > > > I'd figure a byte or two would be good enough for the counts, but a C > > uint would be somewhat faster, and wouldn't wrap as quickly. > > > > -- > > > > DaveA Hi D. Angel, The serial index constantly reminds me of upper limits. I have the same problem with PHP arrays, though it's not a problem with the language itself. The linked list doesn't have a counter, it invalidates iterators when a modification is made, therefore it's the "correct" structure in my interpretation. But it does seem more precarious comparatively, IMHO. Both strategies solve the problem I posed originally, they both involve trade-offs, and it's too late to include either in 3.3.0. From castironpi at gmail.com Mon Sep 3 20:24:02 2012 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 3 Sep 2012 17:24:02 -0700 (PDT) Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> <1567e8c7-a2bb-41f4-9be8-18e9f4d063cb@googlegroups.com> Message-ID: On Monday, September 3, 2012 3:28:28 PM UTC-5, Dave Angel wrote: > On 09/03/2012 04:04 PM, Aaron Brady wrote: > > > On Monday, September 3, 2012 2:30:24 PM UTC-5, Ian wrote: > > >> On Sun, Sep 2, 2012 at 11:43 AM, Aaron Brady wrote: > > >> > > >>> We could use a Python long object for the version index to prevent overflow. Combined with P. Rubin's idea to count the number of open iterators, most use cases still wouldn't exceed a single word comparison; we could reset the counter when there weren't any. > > >> > > >> > > >> We could use a Python long; I just don't think the extra overhead is > > >> > > >> justified in a data structure that is already highly optimized for > > >> > > >> speed. Incrementing and testing a C int is *much* faster than doing > > >> > > >> the same with a Python long. > > > I think the technique would require two python longs and a bool in the set, and a python long in the iterator. > > > > > > One long counts the number of existing (open) iterators. Another counts the version. The bool keeps track of whether an iterator has been created since the last modification, in which case the next modification requires incrementing the version and resetting the flag. > > > > I think you're over-engineering the problem. it's a bug if an iterator > > is used after some change is made to the set it's iterating over. We > > don't need to catch every possible instance of the bug, that's what > > testing is for. The point is to "probably" detect it, and for that, all > > we need is a counter in the set and a counter in the open iterator. > > Whenever changing the set, increment its count. And whenever iterating, > > check the two counters. if they don't agree, throw an exception, and > > destroy the iterator. i suppose that could be done with a flag, but it > > could just as easily be done by zeroing the pointer to the set. > > > > I'd figure a byte or two would be good enough for the counts, but a C > > uint would be somewhat faster, and wouldn't wrap as quickly. > > > > -- > > > > DaveA Hi D. Angel, The serial index constantly reminds me of upper limits. I have the same problem with PHP arrays, though it's not a problem with the language itself. The linked list doesn't have a counter, it invalidates iterators when a modification is made, therefore it's the "correct" structure in my interpretation. But it does seem more precarious comparatively, IMHO. Both strategies solve the problem I posed originally, they both involve trade-offs, and it's too late to include either in 3.3.0. From steve+comp.lang.python at pearwood.info Mon Sep 3 20:53:19 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Sep 2012 00:53:19 GMT Subject: Flexible string representation, unicode, typography, ... References: <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <2a12ba52-232a-41b7-a906-1ec379bbddd7@googlegroups.com> <50440af0$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <504550ff$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 03 Sep 2012 18:26:02 +0300, Serhiy Storchaka wrote: > On 03.09.12 04:42, Steven D'Aprano wrote: >> If you are *seriously* interested in debugging why string code is >> slower for you, you can start by running the full suite of Python >> string benchmarks: see the stringbench benchmark in the Tools directory >> of source installations, or see here: >> >> http://hg.python.org/cpython/file/8ff2f4634ed8/Tools/stringbench > > http://hg.python.org/cpython/file/default/Tools/stringbench > > However, stringbench is not good tool to measure the effectiveness of > new string representation, because it focuses mainly on ASCII strings > and comparing strings with bytes. But it is a good place to start, so you can develop unicode benchmarks. -- Steven From steve+comp.lang.python at pearwood.info Mon Sep 3 21:13:09 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Sep 2012 01:13:09 GMT Subject: The opener parameter of Python 3 open() built-in References: Message-ID: <504555a5$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 03 Sep 2012 15:29:05 +0200, Christian Heimes wrote: > Am 03.09.2012 14:32, schrieb Marco: >> Does anyone have an example of utilisation? > > The opener argument is a new 3.3 feature. For example you can use the > feature to implement exclusive creation of a file to avoid symlink > attacks. > > import os > > def opener(file, flags): > return os.open(file, flags | os.O_EXCL) > > open("newfile", "w", opener=opener) Why does the open builtin need this added complexity? Why not just call os.open directly? Or for more complex openers, just call the opener directly? What is the rationale for complicating open instead of telling people to just call their opener directly? -- Steven From steve+comp.lang.python at pearwood.info Mon Sep 3 21:26:35 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Sep 2012 01:26:35 GMT Subject: set and dict iteration References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> <1567e8c7-a2bb-41f4-9be8-18e9f4d063cb@googlegroups.com> Message-ID: <504558cb$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 03 Sep 2012 13:04:23 -0700, Aaron Brady wrote: > On Monday, September 3, 2012 2:30:24 PM UTC-5, Ian wrote: >> On Sun, Sep 2, 2012 at 11:43 AM, Aaron Brady >> wrote: >> >> > We could use a Python long object for the version index to prevent >> > overflow. Combined with P. Rubin's idea to count the number of open >> > iterators, most use cases still wouldn't exceed a single word >> > comparison; we could reset the counter when there weren't any. >> >> We could use a Python long; I just don't think the extra overhead is >> justified in a data structure that is already highly optimized for >> speed. Incrementing and testing a C int is *much* faster than doing >> the same with a Python long. > > I think the technique would require two python longs and a bool in the > set, and a python long in the iterator. > > One long counts the number of existing (open) iterators. Another counts > the version. The bool keeps track of whether an iterator has been > created since the last modification, in which case the next modification > requires incrementing the version and resetting the flag. I think that is over-engineered and could be the difference between having the patch accepted and having it rejected. After all, many people will argue that the existing solution to the problem is good enough. Dicts are extremely common, and your patch increases both the memory usage of every dict, and the overhead of every write operation (__setitem__, __delitem__, update). Only a very few dicts will actually need this overhead, for the rest it is waste. It is important to keep that waste to a minimum or risk having the patch rejected. An unsigned C int can count up to 4,294,967,295. I propose that you say that is enough iterators for anyone, and use a single, simple, version counter in the dict and the iterator. If somebody exceeds that many iterators to a single dict or set, and the version field overflows by exactly 2**32 versions, the results are no worse than they are now. You won't be introducing any new bugs. Complicating the solution is, in my opinion, unnecessary. Why should every set and dict carry the cost of incrementing TWO Python longs and a flag when just a single C int is sufficient for all realistic use-cases? The opportunity for failure is extremely narrow: - I must have an iterator over a dict or set; - and I must have paused the iteration in some way; - and then I must create exactly 2**32 other iterators to the same dict or set; - and at some point modify the dict or set - and then restart the first iterator at which point some items returned by the iterator *may* be duplicated or skipped (depends on the nature of the modifications). -- Steven From contropinion at gmail.com Mon Sep 3 21:47:57 2012 From: contropinion at gmail.com (contro opinion) Date: Mon, 3 Sep 2012 21:47:57 -0400 Subject: is there history command in python? Message-ID: in bash ,history command can let me know every command which i execute in history, is there a same command in python console?if there is no,how can i know the historical inputs? it is not convenient to use direction key( up, or down arrow key) to see my historical inputs. i want an another convenient method. -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Mon Sep 3 21:50:57 2012 From: d at davea.name (Dave Angel) Date: Mon, 03 Sep 2012 21:50:57 -0400 Subject: set and dict iteration In-Reply-To: <504558cb$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> <1567e8c7-a2bb-41f4-9be8-18e9f4d063cb@googlegroups.com> <504558cb$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50455E81.1000101@davea.name> On 09/03/2012 09:26 PM, Steven D'Aprano wrote: > On Mon, 03 Sep 2012 13:04:23 -0700, Aaron Brady wrote: > >> >> >> I think the technique would require two python longs and a bool in the >> set, and a python long in the iterator. >> >> One long counts the number of existing (open) iterators. Another counts >> the version. The bool keeps track of whether an iterator has been >> created since the last modification, in which case the next modification >> requires incrementing the version and resetting the flag. > I think that is over-engineered and could be the difference between > having the patch accepted and having it rejected. After all, many people > will argue that the existing solution to the problem is good enough. > > Dicts are extremely common, and your patch increases both the memory > usage of every dict, and the overhead of every write operation > (__setitem__, __delitem__, update). Only a very few dicts will actually > need this overhead, for the rest it is waste. It is important to keep > that waste to a minimum or risk having the patch rejected. > > An unsigned C int can count up to 4,294,967,295. I propose that you say > that is enough iterators for anyone, and use a single, simple, version > counter in the dict and the iterator. If somebody exceeds that many > iterators to a single dict or set, I think you have the count confused. it has to be a count of how many changes have been made to the dict or set, not how many iterators exist. > and the version field overflows by > exactly 2**32 versions, the results are no worse than they are now. You > won't be introducing any new bugs. > > Complicating the solution is, in my opinion, unnecessary. Why should > every set and dict carry the cost of incrementing TWO Python longs and a > flag when just a single C int is sufficient for all realistic use-cases? > > The opportunity for failure is extremely narrow: > > - I must have an iterator over a dict or set; > - and I must have paused the iteration in some way; > - and then I must create exactly 2**32 other iterators to the > same dict or set; > - and at some point modify the dict or set > - and then restart the first iterator > > at which point some items returned by the iterator *may* be duplicated or > skipped (depends on the nature of the modifications). > > I agree with almost your entire point, exact that the place where it would fail to detect a bug is when somebody has modified the dict exactly 2**32 times while an iterator is paused. See my own response, of 4:27pm. (my time). -- DaveA From roy at panix.com Mon Sep 3 21:54:01 2012 From: roy at panix.com (Roy Smith) Date: Mon, 03 Sep 2012 21:54:01 -0400 Subject: Comparing strings from the back? Message-ID: There's been a bunch of threads lately about string implementations, and that got me thinking (which is often a dangerous thing). Let's assume you're testing two strings for equality. You've already done the obvious quick tests (i.e they're the same length), and you're down to the O(n) part of comparing every character. I'm wondering if it might be faster to start at the ends of the strings instead of at the beginning? If the strings are indeed equal, it's the same amount of work starting from either end. But, if it turns out that for real-life situations, the ends of strings have more entropy than the beginnings, the odds are you'll discover that they're unequal quicker by starting at the end. It doesn't seem un-plausible that this is the case. For example, most of the filenames I work with begin with "/home/roy/". Most of the strings I use as memcache keys have one of a small number of prefixes. Most of the strings I use as logger names have common leading substrings. Things like credit card and telephone numbers tend to have much more entropy in the trailing digits. On the other hand, hostnames (and thus email addresses) exhibit the opposite pattern. Anyway, it's just a thought. Has anybody studied this for real-life usage patterns? I'm also not sure how this work with all the possible UCS/UTF encodings. With some of them, you may get the encoding semantics wrong if you don't start from the front. From steve+comp.lang.python at pearwood.info Mon Sep 3 21:59:16 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Sep 2012 01:59:16 GMT Subject: set and dict iteration References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> <1567e8c7-a2bb-41f4-9be8-18e9f4d063cb@googlegroups.com> <504558cb$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50456073$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 03 Sep 2012 21:50:57 -0400, Dave Angel wrote: > On 09/03/2012 09:26 PM, Steven D'Aprano wrote: >> An unsigned C int can count up to 4,294,967,295. I propose that you say >> that is enough iterators for anyone, and use a single, simple, version >> counter in the dict and the iterator. If somebody exceeds that many >> iterators to a single dict or set, > > I think you have the count confused. it has to be a count of how many > changes have been made to the dict or set, not how many iterators exist. Oops, yes you are absolutely right. It's a version number, not a count of iterators. -- Steven From dwightdhutto at gmail.com Mon Sep 3 22:06:44 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 3 Sep 2012 22:06:44 -0400 Subject: Comparing strings from the back? In-Reply-To: References: Message-ID: On Mon, Sep 3, 2012 at 9:54 PM, Roy Smith wrote: > There's been a bunch of threads lately about string implementations, and > that got me t > > On > hinking (which is often a dangerous thing). > > Let's assume you're testing two strings for equality. You've already > done the obvious quick tests (i.e they're the same length), and you're > down to the O(n) part of comparing every character. > > I'm wondering if it might be faster to start at the ends of the strings > instead of at the beginning? If the strings are indeed equal, it's the > same amount of work starting from either end. But, if it turns out that > for real-life situations, the ends of strings have more entropy than the > beginnings, the odds are you'll discover that they're unequal quicker by > starting at the end. > > It doesn't seem un-plausible that this is the case. For example, most > of the filenames I work with begin with "/home/roy/". Most of the > strings I use as memcache keys have one of a small number of prefixes. > Most of the strings I use as logger names have common leading > substrings. Things like credit card and telephone numbers tend to have > much more entropy in the trailing digits. > > On the other hand, hostnames (and thus email addresses) exhibit the > opposite pattern. > > Anyway, it's just a thought. Has anybody studied this for real-life > usage patterns? > > I'm also not sure how this work with all the possible UCS/UTF encodings. > With some of them, you may get the encoding semantics wrong if you don't > start from the front. > -- > http://mail.python.org/mailman/listinfo/python-list > First include len(string)/2, in order to include starting at the center of the string, and threading/weaving by 2 processes out. import timeit do the the rest, and see which has the fastest time. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Sep 3 22:07:22 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Sep 2012 12:07:22 +1000 Subject: Comparing strings from the back? In-Reply-To: References: Message-ID: On Tue, Sep 4, 2012 at 11:54 AM, Roy Smith wrote: > I'm wondering if it might be faster to start at the ends of the strings > instead of at the beginning? > I'm also not sure how this work with all the possible UCS/UTF encodings. > With some of them, you may get the encoding semantics wrong if you don't > start from the front. No problem there; Python uses only fixed-width encodings. Also, any canonical encoding can be safely compared byte-for-byte; two identical Unicode strings will be bit-wise identical in (say) UTF-8. There's issues of cache locality and such that quite possibly mean it's not going to be faster overall, but it wouldn't be difficult to tweak the Python sources, recompile, and run some tests. I'm sure python-dev or python-list will be most happy to discuss some benchmark figures! ChrisA From steve+comp.lang.python at pearwood.info Mon Sep 3 22:17:30 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Sep 2012 02:17:30 GMT Subject: Comparing strings from the back? References: Message-ID: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 03 Sep 2012 21:54:01 -0400, Roy Smith wrote: > Let's assume you're testing two strings for equality. You've already > done the obvious quick tests (i.e they're the same length), and you're > down to the O(n) part of comparing every character. > > I'm wondering if it might be faster to start at the ends of the strings > instead of at the beginning? If the strings are indeed equal, it's the > same amount of work starting from either end. But, if it turns out that > for real-life situations, the ends of strings have more entropy than the > beginnings, the odds are you'll discover that they're unequal quicker by > starting at the end. And if the strings have the same end and different beginnings: running jumping cooking then you'll find out quicker by starting at the beginning. No general-purpose string comparison operator can make assumptions about the content of the strings, like "they are nearly always pathnames on Unix-like systems like /home/user/x and /home/user/y". I suppose you could have two different operators, == for "test from the front" and === for "test from the back", and push that decision onto the user, who will then spend hours angsting about the "most efficient" equality test and days painstakingly profiling his data to save four nanoseconds at runtime. Besides, then somebody will say "Yes, but what about the cases where the prefix and the suffix are both equal, but the middle will be different?" and propose a third string-equality operator ==== and then there will be bloodshed. On average, string equality needs to check half the characters in the string. Any individual comparisons may require fewer, or more, than that, but whichever way you scan the string, some comparisons will take more and some will take fewer. With no general way of telling ahead of time which will be which, on average you can't do better than O(N/2) and no complexity justification for picking "start from the end" from "start from the start". -- Steven From aldrich.demata at gmail.com Mon Sep 3 22:21:32 2012 From: aldrich.demata at gmail.com (Aldrich DeMata) Date: Mon, 3 Sep 2012 22:21:32 -0400 Subject: is there history command in python? In-Reply-To: References: Message-ID: Look at the readline module or use ipython. Aldrich On Mon, Sep 3, 2012 at 9:47 PM, contro opinion wrote: > in bash ,history command can let me know every command which i execute in > history, > is there a same command in python console?if there is no,how can i know > the historical inputs? > it is not convenient to use direction key( up, or down arrow key) to see > my historical inputs. > i want an another convenient method. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From PointedEars at web.de Mon Sep 3 22:25:14 2012 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Tue, 04 Sep 2012 04:25:14 +0200 Subject: simple client data base References: Message-ID: <1454469.9HWcpyvaek@PointedEars.de> Mark R Rivet wrote: > Hello all, I am learning to program in python. I have a need to make a > program that can store, retrieve, add, and delete client data such as > name, address, social, telephone number and similar information. This > would be a small client database for my wife who has a home accounting > business. > > I have been reading about lists, tuples, and dictionary data > structures in python and I am confused as to which would be more > appropriate for a simple database. > > I know that python has real database capabilities but I'm not there > yet and would like to proceed with as simple a structure as possible. > > Can anyone give me some idea's or tell me which structure would be > best to use? > > Maybe its a combination of structures? I need some help. The data types that would choose are defined by your requirements and how well a data type meets your requirements. I can imagine: In a database you would want quick access to data. You would want to access fields primarily by name. You would also want to filter data by various criteria. Therefore, it appears to me that it would be best if your records were dictionaries or dictionary-like objects, and your recordsets were lists of records, like so #!/usr/bin/env python3 from datetime import date data = [ { 'lastname': 'Doe', 'firstname': 'John', 'sn': '123-451-671-890', 'birthdata': date(2000, 1, 2) }, { 'lastname': 'Doe', 'firstname': 'Jane', 'sn': '409-212-582-452', 'birthdata': date(2001, 2, 3) }, ] - You could quickly access the second record with data[1]. - You could access the 'lastname' field of the second record with data[1]['lastname'] - You could get a list of records where the person is born before 2001 CE with filter(lambda record: record['birthdate'] < date(2001, 1, 1), data) The advantage of dictionaries over dictionary-like objects is that they are easily extensible and that the memory footprint is probably lower (CMIIW); the disadvantage is slightly more complicated syntax and that you have to keep track of the keys. Therefore, you might want to consider instantiating a Record class instead; in its simplest form: class Record(object): def __init__(self, lastname, firstname, sn=None, birthdate=None): self.lastname = lastname self.firstname = firstname self.sn = str(sn) self.birthdate = birthdate data = [ Record(lastname='Doe', firstname='John', sn='123-451-671-890', birthdate=date(2000, 1, 2)), Record(lastname='Doe', firstname='Jane', sn='409-212-582-452', birthdate=date(2001, 2, 3)) ] - You could access the 'lastname' property of the second record with data[1].lastname - You get a list of records where the person is born before 2001 CE with list(filter(lambda record: record.birthdate < date(2001, 1, 1), data)) (in Python 2.x without list()) However, if you want your program to manipulate the data *persistently*. as it will probably be needed for business, you will need to also store it somewhere else than in the volatile memory in which these data structures are usually stored. The most simple way would be to store and parse the string representation of the objects. Production-quality implementations of those and other concepts already exist, of course, but using something finished and polished does not provide as much learning experience. HTH -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail. From dwightdhutto at gmail.com Mon Sep 3 22:27:03 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 3 Sep 2012 22:27:03 -0400 Subject: is there history command in python? In-Reply-To: References: Message-ID: Google can help tremendously, if you use it correctly: Used search term 'python console remember history', and got https://www.google.com/search?client=ubuntu&channel=fs&q=python+console+remember+history&ie=utf-8&oe=utf-8, and the first one listed is below: http://stackoverflow.com/questions/947810/how-to-save-a-python-interactive-session > > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at tombstonezero.net Tue Sep 4 00:56:51 2012 From: dan at tombstonezero.net (Dan Sommers) Date: Mon, 3 Sep 2012 21:56:51 -0700 Subject: Comparing strings from the back? In-Reply-To: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120904045651.GB4703@particle> On 2012-09-04 at 02:17:30 +0000, Steven D'Aprano wrote: > Besides, then somebody will say "Yes, but what about the cases where > the prefix and the suffix are both equal, but the middle will be > different?" and propose a third string-equality operator ==== and > then there will be bloodshed. Lisp has several equality forms, although they're for different kinds or levels of equality rather than for different algorithms for determining that equality. I imagine that a discussion similar to this one spawned many of those forms. I agree with Steven: decisions such as this belong to the application developer, not the standard library. Don't forget the fourth string-equality operator for case-insensitive comparisons and the fifth string-equality operator for strings that are likely to be palindromes. That said, if I really wanted bloodshed, I would propose = for the third string-equality operator! ;-) Dan From ben+python at benfinney.id.au Tue Sep 4 01:12:48 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 04 Sep 2012 15:12:48 +1000 Subject: The opener parameter of Python 3 open() built-in References: <504555a5$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87bohm8j73.fsf@benfinney.id.au> Dennis Lee Bieber writes: > On 04 Sep 2012 01:13:09 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > > What is the rationale for complicating [the builtin] open instead of > > telling people to just call their opener directly? > > To avoid the new syntax would mean coding the example as > > f = os.fdopen(os.open("newfile", flags | os.O_EXCL), "w") > > which does NOT look any cleaner to me... Especially not if "opener" is > to be used in more than one location. Exactly. That's not what was asked, though. Steven asked why not call the opener. So, having written the opener: > On Mon, 03 Sep 2012 15:29:05 +0200, Christian Heimes wrote: > > import os > > > > def opener(file, flags): > > return os.open(file, flags | os.O_EXCL) why not call that directly? f = opener(file, flags) It certainly is cleaner than either of the alternatives so far, and it doesn't add a parameter to the builtin. > Furthermore, using "opener" could allow for a localized change to > affect all open statements in the module -- change file path, open for > string I/O rather than file I/O, etc. I don't know of any real-life code which would be significantly improved by that. Can you point us to some? -- \ ?I find the whole business of religion profoundly interesting. | `\ But it does mystify me that otherwise intelligent people take | _o__) it seriously.? ?Douglas Adams | Ben Finney From tjreedy at udel.edu Tue Sep 4 01:13:18 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 04 Sep 2012 01:13:18 -0400 Subject: Comparing strings from the back? In-Reply-To: References: Message-ID: On 9/3/2012 9:54 PM, Roy Smith wrote: > There's been a bunch of threads lately about string implementations, and > that got me thinking (which is often a dangerous thing). > > Let's assume you're testing two strings for equality. You've already > done the obvious quick tests (i.e they're the same length), and you're > down to the O(n) part of comparing every character. > > I'm wondering if it might be faster to start at the ends of the strings > instead of at the beginning? I posted the 3.3 str (in)equality compare a few days ago. It first compares length and then kind, then the actual bytes in whatever chunks. If the latter uses the C/system mem compare, that is faster than anything coded in Python or even C. -- Terry Jan Reedy From ben+python at benfinney.id.au Tue Sep 4 01:20:31 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 04 Sep 2012 15:20:31 +1000 Subject: The opener parameter of Python 3 open() built-in References: <504555a5$0$29978$c3e8da3$5496439d@news.astraweb.com> <87bohm8j73.fsf@benfinney.id.au> Message-ID: <877gsa8iu8.fsf@benfinney.id.au> Ben Finney writes: > So, having written the opener: > > > On Mon, 03 Sep 2012 15:29:05 +0200, Christian Heimes wrote: > > > import os > > > > > > def opener(file, flags): > > > return os.open(file, flags | os.O_EXCL) > > why not call that directly? > > f = opener(file, flags) Ah, because that returns the file descriptor, not the file. I see. -- \ ?If nature has made any one thing less susceptible than all | `\ others of exclusive property, it is the action of the thinking | _o__) power called an idea? ?Thomas Jefferson, 1813-08-13 | Ben Finney From steve+comp.lang.python at pearwood.info Tue Sep 4 01:25:27 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Sep 2012 05:25:27 GMT Subject: The opener parameter of Python 3 open() built-in References: <504555a5$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <504590c6$0$29977$c3e8da3$5496439d@news.astraweb.com> On Mon, 03 Sep 2012 23:19:51 -0400, Dennis Lee Bieber wrote: > On 04 Sep 2012 01:13:09 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > > > >> Why does the open builtin need this added complexity? Why not just call >> os.open directly? Or for more complex openers, just call the opener >> directly? >> > Because os.open() returns a low-level file descriptor, not a > Python file object? Good point. But you can wrap the call to os.open, as you mention below. The only complication is that you have to give the mode twice, converting between low-level O_* integer modes and high-level string modes: a = os.open('/tmp/foo', os.O_WRONLY | os.O_CREAT) b = os.fdopen(a, 'w') But to some degree, you still have to do that with the opener argument, at least in your own head. >> What is the rationale for complicating open instead of telling people >> to just call their opener directly? > > To avoid the new syntax would mean coding the example as > > f = os.fdopen(os.open("newfile", flags | os.O_EXCL), "w") > > which does NOT look any cleaner to me... Well, I don't know about that. Once you start messing about with low- level O_* flags, it's never going to exactly be clean no matter what you do. But I think a one-liner like the above *is* cleaner than a three- liner like the original: def opener(file, flags): return os.open(file, flags | os.O_EXCL) open("newfile", "w", opener=opener) although I accept that this is a matter of personal taste. Particularly if the opener is defined far away from where you eventually use it. A lambda is arguably better from that perspective: open("newfile", "w", opener=lambda file, flags: os.open(file, flags | os.O_EXCL) ) but none of these solutions are exactly neat or clean. You still have to mentally translate between string modes and int modes, and make sure you're not passing the wrong mode: py> open('junk', 'w').write('hello world') 11 py> open('junk', 'r', opener=lambda file, flags: os.open(file, flags | os.O_TRUNC)).read() # oops '' so it's not exactly a high-level interface. In my opinion, a cleaner, more Pythonic interface would be either: * allow built-in open to take numeric modes: open(file, os.O_CREAT | os.O_WRONLY | os.O_EXCL) * or even more Pythonic, expose those numeric modes using strings: open(file, 'wx') That's not as general as an opener, but it covers the common use-case and for everything else, write a helper function. > Especially not if "opener" is to be used in more than one location. The usual idiom for fixing the "used more than once" is "write a helper", not "add a callback function to a builtin" :) > Furthermore, using "opener" could > allow for a localized change to affect all open statements in the module > -- change file path, open for string I/O rather than file I/O, etc. A common idiom for that is to shadow open in the module, like this: _open = open def open(file, *args): file = file.lowercase() return _open(file, *args) -- Steven From ben+python at benfinney.id.au Tue Sep 4 01:45:39 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 04 Sep 2012 15:45:39 +1000 Subject: The opener parameter of Python 3 open() built-in References: <504555a5$0$29978$c3e8da3$5496439d@news.astraweb.com> <504590c6$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zk56733w.fsf@benfinney.id.au> Steven D'Aprano writes: > On Mon, 03 Sep 2012 23:19:51 -0400, Dennis Lee Bieber wrote: > > f = os.fdopen(os.open("newfile", flags | os.O_EXCL), "w") > > > > which does NOT look any cleaner to me... > > Well, I don't know about that. Once you start messing about with low- > level O_* flags, it's never going to exactly be clean no matter what you > do. But I think a one-liner like the above *is* cleaner than a three- > liner like the original: > > def opener(file, flags): > return os.open(file, flags | os.O_EXCL) > > open("newfile", "w", opener=opener) > > although I accept that this is a matter of personal taste. If the opener has an unhelpful name like ?opener?, yes. But if it's named as any function should be named ? to say what it does that's special ? then I think the result would be much clearer:: outfile = open("newfile", "w", opener=open_exclusive) > Particularly if the opener is defined far away from where you > eventually use it. Another good reason to name helper functions descriptively. > * or even more Pythonic, expose those numeric modes using strings: > > open(file, 'wx') Which is, indeed, another improvement in Python 3.3 ? the ?x? mode for ?open? . -- \ ?The greatest tragedy in mankind's entire history may be the | `\ hijacking of morality by religion.? ?Arthur C. Clarke, 1991 | _o__) | Ben Finney From gandalf at shopzeus.com Tue Sep 4 03:30:07 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 04 Sep 2012 09:30:07 +0200 Subject: tornado.web ioloop add_timeout eats CPU In-Reply-To: References: Message-ID: <5045ADFF.5010804@shopzeus.com> > What's wrong is the 1,135,775 calls to "method 'poll' of > 'select.epoll' objects". I was affraid you are going to say that. :-) > With five browsers waiting for messages over 845 seconds, that works > out to each waiting browser inducing 269 epolls per second. > > Almost equally important is what the problem is *not*. The problem is > *not* spending the vast majority of time in epoll; that's *good* news. > The problem is *not* that CPU load goes up linearly as we connect more > clients. This is an efficiency problem, not a scaling problem. > > So what's the fix? I'm not a Tornado user; I don't have a patch. > Obviously Laszlo's polling strategy is not performing, and the > solution is to adopt the event-driven approach that epoll and Tornado > do well. Actually, I have found a way to overcome this problem, and it seems to be working. Instead of calling add_timeout from every request, I save the request objects in a list, and operate a "message distributor" service in the background that routes messages to clients, and finish their long poll requests when needed. The main point is that the "message distributor" has a single entry point, and it is called back at given intervals. So the number of callbacks per second does not increase with the number of clients. Now the CPU load is about 1% with one client, and it is the same with 15 clients. While the response time is the same (50-100msec). It is efficient enough for me. I understand that most people do a different approach: they do a fast poll request from the browser in every 2 seconds or so. But this is not good for me, because then it can take 2 seconds to send a message from one browser into another that is not acceptable in my case. Implementing long polls with a threaded server would be trivial, but a threaded server cannot handle 100+ simultaneous (long running) requests, because that would require 100+ threads to be running. This central "message distributor" concept seems to be working. About 1-2% CPU overhead I have to pay for being able to send messages from one browser into another within 100msec, which is fine. I could have not done this without your help. Thank you! Laszlo From breamoreboy at yahoo.co.uk Tue Sep 4 03:50:58 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 04 Sep 2012 08:50:58 +0100 Subject: Comparing strings from the back? In-Reply-To: <20120904045651.GB4703@particle> References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <20120904045651.GB4703@particle> Message-ID: On 04/09/2012 05:56, Dan Sommers wrote: > > That said, if I really wanted bloodshed, I would propose = for the third > string-equality operator! ;-) > > Dan > Dan "agent provocateur" Sommers? :) -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Tue Sep 4 03:56:11 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 04 Sep 2012 08:56:11 +0100 Subject: Comparing strings from the back? In-Reply-To: References: Message-ID: On 04/09/2012 02:54, Roy Smith wrote: > There's been a bunch of threads lately about string implementations, and > that got me thinking (which is often a dangerous thing). > > Let's assume you're testing two strings for equality. You've already > done the obvious quick tests (i.e they're the same length), and you're > down to the O(n) part of comparing every character. > > I'm wondering if it might be faster to start at the ends of the strings > instead of at the beginning? If the strings are indeed equal, it's the > same amount of work starting from either end. But, if it turns out that > for real-life situations, the ends of strings have more entropy than the > beginnings, the odds are you'll discover that they're unequal quicker by > starting at the end. > > It doesn't seem un-plausible that this is the case. For example, most > of the filenames I work with begin with "/home/roy/". Most of the > strings I use as memcache keys have one of a small number of prefixes. > Most of the strings I use as logger names have common leading > substrings. Things like credit card and telephone numbers tend to have > much more entropy in the trailing digits. > > On the other hand, hostnames (and thus email addresses) exhibit the > opposite pattern. > > Anyway, it's just a thought. Has anybody studied this for real-life > usage patterns? > > I'm also not sure how this work with all the possible UCS/UTF encodings. > With some of them, you may get the encoding semantics wrong if you don't > start from the front. > Good grief, what timing!!! The dust has yet to settle over the "Flexible string representation, unicode, typography, ..." thread and you ask this. I'll just cross my fingers and hope that people stick with facts, realistic benchmarks etc, and not good old fashioned FUD. -- Cheers. Mark Lawrence. From no.email at nospam.invalid Tue Sep 4 04:21:40 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 04 Sep 2012 01:21:40 -0700 Subject: tornado.web ioloop add_timeout eats CPU References: Message-ID: <7xvcfui4ff.fsf@ruckus.brouhaha.com> Laszlo Nagy writes: > but a threaded server cannot handle 100+ simultaneous (long running) > requests, because that would require 100+ threads to be running. On a reasonable server these days, 100 threads seems to be no big deal. I've run several times that many. I think things get ragged at a few thousand threads. From buzzi.paolo at gmail.com Tue Sep 4 05:34:56 2012 From: buzzi.paolo at gmail.com (Paolo) Date: Tue, 4 Sep 2012 02:34:56 -0700 (PDT) Subject: focus on jtextfield Message-ID: <50a09acc-a7ac-4c17-b790-65cf3db80478@googlegroups.com> how do I know if a JTextField has the focus? thank to all From alain at dpt-info.u-strasbg.fr Tue Sep 4 05:58:08 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 04 Sep 2012 11:58:08 +0200 Subject: Comparing strings from the back? References: Message-ID: <87ipbuyurz.fsf@dpt-info.u-strasbg.fr> Roy Smith writes: > There's been a bunch of threads lately about string implementations, and > that got me thinking (which is often a dangerous thing). > > Let's assume you're testing two strings for equality. You've already > done the obvious quick tests (i.e they're the same length), and you're > down to the O(n) part of comparing every character. > > I'm wondering if it might be faster to start at the ends of the strings > instead of at the beginning? If the strings are indeed equal, it's the > same amount of work starting from either end. But, if it turns out that > for real-life situations, the ends of strings have more entropy than the > beginnings, the odds are you'll discover that they're unequal quicker by > starting at the end. I guess we all have examples with specific entropy distribution. Going backwards on long strings can be profitable with file paths. If that is the case, and if you spend a lot of time comparing strings, why not store them in reverse? > It doesn't seem un-plausible that this is the case. For example, most > of the filenames I work with begin with "/home/roy/". Most of the > strings I use as memcache keys have one of a small number of prefixes. > Most of the strings I use as logger names have common leading > substrings. In that case I would split the paths, and use some sort of string-id, or use intern() and then compare components with "is" instead of "==". (Basically, turning the string of chars into a strings of ids/ints/pointers.) > Things like credit card and telephone numbers tend to have much more > entropy in the trailing digits. On the other hand, hostnames (and thus > email addresses) exhibit the opposite pattern. Yes, real-world is a mess. > Anyway, it's just a thought. Has anybody studied this for real-life > usage patterns? I've tried the "intern()" trick several times with lists of strings, and was satisfied, but this was in specific cases (with a finite set of strings). For "short" strings of chars (up to, say a hundred of characters), I've never found anything significantly faster than the default sweep (that was in C/C++, not python). For longer and/or more structured strings/lists, making use of the structure is a good idea, but I see no general pattern here (as you note). > I'm also not sure how this work with all the possible UCS/UTF encodings. > With some of them, you may get the encoding semantics wrong if you don't > start from the front. If you're testing for equality, I can't see how this could matter, even with variable-length encodings. If you're comparing different encodings, then you need different access methods to random characters (but this doesn't affect the algorithm). If you're using variable-length encoding, e.g., UTF-8, accessing at a specific position is not possible. -- Alain. From tjandacw at cox.net Tue Sep 4 08:16:32 2012 From: tjandacw at cox.net (Tim Williams) Date: Tue, 4 Sep 2012 05:16:32 -0700 (PDT) Subject: calling loaded DLL function expecting POINT * argument In-Reply-To: References: <1486b835-f9e5-454b-abb7-a3289b1a4fe1@googlegroups.com> Message-ID: On Sunday, August 26, 2012 9:23:49 PM UTC-4, Tim Roberts wrote: > Tim Williams wrote: > > > > >Hello all, > > > > > >I'm trying to use the ctypes module to call functions in a DLL. I've > > >figured out how to modify my path so the library is found, and I can > > >call LoadLibrary on it, but one of the functions expects an array of > > > POINTS. Here is the prototype from the .h file: > > > > > > > > >TRACKER_API HRESULT InitializeMask(HANDLE pHandle, int nWidth, int nHeight, POINT* ptMasks, int nNumPoints); > > > > How is TRACKER_API defined? You're using ctypes.oledll, which uses the > > __stdcall calling convention. It's possible your DLL is defined as > > __cdecl. Try cdll.LoadLibrary instead of oledll.LoadLibrary. > > -- > > Tim Roberts, timr at probo.com > > Providenza & Boekelheide, Inc. Thanks for the reply. I've been out all last week. I'll give it a try. From storchaka at gmail.com Tue Sep 4 08:58:09 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Tue, 04 Sep 2012 15:58:09 +0300 Subject: The opener parameter of Python 3 open() built-in In-Reply-To: <504555a5$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <504555a5$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04.09.12 04:13, Steven D'Aprano wrote: > Why does the open builtin need this added complexity? Why not just call > os.open directly? Or for more complex openers, just call the opener > directly? > > What is the rationale for complicating open instead of telling people to > just call their opener directly? See http://bugs.python.org/issue12797. From storchaka at gmail.com Tue Sep 4 09:01:38 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Tue, 04 Sep 2012 16:01:38 +0300 Subject: The opener parameter of Python 3 open() built-in In-Reply-To: References: Message-ID: On 03.09.12 15:32, Marco wrote: > Does anyone have an example of utilisation? http://bugs.python.org/issue13424 From tjandacw at cox.net Tue Sep 4 09:05:20 2012 From: tjandacw at cox.net (Tim Williams) Date: Tue, 4 Sep 2012 06:05:20 -0700 (PDT) Subject: calling loaded DLL function expecting POINT * argument In-Reply-To: References: <1486b835-f9e5-454b-abb7-a3289b1a4fe1@googlegroups.com> Message-ID: <06861f1e-26fa-4781-a74e-f6d4b51f813f@googlegroups.com> On Tuesday, September 4, 2012 8:16:33 AM UTC-4, Tim Williams wrote: > On Sunday, August 26, 2012 9:23:49 PM UTC-4, Tim Roberts wrote: > > > Tim Williams wrote: > > > > > > > > > > > > >Hello all, > > > > > > > > > > > > > >I'm trying to use the ctypes module to call functions in a DLL. I've > > > > > > >figured out how to modify my path so the library is found, and I can > > > > > > >call LoadLibrary on it, but one of the functions expects an array of > > > > > > > POINTS. Here is the prototype from the .h file: > > > > > > > > > > > > > > > > > > > > >TRACKER_API HRESULT InitializeMask(HANDLE pHandle, int nWidth, int nHeight, POINT* ptMasks, int nNumPoints); > > > > > > > > > > > > How is TRACKER_API defined? You're using ctypes.oledll, which uses the > > > > > > __stdcall calling convention. It's possible your DLL is defined as > > > > > > __cdecl. Try cdll.LoadLibrary instead of oledll.LoadLibrary. > > > > > > -- > > > > > > Tim Roberts, timr at probo.com > > > > > > Providenza & Boekelheide, Inc. > > > > Thanks for the reply. I've been out all last week. I'll give it a try. cdll.LoadLibrary did trick! Thanks again. Now on to the next step.... From feliphil at gmx.net Tue Sep 4 09:17:10 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Tue, 4 Sep 2012 15:17:10 +0200 Subject: simple client data base References: <20120903180327.94ba442a44e4f26803de0747@gmx.net> Message-ID: <20120904151710.54ddd61b9e6a302aa2beaa76@gmx.net> > Personally, I wouldn't bother with SQLAlchemy for this. I'd just use > Python as the front end, PostgreSQL for the database, and psycopg2 > for the interface. Then you have to implement the entire logic, "event binding" etc. yourself. If you use e.g. Pypapi (the latest version), implementing an entire CRUD application is as simple as declaring your domain object model and laying out your GUI with Qt Designer. In Sqlkit, you don't have to do much more, you just don't use a designer for the GUI, but also a declarative approach. Sincerely, Wolfgang From sdiwcconferences at gmail.com Tue Sep 4 10:15:43 2012 From: sdiwcconferences at gmail.com (sdiwc conferences) Date: Tue, 4 Sep 2012 07:15:43 -0700 (PDT) Subject: CFP: Computing, Networking and Digital Technologies Message-ID: <781dccb6-9da5-45ea-8862-225f52c9c07f@io6g2000pbc.googlegroups.com> We invite participation and submissions to The International Conference on Computing, Networking and Digital Technologies (ICCNDT 2012) that will be held at Gulf University, Sanad, Bahrain from Nov. 11-13, 2012. More details can be found at the conference's official web site, visit http://sdiwc.net/bh *RESEARCH TOPICS (but not limited to): - Software Specification - Software Assurance - Social Search - Software Process Modeling - Software Reuse - Cloud Computing - Grid Computing - Green Computing - Information and Data Management *IMPORTANT DATES Paper Submission Deadline: Sept. 25, 2012 Notification of Acceptance: Oct. 10, 2012 Camera Ready Submission: Oct. 30, 2012 Registration: Oct. 30, 2012 **Please consider forwarding this message to persons who might be interested. Thank you.** From jldunn2000 at gmail.com Tue Sep 4 11:26:21 2012 From: jldunn2000 at gmail.com (loial) Date: Tue, 4 Sep 2012 08:26:21 -0700 (PDT) Subject: sockets,threads and interupts Message-ID: <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com> I have threaded python script that uses sockets to monitor network ports. I want to ensure that the socket is closed cleanly in all circumstances. This includes if the script is killed or interupted in some other way. As I understand it signal only works in the main thread, so how can I trap interupts in my threaded class and always ensure I close the socket? Using KeyboardInterupt does not seem to work. From mathieu.courtois at gmail.com Tue Sep 4 11:57:00 2012 From: mathieu.courtois at gmail.com (Mathieu Courtois) Date: Tue, 4 Sep 2012 08:57:00 -0700 (PDT) Subject: Why derivated exception can not be pickled ? Message-ID: <7bb72fb5-5ab5-4748-acbf-c8e7666ee834@googlegroups.com> Here is my example : import cPickle ParentClass = object # works ParentClass = Exception # does not class MyError(ParentClass): def __init__(self, arg): self.arg = arg def __getstate__(self): print '#DBG pass in getstate' odict = self.__dict__.copy() return odict def __setstate__(self, state): print '#DBG pass in setstate' self.__dict__.update(state) exc = MyError('IDMESS') fo = open('pick.1', 'w') cPickle.dump(exc, fo) fo.close() fo = open('pick.1', 'r') obj = cPickle.load(fo) fo.close() 1. With ParentClass=object, it works as expected. 2. With ParentClass=Exception, __getstate__/__setstate__ are not called. Does anyone explain me why ? Thanks. From dfnsonfsduifb at gmx.de Tue Sep 4 12:32:57 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Tue, 04 Sep 2012 18:32:57 +0200 Subject: Comparing strings from the back? In-Reply-To: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04.09.2012 04:17, Steven D'Aprano wrote: > On average, string equality needs to check half the characters in the > string. How do you arrive at that conclusion? When comparing two random strings, I just derived n = (256 / 255) * (1 - 256 ^ (-c)) where n is the average number of character comparisons and c. The rationale as follows: The first character has to be compared in any case. The second with a probability of 1/256, the third with 1/(256^2) and so on. Best regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From python at mrabarnett.plus.com Tue Sep 4 13:06:17 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 04 Sep 2012 18:06:17 +0100 Subject: sockets,threads and interupts In-Reply-To: <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com> References: <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com> Message-ID: <50463509.5050209@mrabarnett.plus.com> On 04/09/2012 16:26, loial wrote: > I have threaded python script that uses sockets to monitor network > ports. > > I want to ensure that the socket is closed cleanly in all > circumstances. This includes if the script is killed or interupted in > some other way. > > As I understand it signal only works in the main thread, so how can I > trap interupts in my threaded class and always ensure I close the > socket? Using KeyboardInterupt does not seem to work. > You could wrap it in try...finally. The 'finally' clause is guaranteed to be run, so you can close the sockets there. However, if the script is just killed, then it won't get the chance to tidy up. From sreenathk17296 at gmail.com Tue Sep 4 13:08:03 2012 From: sreenathk17296 at gmail.com (Sreenath k) Date: Tue, 4 Sep 2012 10:08:03 -0700 (PDT) Subject: Error 32 - Broken Pipe . Please Help!! Message-ID: Error: Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/monitor.py", line 575, in run already_pickled=True) File "/usr/lib/python2.7/dist-packages/spyderlib/utils/bsdsocket.py", line 24, in write_packet sock.send(struct.pack("l", len(sent_data)) + sent_data) error: [Errno 32] Broken pipe Code : #code s=1 f=0 c=0 for i in range (1,100): c=0 for j in (1,i): s+=j c=0 for k in range(1,(s/2+1)): #print s t=s%k if t==0: c+=1 if c>=5: f=1 print s break print s #code ends. The program is runnning. It has been more than 10 minutes ( currently). Should I raise my hopes for an answer ? From gandalf at shopzeus.com Tue Sep 4 13:21:54 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 04 Sep 2012 19:21:54 +0200 Subject: Error 32 - Broken Pipe . Please Help!! In-Reply-To: References: Message-ID: <504638B2.3010601@shopzeus.com> 2012.09.04. 19:08 keltez?ssel, Sreenath k ?rta: > Error: > > > Exception in thread Thread-1: > Traceback (most recent call last): > File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner > self.run() > File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/monitor.py", line 575, in run > already_pickled=True) > File "/usr/lib/python2.7/dist-packages/spyderlib/utils/bsdsocket.py", line 24, in write_packet > sock.send(struct.pack("l", len(sent_data)) + sent_data) > error: [Errno 32] Broken pipe > > Code : > > #code > > s=1 > f=0 > c=0 > > for i in range (1,100): > c=0 > for j in (1,i): > s+=j > c=0 > for k in range(1,(s/2+1)): > #print s > t=s%k > if t==0: > c+=1 > if c>=5: > f=1 > print s > break > > print s > > #code ends. > > The program is runnning. It has been more than 10 minutes ( currently). Should I raise my hopes for an answer ? It must not be your full program. The traceback shows "Thread-1" which indicates that you are using the threading module. The other possibility is that you are feeding the output of your program into another program with a pipeline. In that case, the exception might have occured in the other program, not yours. From emile at fenx.com Tue Sep 4 13:26:36 2012 From: emile at fenx.com (Emile van Sebille) Date: Tue, 04 Sep 2012 10:26:36 -0700 Subject: Error 32 - Broken Pipe . Please Help!! In-Reply-To: References: Message-ID: On 9/4/2012 10:08 AM Sreenath k said... > Error: > > > Exception in thread Thread-1: > Traceback (most recent call last): > File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner > self.run() > File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/monitor.py", line 575, in run > already_pickled=True) > File "/usr/lib/python2.7/dist-packages/spyderlib/utils/bsdsocket.py", line 24, in write_packet > sock.send(struct.pack("l", len(sent_data)) + sent_data) > error: [Errno 32] Broken pipe > > Code : So, what code is invoking spyderlib stuff that's causing the error? Emile From dhoese at gmail.com Tue Sep 4 13:58:43 2012 From: dhoese at gmail.com (David Hoese) Date: Tue, 04 Sep 2012 13:58:43 -0400 Subject: python docs search for 'print' Message-ID: <50464153.5090402@gmail.com> A friend made me aware of this: When a python beginner (2.x) quick searches for "print" on docs.python.org, the print function doesn't even come up in the top 20 results. The print statement isn't even listed as far as I can tell. Is there something that can be done about this to make it easier for beginners? I understand that this is a very basic search and "print" is a very common word and a very basic python statement, but it's pretty difficult for a beginner to learn when the first 5 results are about the disassembler and the next 5 are C functions. -Dave From steve+comp.lang.python at pearwood.info Tue Sep 4 14:07:29 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Sep 2012 18:07:29 GMT Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50464361$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Sep 2012 18:32:57 +0200, Johannes Bauer wrote: > On 04.09.2012 04:17, Steven D'Aprano wrote: > >> On average, string equality needs to check half the characters in the >> string. > > How do you arrive at that conclusion? Take two non-empty strings of the same length, N. If the strings are equal, you have to make N comparisons to be sure they are equal (you check all N pairs of characters). If they are unequal, you have to check each pair of characters up to the first pair that are different: def string_equality(astr, bstr): # Assumes lengths are equal. for achr, bchr in zip(astr, bstr): if achr != bchr: return False return True For the unequal case, how many comparisons do you do? Ahead of time, we know very little about the strings. We don't even know how many possible characters there are (are they English alphanumeric, ASCII, Greek, Thai, or from the full range of 1114111 Unicode code points?) or what their probability distribution is. A reasonable, conservative assumption is to calculate the largest possible value of the average for random strings. That largest value occurs when the alphabet is as small as possible, namely two characters. In practice, strings come from a larger alphabet, up to 1114111 different characters for full Unicode strings, so the average for them will be less than the average we calculate now. So for unequal strings, the number of comparisons is equally likely to be 1, 2, 3, ..., N. The average then is: sum([1, 2, 3, ..., N])/N which by a bit of simple algebra works out to be (N+1)/2, or half the characters as I said. (Note that this average assumes the strings are completely random. In practice, strings tend to come from strongly non-uniform distributions of characters. For instance, in English texts, 'e' is much more likely than 'q' and most characters are vanishingly rare, and in practice, strings are likely to be highly non-random.) -- Steven From invalid at invalid.invalid Tue Sep 4 14:11:12 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 4 Sep 2012 18:11:12 +0000 (UTC) Subject: sockets,threads and interupts References: <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com> Message-ID: On 2012-09-04, MRAB wrote: > On 04/09/2012 16:26, loial wrote: >> I have threaded python script that uses sockets to monitor network >> ports. >> >> I want to ensure that the socket is closed cleanly in all >> circumstances. This includes if the script is killed or interupted in >> some other way. >> >> As I understand it signal only works in the main thread, so how can I >> trap interupts in my threaded class and always ensure I close the >> socket? Using KeyboardInterupt does not seem to work. >> > You could wrap it in try...finally. The 'finally' clause is guaranteed > to be run, so you can close the sockets there. > > However, if the script is just killed, then it won't get the chance > to tidy up. That depends on the signal used to "kill" the thread. You can catch SIGTERM and SIGINT and clean up before exiting. You can't catch SIGKILL, but sending a SIGKILL isn't considered polite unless you've already tried SIGTERM/SIGINT and it didn't work. -- Grant Edwards grant.b.edwards Yow! Are we on STRIKE yet? at gmail.com From joel.goldstick at gmail.com Tue Sep 4 14:27:35 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 4 Sep 2012 14:27:35 -0400 Subject: python docs search for 'print' In-Reply-To: <50464153.5090402@gmail.com> References: <50464153.5090402@gmail.com> Message-ID: On Tue, Sep 4, 2012 at 1:58 PM, David Hoese wrote: > A friend made me aware of this: > When a python beginner (2.x) quick searches for "print" on docs.python.org, > the print function doesn't even come up in the top 20 results. > -Dave > -- > http://mail.python.org/mailman/listinfo/python-list That's pretty interesting. I always use google python and get very results. Not a correction for what you think isn't working well on python.org (I think I agree)., but if your friend is looking to learn, my suggestion works great -- Joel Goldstick From PointedEars at web.de Tue Sep 4 14:27:38 2012 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Tue, 04 Sep 2012 20:27:38 +0200 Subject: python docs search for 'print' References: Message-ID: <2142958.VIB8zyE3RV@PointedEars.de> David Hoese wrote: > A friend made me aware of this: > When a python beginner (2.x) quick searches for "print" on > docs.python.org, the print function doesn't even come up in the top 20 > results. The print statement isn't even listed as far as I can tell. > Is there something that can be done about this to make it easier for > beginners? > > I understand that this is a very basic search and "print" is a very > common word and a very basic python statement, but it's pretty difficult > for a beginner to learn when the first 5 results are about the > disassembler and the next 5 are C functions. If they scroll down they will find, among other entries, "1. Introduction" (to the "Python library"), which they should have read in the first place. The main problem, as I see it, is that the first search results are Unicode- sorted by document title, where uppercase letters come first. However, I do not think that posting to this newsgroup will change anything there. You should take it to the python.org people instead who are, I am sorry to say so, responsible for this mess as well? (I have seldom, if ever, found anything useful using that search; usually I go by TOC and index). There is a "Found a bug?" link at the bottom that appears to be of use. _____ ? The other mess they created (or allowed to be created) is this mashup of newsgroup and mailing list, neither of which works properly, because the underlying protocols are not compatible. Add to that the abomination that Google Groups has become. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail. From steve+comp.lang.python at pearwood.info Tue Sep 4 14:28:31 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Sep 2012 18:28:31 GMT Subject: python docs search for 'print' References: Message-ID: <5046484f$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Sep 2012 13:58:43 -0400, David Hoese wrote: > A friend made me aware of this: > When a python beginner (2.x) quick searches for "print" on > docs.python.org, the print function doesn't even come up in the top 20 > results. The print statement isn't even listed as far as I can tell. Is > there something that can be done about this to make it easier for > beginners? > > I understand that this is a very basic search and "print" is a very > common word and a very basic python statement, but it's pretty difficult > for a beginner to learn when the first 5 results are about the > disassembler and the next 5 are C functions. I sympathise. The search functionality on docs.python.org is frankly crap, and the best thing for your friend to do is to learn to use google, duckduckgo or some other search engine: https://www.google.com.au/search?q=python+print http://duckduckgo.com/html/?q=python+print In this case, google hits the right Python documentation on the first link. Duckduckgo doesn't do nearly so well, but it comes up with a bunch of useful third-party links. It does better for searches with fewer The second best thing for your friend to do is to learn to read the index to the docs, where the print statement is listed: http://docs.python.org/reference/index.html You can use your browser's Find command to search the page for "print". -- Steven From steve+comp.lang.python at pearwood.info Tue Sep 4 14:35:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Sep 2012 18:35:22 GMT Subject: python docs search for 'print' References: <2142958.VIB8zyE3RV@PointedEars.de> Message-ID: <504649ea$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Sep 2012 20:27:38 +0200, Thomas 'PointedEars' Lahn wrote: > ? The other mess they created (or allowed to be created) is this mashup > of newsgroup and mailing list, neither of which works properly, In what way do they not work properly? > because > the underlying protocols are not compatible. What? That is rather like saying that you can't read email via a web interface because the http protocol is not compatible with the smtp protocol. > Add to that the abomination that Google Groups has become. It's always been an abomination, although I understand it is much, much worse now. Blame Google for that. -- Steven From wrw at mac.com Tue Sep 4 14:38:47 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Tue, 04 Sep 2012 14:38:47 -0400 Subject: python docs search for 'print' In-Reply-To: <50464153.5090402@gmail.com> References: <50464153.5090402@gmail.com> Message-ID: <72C47821-7993-4B5E-89F2-5C79142A5791@mac.com> On Sep 4, 2012, at 1:58 PM, David Hoese wrote: > A friend made me aware of this: > When a python beginner (2.x) quick searches for "print" on docs.python.org, the print function doesn't even come up in the top 20 results. The print statement isn't even listed as far as I can tell. Is there something that can be done about this to make it easier for beginners? > > I understand that this is a very basic search and "print" is a very common word and a very basic python statement, but it's pretty difficult for a beginner to learn when the first 5 results are about the disassembler and the next 5 are C functions. > > -Dave > -- > http://mail.python.org/mailman/listinfo/python-list +100 (or some very large number). This is a general problem in searching the python library reference ("keep this under your pillow"). Try searching for list, iter, read, or write or any one of a whole bunch of things a newbie would logically be looking for. (Or even a not-quite-newbie who wanted to check some detail.) -Bill From oscar.j.benjamin at gmail.com Tue Sep 4 14:40:19 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 4 Sep 2012 19:40:19 +0100 Subject: Comparing strings from the back? In-Reply-To: <50464361$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <50464361$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4 September 2012 19:07, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Tue, 04 Sep 2012 18:32:57 +0200, Johannes Bauer wrote: > > > On 04.09.2012 04:17, Steven D'Aprano wrote: > > > >> On average, string equality needs to check half the characters in the > >> string. > > > > How do you arrive at that conclusion? > > Take two non-empty strings of the same length, N. If the strings are > equal, you have to make N comparisons to be sure they are equal (you > check all N pairs of characters). If they are unequal, you have to check > each pair of characters up to the first pair that are different: > > def string_equality(astr, bstr): > # Assumes lengths are equal. > for achr, bchr in zip(astr, bstr): > if achr != bchr: > return False > return True > > For the unequal case, how many comparisons do you do? Ahead of time, we > know very little about the strings. We don't even know how many possible > characters there are (are they English alphanumeric, ASCII, Greek, Thai, > or from the full range of 1114111 Unicode code points?) or what their > probability distribution is. > > A reasonable, conservative assumption is to calculate the largest > possible value of the average for random strings. That largest value > occurs when the alphabet is as small as possible, namely two characters. > In practice, strings come from a larger alphabet, up to 1114111 different > characters for full Unicode strings, so the average for them will be less > than the average we calculate now. > > So for unequal strings, the number of comparisons is equally likely to be > 1, 2, 3, ..., N. The average then is: What? > > sum([1, 2, 3, ..., N])/N > > which by a bit of simple algebra works out to be (N+1)/2, or half the > characters as I said. > > (Note that this average assumes the strings are completely random. In > practice, strings tend to come from strongly non-uniform distributions of > characters. For instance, in English texts, 'e' is much more likely than > 'q' and most characters are vanishingly rare, and in practice, strings > are likely to be highly non-random.) If the strings are 'completely random' (by which I assume you mean that each character is IID) then the probability of a match for the character at any one index is the same as the probability for a match at any other index. Lets say the probability for a match is p and that p < 1. Then for the first comparison: 1) with probability (1 - p) we terminate the loop after 1 comparison. 2) With probability p we continue to the second comparison The second comparison occurs with probability p (from 2 above) and if we reach this point then: 1) with probability (1 - p) we terminate the loop after this second comparison 2) With probability p we continue to the third comparison The probability of reaching the second comparison is p and the probability of terminating at this comparison *if we reach it* is (1-p). So the probability from the outset that we terminate at the second comparison is p*(1 - p). Prob(1 comparison) = (1-p) > p*(1-p) = prob(2 comparisons) (since p < 1) This can easily be extended by induction or otherwise to show that the probability of terminating after N comparisons decreases as N increases. In fact since it decreases by a factor of p each time, even if p is 1/2 (as would be the case if there were two equally likely characters) the probability of continuing to N comparisons becomes vanishingly small very quickly as N increases. In practise p is larger for mast ascii/bmp/unicode problems so the probability vanishes even more quickly. If you follow this through you should arrive at Johannes' result above. Applying this to real data is obviously more complicated since successive characters are not independent but it would be a fairly unusual situation if you were not more likely to stop at an earlier point in the comparison loop than a later one. Oscar. -------------- next part -------------- An HTML attachment was scrubbed... URL: From andipersti at gmail.com Tue Sep 4 14:42:15 2012 From: andipersti at gmail.com (Andreas Perstinger) Date: Tue, 04 Sep 2012 20:42:15 +0200 Subject: focus on jtextfield In-Reply-To: <50a09acc-a7ac-4c17-b790-65cf3db80478@googlegroups.com> References: <50a09acc-a7ac-4c17-b790-65cf3db80478@googlegroups.com> Message-ID: <50464B87.8060001@gmail.com> On 04.09.2012 11:34, Paolo wrote: > how do I know if a JTextField has the focus? > thank to all Look there: http://www.catb.org/esr/faqs/smart-questions.html#forum Bye, Andreas From invalid at invalid.invalid Tue Sep 4 14:44:12 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 4 Sep 2012 18:44:12 +0000 (UTC) Subject: python docs search for 'print' References: <50464153.5090402@gmail.com> Message-ID: On 2012-09-04, Joel Goldstick wrote: > On Tue, Sep 4, 2012 at 1:58 PM, David Hoese wrote: >> A friend made me aware of this: >> When a python beginner (2.x) quick searches for "print" on >> docs.python.org, the print function doesn't even come up in the top >> 20 results. > > That's pretty interesting. I always use google python and > get very results. Not a correction for what you think isn't working > well on python.org (I think I agree)., but if your friend is looking > to learn, my suggestion works great googling "site:python.org " also works nicely if you know what you want is on the python.org site. I never bother with the site's search function -- the results are always far better using google. [This isn't a particular fault of the python.org site, I find the same is true for pretty much every site I've ever used.] -- Grant Edwards grant.b.edwards Yow! FROZEN ENTREES may at be flung by members of gmail.com opposing SWANSON SECTS ... From tjreedy at udel.edu Tue Sep 4 15:16:38 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 04 Sep 2012 15:16:38 -0400 Subject: The opener parameter of Python 3 open() built-in In-Reply-To: References: <504555a5$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/4/2012 8:58 AM, Serhiy Storchaka wrote: > On 04.09.12 04:13, Steven D'Aprano wrote: >> Why does the open builtin need this added complexity? Why not just call >> os.open directly? Or for more complex openers, just call the opener >> directly? >> >> What is the rationale for complicating open instead of telling people to >> just call their opener directly? > > See http://bugs.python.org/issue12797. io.open depends on a function the returns an open file descriptor. opener exposes that dependency so it can be replaced. (Obviously, one could go crazily overboard with this idea.) I believe this is a simple form of dependency injection, though it might be hard to discern from the Java-inspired verbiage of the Wikipedia article. Part of the rationale in the issue is to future-proof io.open from any future needs for alternate fd fetching. It could also be used to decouple a test of io.open from os.open -- Terry Jan Reedy From jimmyli1528 at gmail.com Tue Sep 4 15:49:25 2012 From: jimmyli1528 at gmail.com (jimmyli1528 at gmail.com) Date: Tue, 4 Sep 2012 12:49:25 -0700 (PDT) Subject: Import Problem on WIndows py3 Message-ID: <5087114e-3c76-4a39-b0dd-881c8adc76ab@googlegroups.com> I have a main program and a 3rd party module. Trying to import colorama, where colorama is a folder with files in it, returns an ImportError: No module named colorama. How should I import folders? From channel727272 at gmail.com Tue Sep 4 16:28:08 2012 From: channel727272 at gmail.com (channel727272 at gmail.com) Date: Tue, 4 Sep 2012 13:28:08 -0700 (PDT) Subject: C Python: Running Python code within function scope Message-ID: <522c6780-f093-4456-b87b-fb8eb77e77f6@googlegroups.com> The Python C API function PyEval_EvalCode let's you execute compiled Python code. I want to execute a block of Python code as if it were executing within the scope of a function, so that it has its own dictionary of local variables which don't affect the global state. This seems easy enough to do, since PyEval_EvalCode lets you provide a Global and Local dictionary: PyObject* PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals) The problem I run into has to do with how Python looks up variable names. Consider the following code, that I execute with PyEval_EvalCode: myvar = 300 def func(): return myvar func() This simple code actually raises an error, because Python is unable to find the variable myvar from within func. Even though myvar is in the local dictionary in the outer scope, Python doesn't copy it into the local dictionary in the inner scope. The reason for this is as follows: Whenever Python looks up a variable name, first it checks locals, then it checks globals, and finally it checks builtins. At module scope, locals and globals are the SAME dictionary object. So the statement x = 5 at module scope will place x in the the locals dictionary, which is also the globals dictionary. Now, a function defined at module scope which needs to lookup x won't find x within the function-scope locals, because Python doesn't copy module-scope locals into function-scope locals. But this normally isn't a problem, because it can find x in globals. x = 5 def foo(): print(x) # This works because 'x' in globals() == True It's only with nested functions, that Python seems to copy outer-scope locals into inner-scope locals. (It also seems to do so lazily, only if they are needed within the inner scope.) def foo(): x = 5 def bar(): print(x) # Now 'x' in locals() == True bar() So the result of all this is that, when executing code at module scope, you HAVE to make sure that your global dictionary and local dictionary are the SAME object, otherwise module-scope functions won't be able to access module-scope variables. But in my case, I don't WANT the global dictionary and local dictionary to be the same. So I need some way to tell the Python interpreter that I am executing code at function scope. Is there some way to do this? I looked at the PyCompileFlags as well as the additional arguments to PyEval_EvalCodeEx and can't find any way to do this. From werner at thieprojects.ch Tue Sep 4 16:45:30 2012 From: werner at thieprojects.ch (Werner Thie) Date: Tue, 04 Sep 2012 10:45:30 -1000 Subject: Import Problem on WIndows py3 In-Reply-To: <5087114e-3c76-4a39-b0dd-881c8adc76ab@googlegroups.com> References: <5087114e-3c76-4a39-b0dd-881c8adc76ab@googlegroups.com> Message-ID: <5046686A.9060805@thieprojects.ch> On 9/4/12 9:49 AM, jimmyli1528 at gmail.com wrote: > I have a main program and a 3rd party module. Trying to import colorama, where colorama is a folder with files in it, returns an ImportError: No module named colorama. How should I import folders? > Do you have a (empty) __init__.py file present in this particular directory? Werner From jimmyli1528 at gmail.com Tue Sep 4 16:52:29 2012 From: jimmyli1528 at gmail.com (Jimbo Jim) Date: Tue, 4 Sep 2012 13:52:29 -0700 (PDT) Subject: Import Problem on WIndows py3 In-Reply-To: References: <5087114e-3c76-4a39-b0dd-881c8adc76ab@googlegroups.com> Message-ID: On Tuesday, September 4, 2012 1:45:55 PM UTC-7, Werner Thie wrote: > On 9/4/12 9:49 AM, jimmyli1528 wrote: > > > I have a main program and a 3rd party module. Trying to import colorama, where colorama is a folder with files in it, returns an ImportError: No module named colorama. How should I import folders? > > > > > > > > > Do you have a (empty) __init__.py file present in this particular directory? > > > > Werner OK works perfectly! From jimmyli1528 at gmail.com Tue Sep 4 16:52:29 2012 From: jimmyli1528 at gmail.com (Jimbo Jim) Date: Tue, 4 Sep 2012 13:52:29 -0700 (PDT) Subject: Import Problem on WIndows py3 In-Reply-To: References: <5087114e-3c76-4a39-b0dd-881c8adc76ab@googlegroups.com> Message-ID: On Tuesday, September 4, 2012 1:45:55 PM UTC-7, Werner Thie wrote: > On 9/4/12 9:49 AM, jimmyli1528 wrote: > > > I have a main program and a 3rd party module. Trying to import colorama, where colorama is a folder with files in it, returns an ImportError: No module named colorama. How should I import folders? > > > > > > > > > Do you have a (empty) __init__.py file present in this particular directory? > > > > Werner OK works perfectly! From breamoreboy at yahoo.co.uk Tue Sep 4 17:43:25 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 04 Sep 2012 22:43:25 +0100 Subject: python docs search for 'print' In-Reply-To: <72C47821-7993-4B5E-89F2-5C79142A5791@mac.com> References: <50464153.5090402@gmail.com> <72C47821-7993-4B5E-89F2-5C79142A5791@mac.com> Message-ID: On 04/09/2012 19:38, William R. Wing (Bill Wing) wrote: > On Sep 4, 2012, at 1:58 PM, David Hoese wrote: > >> A friend made me aware of this: >> When a python beginner (2.x) quick searches for "print" on docs.python.org, the print function doesn't even come up in the top 20 results. The print statement isn't even listed as far as I can tell. Is there something that can be done about this to make it easier for beginners? >> >> I understand that this is a very basic search and "print" is a very common word and a very basic python statement, but it's pretty difficult for a beginner to learn when the first 5 results are about the disassembler and the next 5 are C functions. >> >> -Dave >> -- >> http://mail.python.org/mailman/listinfo/python-list > > +100 (or some very large number). This is a general problem in searching the python library reference ("keep this under your pillow"). Try searching for list, iter, read, or write or any one of a whole bunch of things a newbie would logically be looking for. (Or even a not-quite-newbie who wanted to check some detail.) > > -Bill > > I never have a problem with this because the compiled help file on windows is awesome. It even works offline. -- Cheers. Mark Lawrence. From rosuav at gmail.com Tue Sep 4 17:59:43 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Sep 2012 07:59:43 +1000 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 5, 2012 at 2:32 AM, Johannes Bauer wrote: > How do you arrive at that conclusion? When comparing two random strings, > I just derived > > n = (256 / 255) * (1 - 256 ^ (-c)) > > where n is the average number of character comparisons and c. The > rationale as follows: The first character has to be compared in any > case. The second with a probability of 1/256, the third with 1/(256^2) > and so on. That would be for comparing two random areas of memory. Python strings don't have 256 options per character; and in terms of actual strings, there's so many possibilities. The strings that a program is going to compare for equality are going to use a vastly restricted alphabet; for a lot of cases, there might be only a few dozen plausible characters. But even so, it's going to scale approximately linearly with the string length. If they're really random, then yes, there's little chance that either a 1MB string or a 2MB string will be the same, but with real data, they might very well have a long common prefix. So it's still going to be more or less O(n). ChrisA From tjreedy at udel.edu Tue Sep 4 18:18:38 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 04 Sep 2012 18:18:38 -0400 Subject: C Python: Running Python code within function scope In-Reply-To: <522c6780-f093-4456-b87b-fb8eb77e77f6@googlegroups.com> References: <522c6780-f093-4456-b87b-fb8eb77e77f6@googlegroups.com> Message-ID: On 9/4/2012 4:28 PM, channel727272 at gmail.com wrote: > The Python C API function PyEval_EvalCode let's you execute compiled > Python code. I want to execute a block of Python code as if it were > executing within the scope of a function, so that it has its own > dictionary of local variables which don't affect the global state. You cannot really do this. The local namespace of functions is not a dict. > This seems easy enough to do, since PyEval_EvalCode lets you provide > a Global and Local dictionary: > > PyObject* PyEval_EvalCode(PyCodeObject *co, PyObject *globals, > PyObject *locals) When you do this, you are executing code as if in a class statement, not as if in a function. > The problem I run into has to do with how Python looks up variable > names. Consider the following code, that I execute with > PyEval_EvalCode: > > myvar = 300 > def func(): return myvar > func() if you wrapped this in def outer(), myvar would be a nonlocal variable, neither local nor global. exec does not allow for that. > This simple code actually raises an error, because Python is unable > to find the variable myvar from within func. This is the same as if you indented the above under class xxx: ... > It's only with nested functions, that Python seems to copy > outer-scope locals into inner-scope locals. I was surprised to find that nonlocals do appear in locals(), but I would not exactly say that they are copied into the actual local namespace. def outer(): x = 1 def inner(z=3): y = 2 print(x) print(locals()) inner() print(inner.__code__.co_varnames, inner.__code__.co_freevars) outer() # 1 {'x': 1, 'y': 2, 'z': 3} ('z', 'y') ('x',) Varnames are the local names, freevars are the nonlocal names. In any case, this complexity requires the presence of an outer function when the code is compiled. There is no way to simulate it after the fact by fiddling with just locals and globals when the compiled code is exec'ed. Class statement, on the other hand, simply introduce a local namespace separate from the module namespace. -- Terry Jan Reedy From rosuav at gmail.com Tue Sep 4 18:18:57 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Sep 2012 08:18:57 +1000 Subject: The opener parameter of Python 3 open() built-in In-Reply-To: References: <504555a5$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 5, 2012 at 5:16 AM, Terry Reedy wrote: > io.open depends on a function the returns an open file descriptor. opener > exposes that dependency so it can be replaced. I skimmed the bug report comments but didn't find an answer to this: Why not just monkey-patch? When a module function calls on a support function and you want to change that support function's behaviour, isn't monkey-patching the most usual? Several possibilities come to mind, but without knowledge of internals, I have no idea what's actually the case. * Patching builtins is too confusing or dangerous, and should be avoided? * You want to narrow the scope of the patch rather than do it globally? * Explicit is better than implicit? It just strikes me as something where an API change may not be necessary. ChrisA From tjreedy at udel.edu Tue Sep 4 18:32:09 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 04 Sep 2012 18:32:09 -0400 Subject: python docs search for 'print' In-Reply-To: References: <50464153.5090402@gmail.com> Message-ID: > On Tue, Sep 4, 2012 at 1:58 PM, David Hoese wrote: >> A friend made me aware of this: >> When a python beginner (2.x) quick searches for "print" on docs.python.org, >> the print function doesn't even come up in the top 20 results. In the Windows Help version of the docs, enter print in the index tab and print builtin function is at the top. Same is true of the online index. (There are only three 'print' entries. There is a duplicate for the builtin and one for the fixer. Moral: look for things that would be indexed in the index. Searching for a word in text, especially a common one like print, brings in lots of junk. -- Terry Jan Reedy From tjreedy at udel.edu Tue Sep 4 18:58:52 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 04 Sep 2012 18:58:52 -0400 Subject: python docs search for 'print' In-Reply-To: References: <50464153.5090402@gmail.com> Message-ID: On 9/4/2012 6:32 PM, Terry Reedy wrote: > >> On Tue, Sep 4, 2012 at 1:58 PM, David Hoese wrote: >>> A friend made me aware of this: >>> When a python beginner (2.x) quick searches for "print" on >>> docs.python.org, >>> the print function doesn't even come up in the top 20 results. > > In the Windows Help version of the docs, enter print in the index tab > and print builtin function is at the top. Same is true of the online > index. (There are only three 'print' entries. There is a duplicate for > the builtin and one for the fixer. Moral: look for things that would be > indexed in the index. Searching for a word in text, especially a common > one like print, brings in lots of junk. Search rather blindly searches pages for words. As an experiment, I entered 'print' on the search tab of the 3.3 Windows-version doc. It found 193 pages containing 'print'. The builtin functions page was ranked 75. It is a fairly long page with just 3 occurences of 'print'. To repeat, use the index to find defining entries for Python objects. If someone wants to volunteer to write a more intelligent search algorithm, that incorporates info from the index and markup, feel free. -- Terry Jan Reedy From ben+python at benfinney.id.au Tue Sep 4 19:05:58 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 05 Sep 2012 09:05:58 +1000 Subject: How to tell people to ask questions the smart way (was: focus on jtextfield) References: <50a09acc-a7ac-4c17-b790-65cf3db80478@googlegroups.com> Message-ID: <87vcft75ih.fsf_-_@benfinney.id.au> Andreas Perstinger writes: > On 04.09.2012 11:34, Paolo wrote: > > how do I know if a JTextField has the focus? > > thank to all > > Look there: > http://www.catb.org/esr/faqs/smart-questions.html#forum That is an unhelpful response. You aren't giving anything to help the original poster improve their question. Moreover, it is rude and dismissive, which doesn't belong in this forum. The ?how to ask question the smart way? essay is not a blunt instrument for beating people over the head with, and it is brutish to use it that way. Instead, please point out *how* the original poster's question can be improved. -- \ ?I think Western civilization is more enlightened precisely | `\ because we have learned how to ignore our religious leaders.? | _o__) ?Bill Maher, 2003 | Ben Finney From tjreedy at udel.edu Tue Sep 4 19:16:41 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 04 Sep 2012 19:16:41 -0400 Subject: The opener parameter of Python 3 open() built-in In-Reply-To: References: <504555a5$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/4/2012 6:18 PM, Chris Angelico wrote: > On Wed, Sep 5, 2012 at 5:16 AM, Terry Reedy wrote: >> io.open depends on a function the returns an open file descriptor. opener >> exposes that dependency so it can be replaced. > > I skimmed the bug report comments but didn't find an answer to this: > Why not just monkey-patch? As far as I know, one can only use normal Python code to monkey patch modules written in Python. Even then, one can only rebind names stored in writable dicts -- the module dict and class attribute dicts. The attributes of function code objects are readonly. Replacing a code object is not for the faint of heart. io.py mostly loads _io compiled from C. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Tue Sep 4 19:28:55 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 05 Sep 2012 00:28:55 +0100 Subject: How to tell people to ask questions the smart way In-Reply-To: <87vcft75ih.fsf_-_@benfinney.id.au> References: <50a09acc-a7ac-4c17-b790-65cf3db80478@googlegroups.com> <87vcft75ih.fsf_-_@benfinney.id.au> Message-ID: On 05/09/2012 00:05, Ben Finney wrote: > Andreas Perstinger writes: > >> On 04.09.2012 11:34, Paolo wrote: >>> how do I know if a JTextField has the focus? >>> thank to all >> >> Look there: >> http://www.catb.org/esr/faqs/smart-questions.html#forum > > That is an unhelpful response. You aren't giving anything to help the > original poster improve their question. Moreover, it is rude and > dismissive, which doesn't belong in this forum. > > The ?how to ask question the smart way? essay is not a blunt instrument > for beating people over the head with, and it is brutish to use it that > way. Instead, please point out *how* the original poster's question can > be improved. > It is my opinion that the OP got exactly what they deserved, hence I entirely disagree with your response. -- Cheers. Mark Lawrence. From rosuav at gmail.com Tue Sep 4 19:34:50 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Sep 2012 09:34:50 +1000 Subject: How to tell people to ask questions the smart way In-Reply-To: References: <50a09acc-a7ac-4c17-b790-65cf3db80478@googlegroups.com> <87vcft75ih.fsf_-_@benfinney.id.au> Message-ID: On Wed, Sep 5, 2012 at 9:28 AM, Mark Lawrence wrote: > On 05/09/2012 00:05, Ben Finney wrote: >> >>> Look there: >>> http://www.catb.org/esr/faqs/smart-questions.html#forum >> >> The ?how to ask question the smart way? essay is not a blunt instrument >> for beating people over the head with, and it is brutish to use it that >> way. Instead, please point out *how* the original poster's question can >> be improved. > > It is my opinion that the OP got exactly what they deserved, hence I > entirely disagree with your response. There are courteous and discourteous ways to hit someone over the head with a blunt instrument. The instrument was, imho, appropriate in this instance. ChrisA From oscar.j.benjamin at gmail.com Tue Sep 4 19:37:26 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 5 Sep 2012 00:37:26 +0100 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4 September 2012 22:59, Chris Angelico wrote: > On Wed, Sep 5, 2012 at 2:32 AM, Johannes Bauer > wrote: > > How do you arrive at that conclusion? When comparing two random strings, > > I just derived > > > > n = (256 / 255) * (1 - 256 ^ (-c)) > > > > where n is the average number of character comparisons and c. The > > rationale as follows: The first character has to be compared in any > > case. The second with a probability of 1/256, the third with 1/(256^2) > > and so on. > > That would be for comparing two random areas of memory. Python strings > don't have 256 options per character; and in terms of actual strings, > there's so many possibilities. The strings that a program is going to > compare for equality are going to use a vastly restricted alphabet; > for a lot of cases, there might be only a few dozen plausible > characters. > > But even so, it's going to scale approximately linearly with the > string length. If they're really random, then yes, there's little > chance that either a 1MB string or a 2MB string will be the same, but > with real data, they might very well have a long common prefix. So > it's still going to be more or less O(n). > It doesn't matter whether there are 256 possible characters or 2. String comparisons are best case O(1) and worst case O(n). For the average case we need to assume the distribution of the strings. Assuming random strings (with IID characters), even if there are only 2 characters the probability that all the characters up to the jth compare equal will still decrease exponentially with n, giving an average case of O(1) comparisons (if the two characters are equally likely: 1/2 + 2/4 + 3/8 + 4/16 + ... + j / (2 ** j) + ...). For real strings common prefixes may be more likely but unless the length of those common prefixes scales with n the average case number of comparisons required will not be O(n). The only way to get round the problem of O(1) string comparisons is to use strings composed entirely from a set of 1 possible character. Not only does this do away with all of the inherent performance problems of flexible string representations but it results in O(0) comparison complexity (far outstripping previous Python versions). Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Tue Sep 4 19:44:29 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 4 Sep 2012 19:44:29 -0400 Subject: How to tell people to ask questions the smart way In-Reply-To: References: <50a09acc-a7ac-4c17-b790-65cf3db80478@googlegroups.com> <87vcft75ih.fsf_-_@benfinney.id.au> Message-ID: Just to play advocatus diaboli, what if some seemingly simple questions are asked just to jump in and start talking python? In other words, they just wanna talk shop, no matter what it is. An OT(off topic) so to speak, and have an enlightened, and evolutionary(via brain structured acceptance of data approved for output, at the time) to discuss and get things wrong. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Sep 4 19:44:44 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Sep 2012 23:44:44 GMT Subject: python docs search for 'print' References: <5046484f$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5046926b$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Sep 2012 18:28:31 +0000, Steven D'Aprano wrote: > https://www.google.com.au/search?q=python+print > http://duckduckgo.com/html/?q=python+print > > In this case, google hits the right Python documentation on the first > link. Duckduckgo doesn't do nearly so well, but it comes up with a bunch > of useful third-party links. It does better for searches with fewer Gah! Brain meltdown! DDG does better on searches for Python terms with fewer extraneous meanings, e.g. "python print" finds many links about fashion, but https://duckduckgo.com/html/?q=python+tuple is all about Python tuples :) -- Steven From steve+comp.lang.python at pearwood.info Tue Sep 4 20:34:40 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Sep 2012 00:34:40 GMT Subject: Why derivated exception can not be pickled ? References: <7bb72fb5-5ab5-4748-acbf-c8e7666ee834@googlegroups.com> Message-ID: <50469e1f$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Sep 2012 08:57:00 -0700, Mathieu Courtois wrote: > Here is my example : > > > import cPickle > > ParentClass = object # works > ParentClass = Exception # does not [...] > 1. With ParentClass=object, it works as expected. > > 2. With ParentClass=Exception, __getstate__/__setstate__ are not called. > > Does anyone explain me why ? I think it is a bug. According to the documentation, if your class is unpickleable, an exception should be raised. If it is pickleable, __getstate__ should be called. I can't see anything to explain that what you are seeing is expected behaviour. Exceptions should definitely be pickleable: http://bugs.python.org/issue1692335 so __getstate__ should be called. I think you should report this as a bug. -- Steven From ben+python at benfinney.id.au Tue Sep 4 21:40:57 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 05 Sep 2012 11:40:57 +1000 Subject: python docs search for 'print' References: <5046484f$0$29981$c3e8da3$5496439d@news.astraweb.com> <5046926b$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r4qh6yc6.fsf@benfinney.id.au> Steven D'Aprano writes: > Gah! Brain meltdown! DDG does better on searches for Python terms with > fewer extraneous meanings, e.g. "python print" finds many links about > fashion, but https://duckduckgo.com/html/?q=python+tuple is all about > Python tuples :) Adding the ?site:docs.python.org? term will make any DuckDuckGo search far more relevant to Python documentation. -- \ ?The truth is the most valuable thing we have. Let us economize | `\ it.? ?Mark Twain, _Following the Equator_ | _o__) | Ben Finney From nhodgson at iinet.net.au Tue Sep 4 22:18:28 2012 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Wed, 05 Sep 2012 12:18:28 +1000 Subject: Comparing strings from the back? In-Reply-To: References: Message-ID: <-9CdnaqjTK6NKtvNnZ2dnUVZ_gednZ2d@westnet.com.au> Roy Smith: > I'm wondering if it might be faster to start at the ends of the strings > instead of at the beginning? If the strings are indeed equal, it's the > same amount of work starting from either end. Most people write loops that go forwards. This leads to the processor designers prioritizing detection mechanisms like cache prefetching for that case. However, its not always the situation: a couple of years ago Intel contributed a memcpy implementation to glibc that went backwards for a performance improvement. An explanation from a related patch involves speculative and committed operations and address bits on some processors and quickly lost me: paragraph 3 of http://lists.freedesktop.org/archives/pixman/2010-August/000423.html The memcpy patch was controversial as it broke Adobe Flash which assumed memcpy was safe like memmove. Neil From python at mrabarnett.plus.com Tue Sep 4 22:39:01 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 05 Sep 2012 03:39:01 +0100 Subject: Comparing strings from the back? In-Reply-To: <-9CdnaqjTK6NKtvNnZ2dnUVZ_gednZ2d@westnet.com.au> References: <-9CdnaqjTK6NKtvNnZ2dnUVZ_gednZ2d@westnet.com.au> Message-ID: <5046BB45.20809@mrabarnett.plus.com> On 05/09/2012 03:18, Neil Hodgson wrote: > Roy Smith: > >> I'm wondering if it might be faster to start at the ends of the strings >> instead of at the beginning? If the strings are indeed equal, it's the >> same amount of work starting from either end. > > Most people write loops that go forwards. This leads to the > processor designers prioritizing detection mechanisms like cache > prefetching for that case. > > However, its not always the situation: a couple of years ago Intel > contributed a memcpy implementation to glibc that went backwards for a > performance improvement. An explanation from a related patch involves > speculative and committed operations and address bits on some processors > and quickly lost me: > paragraph 3 of > http://lists.freedesktop.org/archives/pixman/2010-August/000423.html > > The memcpy patch was controversial as it broke Adobe Flash which > assumed memcpy was safe like memmove. > I don't think I've ever use memcpy, only memmove. From roy at panix.com Tue Sep 4 22:48:20 2012 From: roy at panix.com (Roy Smith) Date: Tue, 04 Sep 2012 22:48:20 -0400 Subject: Comparing strings from the back? References: <-9CdnaqjTK6NKtvNnZ2dnUVZ_gednZ2d@westnet.com.au> Message-ID: In article <-9CdnaqjTK6NKtvNnZ2dnUVZ_gednZ2d at westnet.com.au>, Neil Hodgson wrote: > The memcpy patch was controversial as it broke Adobe Flash An added benefit! From maniandram01 at gmail.com Tue Sep 4 23:22:15 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 4 Sep 2012 20:22:15 -0700 (PDT) Subject: python docs search for 'print' In-Reply-To: References: Message-ID: On Tuesday, 4 September 2012 23:29:26 UTC+5:30, David Hoese wrote: > A friend made me aware of this: > > When a python beginner (2.x) quick searches for "print" on > > docs.python.org, the print function doesn't even come up in the top 20 > > results. The print statement isn't even listed as far as I can tell. > > Is there something that can be done about this to make it easier for > > beginners? > > > > I understand that this is a very basic search and "print" is a very > > common word and a very basic python statement, but it's pretty difficult > > for a beginner to learn when the first 5 results are about the > > disassembler and the next 5 are C functions. > > > > -Dave I was actually planning to write a bug on this. ---------------- my project which you will *never* *never* contribute to http://code.google.com/p/py2c From maniandram01 at gmail.com Tue Sep 4 23:22:15 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 4 Sep 2012 20:22:15 -0700 (PDT) Subject: python docs search for 'print' In-Reply-To: References: Message-ID: On Tuesday, 4 September 2012 23:29:26 UTC+5:30, David Hoese wrote: > A friend made me aware of this: > > When a python beginner (2.x) quick searches for "print" on > > docs.python.org, the print function doesn't even come up in the top 20 > > results. The print statement isn't even listed as far as I can tell. > > Is there something that can be done about this to make it easier for > > beginners? > > > > I understand that this is a very basic search and "print" is a very > > common word and a very basic python statement, but it's pretty difficult > > for a beginner to learn when the first 5 results are about the > > disassembler and the next 5 are C functions. > > > > -Dave I was actually planning to write a bug on this. ---------------- my project which you will *never* *never* contribute to http://code.google.com/p/py2c From maniandram01 at gmail.com Tue Sep 4 23:40:57 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 4 Sep 2012 20:40:57 -0700 (PDT) Subject: Error 32 - Broken Pipe . Please Help!! In-Reply-To: References: Message-ID: <98256fa5-e921-41a7-ae93-82a432c99056@googlegroups.com> On Tuesday, 4 September 2012 22:38:03 UTC+5:30, Sreenath k wrote: > Error: > > > > > > Exception in thread Thread-1: > > Traceback (most recent call last): > > File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner > > self.run() > > File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/monitor.py", line 575, in run > > already_pickled=True) > > File "/usr/lib/python2.7/dist-packages/spyderlib/utils/bsdsocket.py", line 24, in write_packet > > sock.send(struct.pack("l", len(sent_data)) + sent_data) > > error: [Errno 32] Broken pipe > > > > Code : > > > > #code > > > > s=1 > > f=0 > > c=0 > > > > for i in range (1,100): > > c=0 > > for j in (1,i): > > s+=j > > c=0 > > for k in range(1,(s/2+1)): > > #print s > > t=s%k > > if t==0: > > c+=1 > > if c>=5: > > f=1 > > print s > > break > > > > print s > > > > #code ends. > > > > The program is runnning. It has been more than 10 minutes ( currently). Should I raise my hopes for an answer ? *Please* make your variable names more descriptive. From maniandram01 at gmail.com Tue Sep 4 23:43:11 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 4 Sep 2012 20:43:11 -0700 (PDT) Subject: sockets,threads and interupts In-Reply-To: References: <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com> Message-ID: <340d794c-b7e8-49e1-9449-5e5314baa98c@googlegroups.com> On Tuesday, 4 September 2012 23:41:13 UTC+5:30, Grant Edwards wrote: > On 2012-09-04, MRAB wrote: > > > On 04/09/2012 16:26, loial wrote: > > >> I have threaded python script that uses sockets to monitor network > > >> ports. > > >> > > >> I want to ensure that the socket is closed cleanly in all > > >> circumstances. This includes if the script is killed or interupted in > > >> some other way. > > >> > > >> As I understand it signal only works in the main thread, so how can I > > >> trap interupts in my threaded class and always ensure I close the > > >> socket? Using KeyboardInterupt does not seem to work. > > >> > > > You could wrap it in try...finally. The 'finally' clause is guaranteed > > > to be run, so you can close the sockets there. > > > > > > However, if the script is just killed, then it won't get the chance > > > to tidy up. > > > > That depends on the signal used to "kill" the thread. > > > > You can catch SIGTERM and SIGINT and clean up before exiting. > > > > You can't catch SIGKILL, but sending a SIGKILL isn't considered polite > > unless you've already tried SIGTERM/SIGINT and it didn't work. > > > > -- > > Grant Edwards grant.b.edwards Yow! Are we on STRIKE yet? > > at > > gmail.com We could just use a "with" statement. Neater, easier. From dwightdhutto at gmail.com Tue Sep 4 23:52:37 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 4 Sep 2012 23:52:37 -0400 Subject: python docs search for 'print' In-Reply-To: References: Message-ID: The generated code can be run without Python installed and does not embed Python. For example: print("Hello World to py2c!") would be translated to #include "iostream" using namespace std; //If you want you can make py2c not add this and use std::cout instead of cout int main() { cout<<"Hello World to py2c!\n"; return 0; } Python is written in C, or so I'm told. So why don't you just look at the interpreter section/built-ins for the function of print? A good command line tutorial in C/C++ could show how python is handled through the terminal with a cin << print value; cout >> 'value', printf, etc. But I believe the original question is why is it not listed further up, maybe it's going alphabetically. -- Something like Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jimmyli1528 at gmail.com Tue Sep 4 23:54:46 2012 From: jimmyli1528 at gmail.com (jimbo1qaz) Date: Tue, 4 Sep 2012 20:54:46 -0700 (PDT) Subject: Zooming and Editing TkInter Images Message-ID: <836448fe-d0a3-4590-8c31-4a52b6d303b9@googlegroups.com> How do I zoom in on a tkinter image? And how do I change the selected pixel to a changeable color when the user clicks or drags? From tjreedy at udel.edu Wed Sep 5 00:05:25 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 05 Sep 2012 00:05:25 -0400 Subject: python docs search for 'print' In-Reply-To: References: Message-ID: On 9/4/2012 11:22 PM, Ramchandra Apte wrote: > I was actually planning to write a bug on this. If you do, find the right place to submit it. bugs.python.org is for issues relating to the cpython repository.' I fairly sure that the website search code is not there. If you do find the right place, you should contribute something to an improvement. The current search performance is not a secret, so mere complaints are useless. -- Terry Jan Reedy From rustompmody at gmail.com Wed Sep 5 00:32:00 2012 From: rustompmody at gmail.com (rusi) Date: Tue, 4 Sep 2012 21:32:00 -0700 (PDT) Subject: How to tell people to ask questions the smart way References: <50a09acc-a7ac-4c17-b790-65cf3db80478@googlegroups.com> <87vcft75ih.fsf_-_@benfinney.id.au> Message-ID: <36852e7d-2c9d-4341-8b62-bcd9c8cfffe7@io6g2000pbc.googlegroups.com> On Sep 5, 4:27?am, Mark Lawrence wrote: > On 05/09/2012 00:05, Ben Finney wrote: > > > > > > > > > > > Andreas Perstinger writes: > > >> On 04.09.2012 11:34, Paolo wrote: > >>> how do I know if a JTextField has the focus? > >>> thank to all > > >> Look there: > >>http://www.catb.org/esr/faqs/smart-questions.html#forum > > > That is an unhelpful response. You aren't giving anything to help the > > original poster improve their question. Moreover, it is rude and > > dismissive, which doesn't belong in this forum. > > > The ?how to ask question the smart way? essay is not a blunt instrument > > for beating people over the head with, and it is brutish to use it that > > way. Instead, please point out *how* the original poster's question can > > be improved. > > It is my opinion that the OP got exactly what they deserved, hence I > entirely disagree with your response. As a impartial response to what is 'deserved' it is fine. However... If we did not make these dicta as a norm - return unkindness with less unkindness (said in strange terms of cheeks and coats etc) - Do unto others as you would have them etc we would be back in the jungle. In the context of mailing lists/fora hopefully one needs to distinguish new post-ers/members from habitual idiots? And if all this sounds over-Christian see http://en.wikipedia.org/wiki/Robustness_principle Or more in line with python principles, the dilemma http://chrismdp.github.com/2012/02/on-coding-defensively/ From maniandram01 at gmail.com Wed Sep 5 01:22:12 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 4 Sep 2012 22:22:12 -0700 (PDT) Subject: python docs search for 'print' In-Reply-To: References: Message-ID: <9b4e3057-30a0-4731-95d2-131bfa495904@googlegroups.com> On Wednesday, 5 September 2012 09:35:43 UTC+5:30, Terry Reedy wrote: > On 9/4/2012 11:22 PM, Ramchandra Apte wrote: > > > > > I was actually planning to write a bug on this. > > > > If you do, find the right place to submit it. > > bugs.python.org is for issues relating to the cpython repository.' > > I fairly sure that the website search code is not there. > > > > If you do find the right place, you should contribute something to an > > improvement. The current search performance is not a secret, so mere > > complaints are useless. > > > > -- > > Terry Jan Reedy I was thinking we could just use Google Site search (it's fast easy to setup and gives good results) From maniandram01 at gmail.com Wed Sep 5 01:22:12 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 4 Sep 2012 22:22:12 -0700 (PDT) Subject: python docs search for 'print' In-Reply-To: References: Message-ID: <9b4e3057-30a0-4731-95d2-131bfa495904@googlegroups.com> On Wednesday, 5 September 2012 09:35:43 UTC+5:30, Terry Reedy wrote: > On 9/4/2012 11:22 PM, Ramchandra Apte wrote: > > > > > I was actually planning to write a bug on this. > > > > If you do, find the right place to submit it. > > bugs.python.org is for issues relating to the cpython repository.' > > I fairly sure that the website search code is not there. > > > > If you do find the right place, you should contribute something to an > > improvement. The current search performance is not a secret, so mere > > complaints are useless. > > > > -- > > Terry Jan Reedy I was thinking we could just use Google Site search (it's fast easy to setup and gives good results) From dieter at handshake.de Wed Sep 5 01:56:02 2012 From: dieter at handshake.de (Dieter Maurer) Date: Wed, 05 Sep 2012 07:56:02 +0200 Subject: sockets,threads and interupts References: <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com> Message-ID: <87obllggi5.fsf@handshake.de> loial writes: > I have threaded python script that uses sockets to monitor network ports. > > I want to ensure that the socket is closed cleanly in all circumstances. This includes if the script is killed or interupted in some other way. The operating system should close all sockets automatically when the process dies. Thus, if closing alone is sufficient... From dieter at handshake.de Wed Sep 5 02:02:12 2012 From: dieter at handshake.de (Dieter Maurer) Date: Wed, 05 Sep 2012 08:02:12 +0200 Subject: Why derivated exception can not be pickled ? References: <7bb72fb5-5ab5-4748-acbf-c8e7666ee834@googlegroups.com> Message-ID: <87k3w9gg7v.fsf@handshake.de> Mathieu Courtois writes: > Here is my example : > > > import cPickle > > ParentClass = object # works > ParentClass = Exception # does not > > class MyError(ParentClass): > def __init__(self, arg): > self.arg = arg > > def __getstate__(self): > print '#DBG pass in getstate' > odict = self.__dict__.copy() > return odict > > def __setstate__(self, state): > print '#DBG pass in setstate' > self.__dict__.update(state) > > exc = MyError('IDMESS') > > fo = open('pick.1', 'w') > cPickle.dump(exc, fo) > fo.close() > > fo = open('pick.1', 'r') > obj = cPickle.load(fo) > fo.close() > > > 1. With ParentClass=object, it works as expected. > > 2. With ParentClass=Exception, __getstate__/__setstate__ are not called. The pickle interface is actually more complex and there are several ways an object can ensure picklability. For example, there is also a "__reduce__" method. I suppose, that "Exception" defines methods which trigger the use of an alternative picklability approach (different from "__getstate__/__setstate__"). I would approach your case the following way: Use "pickle" instead of "cPickle" and debug picking/unpickling to find out what happens in detail. From charvigroups at gmail.com Wed Sep 5 02:28:25 2012 From: charvigroups at gmail.com (charvigroups at gmail.com) Date: Tue, 4 Sep 2012 23:28:25 -0700 (PDT) Subject: Beginners question In-Reply-To: References: Message-ID: <782893e7-a2dc-4018-a5c6-2a9cd07ecf99@googlegroups.com> Hi, I have attached python interview questions and answers for beginners. Please visit http://www.f2finterview.com/web/CorePython/ for core python and http://www.f2finterview.com/web/PythonAdvanced/ for advanced python On Thursday, August 30, 2012 5:24:08 PM UTC+5:30, (unknown) wrote: > Hello > > > > I'm slowly teaching myself python so apologies if this is a dumb question. > > but something has confused me with the os.stat() function: > > > > >>> s = os.stat(".") > > >>> print s > > posix.stat_result(st_mode=16877, st_ino=2278764L, st_dev=2053L, st_nlink=2, st_u > > id=1000, st_gid=100, st_size=4096L, st_atime=1346327745, st_mtime=1346327754, st > > _ctime=1346327754) > > > > What sort of object is posix.stat_result? Its not a dictionary or list or a > > class object as far as I can tell. Thanks for any help. > > > > B2003 From levinie001 at gmail.com Wed Sep 5 02:30:01 2012 From: levinie001 at gmail.com (Levi Nie) Date: Wed, 5 Sep 2012 14:30:01 +0800 Subject: why did the WindowsError occur? Message-ID: my code: import os os.startfile(r'C:\Program Files\Internet Explorer.exe') the error: os.startfile(r'C:\Program Files\Internet Explorer.exe') WindowsError: [Error 2] : 'C:\\Program Files\\Internet Explorer.exe' -------------- next part -------------- An HTML attachment was scrubbed... URL: From franck at ditter.org Wed Sep 5 02:30:31 2012 From: franck at ditter.org (Franck Ditter) Date: Wed, 05 Sep 2012 08:30:31 +0200 Subject: is implemented with id ? Message-ID: Hi ! a is b <==> id(a) == id(b) in builtin classes. Is that true ? Thanks, franck From benjamin.kaplan at case.edu Wed Sep 5 02:37:57 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 4 Sep 2012 23:37:57 -0700 Subject: why did the WindowsError occur? In-Reply-To: References: Message-ID: On Tue, Sep 4, 2012 at 11:30 PM, Levi Nie wrote: > my code: > import os > os.startfile(r'C:\Program Files\Internet Explorer.exe') > > the error: > os.startfile(r'C:\Program Files\Internet Explorer.exe') > WindowsError: [Error 2] : 'C:\\Program Files\\Internet Explorer.exe' > There's no such thing as C:\Program Files\Internet Explorer.exe. You probably want C:\Program Files\Internet Explorer\iexplore.exe. From benjamin.kaplan at case.edu Wed Sep 5 02:40:33 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 4 Sep 2012 23:40:33 -0700 Subject: is implemented with id ? In-Reply-To: References: Message-ID: On Tue, Sep 4, 2012 at 11:30 PM, Franck Ditter wrote: > Hi ! > a is b <==> id(a) == id(b) in builtin classes. > Is that true ? > Thanks, > > franck No. It is true that if a is b then id(a) == id(b) but the reverse is not necessarily true. id is only guaranteed to be unique among objects alive at the same time. If objects are discarded, their ids may be reused even though the objects are not the same. From marcin.tustin at gmail.com Wed Sep 5 02:43:31 2012 From: marcin.tustin at gmail.com (Marcin Tustin) Date: Wed, 5 Sep 2012 02:43:31 -0400 Subject: [Ann] superfixer - stop hardcoding class names in super calls Message-ID: Hi All, I have a small library which supplies a metaclass superfixer, which when applied to a class, provides every method with a variable __class__, which refers to the class in which the method is defined. This avoids the need to refer to the current class name in calls to super. If there's any interest, it could be extended to provide a no-args form of super. All suggestions and enhancements gratefully accepted! https://github.com/marcintustin/superfixer -- Marcin Tustin -------------- next part -------------- An HTML attachment was scrubbed... URL: From charvigroups at gmail.com Wed Sep 5 02:50:10 2012 From: charvigroups at gmail.com (charvigroups at gmail.com) Date: Tue, 4 Sep 2012 23:50:10 -0700 (PDT) Subject: Python Interview Questions In-Reply-To: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: Hi Guys, Finally I have decided to put best interview question and answers. Please visit http://www.f2finterview.com/web/CorePython/ for core python and http://www.f2finterview.com/web/PythonAdvanced/ for advanced python On Tuesday, October 30, 2007 11:44:01 PM UTC+5:30, Krypto wrote: > Hi, > > I have used Python for a couple of projects last year and I found it > extremely useful. I could write two middle size projects in 2-3 months > (part time). Right now I am a bit rusty and trying to catch up again > with Python. > > I am now appearing for Job Interviews these days and I am wondering if > anybody of you appeared for a Python Interview. Can you please share > the questions you were asked. That will be great help to me. > > Thanks, From andipersti at gmail.com Wed Sep 5 03:00:57 2012 From: andipersti at gmail.com (Andreas Perstinger) Date: Wed, 05 Sep 2012 09:00:57 +0200 Subject: How to tell people to ask questions the smart way In-Reply-To: <87vcft75ih.fsf_-_@benfinney.id.au> References: <50a09acc-a7ac-4c17-b790-65cf3db80478@googlegroups.com> <87vcft75ih.fsf_-_@benfinney.id.au> Message-ID: <5046F8A9.30901@gmail.com> On 05.09.2012 01:05, Ben Finney wrote: > Andreas Perstinger writes: > >> On 04.09.2012 11:34, Paolo wrote: >> > how do I know if a JTextField has the focus? >> > thank to all >> >> Look there: >> http://www.catb.org/esr/faqs/smart-questions.html#forum > > That is an unhelpful response. So we have to agree to disagree. EOD. Bye, Andreas From breamoreboy at yahoo.co.uk Wed Sep 5 03:38:51 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 05 Sep 2012 08:38:51 +0100 Subject: Error 32 - Broken Pipe . Please Help!! In-Reply-To: References: <98256fa5-e921-41a7-ae93-82a432c99056@googlegroups.com> Message-ID: On 05/09/2012 06:33, Dennis Lee Bieber wrote: > On Tue, 4 Sep 2012 20:40:57 -0700 (PDT), Ramchandra Apte > declaimed the following in > gmane.comp.python.general: > >> >> *Please* make your variable names more descriptive. > > No kidding... I haven't seen such cryptic names since 1972 -- an era > when BASIC only allowed for > > A..Z{"" | 1..0}{"" | $} > > {that is, one letter, with optional single digit, with optional $ for > string} > Presumably BASIC aficianodas still insist that BASIC is the second best programming language in the world, with the best yet to be invented :) -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Wed Sep 5 03:52:57 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 05 Sep 2012 08:52:57 +0100 Subject: why did the WindowsError occur? In-Reply-To: References: Message-ID: On 05/09/2012 07:30, Levi Nie wrote: > my code: > import os > os.startfile(r'C:\Program Files\Internet Explorer.exe') > > the error: > os.startfile(r'C:\Program Files\Internet Explorer.exe') > WindowsError: [Error 2] : 'C:\\Program Files\\Internet Explorer.exe' > > > Because you've done something wrong. If you'd like to tell us what you've done to find out where the problem is, we are far more likely to help. Please remember that the rates of pay here are amongst the lowest in the world :) -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Wed Sep 5 04:03:00 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 05 Sep 2012 09:03:00 +0100 Subject: Beginners question In-Reply-To: <782893e7-a2dc-4018-a5c6-2a9cd07ecf99@googlegroups.com> References: <782893e7-a2dc-4018-a5c6-2a9cd07ecf99@googlegroups.com> Message-ID: On 05/09/2012 07:28, charvigroups at gmail.com wrote: > Hi, > > I have attached python interview questions and answers for beginners. > > Please visit http://www.f2finterview.com/web/CorePython/ for core python and > > http://www.f2finterview.com/web/PythonAdvanced/ for advanced python > > The first question from the advanced list is really going to stretch an advanced Python developer, so only gurus need bother as it's so difficult. Not. -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Wed Sep 5 04:06:39 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 05 Sep 2012 09:06:39 +0100 Subject: How to tell people to ask questions the smart way In-Reply-To: <5046F8A9.30901@gmail.com> References: <50a09acc-a7ac-4c17-b790-65cf3db80478@googlegroups.com> <87vcft75ih.fsf_-_@benfinney.id.au> <5046F8A9.30901@gmail.com> Message-ID: On 05/09/2012 08:00, Andreas Perstinger wrote: > On 05.09.2012 01:05, Ben Finney wrote: >> Andreas Perstinger writes: >> >>> On 04.09.2012 11:34, Paolo wrote: >>> > how do I know if a JTextField has the focus? >>> > thank to all >>> >>> Look there: >>> http://www.catb.org/esr/faqs/smart-questions.html#forum >> >> That is an unhelpful response. > > So we have to agree to disagree. > > EOD. > > Bye, Andreas Thinking about it your post was very unhelpful as I couldn't find anything about JTextField at the url you posted as seen above. Fancy wasting my time like that :) -- Cheers. Mark Lawrence. From __peter__ at web.de Wed Sep 5 04:29:14 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 05 Sep 2012 10:29:14 +0200 Subject: Comparing strings from the back? References: Message-ID: Roy Smith wrote: > There's been a bunch of threads lately about string implementations, and > that got me thinking (which is often a dangerous thing). > > Let's assume you're testing two strings for equality. You've already > done the obvious quick tests (i.e they're the same length), and you're > down to the O(n) part of comparing every character. > > I'm wondering if it might be faster to start at the ends of the strings > instead of at the beginning? If the strings are indeed equal, it's the > same amount of work starting from either end. But, if it turns out that > for real-life situations, the ends of strings have more entropy than the > beginnings, the odds are you'll discover that they're unequal quicker by > starting at the end. > > It doesn't seem un-plausible that this is the case. For example, most > of the filenames I work with begin with "/home/roy/". Most of the > strings I use as memcache keys have one of a small number of prefixes. > Most of the strings I use as logger names have common leading > substrings. Things like credit card and telephone numbers tend to have > much more entropy in the trailing digits. But do you actually compare them with each other? Even if you do I'd guess that Python looks at the hash values most of the time. > On the other hand, hostnames (and thus email addresses) exhibit the > opposite pattern. Nor do english words: $ python3 reverse_compare2.py compare /usr/share/dict/words --word-len 8 comparing every pair in a sample of 1000 8-char words taken from '/usr/share/dict/words' head 1: 477222 ************************************************************ 2: 18870 ** 3: 2870 4: 435 5: 74 6: 17 7: 12 tail 1: 386633 ************************************************************ 2: 74966 *********** 3: 29698 **** 4: 6536 * 5: 1475 6: 154 7: 28 8: 10 > Anyway, it's just a thought. Has anybody studied this for real-life > usage patterns? > > I'm also not sure how this work with all the possible UCS/UTF encodings. > With some of them, you may get the encoding semantics wrong if you don't > start from the front. From rosuav at gmail.com Wed Sep 5 04:33:04 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Sep 2012 18:33:04 +1000 Subject: Comparing strings from the back? In-Reply-To: References: Message-ID: On Wed, Sep 5, 2012 at 6:29 PM, Peter Otten <__peter__ at web.de> wrote: > comparing every pair in a sample of 1000 8-char words > taken from '/usr/share/dict/words' > > head > 1: 477222 ************************************************************ > 2: 18870 ** > ... Not understanding this. What are the statistics, and what (if it's not obvious from the previous answer) do they prove? ChrisA From kushal.kumaran+python at gmail.com Wed Sep 5 04:40:35 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Wed, 5 Sep 2012 14:10:35 +0530 Subject: Python Interview Questions In-Reply-To: References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: On Wed, Sep 5, 2012 at 12:20 PM, wrote: > On Tuesday, October 30, 2007 11:44:01 PM UTC+5:30, Krypto wrote: >> Hi, >> >> I have used Python for a couple of projects last year and I found it >> extremely useful. I could write two middle size projects in 2-3 months >> (part time). Right now I am a bit rusty and trying to catch up again >> with Python. >> >> I am now appearing for Job Interviews these days and I am wondering if >> anybody of you appeared for a Python Interview. Can you please share >> the questions you were asked. That will be great help to me. >> > > Finally I have decided to put best interview question and answers. > > Please visit http://www.f2finterview.com/web/CorePython/ for core python and http://www.f2finterview.com/web/PythonAdvanced/ for advanced python > As I see from a quick glance, several of your answers seem to be copied from the python faq at http://docs.python.org/faq/. The copyright notice for the python.org website seems to be at http://docs.python.org/copyright.html. Do you have the Python Software Foundation's permission to copy large chunks of the python.org website and claim it as your own content? -- regards, kushal From mathieu.courtois at gmail.com Wed Sep 5 04:54:21 2012 From: mathieu.courtois at gmail.com (Mathieu Courtois) Date: Wed, 5 Sep 2012 01:54:21 -0700 (PDT) Subject: Why derivated exception can not be pickled ? In-Reply-To: References: <7bb72fb5-5ab5-4748-acbf-c8e7666ee834@googlegroups.com> Message-ID: Thanks for your reply On Wednesday, September 5, 2012 8:02:55 AM UTC+2, Dieter Maurer wrote: > > The pickle interface is actually more complex and there are several > > ways an object can ensure picklability. For example, there is > > also a "__reduce__" method. I suppose, that "Exception" defines methods > > which trigger the use of an alternative picklability approach (different > > from "__getstate__/__setstate__"). You're right: Exception has __reduce__ & __reduce_ex__ methods. Always read carefully the manual ;-) I must override these methods. MC From mathieu.courtois at gmail.com Wed Sep 5 04:54:21 2012 From: mathieu.courtois at gmail.com (Mathieu Courtois) Date: Wed, 5 Sep 2012 01:54:21 -0700 (PDT) Subject: Why derivated exception can not be pickled ? In-Reply-To: References: <7bb72fb5-5ab5-4748-acbf-c8e7666ee834@googlegroups.com> Message-ID: Thanks for your reply On Wednesday, September 5, 2012 8:02:55 AM UTC+2, Dieter Maurer wrote: > > The pickle interface is actually more complex and there are several > > ways an object can ensure picklability. For example, there is > > also a "__reduce__" method. I suppose, that "Exception" defines methods > > which trigger the use of an alternative picklability approach (different > > from "__getstate__/__setstate__"). You're right: Exception has __reduce__ & __reduce_ex__ methods. Always read carefully the manual ;-) I must override these methods. MC From andrew.artajos.dev at gmail.com Wed Sep 5 04:54:45 2012 From: andrew.artajos.dev at gmail.com (Andrew Artajos) Date: Wed, 5 Sep 2012 16:54:45 +0800 Subject: How to tell people to ask questions the smart way In-Reply-To: <1346834438.15070.YahooMailNeo@web29603.mail.ird.yahoo.com> References: <50a09acc-a7ac-4c17-b790-65cf3db80478@googlegroups.com> <87vcft75ih.fsf_-_@benfinney.id.au> <5046F8A9.30901@gmail.com> <1346834438.15070.YahooMailNeo@web29603.mail.ird.yahoo.com> Message-ID: Stack Overflow has a nice guideline on how to ask a question. http://stackoverflow.com/questions/ask/advice? -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrew.artajos.dev at gmail.com Wed Sep 5 04:55:51 2012 From: andrew.artajos.dev at gmail.com (Andrew Artajos) Date: Wed, 5 Sep 2012 16:55:51 +0800 Subject: Comparing strings from the back? In-Reply-To: References: Message-ID: a random idea: you could compare strings by their hashes.. print hash("randomstring") == hash("randomstring") print hash("randomstring") == hash("randoMstring") -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Sep 5 05:14:23 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Sep 2012 09:14:23 GMT Subject: is implemented with id ? References: Message-ID: <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Sep 2012 08:30:31 +0200, Franck Ditter wrote: > Hi ! > a is b <==> id(a) == id(b) in builtin classes. Is that true ? Not just for builtin classes, for any objects, provided that they are alive at the same time. There is no guarantee whether IDs will be re-used. Some versions of Python do re-use IDs, e.g. CPython: steve at runes:~$ python Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = ["some", "object"] >>> id(a) 3074285228L >>> del a >>> b = [100, 200] >>> id(b) 3074285228L but others do not, e.g. Jython and IronPython: steve at runes:~$ jython Jython 2.5.1+ (Release_2_5_1, Aug 4 2010, 07:18:19) [OpenJDK Client VM (Sun Microsystems Inc.)] on java1.6.0_18 Type "help", "copyright", "credits" or "license" for more information. >>> a = ["some", "object"] >>> id(a) 1 >>> del a >>> b = [100, 200] >>> id(b) 2 steve at runes:~$ ipy IronPython 2.6 Beta 2 DEBUG (2.6.0.20) on .NET 2.0.50727.1433 Type "help", "copyright", "credits" or "license" for more information. >>> a = ["some", "object"] >>> id(a) 43 >>> del a >>> b = [100, 200] >>> id(b) 44 CPython especially has the most complicated behaviour with IDs and object identity: >>> a = 99.99 >>> b = 99.99 >>> a is b False >>> a = 99.99; b = 99.99; a is b True In general, you almost never need to care about IDs and object identity. The main exception is testing for None, which should always be written as: if x is None -- Steven From dfnsonfsduifb at gmx.de Wed Sep 5 05:17:33 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Wed, 05 Sep 2012 11:17:33 +0200 Subject: Comparing strings from the back? In-Reply-To: <50464361$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <50464361$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04.09.2012 20:07, Steven D'Aprano wrote: > A reasonable, conservative assumption is to calculate the largest > possible value of the average for random strings. That largest value > occurs when the alphabet is as small as possible, namely two characters. > In practice, strings come from a larger alphabet, up to 1114111 different > characters for full Unicode strings, so the average for them will be less > than the average we calculate now. > > So for unequal strings, the number of comparisons is equally likely to be > 1, 2, 3, ..., N. The average then is: That is exactly what I don't agree with. For unequal random strings, the distribution is *not* equally likely to have the same amount of comparisons. For demonstration, let's look at bitstrings and the string "1010". There 15 bitstrings of same length which are unequal and I'll put the number of comparisons needed next to them going left to right: 0000 1 0001 1 0010 1 0011 1 0100 1 0101 1 0110 1 0111 1 1100 2 1101 2 1110 2 1111 2 1000 3 1001 3 1011 4 i.e. about 1.73 (26/15) comparisons in average with random strings compared to the 2.5 comparisons you end up with. My formula does respect lazy termination (because the probabilty of higher comparisons gets exponentially lower). > sum([1, 2, 3, ..., N])/N > > which by a bit of simple algebra works out to be (N+1)/2, or half the > characters as I said. Yes, but it's a flawed assumption you're making since you're neglecting lazy evaluation and early abort of comparison. Best regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From dfnsonfsduifb at gmx.de Wed Sep 5 05:24:52 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Wed, 05 Sep 2012 11:24:52 +0200 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04.09.2012 23:59, Chris Angelico wrote: >> n = (256 / 255) * (1 - 256 ^ (-c)) >> >> where n is the average number of character comparisons and c. The >> rationale as follows: The first character has to be compared in any >> case. The second with a probability of 1/256, the third with 1/(256^2) >> and so on. > > That would be for comparing two random areas of memory. Python strings > don't have 256 options per character; and in terms of actual strings, > there's so many possibilities. The unit of comparison is completely arbitraty and can equally be used to compare bitstrings if changed accordingly. > The strings that a program is going to > compare for equality are going to use a vastly restricted alphabet; > for a lot of cases, there might be only a few dozen plausible > characters. This is very true. But if so, I would like to see the assumtion that you're making (which might very well be plausible) in order to arrive at a average of N/2 comparisons (which just seems *way* off). > But even so, it's going to scale approximately linearly with the > string length. If they're really random, then yes, there's little > chance that either a 1MB string or a 2MB string will be the same, but > with real data, they might very well have a long common prefix. So > it's still going to be more or less O(n). I understand what you're saying and surely this is true to some extent (someone mentioned filenames, which is an excellent example). However in order to derive a *formula* you need to formularize your assumtions. With random data, it's definitely not O(n). And even in reality (with a more limited alphabet) it usually will early abort: Consider sorting a large dictionary. Sorting is in O(n log(n)), but this assumes O(1) comparisons! If the comparison operation itself were in O(n), the total sorting complexity would be O(n^2 log(n)), which is definitely false. Most comparisons will abort *very* early (after the first character). Best regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From tjreedy at udel.edu Wed Sep 5 05:33:20 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 05 Sep 2012 05:33:20 -0400 Subject: python docs search for 'print' In-Reply-To: <9b4e3057-30a0-4731-95d2-131bfa495904@googlegroups.com> References: <9b4e3057-30a0-4731-95d2-131bfa495904@googlegroups.com> Message-ID: On 9/5/2012 1:22 AM, Ramchandra Apte wrote: > On Wednesday, 5 September 2012 09:35:43 UTC+5:30, Terry Reedy wrote: >> If you do find the right place, you should contribute something to an >> improvement. The current search performance is not a secret, so mere >> complaints are useless. > I was thinking we could just use Google Site search (it's fast easy to > setup and gives good results) I have the impression that that is what we once did, but maybe not. Or maybe that is or was for python.org but not docs.python.org, etc. Ease version of the docs needs the search restricted to that version. If you can give the way to do the easy setup, with that constraint, that would be a positive suggestion, accepted or not. -- Terry Jan Reedy From dfnsonfsduifb at gmx.de Wed Sep 5 05:43:08 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Wed, 05 Sep 2012 11:43:08 +0200 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05.09.2012 11:24, Johannes Bauer wrote: > Consider sorting a large dictionary. Sorting is in O(n log(n)), but this > assumes O(1) comparisons! If the comparison operation itself were in > O(n), the total sorting complexity would be O(n^2 log(n)), which is > definitely false. Most comparisons will abort *very* early (after the > first character). I've just written a program to demonstrate this (below it's attached). I used my aspell dictionary, which contains about 100k words. To have complexity down I went for only words wich occur most often (in this case 9 characters or ~13k words). Here's the results (note it's randomized, so they'll always differ a little, but are pretty stable) Max Cmp: 100 Sum Cmp: 32111 Avg Cmp: 2.393842254361115 Num words : 13414 Min wordlen: 9 Max wordlen: 9 Avg wordlen: 9.0 Going up in wordlength (only showing part now) Avg Cmp: 2.2374929735806632 Num words : 10674 Avg wordlen: 10.0 Avg Cmp: 2.261727078891258 Num words : 7504 Avg wordlen: 11.0 Avg Cmp: 2.2335647202939977 Num words : 4898 Avg wordlen: 12.0 Avg Cmp: 2.1743341404358354 Num words : 2891 Avg wordlen: 13.0 Avg Cmp: 2.156782549420586 Num words : 1467 Avg wordlen: 14.0 Avg Cmp: 2.112449799196787 Num words : 747 Avg wordlen: 15.0 So, interestingly, in this real-world case(tm), the complexity does not scale with O(n). It actually goes down (which is probably due to the limit amount of words of higher length). In summary, let's please not debate "feelings" or such. Either measurements (with clear indiciation on what data they're based on and how the test was conducted) or derivations (with an explanation of the assumtions). Feelings can be very misleading in cases like this. Best regards, Johannes #!/usr/bin/python3 import random class Word(): def __init__(self, s): self._s = s self._c = 0 def __lt__(self, other): if len(self) < len(other): return True elif len(self) > len(other): return False for i in range(len(self)): self._c += 1 if self._s[i] < other._s[i]: return True return False def __repr__(self): return "%s<%d>" % (self._s, self._c) def __len__(self): return len(self._s) def getcmp(self): return self._c wordlist = [ ] for line in open("dict", "r"): word = Word(line[:-1]) if len(word) == 9: wordlist.append(word) random.shuffle(wordlist) wordlist.sort() comparisons = [ word.getcmp() for word in wordlist ] print("Max Cmp:", max(comparisons)) print("Sum Cmp:", sum(comparisons)) print("Avg Cmp:", sum(comparisons) / len(comparisons)) wordlengths = [ len(word) for word in wordlist ] print("Min wordlen:", min(wordlengths)) print("Max wordlen:", max(wordlengths)) print("Avg wordlen:", sum(wordlengths) / len(wordlengths)) -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From __peter__ at web.de Wed Sep 5 05:48:38 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 05 Sep 2012 11:48:38 +0200 Subject: Comparing strings from the back? References: Message-ID: Chris Angelico wrote: > On Wed, Sep 5, 2012 at 6:29 PM, Peter Otten <__peter__ at web.de> wrote: >> comparing every pair in a sample of 1000 8-char words >> taken from '/usr/share/dict/words' >> >> head >> 1: 477222 ************************************************************ >> 2: 18870 ** >> ... tail 1: 386633 ************************************************************ 2: 74966 *********** > Not understanding this. What are the statistics, I measured how many chars they have in common for all combinations of 1000 words taken from /usr/share/dict/words. 477222 pairs have one char in common, 18870 pairs have two chars in common when compared from the *beginning* of the string. 386633 pairs have one char in common, 74966 pairs have two chars in common when compared from the *end* of the string. and what (if it's not obvious from the previous answer) do they prove? They demonstrate that for two words from that particular corpus it is likely that a[::-1] == b[::-1] has to take more (1.34 versus 1.05 on average) characters into account than a == b, i. e. comparing from the back should be slower rather than faster. If that doesn't help, here's the code ;) import random import itertools from contextlib import contextmanager from collections import defaultdict @contextmanager def open_corpus(args): with open(args.name) as instream: words = (line.strip() for line in instream) #words = (word for word in words if not word.endswith("'s")) yield words def pick(items, count): items = list(items) return random.sample(items, count) def count_common(a, b): i = 0 for i, (x, y) in enumerate(zip(a, b), 1): if x != y: break return i def corpus(args): with open_corpus(args) as words: wordlens = (len(line.strip()) for line in words) freq = defaultdict(int) for wordlen in wordlens: freq[wordlen] += 1 show_histogram(freq) def show_histogram(freq): peak = max(freq.values()) freq_width = len(str(peak)) max_freq = max(freq) len_width = len(str(max_freq)) for i in range(min(freq), max_freq+1): value = freq[i] print("{:{}}: {:{}} {}".format( i, len_width, value, freq_width, "*" * (60 * value // peak))) def compare(args): with open_corpus(args) as words: words = pick( (word for word in words if len(word) == args.word_len), args.sample_size) n = 0 head_common = defaultdict(int) tail_common = defaultdict(int) n_tail = n_head = 0 for n, (a, b) in enumerate(itertools.combinations(words, 2), 1): cc = count_common(a, b) n_head += cc head_common[cc] += 1 ccr = count_common(a[::-1], b[::-1]) n_tail += ccr tail_common[ccr] += 1 print(n, "combinations") print("average common chars (head) {:.3}".format(n_head/n)) print("average common chars (tail) {:.3}".format(n_tail/n)) print("comparing every pair in a " "sample of {sample} {len}-char words\n" "taken from {name!r}".format( sample=args.sample_size, len=args.word_len, name=args.name)) print() print("head") show_histogram(head_common) print() print("tail") show_histogram(tail_common) def main(): import argparse parser = argparse.ArgumentParser() parsers = parser.add_subparsers() pcorpus = parsers.add_parser("corpus") pcorpus.add_argument("name") pcorpus.set_defaults(func=corpus) pcompare = parsers.add_parser("compare") pcompare.add_argument("name") pcompare.add_argument("--sample-size", type=int, default=1000) pcompare.add_argument("--word-len", type=int, default=8) pcompare.set_defaults(func=compare) args = parser.parse_args() args.func(args) if __name__ == "__main__": main() From mathieu.courtois at gmail.com Wed Sep 5 06:18:07 2012 From: mathieu.courtois at gmail.com (Mathieu Courtois) Date: Wed, 5 Sep 2012 03:18:07 -0700 (PDT) Subject: Why derivated exception can not be pickled ? In-Reply-To: <7bb72fb5-5ab5-4748-acbf-c8e7666ee834@googlegroups.com> References: <7bb72fb5-5ab5-4748-acbf-c8e7666ee834@googlegroups.com> Message-ID: Hello, The simple example works fine using __reduce__: class MyError(Exception): def __init__(self, arg): self.arg = arg def __reduce__(self): return (MyError, (self.arg, )) From nospam at nospam.com Wed Sep 5 08:03:26 2012 From: nospam at nospam.com (Gilles) Date: Wed, 05 Sep 2012 14:03:26 +0200 Subject: [web] Long-running process: FCGI? SCGI? WSGI? Message-ID: <4ofe485b0m50fi2qa7sk8d01369g2lo5el@4ax.com> Hello To write a long-running web application, I'd like to some feedback about which option to choose. Apparently, the choice boilds down to this: - FastCGI - SCGI - WSGI It seems like FCGI and SCGI are language-neutral, while WSGI is Python-specific. Besides that, how to make an informed choice about which option to choose? Thank you. From maniandram01 at gmail.com Wed Sep 5 08:45:00 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 5 Sep 2012 05:45:00 -0700 (PDT) Subject: python docs search for 'print' In-Reply-To: References: <9b4e3057-30a0-4731-95d2-131bfa495904@googlegroups.com> Message-ID: On Wednesday, 5 September 2012 15:03:56 UTC+5:30, Terry Reedy wrote: > On 9/5/2012 1:22 AM, Ramchandra Apte wrote: > > > On Wednesday, 5 September 2012 09:35:43 UTC+5:30, Terry Reedy wrote: > > > > >> If you do find the right place, you should contribute something to an > > >> improvement. The current search performance is not a secret, so mere > > >> complaints are useless. > > > > > I was thinking we could just use Google Site search (it's fast easy to > > > setup and gives good results) > > > > I have the impression that that is what we once did, but maybe not. Or > > maybe that is or was for python.org but not docs.python.org, etc. Ease > > version of the docs needs the search restricted to that version. If you > > can give the way to do the easy setup, with that constraint, that would > > be a positive suggestion, accepted or not. > > > > > > -- > > Terry Jan Reedy Google site search costs 2000$ for 500,000 searches per year and 750$ for 150,000 searches so its quite expensive. Also the print function only comes in the third result (python 3.2) if you search for "site:docs.python.org/release/3.2 print" the print function is not found at all. I think a specialized algorithm would work better. I'm going to code an program for this. From maniandram01 at gmail.com Wed Sep 5 08:45:00 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 5 Sep 2012 05:45:00 -0700 (PDT) Subject: python docs search for 'print' In-Reply-To: References: <9b4e3057-30a0-4731-95d2-131bfa495904@googlegroups.com> Message-ID: On Wednesday, 5 September 2012 15:03:56 UTC+5:30, Terry Reedy wrote: > On 9/5/2012 1:22 AM, Ramchandra Apte wrote: > > > On Wednesday, 5 September 2012 09:35:43 UTC+5:30, Terry Reedy wrote: > > > > >> If you do find the right place, you should contribute something to an > > >> improvement. The current search performance is not a secret, so mere > > >> complaints are useless. > > > > > I was thinking we could just use Google Site search (it's fast easy to > > > setup and gives good results) > > > > I have the impression that that is what we once did, but maybe not. Or > > maybe that is or was for python.org but not docs.python.org, etc. Ease > > version of the docs needs the search restricted to that version. If you > > can give the way to do the easy setup, with that constraint, that would > > be a positive suggestion, accepted or not. > > > > > > -- > > Terry Jan Reedy Google site search costs 2000$ for 500,000 searches per year and 750$ for 150,000 searches so its quite expensive. Also the print function only comes in the third result (python 3.2) if you search for "site:docs.python.org/release/3.2 print" the print function is not found at all. I think a specialized algorithm would work better. I'm going to code an program for this. From maniandram01 at gmail.com Wed Sep 5 08:48:26 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 5 Sep 2012 05:48:26 -0700 (PDT) Subject: is implemented with id ? In-Reply-To: <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, 5 September 2012 14:44:23 UTC+5:30, Steven D'Aprano wrote: > On Wed, 05 Sep 2012 08:30:31 +0200, Franck Ditter wrote: > > > > > Hi ! > > > a is b <==> id(a) == id(b) in builtin classes. Is that true ? > > > > Not just for builtin classes, for any objects, provided that they are > Seeing this thread, I think the is statment should be removed. It has a replacement syntax of id(x) == id(y) and "a==True" should be automatically changed into memory comparison. > alive at the same time. > > > > There is no guarantee whether IDs will be re-used. Some versions of > > Python do re-use IDs, e.g. CPython: > > > > steve at runes:~$ python > > Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) > > [GCC 4.4.5] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> a = ["some", "object"] > > >>> id(a) > > 3074285228L > > >>> del a > > >>> b = [100, 200] > > >>> id(b) > > 3074285228L > > > > but others do not, e.g. Jython and IronPython: > > > > steve at runes:~$ jython > > Jython 2.5.1+ (Release_2_5_1, Aug 4 2010, 07:18:19) > > [OpenJDK Client VM (Sun Microsystems Inc.)] on java1.6.0_18 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> a = ["some", "object"] > > >>> id(a) > > 1 > > >>> del a > > >>> b = [100, 200] > > >>> id(b) > > 2 > > > > > > steve at runes:~$ ipy > > IronPython 2.6 Beta 2 DEBUG (2.6.0.20) on .NET 2.0.50727.1433 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> a = ["some", "object"] > > >>> id(a) > > 43 > > >>> del a > > >>> b = [100, 200] > > >>> id(b) > > 44 > > > > > > CPython especially has the most complicated behaviour with IDs and object > > identity: > > > > >>> a = 99.99 > > >>> b = 99.99 > > >>> a is b > > False > > >>> a = 99.99; b = 99.99; a is b > > True > > > > > > In general, you almost never need to care about IDs and object identity. > > The main exception is testing for None, which should always be written as: > > > > if x is None > > > > > > -- > > Steven From maniandram01 at gmail.com Wed Sep 5 08:51:57 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 5 Sep 2012 05:51:57 -0700 (PDT) Subject: why did the WindowsError occur? In-Reply-To: References: Message-ID: On Wednesday, 5 September 2012 13:21:58 UTC+5:30, Mark Lawrence wrote: > On 05/09/2012 07:30, Levi Nie wrote: > > > my code: > > > import os > > > os.startfile(r'C:\Program Files\Internet Explorer.exe') > > > > > > the error: > > > os.startfile(r'C:\Program Files\Internet Explorer.exe') > > > WindowsError: [Error 2] : 'C:\\Program Files\\Internet Explorer.exe' > > > > > > > > > > > > > Because you've done something wrong. If you'd like to tell us what > > you've done to find out where the problem is, we are far more likely to > > help. Please remember that the rates of pay here are amongst the lowest > > in the world :) I haven't heard anybody in a group paying money to be able to answer a question! So it should be the lowest rates of pay in the world. > > > > -- > > Cheers. > > > > Mark Lawrence. From maniandram01 at gmail.com Wed Sep 5 08:51:57 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 5 Sep 2012 05:51:57 -0700 (PDT) Subject: why did the WindowsError occur? In-Reply-To: References: Message-ID: On Wednesday, 5 September 2012 13:21:58 UTC+5:30, Mark Lawrence wrote: > On 05/09/2012 07:30, Levi Nie wrote: > > > my code: > > > import os > > > os.startfile(r'C:\Program Files\Internet Explorer.exe') > > > > > > the error: > > > os.startfile(r'C:\Program Files\Internet Explorer.exe') > > > WindowsError: [Error 2] : 'C:\\Program Files\\Internet Explorer.exe' > > > > > > > > > > > > > Because you've done something wrong. If you'd like to tell us what > > you've done to find out where the problem is, we are far more likely to > > help. Please remember that the rates of pay here are amongst the lowest > > in the world :) I haven't heard anybody in a group paying money to be able to answer a question! So it should be the lowest rates of pay in the world. > > > > -- > > Cheers. > > > > Mark Lawrence. From nospam at nospam.com Wed Sep 5 08:52:12 2012 From: nospam at nospam.com (Gilles) Date: Wed, 05 Sep 2012 14:52:12 +0200 Subject: [2.5.1] Read each line from txt file, replace, and save? References: Message-ID: On Sun, 02 Sep 2012 14:04:29 -0400, Terry Reedy wrote: >If you process each line separately, there is no reason to read them all >at once. Use the file as an iterator directly. Since line is already a >string, there is no reason to copy it into a new string. Combining these >two changes with Mark's suggestion to use with and we have the following >simple code: Thanks guys for the suggestion. From maniandram01 at gmail.com Wed Sep 5 08:54:41 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 5 Sep 2012 05:54:41 -0700 (PDT) Subject: sockets,threads and interupts In-Reply-To: References: <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com> Message-ID: <4baa457c-3408-46dd-a98b-ae7e097ac5e5@googlegroups.com> On Wednesday, 5 September 2012 11:26:16 UTC+5:30, Dieter Maurer wrote: > loial writes: > > > > > I have threaded python script that uses sockets to monitor network ports. > > > > > > I want to ensure that the socket is closed cleanly in all circumstances. This includes if the script is killed or interupted in some other way. > > > > The operating system should close all sockets automatically when > > the process dies. Thus, if closing alone is sufficient... At least on Linux, if you kill a process using sockets, it takes about 10 seconds for socket to be closed. A program should try to close all resources. OS'es may take a long time to close a unclosed socket automatically. From maniandram01 at gmail.com Wed Sep 5 08:54:41 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 5 Sep 2012 05:54:41 -0700 (PDT) Subject: sockets,threads and interupts In-Reply-To: References: <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com> Message-ID: <4baa457c-3408-46dd-a98b-ae7e097ac5e5@googlegroups.com> On Wednesday, 5 September 2012 11:26:16 UTC+5:30, Dieter Maurer wrote: > loial writes: > > > > > I have threaded python script that uses sockets to monitor network ports. > > > > > > I want to ensure that the socket is closed cleanly in all circumstances. This includes if the script is killed or interupted in some other way. > > > > The operating system should close all sockets automatically when > > the process dies. Thus, if closing alone is sufficient... At least on Linux, if you kill a process using sockets, it takes about 10 seconds for socket to be closed. A program should try to close all resources. OS'es may take a long time to close a unclosed socket automatically. From overhaalsgang_24_bob at me.com Wed Sep 5 08:57:05 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Wed, 5 Sep 2012 05:57:05 -0700 (PDT) Subject: HTMLParser skipping HTML? [newbie] Message-ID: <80d8623b-bb08-415c-900b-4a56556435ae@googlegroups.com> I'm trying to understand the HTMLParser so I've copied some code from http://docs.python.org/library/htmlparser.html?highlight=html#HTMLParser and tried that on my LinkedIn page. No errors, but some of the tags seem to go missing for no apparent reason - any advice? I have searched extensively for this, but seem to be the only one with missing data from HTMLParser :( Code: import urllib2 from HTMLParser import HTMLParser from GetHttpFileContents import getHttpFileContents # create a subclass and override the handler methods class MyHTMLParser(HTMLParser): def handle_starttag(self, tag, attrs): print "Start tag:\n\t", tag for attr in attrs: print "\t\tattr:", attr # end for attr in attrs: # def handle_endtag(self, tag): print "End tag :\n\t", tag # def handle_data(self, data): if data != '\n\n': if data != '\n': print "Data :\t\t", data # end if 1 # end if 2 # # # --------------------------------------------------------------------- # def removeHtmlFromFileContents(): TextOut = '' parser = MyHTMLParser() parser.feed(urllib2.urlopen('http://nl.linkedin.com/in/bobaalsma').read()) return TextOut # # --------------------------------------------------------------------- # if __name__ == '__main__': TextOut = removeHtmlFromFileContents() Part of the output: End tag : script Start tag: title Data : Bob Aalsma - Nederland | LinkedIn End tag : title Start tag: script attr: ('type', 'text/javascript') attr: ('src', 'http://www.linkedin.com/uas/authping?url=http%3A%2F%2Fnl%2Elinkedin%2Ecom%2Fin%2Fbobaalsma') End tag : script Start tag: link attr: ('rel', 'stylesheet') attr: ('type', 'text/css') attr: ('href', 'http://s3.licdn.com/scds/concat/common/css?h=5v4lkweptdvona6w56qelodrj-7pfvsr76gzb22ys278pbj80xm-b1io9ndljf1bvpack85gyxhv4-5xxmkfcm1ny97biv0pwj7ch69') Start tag: script attr: ('type', 'text/javascript') attr: ('src', 'http://s4.licdn.com/scds/concat/common/js?h=7nhn6ycbvnz80dydsu88wbuk-1kjdwxpxv0c3z97afuz9dlr9g-dlsf699o6xkxgppoxivctlunb-8v6o0480wy5u6j7f3sh92hzxo') End tag : script End tag : head But the source text for this is [and all of the " seem to go missing: Bob Aalsma | LinkedIn From maniandram01 at gmail.com Wed Sep 5 08:57:24 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 5 Sep 2012 05:57:24 -0700 (PDT) Subject: simple client data base In-Reply-To: References: Message-ID: <11edefc8-5594-4cc9-8d73-f24f39bf8e11@googlegroups.com> On Monday, 3 September 2012 19:42:21 UTC+5:30, Manatee wrote: > Hello all, I am learning to program in python. I have a need to make a > > program that can store, retrieve, add, and delete client data such as > > name, address, social, telephone number and similar information. This > > would be a small client database for my wife who has a home accounting > > business. > > > > I have been reading about lists, tuples, and dictionary data > > structures in python and I am confused as to which would be more > > appropriate for a simple database. > > > > I know that python has real database capabilities but I'm not there > > yet and would like to proceed with as simple a structure as possible. > > > > Can anyone give me some idea's or tell me which structure would be > > best to use? > > > > Maybe its a combination of structures? I need some help. > > > > Thanks for your help. If there are not more than 1000 records you can just use `pickle` From maniandram01 at gmail.com Wed Sep 5 09:04:06 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 5 Sep 2012 06:04:06 -0700 (PDT) Subject: Is there a way to configure IDLE to use spaces instead of tabs for indenting? In-Reply-To: References: Message-ID: On Saturday, 25 August 2012 04:03:52 UTC+5:30, Alex wrote: > I'm new to Python and have been using IDLE 3.2.3 to experiment with > > code as I learn. Despite being configured to use a 4 space indentation > > width, sometimes IDLE's "smart" indentation insists upon using width-8 > > tabs. > > > > From what I've been able to find on Google, this is due to a > > shortcoming in Tk. While it's not that big a deal in the grand scheme > > of things, I think it looks like poop, and I'd like to change IDLE to > > use 4-space indentation instead of tabs for all indentation levels. > > > > Is there any way for me to achieve what I want in IDLE, or do I have to > > start up my full-blown IDE if I want consistent 4-space indentation? > > > > Alex I think an IDE is better than IDLE. Try NINJA IDE. http://ninja-ide.org From rosuav at gmail.com Wed Sep 5 09:04:22 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Sep 2012 23:04:22 +1000 Subject: sockets,threads and interupts In-Reply-To: <4baa457c-3408-46dd-a98b-ae7e097ac5e5@googlegroups.com> References: <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com> <4baa457c-3408-46dd-a98b-ae7e097ac5e5@googlegroups.com> Message-ID: On Wed, Sep 5, 2012 at 10:54 PM, Ramchandra Apte wrote: > At least on Linux, if you kill a process using sockets, it takes about 10 seconds for socket to be closed. A program should try to close all resources. OS'es may take a long time to close a unclosed socket automatically. Err, that's not my experience. When a process terminates, its resources are released promptly. ChrisA From maniandram01 at gmail.com Wed Sep 5 09:08:04 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 5 Sep 2012 06:08:04 -0700 (PDT) Subject: Extract Text Table From File In-Reply-To: References: <481dc39d-1dee-4ebe-97d5-ccad659f8c74@googlegroups.com> Message-ID: <9187c848-9b47-45e3-815f-9bb44bbc66d1@googlegroups.com> On Monday, 27 August 2012 15:42:14 UTC+5:30, Laszlo Nagy wrote: > On 2012-08-27 11:53, Huso wrote: > > > Hi, > > > > > > I am trying to extract some text table data from a log file. I am trying different methods, but I don't seem to get anything to work. I am kind of new to python as well. Hence, appreciate if someone could help me out. > > > > # > > # Write test data to test.txt > > # > > > > data = """ > > ROUTES TRAFFIC RESULTS, LSR > > TRG MP DATE TIME > > 37 17 120824 0000 > > > > R TRAFF NBIDS CCONG NDV ANBLO MHTIME NBANSW > > AABBCCO 6.4 204 0.0 115 1.0 113.4 144 > > AABBCCI 3.0 293 115 1.0 37.0 171 > > DDEEFFO 0.2 5 0.0 59 0.0 107.6 3 > > EEFFEEI 0.0 0 59 0.0 0.0 0 > > HHGGFFO 0.0 0 0.0 30 0.0 0.0 0 > > HHGGFFI 0.3 15 30 0.0 62.2 4 > > END > > """ > > fout = open("test.txt","wb+") > > fout.write(data) > > fout.close() > > > > # > > # This is how you iterate over a file and process its lines > > # > > fin = open("test.txt","r") > > for line in fin: > > # This is one possible way to extract values. > > values = line.strip().split() > > print values > > > > > > This will print: > > > > [] > > ['ROUTES', 'TRAFFIC', 'RESULTS,', 'LSR'] > > ['TRG', 'MP', 'DATE', 'TIME'] > > ['37', '17', '120824', '0000'] > > [] > > ['R', 'TRAFF', 'NBIDS', 'CCONG', 'NDV', 'ANBLO', 'MHTIME', 'NBANSW'] > > ['AABBCCO', '6.4', '204', '0.0', '115', '1.0', '113.4', '144'] > > ['AABBCCI', '3.0', '293', '115', '1.0', '37.0', '171'] > > ['DDEEFFO', '0.2', '5', '0.0', '59', '0.0', '107.6', '3'] > > ['EEFFEEI', '0.0', '0', '59', '0.0', '0.0', '0'] > > ['HHGGFFO', '0.0', '0', '0.0', '30', '0.0', '0.0', '0'] > > ['HHGGFFI', '0.3', '15', '30', '0.0', '62.2', '4'] > > ['END'] > > > > > > The "values" list in the last line contains these values. This will work > > only if you don't have spaces in your values. Otherwise you can use > > regular expressions to parse a line. See here: > > > > http://docs.python.org/library/re.html > > > the csv module should be used for this not regex > Since you did not give any specification on your file format, it would > > be hard to give a concrete program that parses your file(s) > > > > Best, > > > > Laszlo From maniandram01 at gmail.com Wed Sep 5 09:08:04 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 5 Sep 2012 06:08:04 -0700 (PDT) Subject: Extract Text Table From File In-Reply-To: References: <481dc39d-1dee-4ebe-97d5-ccad659f8c74@googlegroups.com> Message-ID: <9187c848-9b47-45e3-815f-9bb44bbc66d1@googlegroups.com> On Monday, 27 August 2012 15:42:14 UTC+5:30, Laszlo Nagy wrote: > On 2012-08-27 11:53, Huso wrote: > > > Hi, > > > > > > I am trying to extract some text table data from a log file. I am trying different methods, but I don't seem to get anything to work. I am kind of new to python as well. Hence, appreciate if someone could help me out. > > > > # > > # Write test data to test.txt > > # > > > > data = """ > > ROUTES TRAFFIC RESULTS, LSR > > TRG MP DATE TIME > > 37 17 120824 0000 > > > > R TRAFF NBIDS CCONG NDV ANBLO MHTIME NBANSW > > AABBCCO 6.4 204 0.0 115 1.0 113.4 144 > > AABBCCI 3.0 293 115 1.0 37.0 171 > > DDEEFFO 0.2 5 0.0 59 0.0 107.6 3 > > EEFFEEI 0.0 0 59 0.0 0.0 0 > > HHGGFFO 0.0 0 0.0 30 0.0 0.0 0 > > HHGGFFI 0.3 15 30 0.0 62.2 4 > > END > > """ > > fout = open("test.txt","wb+") > > fout.write(data) > > fout.close() > > > > # > > # This is how you iterate over a file and process its lines > > # > > fin = open("test.txt","r") > > for line in fin: > > # This is one possible way to extract values. > > values = line.strip().split() > > print values > > > > > > This will print: > > > > [] > > ['ROUTES', 'TRAFFIC', 'RESULTS,', 'LSR'] > > ['TRG', 'MP', 'DATE', 'TIME'] > > ['37', '17', '120824', '0000'] > > [] > > ['R', 'TRAFF', 'NBIDS', 'CCONG', 'NDV', 'ANBLO', 'MHTIME', 'NBANSW'] > > ['AABBCCO', '6.4', '204', '0.0', '115', '1.0', '113.4', '144'] > > ['AABBCCI', '3.0', '293', '115', '1.0', '37.0', '171'] > > ['DDEEFFO', '0.2', '5', '0.0', '59', '0.0', '107.6', '3'] > > ['EEFFEEI', '0.0', '0', '59', '0.0', '0.0', '0'] > > ['HHGGFFO', '0.0', '0', '0.0', '30', '0.0', '0.0', '0'] > > ['HHGGFFI', '0.3', '15', '30', '0.0', '62.2', '4'] > > ['END'] > > > > > > The "values" list in the last line contains these values. This will work > > only if you don't have spaces in your values. Otherwise you can use > > regular expressions to parse a line. See here: > > > > http://docs.python.org/library/re.html > > > the csv module should be used for this not regex > Since you did not give any specification on your file format, it would > > be hard to give a concrete program that parses your file(s) > > > > Best, > > > > Laszlo From rosuav at gmail.com Wed Sep 5 09:13:58 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Sep 2012 23:13:58 +1000 Subject: why did the WindowsError occur? In-Reply-To: References: Message-ID: On Wed, Sep 5, 2012 at 10:51 PM, Ramchandra Apte wrote: > On Wednesday, 5 September 2012 13:21:58 UTC+5:30, Mark Lawrence wrote: >> Because you've done something wrong. If you'd like to tell us what >> you've done to find out where the problem is, we are far more likely to >> help. Please remember that the rates of pay here are amongst the lowest >> in the world :) > > I haven't heard anybody in a group paying money to be able to answer a question! > So it should be the lowest rates of pay in the world. Technically no, but when you consider the number of man-hours that get donated, it's pretty impressive. We may not pay money, but we sure do pay a lot of time. And why? Because the problems are interesting and fun to solve. There's a lot more "replay value" in this list than there is in most video games! ChrisA From franck at ditter.org Wed Sep 5 09:19:47 2012 From: franck at ditter.org (Franck Ditter) Date: Wed, 05 Sep 2012 15:19:47 +0200 Subject: is implemented with id ? References: Message-ID: Thanks to all, but : - I should have said that I work with Python 3. Does that matter ? - May I reformulate the queston : "a is b" and "id(a) == id(b)" both mean : "a et b share the same physical address". Is that True ? Thanks, franck In article , Benjamin Kaplan wrote: > On Tue, Sep 4, 2012 at 11:30 PM, Franck Ditter wrote: > > Hi ! > > a is b <==> id(a) == id(b) in builtin classes. > > Is that true ? > > Thanks, > > > > franck > > No. It is true that if a is b then id(a) == id(b) but the reverse is > not necessarily true. id is only guaranteed to be unique among objects > alive at the same time. If objects are discarded, their ids may be > reused even though the objects are not the same. From oscar.j.benjamin at gmail.com Wed Sep 5 09:20:49 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 5 Sep 2012 14:20:49 +0100 Subject: Comparing strings from the back? In-Reply-To: References: Message-ID: On 5 September 2012 10:48, Peter Otten <__peter__ at web.de> wrote: > Chris Angelico wrote: > > > On Wed, Sep 5, 2012 at 6:29 PM, Peter Otten <__peter__ at web.de> wrote: > >> comparing every pair in a sample of 1000 8-char words > >> taken from '/usr/share/dict/words' > >> > >> head > >> 1: 477222 ************************************************************ > >> 2: 18870 ** > >> ... > > tail > 1: 386633 ************************************************************ > 2: 74966 *********** > > > > Not understanding this. What are the statistics, > > I measured how many chars they have in common for all combinations of 1000 > words taken from /usr/share/dict/words. > > 477222 pairs have one char in common, 18870 pairs have two chars in common > when compared from the *beginning* of the string. > > 386633 pairs have one char in common, 74966 pairs have two chars in common > when compared from the *end* of the string. > > and what (if it's not obvious from the previous answer) do they prove? > > They demonstrate that for two words from that particular corpus it is > likely > that a[::-1] == b[::-1] has to take more (1.34 versus 1.05 on average) > characters into account than a == b, i. e. comparing from the back should > be > slower rather than faster. > > If that doesn't help, here's the code ;) > def count_common(a, b): > i = 0 > for i, (x, y) in enumerate(zip(a, b), 1): > if x != y: > break > return i > This function will return 1 if the first character differs. It does not count the number of common characters but rather the more relevant quantity which is the number of comparisons required to decide if the strings are equal. It shows that, for the English words in this dictionary, the first letters of two randomly selected 8-character words are equal ~5% of the time while the last letters are equal ~20% of the time. But despite the non-uniformity in the distribution of these strings, this provides a good example of the fact that for many situations involving real data, average case comparison complexity is O(1). This is because the probability of stopping after N comparisons decreases exponentially with N, so that the sequence of counts forms something loosely like an arithmetic progression: >>> cmp_forward = [477222, 18870, 2870, 435, 74, 17, 12] >>> cmp_backward = [386633, 74966, 29698, 6536, 1475, 154, 28, 10] >>> def ratios(seq): ... for count1, count2 in zip(seq[:-1], seq[1:]): ... yield count2 / float(count1) ... >>> list(ratios(cmp_forward)) [0.03954134553729711, 0.15209326974032855, 0.15156794425087108, 0.17011494252873563, 0.22972972972972974, 0.7058823529411765] >>> list(ratios(cmp_backward)) [0.19389446839767946, 0.39615292265827173, 0.22008216041484274, 0.22567319461444307, 0.10440677966101695, 0.18181818181818182, 0.35714285714285715] A notable outlier in these sequences is for comparing the first character of the two words which is why for this string distribution it is better to start at the beginning than the end. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Wed Sep 5 09:21:11 2012 From: d at davea.name (Dave Angel) Date: Wed, 05 Sep 2012 09:21:11 -0400 Subject: Beginners question In-Reply-To: References: <782893e7-a2dc-4018-a5c6-2a9cd07ecf99@googlegroups.com> Message-ID: <504751C7.7070802@davea.name> On 09/05/2012 04:03 AM, Mark Lawrence wrote: > On 05/09/2012 07:28, charvigroups at gmail.com wrote: >> Hi, >> >> I have attached python interview questions and answers for beginners. >> >> Please visit http://www.f2finterview.com/web/CorePython/ for core >> python and >> >> http://www.f2finterview.com/web/PythonAdvanced/ for advanced python >> >> > > The first question from the advanced list is really going to stretch > an advanced Python developer, so only gurus need bother as it's so > difficult. Not. > > If the interviewer wants the whole page, and not just the first line, then there's some understanding needed there. What bothers me more is the provided code and description: for c in xrange(len(records)): fvalues = records[c] ... and "Here we start a loop which starts from 1 (understood) to whatever the ..." Isn't an "advanced" Python user going to be expected to replace those two with for fvalues in records: ? -- DaveA From d at davea.name Wed Sep 5 09:46:31 2012 From: d at davea.name (Dave Angel) Date: Wed, 05 Sep 2012 09:46:31 -0400 Subject: is implemented with id ? In-Reply-To: References: <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <504757B7.9020402@davea.name> On 09/05/2012 08:48 AM, Ramchandra Apte wrote: > On Wednesday, 5 September 2012 14:44:23 UTC+5:30, Steven D'Aprano wrote: >> >> > Seeing this thread, I think the is statment should be removed. > It has a replacement syntax of id(x) == id(y) and "a==True" should be automatically changed into memory comparison. You didn't read the whole message carefully enough. Id's can be reused, so there are many ways to mess up comparing id's. One is if the two items x and y are expressions (eg. function calls). You call a function, and say it returns a new object, you call id() on that object, and then the object gets discarded. You now have a stale id, and you haven't even evaluated the second expression yet. It's id() which is superfluous. But it's useful for debugging, and for understanding. -- DaveA From hansmu at xs4all.nl Wed Sep 5 09:48:18 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 05 Sep 2012 15:48:18 +0200 Subject: is implemented with id ? In-Reply-To: References: Message-ID: <50475822$0$6867$e4fe514c@news2.news.xs4all.nl> On 5/09/12 15:19:47, Franck Ditter wrote: > Thanks to all, but : > - I should have said that I work with Python 3. Does that matter ? > - May I reformulate the queston : "a is b" and "id(a) == id(b)" > both mean : "a et b share the same physical address". Is that True ? Yes. Keep in mind, though, that in some implementation (e.g. Jython), the physical address may change during the life time of an object. It's usually phrased as "a and b are the same object". If the object is mutable, then changing a will also change b. If a and b aren't mutable, then it doesn't really matter whether they share a physical address. Keep in mind that physical addresses can be reused when an object is destroyed. For example, in my Python3, id(math.sqrt(17)) == id(math.cos(17)) returns True, even though the floats involved are different, because the flaots have non-overlapping lifetimes and the physical address happens to be reused. Hope this helps, -- HansM From __peter__ at web.de Wed Sep 5 09:54:43 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 05 Sep 2012 15:54:43 +0200 Subject: HTMLParser skipping HTML? [newbie] References: <80d8623b-bb08-415c-900b-4a56556435ae@googlegroups.com> Message-ID: BobAalsma wrote: > I'm trying to understand the HTMLParser so I've copied some code from http://docs.python.org/library/htmlparser.html?highlight=html#HTMLParser and tried that on my LinkedIn page. > No errors, but some of the tags seem to go missing for no apparent reason - any advice? > I have searched extensively for this, but seem to be the only one with missing data from HTMLParser :( > > Code: > import urllib2 > from HTMLParser import HTMLParser > > from GetHttpFileContents import getHttpFileContents > > # create a subclass and override the handler methods > class MyHTMLParser(HTMLParser): > def handle_starttag(self, tag, attrs): > print "Start tag:\n\t", tag > for attr in attrs: > print "\t\tattr:", attr > # end for attr in attrs: > # > def handle_endtag(self, tag): > print "End tag :\n\t", tag > # > def handle_data(self, data): > if data != '\n\n': > if data != '\n': > print "Data :\t\t", data > # end if 1 > # end if 2 Please no! A kitten dies every time you write one of those comments ;) > def removeHtmlFromFileContents(): > TextOut = '' > > parser = MyHTMLParser() > parser.feed(urllib2.urlopen( > 'http://nl.linkedin.com/in/bobaalsma').read()) > > return TextOut > # > # --------------------------------------------------------------------- > # > if __name__ == '__main__': > TextOut = removeHtmlFromFileContents() After removing > from GetHttpFileContents import getHttpFileContents from your script I get the following output (using python 2.7): $ python parse_orig.py | grep meta -C2 script Start tag: meta attr: ('http-equiv', 'content-type') attr: ('content', 'text/html; charset=UTF-8') Start tag: meta attr: ('http-equiv', 'X-UA-Compatible') attr: ('content', 'IE=8') Start tag: meta attr: ('name', 'description') attr: ('content', 'Bekijk het (Nederland) professionele profiel van Bob Aalsma op LinkedIn. LinkedIn is het grootste zakelijke netwerk ter wereld. Professionals als Bob Aalsma kunnen hiermee interne connecties met aanbevolen kandidaten, branchedeskundigen en businesspartners vinden.') Start tag: meta attr: ('name', 'pageImpressionID') attr: ('content', '711eedaa-8273-45ca-a0dd-77eb96749134') Start tag: meta attr: ('name', 'pageKey') attr: ('content', 'nprofile-public-success') Start tag: meta attr: ('name', 'analyticsURL') attr: ('content', '/analytics/noauthtracker') $ So there definitely are some meta tags. Note that if you're logged in into a site the html the browser is "seeing" may differ from the html you are retrieving via urllib.urlopen(...).read(). Perhaps that is the reason why you don't get what you expect. From d at davea.name Wed Sep 5 10:00:09 2012 From: d at davea.name (Dave Angel) Date: Wed, 05 Sep 2012 10:00:09 -0400 Subject: is implemented with id ? In-Reply-To: References: Message-ID: <50475AE9.4020302@davea.name> Please don't top-post. Now your message is out of order, and if I have to delete the part Benjamin said. On 09/05/2012 09:19 AM, Franck Ditter wrote: > Thanks to all, but : > - I should have said that I work with Python 3. Does that matter ? > - May I reformulate the queston : "a is b" and "id(a) == id(b)" > both mean : "a et b share the same physical address". Is that True ? > Thanks, No, id() has nothing to do with physical address. The Python language does not specify anything about physical addresses. Some implementations may happen to use physical addresses, others arbitrary integers. And they may reuse such integers, or not. Up to the implementation. And as others have pointed out, when you compare two id's, you're risking that one of them may no longer be valid. For example, the following expression: flag = id(func1()) == id(func2()) could very well evaluate to True, even if func1() always returns a string, and func2() always returns an int. On the other hand, the 'is' expression makes sure the two expressions are bound to the same object. If a and b are simple names, and not placeholders for arbitrary expressions, then I THINK the following would be true: "a is b" and "id(a) == id(b)" both mean that the names a and b are bound to the same object at the time the statement is executed. -- DaveA From steve+comp.lang.python at pearwood.info Wed Sep 5 10:13:30 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Sep 2012 14:13:30 GMT Subject: is implemented with id ? References: <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50475e0a$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Sep 2012 05:48:26 -0700, Ramchandra Apte wrote: > Seeing this thread, I think the is statment should be removed. It has a > replacement syntax of id(x) == id(y) A terrible idea. Because "is" is a keyword, it is implemented as a fast object comparison directly in C (for CPython) or Java (for Jython). In the C implementation "x is y" is *extremely* fast because it is just a pointer comparison performed directly by the interpreter. Because id() is a function, it is much slower. And because it is not a keyword, Python needs to do a name look-up for it, then push the argument on the stack, call the function (which may not even be the built-in id() any more!) and then pop back to the caller. And worst, *it doesn't even do what you think it does*. In some Python implementations, IDs can be reused. That leads to code like this, from CPython 2.7: py> id("spam ham"[1:]) == id("foo bar"[1:]) True You *cannot* replace is with id() except when the objects are guaranteed to both be alive at the same time, and even then you *shouldn't* replace is with id() because that is a pessimation (the opposite of an optimization -- something that makes code run slower, not faster). > and "a==True" should be automatically changed into memory comparison. Absolutely not. That would be a backward-incompatible change that would break existing programs: py> 1.0 == True True py> from decimal import Decimal py> Decimal("1.0000") == True True -- Steven From __peter__ at web.de Wed Sep 5 10:21:28 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 05 Sep 2012 16:21:28 +0200 Subject: Python Interview Questions References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: charvigroups at gmail.com wrote: > Finally I have decided to put best interview question and answers. > > Please visit http://***/web/CorePython/ for core python > and http://***/web/PythonAdvanced/ for advanced python Hm, are you a reformed PHP programmer who has never heard of sql injection attacks? The first "advanced" answer (and probably all the database-related stuff) should definitely be withdrawn. From steve+comp.lang.python at pearwood.info Wed Sep 5 10:30:07 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Sep 2012 14:30:07 GMT Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Sep 2012 11:43:08 +0200, Johannes Bauer wrote: > On 05.09.2012 11:24, Johannes Bauer wrote: > >> Consider sorting a large dictionary. Sorting is in O(n log(n)), but >> this assumes O(1) comparisons! If the comparison operation itself were >> in O(n), the total sorting complexity would be O(n^2 log(n)), This shows some significant confusion about Big Oh complexity analysis here. When you say that sorting the list of words is O(N log N), the N refers to the number of words in the dictionary. But when you speak about comparisons being O(N), the N doesn't refer to the size of the dict, but the size of the individual strings being compared. There is no reasonable comparison algorithm where the effort required to compare two strings depends on the size of the dictionary they have come from. Since these are *completely different Ns*, you can't combine them to get O(N**2 log N) as the overall algorithmic complexity. Doing so is sheer nonsense. If you state it like this: sorting the list of words is O(N log N) where N = length of the list comparing the words is O(M) where M = the average length of the words then the overall complexity is O(N log N)*O(M), but since M is a constant for any particular dictionary (its just the average length of the words) that reduces down to O(N log N). To say that sorting a dictionary is O(N log N) does *not* imply that string comparisons are O(1). It only implies that string comparisons don't depend on the size of the dictionary. Comparing: s1 = 'a'*30002 s2 = 'a'*30001 + 'b' takes the same amount of time whether they are in a dictionary of 100 words or one of 100000 words. For the purposes of calculating the algorithmic complexity of sorting a large list of words, we can treat comparisons as an elementary operation even though they actually aren't. >> which is >> definitely false. Most comparisons will abort *very* early (after the >> first character). You are making unjustified assumptions about the distribution of letters in the words. This might be a list of long chemical compounds where the words typically differ only in their suffix. It might be a list of people with titles: Herr Professor Frederick Schmidt Herr Professor Frederick Wagner ... But either way, it doesn't matter for the Big Oh behaviour of sorting the words. > I've just written a program to demonstrate this (below it's attached). I have no idea why you think this program demonstrates anything about string equality comparisons. What you are counting is not the average number of comparisons for string equality, but the number of comparisons when sorting. These are *completely different*, because sorting a list does not require testing each string against every other string. Whatever you have measured, it has nothing to do with the Big Oh complexity of string comparisons. It seems to me that you have misunderstood the purpose of Big Oh notation. It gives an asymptotic upper bound on the amount of work done, ignoring all lower terms and multiplicative factors, not an exact formula. If something is O(N), then this tells you: 1) the number of algorithmic steps is proportional to N, plus or minus some terms which are less than N (e.g. sqrt(N), or log(N), or 1/N, or some constant, etc.); 2) if you ignore those other terms, and keep all other influences equal, then doubling N will *at worst* double the number of algorithmic steps; 3) if all those algorithmic steps take exactly the same amount of time, then doubling N will take twice as much time. But of course *none* of those assumptions hold for measurements of actual elapsed time. In real life, operations rarely take constant time, you don't always see worst case behaviour, and the lower terms are not necessarily insignificant enough to ignore. [...] > So, interestingly, in this real-world case(tm), the complexity does not > scale with O(n). It actually goes down (which is probably due to the > limit amount of words of higher length). I would guess that it probably has more to do with the ability of the timsort algorithm to exploit local order within a list and avoid performing comparisons. > In summary, let's please not debate "feelings" or such. I have no idea what feelings you are referring to. -- Steven From levinie001 at gmail.com Wed Sep 5 10:32:02 2012 From: levinie001 at gmail.com (Levi Nie) Date: Wed, 5 Sep 2012 22:32:02 +0800 Subject: how can i register the non-default browser with the webbrowser module? Message-ID: how can i register the non-default browser with the webbrowser module? the case: i want open a site such as "google.com" in ie8 with the python.But my default is chrome. so i want to register a ie8 controller with the webbrowser.register(*name*, *constructor*[, *instance*]). so what does the parameter "constructor" "instance" mean? how can i do it? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dfnsonfsduifb at gmx.de Wed Sep 5 10:33:17 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Wed, 05 Sep 2012 16:33:17 +0200 Subject: Comparing strings from the back? In-Reply-To: <-9CdnaqjTK6NKtvNnZ2dnUVZ_gednZ2d@westnet.com.au> References: <-9CdnaqjTK6NKtvNnZ2dnUVZ_gednZ2d@westnet.com.au> Message-ID: On 05.09.2012 04:18, Neil Hodgson wrote: > The memcpy patch was controversial as it broke Adobe Flash which > assumed memcpy was safe like memmove. Adobe Flash was broken before, making an assumption that is not guaranteed by the standard. The patch only showed the problem. Regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From rosuav at gmail.com Wed Sep 5 10:34:42 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Sep 2012 00:34:42 +1000 Subject: Python Interview Questions In-Reply-To: References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: On Thu, Sep 6, 2012 at 12:21 AM, Peter Otten <__peter__ at web.de> wrote: > charvigroups at gmail.com wrote: > >> Finally I have decided to put best interview question and answers. >> >> Please visit http://***/web/CorePython/ for core python >> and http://***/web/PythonAdvanced/ for advanced python > > Hm, are you a reformed PHP programmer who has never heard of sql injection > attacks? The first "advanced" answer (and probably all the database-related > stuff) should definitely be withdrawn. I wouldn't go that far. The 'name' parameter, I would expect, would be a constant. However, this strikes me as encouraging some really inefficient code, like iterating over all the rows in a table with N+1 queries (one to get the length, then a separate query for each row). Plus, use of limit without order by is not guaranteed (although since this is specific to MySQL, it's unlikely you'll run into trouble - but PostgreSQL, with its MVCC storage system, frequently reorders rows in a table). As a general rule, I don't like SQL builders. I'd prefer to directly embed SQL statements in my code. Although sometimes a class can helpfully manage some things, it's seldom worth having something that tries to pretend a table is iterable in that sort of way. ChrisA From rosuav at gmail.com Wed Sep 5 10:36:50 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Sep 2012 00:36:50 +1000 Subject: Python Interview Questions In-Reply-To: References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: On Thu, Sep 6, 2012 at 12:34 AM, Chris Angelico wrote: > However, this strikes me as encouraging some really > inefficient code, like iterating over all the rows in a table with N+1 > queries (one to get the length, then a separate query for each row). Huh. And then I scroll down, and that's precisely what he's doing. Do you understand why this is a bad thing to do? ChrisA From steve+comp.lang.python at pearwood.info Wed Sep 5 10:41:19 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Sep 2012 14:41:19 GMT Subject: is implemented with id ? References: Message-ID: <5047648f$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Sep 2012 10:00:09 -0400, Dave Angel wrote: > On 09/05/2012 09:19 AM, Franck Ditter wrote: >> Thanks to all, but : >> - I should have said that I work with Python 3. Does that matter ? - >> May I reformulate the queston : "a is b" and "id(a) == id(b)" >> both mean : "a et b share the same physical address". Is that True ? >> Thanks, > > No, id() has nothing to do with physical address. The Python language > does not specify anything about physical addresses. Some > implementations may happen to use physical addresses, others arbitrary > integers. And they may reuse such integers, or not. Up to the > implementation. True. In principle, some day there might be a version of Python that runs on some exotic quantum computer where the very concept of "physical address" is meaningless. Or some sort of peptide or DNA computer, where the calculations are performed via molecular interactions rather than by flipping bits in fixed memory locations. But less exotically, Frank isn't entirely wrong. With current day computers, it is reasonable to say that any object has exactly one physical location at any time. In Jython, objects can move around; in CPython, they can't. But at any moment, any object has a specific location, and no other object can have that same location. Two objects cannot both be at the same memory address at the same time. So, for current day computers at least, it is reasonable to say that "a is b" implies that a and b are the same object at a single location. The second half of the question is more complex: "id(a) == id(b)" *only* implies that a and b are the same object at the same location if they exist at the same time. If they don't exist at the same time, then you can't conclude anything. -- Steven From dfnsonfsduifb at gmx.de Wed Sep 5 10:51:10 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Wed, 05 Sep 2012 16:51:10 +0200 Subject: Comparing strings from the back? In-Reply-To: <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05.09.2012 16:30, Steven D'Aprano wrote: > Since these are *completely different Ns*, you can't combine them to get > O(N**2 log N) as the overall algorithmic complexity. Doing so is sheer > nonsense. If you state it like this: Yes, you are correct here. > You are making unjustified assumptions about the distribution of letters > in the words. This might be a list of long chemical compounds where the > words typically differ only in their suffix. It might be a list of people > with titles: Actually, I'm not. I'm stating exactly what assumptions I'm making to get my calculation. I'm comparing *random* character strings or bitstrings. You, on the other hand, are making vague assumptions which you do not care for formalize and yet you claim that "the number of comparisons is equally likely to be 1, 2, 3, ..., N. The average then is". Without any explanation for this. At all. > Herr Professor Frederick Schmidt > Herr Professor Frederick Wagner > ... Is your assumtion that we're comparing words that have the common prefix "Herr Professor Frederick "? Why don't you clearly state what you're comparing. In the example you gave in the other thread you claimed "Note that this average assumes the strings are completely random.", yet now you're talking about specific word patterns. > I have no idea why you think this program demonstrates anything about > string equality comparisons. What you are counting is not the average > number of comparisons for string equality, but the number of comparisons > when sorting. These are *completely different*, because sorting a list > does not require testing each string against every other string. You're wrong. It's not counting the number of string comparisons, it's counting the number of character comparisons. Which is exactly what we're talking about in this thread, are we not? The sorting of the list is just to show some example where lots of strings are compared. >> So, interestingly, in this real-world case(tm), the complexity does not >> scale with O(n). It actually goes down (which is probably due to the >> limit amount of words of higher length). > > I would guess that it probably has more to do with the ability of the > timsort algorithm to exploit local order within a list and avoid > performing comparisons. Again, it's not counting the number of string comparisons. It's counting the average number of character comparisons per string comparison. The total amount of string comparisons has nothing to do with it. >> In summary, let's please not debate "feelings" or such. > > I have no idea what feelings you are referring to. I'm referring to "the number of comparisons is equally likely to be 1, 2, 3, ..., N. The average then is" without any deduction or rationale. Without any explanation or assumption. Regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From d at davea.name Wed Sep 5 11:09:30 2012 From: d at davea.name (Dave Angel) Date: Wed, 05 Sep 2012 11:09:30 -0400 Subject: is implemented with id ? In-Reply-To: <5047648f$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <5047648f$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50476B2A.10806@davea.name> On 09/05/2012 10:41 AM, Steven D'Aprano wrote: > On Wed, 05 Sep 2012 10:00:09 -0400, Dave Angel wrote: > >> On 09/05/2012 09:19 AM, Franck Ditter wrote: >>> Thanks to all, but : >>> - I should have said that I work with Python 3. Does that matter ? - >>> May I reformulate the queston : "a is b" and "id(a) == id(b)" >>> both mean : "a et b share the same physical address". Is that True ? >>> Thanks, >> No, id() has nothing to do with physical address. The Python language >> does not specify anything about physical addresses. Some >> implementations may happen to use physical addresses, others arbitrary >> integers. And they may reuse such integers, or not. Up to the >> implementation. > True. In principle, some day there might be a version of Python that runs > on some exotic quantum computer where the very concept of "physical > address" is meaningless. Or some sort of peptide or DNA computer, where > the calculations are performed via molecular interactions rather than by > flipping bits in fixed memory locations. > > But less exotically, Frank isn't entirely wrong. With current day > computers, it is reasonable to say that any object has exactly one > physical location at any time. In Jython, objects can move around; in > CPython, they can't. But at any moment, any object has a specific > location, and no other object can have that same location. Two objects > cannot both be at the same memory address at the same time. > > So, for current day computers at least, it is reasonable to say that > "a is b" implies that a and b are the same object at a single location. You're arguing against something i didn't say. I only said that id() doesn't promise to be a memory address. i said nothing about what it might mean if the "is" operator considers them the same. > The second half of the question is more complex: > > "id(a) == id(b)" *only* implies that a and b are the same object at the > same location if they exist at the same time. If they don't exist at the > same time, then you can't conclude anything. > > But by claiming that id() really means address, and that those addresses might move during the lifetime of an object, then the fact that the id() functions are not called simultaneously implies that one object might move to where the other one used to be before the "move." I don't claim to know the jython implementation. But you're claiming that id() means the address of the object, even in jython. So if a garbage collection can occur during the evaluation of the expression id(a) == id(b) then the comparing of id()'s would be useless in jython. Two distinct objects could each be moved during evaluation, (very) coincidentally causing the two to have the same addresses at the two times of evaluation. Or more likely, a single object could move to a new location, rendering the comparison false. Thus you have false positive and false negative possible. I think it much more likely that jython uses integer values for the id() function, and not physical addresses. I doubt they'd want a race condition. -- DaveA From ian.g.kelly at gmail.com Wed Sep 5 11:22:58 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 5 Sep 2012 09:22:58 -0600 Subject: Python Interview Questions In-Reply-To: References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: On Wed, Sep 5, 2012 at 8:34 AM, Chris Angelico wrote: > I wouldn't go that far. The 'name' parameter, I would expect, would be > a constant. The 'item' parameter, though, is probably not a constant, and it's interpolated just the same. > However, this strikes me as encouraging some really > inefficient code, like iterating over all the rows in a table with N+1 > queries (one to get the length, then a separate query for each row). > Plus, use of limit without order by is not guaranteed (although since > this is specific to MySQL, it's unlikely you'll run into trouble - but > PostgreSQL, with its MVCC storage system, frequently reorders rows in > a table). The lack of an ORDER BY is the least of the problems with that SQL. He's also using LIMIT without OFFSET, so the only thing that the 'item' argument changes is how many rows are returned (all but one of which are ignored), not which one is actually fetched. It's a bit sad that these are touted as answers to interview questions. I wouldn't hire anybody who gave answers like these. From rosuav at gmail.com Wed Sep 5 11:34:38 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Sep 2012 01:34:38 +1000 Subject: Python Interview Questions In-Reply-To: References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: On Thu, Sep 6, 2012 at 1:22 AM, Ian Kelly wrote: > The lack of an ORDER BY is the least of the problems with that SQL. > He's also using LIMIT without OFFSET, so the only thing that the > 'item' argument changes is how many rows are returned (all but one of > which are ignored), not which one is actually fetched. No, he's using the two-arg form of LIMIT. > It's a bit sad that these are touted as answers to interview > questions. I wouldn't hire anybody who gave answers like these. The code does not work as posted; there are args missing from the INSERT example, for, uhh, example. It makes it hard to evaluate the quality of the code, in some places. I'm not sure what these posts are supposed to be, but I hope they're not being held up as model answers to interview questions. For a start, I can't find any sort of clear questions. Or is the code itself the question and "How would you improve this"? ChrisA From steve+comp.lang.python at pearwood.info Wed Sep 5 11:36:12 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Sep 2012 15:36:12 GMT Subject: is implemented with id ? References: <5047648f$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5047716c$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Sep 2012 11:09:30 -0400, Dave Angel wrote: > On 09/05/2012 10:41 AM, Steven D'Aprano wrote: [...] >> So, for current day computers at least, it is reasonable to say that "a >> is b" implies that a and b are the same object at a single location. > > You're arguing against something i didn't say. I only said that id() > doesn't promise to be a memory address. i said nothing about what it > might mean if the "is" operator considers them the same. I'm not arguing at all. I'm agreeing with you, but going into more detail. >> The second half of the question is more complex: >> >> "id(a) == id(b)" *only* implies that a and b are the same object at the >> same location if they exist at the same time. If they don't exist at >> the same time, then you can't conclude anything. >> >> > But by claiming that id() really means address, I didn't actually say that. If you re-read Franck Ditter's previous post, he doesn't actually say that either. > and that those addresses > might move during the lifetime of an object, then the fact that the id() > functions are not called simultaneously implies that one object might > move to where the other one used to be before the "move." Well, yes, but I expect that implementations where objects can move will not use memory addresses as IDs. They will do what Jython and IronPython do and use arbitrary numbers as IDs. (Oh how I wish CPython hadn't used memory addresses as IDs.) > I don't claim to know the jython implementation. But you're claiming > that id() means the address of the object, even in jython. Good god no! I'm saying that, *if* a and b exist at the same time, *and* if id(a) == id(b), *then* a and b must be the same object and therefore at the same address. That doesn't mean that the ID is the address! > I think it much more likely that jython uses integer values for the id() > function, and not physical addresses. That's exactly what it does. It appears to be a simple counter: each time you ask for an object's ID, it gets allocated the next value starting from 1, and values are never re-used. -- Steven From __peter__ at web.de Wed Sep 5 11:45:55 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 05 Sep 2012 17:45:55 +0200 Subject: Comparing strings from the back? References: Message-ID: Oscar Benjamin wrote: > On 5 September 2012 10:48, Peter Otten <__peter__ at web.de> wrote: >> def count_common(a, b): [sorry for seriously broken implementation] > This function will return 1 if the first character differs. It does not > count the number of common characters but rather the more relevant > quantity which is the number of comparisons required to decide if the > strings are equal. I remember stumbling over the non-zero frequency for len(word) but somehow plodded on with beautifying the broken results :( def count_common(a, b): """ >>> count_common("alpha", "beta") 0 >>> count_common("", "") 0 >>> count_common("alpha", "argument") 1 >>> count_common("alpha", "alpha") 5 >>> count_common("alpha", "alphx") 4 """ i = 0 for x, y in zip(a, b): if x != y: break i += 1 return i $ python3 reverse_compare2.py compare /usr/share/dict/words 499500 combinations average common chars (head) 0.0535 average common chars (tail) 0.322 comparing every pair in a sample of 1000 8-char words taken from '/usr/share/dict/words' head 0: 477371 ************************************************************ 1: 18310 ** 2: 3191 3: 523 4: 79 5: 15 6: 10 7: 1 tail 0: 385069 ************************************************************ 1: 78742 ************ 2: 26734 **** 3: 7462 * 4: 1297 5: 168 6: 22 7: 6 From maniandram01 at gmail.com Wed Sep 5 11:59:05 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 5 Sep 2012 08:59:05 -0700 (PDT) Subject: sockets,threads and interupts In-Reply-To: References: <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com> <4baa457c-3408-46dd-a98b-ae7e097ac5e5@googlegroups.com> Message-ID: On Wednesday, 5 September 2012 18:34:32 UTC+5:30, Chris Angelico wrote: > On Wed, Sep 5, 2012 at 10:54 PM, Ramchandra Apte wrote: > > > At least on Linux, if you kill a process using sockets, it takes about 10 seconds for socket to be closed. A program should try to close all resources. OS'es may take a long time to close a unclosed socket automatically. > > > > Err, that's not my experience. When a process terminates, its > > resources are released promptly. It is not guaranteed so a program shouldn't presume. > > > > ChrisA From maniandram01 at gmail.com Wed Sep 5 11:59:05 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 5 Sep 2012 08:59:05 -0700 (PDT) Subject: sockets,threads and interupts In-Reply-To: References: <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com> <4baa457c-3408-46dd-a98b-ae7e097ac5e5@googlegroups.com> Message-ID: On Wednesday, 5 September 2012 18:34:32 UTC+5:30, Chris Angelico wrote: > On Wed, Sep 5, 2012 at 10:54 PM, Ramchandra Apte wrote: > > > At least on Linux, if you kill a process using sockets, it takes about 10 seconds for socket to be closed. A program should try to close all resources. OS'es may take a long time to close a unclosed socket automatically. > > > > Err, that's not my experience. When a process terminates, its > > resources are released promptly. It is not guaranteed so a program shouldn't presume. > > > > ChrisA From d at davea.name Wed Sep 5 12:01:13 2012 From: d at davea.name (Dave Angel) Date: Wed, 05 Sep 2012 12:01:13 -0400 Subject: Python Interview Questions In-Reply-To: References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: <50477749.3070306@davea.name> On 09/05/2012 11:34 AM, Chris Angelico wrote: > On Thu, Sep 6, 2012 at 1:22 AM, Ian Kelly wrote: >> The lack of an ORDER BY is the least of the problems with that SQL. >> He's also using LIMIT without OFFSET, so the only thing that the >> 'item' argument changes is how many rows are returned (all but one of >> which are ignored), not which one is actually fetched. > No, he's using the two-arg form of LIMIT. > >> It's a bit sad that these are touted as answers to interview >> questions. I wouldn't hire anybody who gave answers like these. > The code does not work as posted; there are args missing from the > INSERT example, for, uhh, example. It makes it hard to evaluate the > quality of the code, in some places. I'm not sure what these posts are > supposed to be, but I hope they're not being held up as model answers > to interview questions. For a start, I can't find any sort of clear > questions. > > Or is the code itself the question and "How would you improve this"? > > ChrisA Skip ahead to about page 13 to get more traditional questions, There, many of the simplest questions have invalid answers, or confusing explanations. For example, on page 15, the question that says " ... if a list of words is empty..." uses a="" as its source data to test with. The first question on page 16 forgets to construct a loop, thus processing only the first line in the file. page 18 introduces new syntax to the language: print n+=1 ##will work and reassures us in the comment that it will work !! page 18 also claims that values are passed to function by value. -- DaveA From maniandram01 at gmail.com Wed Sep 5 12:01:18 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 5 Sep 2012 09:01:18 -0700 (PDT) Subject: sockets,threads and interupts In-Reply-To: References: <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com> <4baa457c-3408-46dd-a98b-ae7e097ac5e5@googlegroups.com> Message-ID: <2ae930cf-0af2-4526-a15a-667a649633c4@googlegroups.com> On Wednesday, 5 September 2012 21:29:12 UTC+5:30, Ramchandra Apte wrote: > On Wednesday, 5 September 2012 18:34:32 UTC+5:30, Chris Angelico wrote: > > > On Wed, Sep 5, 2012 at 10:54 PM, Ramchandra Apte wrote: > > > > > > > At least on Linux, if you kill a process using sockets, it takes about 10 seconds for socket to be closed. A program should try to close all resources. OS'es may take a long time to close a unclosed socket automatically. > > > > > > > > > > > > Err, that's not my experience. When a process terminates, its > > > > > > resources are released promptly. > > > > It is not guaranteed so a program shouldn't presume. > > > > > > > > > > > > ChrisA oops forgot my signature --- Bragging rights (I belong an exclusive community of banned people): got banned on SO and #python-offtopic Projects:http://code.google.com/p/py2c/ and http://code.google.com/p/uniqos (name may be changed to PyOS) From maniandram01 at gmail.com Wed Sep 5 12:01:18 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 5 Sep 2012 09:01:18 -0700 (PDT) Subject: sockets,threads and interupts In-Reply-To: References: <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com> <4baa457c-3408-46dd-a98b-ae7e097ac5e5@googlegroups.com> Message-ID: <2ae930cf-0af2-4526-a15a-667a649633c4@googlegroups.com> On Wednesday, 5 September 2012 21:29:12 UTC+5:30, Ramchandra Apte wrote: > On Wednesday, 5 September 2012 18:34:32 UTC+5:30, Chris Angelico wrote: > > > On Wed, Sep 5, 2012 at 10:54 PM, Ramchandra Apte wrote: > > > > > > > At least on Linux, if you kill a process using sockets, it takes about 10 seconds for socket to be closed. A program should try to close all resources. OS'es may take a long time to close a unclosed socket automatically. > > > > > > > > > > > > Err, that's not my experience. When a process terminates, its > > > > > > resources are released promptly. > > > > It is not guaranteed so a program shouldn't presume. > > > > > > > > > > > > ChrisA oops forgot my signature --- Bragging rights (I belong an exclusive community of banned people): got banned on SO and #python-offtopic Projects:http://code.google.com/p/py2c/ and http://code.google.com/p/uniqos (name may be changed to PyOS) From bryanjugglercryptographer at yahoo.com Wed Sep 5 12:02:39 2012 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Wed, 5 Sep 2012 09:02:39 -0700 (PDT) Subject: sockets,threads and interupts References: <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com> Message-ID: <8aee6e43-82fd-42a4-aa9f-ff626145577d@ou2g2000pbc.googlegroups.com> loial wrote: > I have threaded python script that uses sockets to monitor network ports. > > I want to ensure that the socket is closed cleanly in all circumstances. This includes if the script is killed or interupted in some other way. > > As I understand it signal only works in the main thread, so how can I trap interupts in my threaded class and always ensure I close the socket? You may have various threads waiting in blocking calls, and I don't think there's a good way to alert them. Closing sockets that other threads may be waiting on is "probably unwise" according to Linux man page on close(2). Do you really need to worry about it? If your process is being forcibly terminated you probably cannot do anything better than the OS will do by default. -Bryan From __peter__ at web.de Wed Sep 5 12:09:39 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 05 Sep 2012 18:09:39 +0200 Subject: how can i register the non-default browser with the webbrowser module? References: Message-ID: Levi Nie wrote: > how can i register the non-default browser with the webbrowser module? > > the case: > i want open a site such as "google.com" in ie8 with the python.But my > default is chrome. > so i want to register a ie8 controller with the > webbrowser.register(*name*, *constructor*[, *instance*]). > so what does the parameter "constructor" "instance" mean? > how can i do it? Isn't there already a controller for ie8? I can't check, but you can list the available browsers with >>> import webbrowser >>> list(webbrowser._browsers) ['x-www-browser', 'kfmclient', 'firefox', 'konqueror'] Then if you want to open a page with a specific browser just do url = "http://www.python.org" browser = "firefox" webbrowser.get(browser).open(url) From roy at panix.com Wed Sep 5 12:11:10 2012 From: roy at panix.com (Roy Smith) Date: Wed, 05 Sep 2012 12:11:10 -0400 Subject: Python Interview Questions References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: In article , charvigroups at gmail.com wrote: > Hi Guys, > > Finally I have decided to put best interview question and answers. > > Please visit http://www.f2finterview.com/web/CorePython/ for core python and > http://www.f2finterview.com/web/PythonAdvanced/ for advanced python I was going to comment on some of the specific items, but I got hung up being unable to copy-paste text from your site so I could quote it. That's usually done with some variation on "user-select: none" in the CSS, but I didn't see that. I'm assuming it's some javascript trickery. Why do you do that? It degrades the usability of the site, and doesn't provide any real protection against people stealing content. From steve+comp.lang.python at pearwood.info Wed Sep 5 12:24:27 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Sep 2012 16:24:27 GMT Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote: [...] >> You are making unjustified assumptions about the distribution of >> letters in the words. This might be a list of long chemical compounds >> where the words typically differ only in their suffix. It might be a >> list of people with titles: > > Actually, I'm not. I'm stating exactly what assumptions I'm making to > get my calculation. I'm comparing *random* character strings or > bitstrings. Excuse me, you are not. You are comparing English words which are highly non-random. > You, on the other hand, are making vague assumptions which you do not > care for formalize and yet you claim that "the number of comparisons is > equally likely to be 1, 2, 3, ..., N. The average then is". Without any > explanation for this. At all. I will accept that my explanation was not good enough, but I strongly disagree that I gave no explanation at all. >> Herr Professor Frederick Schmidt >> Herr Professor Frederick Wagner >> ... > > Is your assumtion that we're comparing words that have the common prefix > "Herr Professor Frederick "? No, I am pointing out that *your* assumption that most string comparisons will halt close to the beginning of the string is an invalid assumption. Your assumption only holds for some non-random strings. [...] >> I have no idea why you think this program demonstrates anything about >> string equality comparisons. What you are counting is not the average >> number of comparisons for string equality, but the number of >> comparisons when sorting. These are *completely different*, because >> sorting a list does not require testing each string against every other >> string. > > You're wrong. It's not counting the number of string comparisons, I didn't say it was. > it's counting the number of character comparisons. Correct. But only out of an extremely limited subset of all possible string comparisons, namely those very few that happen when sorting lists of English words using a very specific algorithm, namely timsort. > Which is exactly what > we're talking about in this thread, are we not? The sorting of the list > is just to show some example where lots of strings are compared. It is not good enough to extract a non-random subset of strings (only English words) and then decrease the data set even further by only comparing an extremely non-uniform subset of those strings: specifically those few string comparisons that happen to occur using timsort. Whatever figure you have calculated by taking this non-random selection, it is irrelevant to the question of the average performance of string equality given random strings. >>> So, interestingly, in this real-world case(tm), the complexity does >>> not scale with O(n). It actually goes down (which is probably due to >>> the limit amount of words of higher length). >> >> I would guess that it probably has more to do with the ability of the >> timsort algorithm to exploit local order within a list and avoid >> performing comparisons. > > Again, it's not counting the number of string comparisons. It's counting > the average number of character comparisons per string comparison. The > total amount of string comparisons has nothing to do with it. I didn't say anything about counting string comparisons. But you are wrong -- the numbers you get are *strongly* influenced by the number of string comparisons performed. That is just one of the reasons why the results you get are biased. Let me spell it out for you: given a list of five letter words: ['fruit', 'apple', 'claim', 'pears', ... , 'toast'] sorting the list may compare: 'fruit' with 'apple' 'apple' with 'claim' but almost certainly will not compare: 'apple' with 'toast' and it definitely won't compare: 'zzzax' with 'zzzaq' because strings like those never get into the list in the first place. For the sake of simple calculations, let's pretend that there are only 1000 five-letter strings possible. We want to know how many character- comparisons are done on average when testing two random five-letter strings for equality. To calculate this average, you must compare every string to every other string, *including* itself. This gives 1000*1000 = one million equality tests to be performed. For each equality test, we count the number of character comparisons performed, sum all those counts, and divide by 1e6. That is the average number of char comparisons for random strings of five letters. But that's not what you do. First you eliminate 900 out of the 1000 possible strings by only sampling English words -- strings like "xxoij" cannot possibly be selected. So you are left with the highly non-random subset of 10000 equality tests. But you haven't finished. Instead of checking all 10000 equality tests, you then decide to only check the 2000 tests that happen to randomly occur when using the timsort algorithm to sort a list. So from the population of one million possible equality tests, you throw away the vast majority, then average the *strongly non-random* few that are remaining. Naturally the result you get is strongly biased, and it has nothing to do with the average Big Oh behaviour of equality on random strings. -- Steven From python.list at tim.thechases.com Wed Sep 5 12:25:02 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 05 Sep 2012 11:25:02 -0500 Subject: Extract Text Table From File In-Reply-To: <9187c848-9b47-45e3-815f-9bb44bbc66d1@googlegroups.com> References: <481dc39d-1dee-4ebe-97d5-ccad659f8c74@googlegroups.com> <9187c848-9b47-45e3-815f-9bb44bbc66d1@googlegroups.com> Message-ID: <50477CDE.4020503@tim.thechases.com> [trimming out a bunch of superfluous text so the thread is actually readable] On 09/05/12 08:08, Ramchandra Apte wrote: > On Monday, 27 August 2012 15:42:14 UTC+5:30, Laszlo Nagy wrote: >> On 2012-08-27 11:53, Huso wrote: >>> I am trying to extract some text table data from a log file >> >> fin = open("test.txt","r") >> >> for line in fin: >> >> # This is one possible way to extract values. >> >> values = line.strip().split() >> >> print values > > the csv module should be used for this not regex The problem is that the csv module expects a single delimiter character, not columnar data. -tkc From python.list at tim.thechases.com Wed Sep 5 12:28:49 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 05 Sep 2012 11:28:49 -0500 Subject: is implemented with id ? In-Reply-To: <504757B7.9020402@davea.name> References: <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com> <504757B7.9020402@davea.name> Message-ID: <50477DC1.7020706@tim.thechases.com> On 09/05/12 08:46, Dave Angel wrote: > It's id() which is superfluous. But it's useful for debugging, > and for understanding. While I assiduously work to eschew shadowing most built-in names such as "list" or "str", I do make an exception for "id" because it's *so* useful in code, and the built-in nets me almost nothing (well, nothing that I generally care about) that "is" doesn't already provide me. -tkc From breamoreboy at yahoo.co.uk Wed Sep 5 12:33:31 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 05 Sep 2012 17:33:31 +0100 Subject: how can i register the non-default browser with the webbrowser module? In-Reply-To: References: Message-ID: On 05/09/2012 15:32, Levi Nie wrote: > how can i register the non-default browser with the webbrowser module? > > the case: > i want open a site such as "google.com" in ie8 with the python.But my > default is chrome. > so i want to register a ie8 controller with the webbrowser.register(*name*, > *constructor*[, *instance*]). > so what does the parameter "constructor" "instance" mean? > how can i do it? > > > Have you read the documentation at all? It clearly states "This entry point is only useful if you plan to either set the BROWSER variable or call get() with a nonempty argument matching the name of a handler you declare." Is this what you plan to do in your code? -- Cheers. Mark Lawrence. From roy at panix.com Wed Sep 5 12:38:03 2012 From: roy at panix.com (Roy Smith) Date: Wed, 05 Sep 2012 12:38:03 -0400 Subject: Python Interview Questions References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: In article , Ian Kelly wrote: > It's a bit sad that these are touted as answers to interview > questions. I wouldn't hire anybody who gave answers like these. Over time, I've become convinced that most interview questions are crap. The best programming interview questions always start with, "write a program ...". From ian.g.kelly at gmail.com Wed Sep 5 12:40:56 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 5 Sep 2012 10:40:56 -0600 Subject: Python Interview Questions In-Reply-To: References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: On Wed, Sep 5, 2012 at 9:34 AM, Chris Angelico wrote: > On Thu, Sep 6, 2012 at 1:22 AM, Ian Kelly wrote: >> The lack of an ORDER BY is the least of the problems with that SQL. >> He's also using LIMIT without OFFSET, so the only thing that the >> 'item' argument changes is how many rows are returned (all but one of >> which are ignored), not which one is actually fetched. > > No, he's using the two-arg form of LIMIT. My mistake. I didn't even know there was a two-arg form of LIMIT. Must be a MySQL thing. :-) Cheers, Ian From roy at panix.com Wed Sep 5 12:45:47 2012 From: roy at panix.com (Roy Smith) Date: Wed, 05 Sep 2012 12:45:47 -0400 Subject: Python Interview Questions References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: In article , Ian Kelly wrote: > My mistake. I didn't even know there was a two-arg form of LIMIT. > Must be a MySQL thing. :-) What are you talking about? SQL is an ISO Standard. Therefore, all implementations work the same way. Didn't you get the memo? From hansmu at xs4all.nl Wed Sep 5 12:47:17 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 05 Sep 2012 18:47:17 +0200 Subject: is implemented with id ? In-Reply-To: References: <5047648f$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50478216$0$6864$e4fe514c@news2.news.xs4all.nl> On 5/09/12 17:09:30, Dave Angel wrote: > But by claiming that id() really means address, and that those addresses > might move during the lifetime of an object, then the fact that the id() > functions are not called simultaneously implies that one object might > move to where the other one used to be before the "move." Whoa! Not so fast! The id() of an object is guaranteed to not change during the object's lifetime. So if an implementation moves objects around (e.g. Jython), then it cannot use memory addresses for the id() function. > I think it much more likely that jython uses integer values for > the id() function, and not physical addresses. The id() function is guaranteed to return some flavour of integer. In Jython, the return values are 1, 2, 3, 4, etc., except, of course, if you invoke id() on an object you've id'd before, you get the same number as before. In current versions of CPython, you do get the (virtual) memory address, converted to an int (or a long). But then, CPython does not move objects. Maybe the next version of CPython should shift id values two or three bits to the right, just to make sure people don't misinterpret ids as memory addresses. Hope this helps, -- HansM From ian.g.kelly at gmail.com Wed Sep 5 13:08:43 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 5 Sep 2012 11:08:43 -0600 Subject: is implemented with id ? In-Reply-To: <50475e0a$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com> <50475e0a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 5, 2012 at 8:13 AM, Steven D'Aprano wrote: > You *cannot* replace is with id() except when the objects are guaranteed > to both be alive at the same time, and even then you *shouldn't* replace > is with id() because that is a pessimation (the opposite of an > optimization -- something that makes code run slower, not faster). Shouldn't that be "pessimization" for symmetry? From d at davea.name Wed Sep 5 13:19:24 2012 From: d at davea.name (Dave Angel) Date: Wed, 05 Sep 2012 13:19:24 -0400 Subject: is implemented with id ? In-Reply-To: <50478216$0$6864$e4fe514c@news2.news.xs4all.nl> References: <5047648f$0$29981$c3e8da3$5496439d@news.astraweb.com> <50478216$0$6864$e4fe514c@news2.news.xs4all.nl> Message-ID: <5047899C.3050403@davea.name> On 09/05/2012 12:47 PM, Hans Mulder wrote: > On 5/09/12 17:09:30, Dave Angel wrote: >> But by claiming that id() really means address, and that those addresses >> might move during the lifetime of an object, then the fact that the id() >> functions are not called simultaneously implies that one object might >> move to where the other one used to be before the "move." > Whoa! Not so fast! The id() of an object is guaranteed to not > change during the object's lifetime. So if an implementation > moves objects around (e.g. Jython), then it cannot use memory > addresses for the id() function. Which is equivalent to my point. I had mistakenly thought that Steven was claiming it was always an address, and disproving that claim by what amounts to reductio ad absurdem. >> I think it much more likely that jython uses integer values for >> the id() function, and not physical addresses. > The id() function is guaranteed to return some flavour of integer. > > In Jython, the return values are 1, 2, 3, 4, etc., except, of course, > if you invoke id() on an object you've id'd before, you get the same > number as before. > > In current versions of CPython, you do get the (virtual) memory > address, converted to an int (or a long). But then, CPython does > not move objects. > > Maybe the next version of CPython should shift id values two or three > bits to the right, just to make sure people don't misinterpret ids as > memory addresses. > > I think i'd prefer if it would put it through one step of a CRC32. -- DaveA From overhaalsgang_24_bob at me.com Wed Sep 5 13:23:44 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Wed, 5 Sep 2012 10:23:44 -0700 (PDT) Subject: HTMLParser skipping HTML? [newbie] In-Reply-To: <80d8623b-bb08-415c-900b-4a56556435ae@googlegroups.com> References: <80d8623b-bb08-415c-900b-4a56556435ae@googlegroups.com> Message-ID: <0ac33349-4938-41a6-a129-05d676a5819f@googlegroups.com> Op woensdag 5 september 2012 14:57:05 UTC+2 schreef BobAalsma het volgende: > I'm trying to understand the HTMLParser so I've copied some code from http://docs.python.org/library/htmlparser.html?highlight=html#HTMLParser and tried that on my LinkedIn page. > > No errors, but some of the tags seem to go missing for no apparent reason - any advice? > > I have searched extensively for this, but seem to be the only one with missing data from HTMLParser :( > > > > Code: > > import urllib2 > > from HTMLParser import HTMLParser > > > > from GetHttpFileContents import getHttpFileContents > > > > # create a subclass and override the handler methods > > class MyHTMLParser(HTMLParser): > > def handle_starttag(self, tag, attrs): > > print "Start tag:\n\t", tag > > for attr in attrs: > > print "\t\tattr:", attr > > # end for attr in attrs: > > # > > def handle_endtag(self, tag): > > print "End tag :\n\t", tag > > # > > def handle_data(self, data): > > if data != '\n\n': > > if data != '\n': > > print "Data :\t\t", data > > # end if 1 > > # end if 2 > > # > > # > > # --------------------------------------------------------------------- > > # > > def removeHtmlFromFileContents(): > > TextOut = '' > > > > parser = MyHTMLParser() > > parser.feed(urllib2.urlopen('http://nl.linkedin.com/in/bobaalsma').read()) > > > > return TextOut > > # > > # --------------------------------------------------------------------- > > # > > if __name__ == '__main__': > > TextOut = removeHtmlFromFileContents() > > > > > > > > > > > > Part of the output: > > End tag : > > script > > Start tag: > > title > > Data : Bob Aalsma - Nederland | LinkedIn > > End tag : > > title > > Start tag: > > script > > attr: ('type', 'text/javascript') > > attr: ('src', 'http://www.linkedin.com/uas/authping?url=http%3A%2F%2Fnl%2Elinkedin%2Ecom%2Fin%2Fbobaalsma') > > End tag : > > script > > Start tag: > > link > > attr: ('rel', 'stylesheet') > > attr: ('type', 'text/css') > > attr: ('href', 'http://s3.licdn.com/scds/concat/common/css?h=5v4lkweptdvona6w56qelodrj-7pfvsr76gzb22ys278pbj80xm-b1io9ndljf1bvpack85gyxhv4-5xxmkfcm1ny97biv0pwj7ch69') > > Start tag: > > script > > attr: ('type', 'text/javascript') > > attr: ('src', 'http://s4.licdn.com/scds/concat/common/js?h=7nhn6ycbvnz80dydsu88wbuk-1kjdwxpxv0c3z97afuz9dlr9g-dlsf699o6xkxgppoxivctlunb-8v6o0480wy5u6j7f3sh92hzxo') > > End tag : > > script > > End tag : > > head > > > > > > > > But the source text for this is [and all of the " seem to go missing: > > > > Bob Aalsma | LinkedIn > > > > > > > > > > > > > > > > Hmm, OK, Peter, thanks. I didn't consider the effect of logging in, that could certainly be a reason. So how could I have the script log in? [Didn't understand the bit about the kittens, though. How about that?] From overhaalsgang_24_bob at me.com Wed Sep 5 13:34:23 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Wed, 5 Sep 2012 10:34:23 -0700 (PDT) Subject: HTMLParser skipping HTML? [newbie] In-Reply-To: <0ac33349-4938-41a6-a129-05d676a5819f@googlegroups.com> References: <80d8623b-bb08-415c-900b-4a56556435ae@googlegroups.com> <0ac33349-4938-41a6-a129-05d676a5819f@googlegroups.com> Message-ID: <6f152539-4028-41ae-9520-f1c77ba55432@googlegroups.com> Op woensdag 5 september 2012 19:23:45 UTC+2 schreef BobAalsma het volgende: > Op woensdag 5 september 2012 14:57:05 UTC+2 schreef BobAalsma het volgende: > > > I'm trying to understand the HTMLParser so I've copied some code from http://docs.python.org/library/htmlparser.html?highlight=html#HTMLParser and tried that on my LinkedIn page. > > > > > > No errors, but some of the tags seem to go missing for no apparent reason - any advice? > > > > > > I have searched extensively for this, but seem to be the only one with missing data from HTMLParser :( > > > > > > > > > > > > Code: > > > > > > import urllib2 > > > > > > from HTMLParser import HTMLParser > > > > > > > > > > > > from GetHttpFileContents import getHttpFileContents > > > > > > > > > > > > # create a subclass and override the handler methods > > > > > > class MyHTMLParser(HTMLParser): > > > > > > def handle_starttag(self, tag, attrs): > > > > > > print "Start tag:\n\t", tag > > > > > > for attr in attrs: > > > > > > print "\t\tattr:", attr > > > > > > # end for attr in attrs: > > > > > > # > > > > > > def handle_endtag(self, tag): > > > > > > print "End tag :\n\t", tag > > > > > > # > > > > > > def handle_data(self, data): > > > > > > if data != '\n\n': > > > > > > if data != '\n': > > > > > > print "Data :\t\t", data > > > > > > # end if 1 > > > > > > # end if 2 > > > > > > # > > > > > > # > > > > > > # --------------------------------------------------------------------- > > > > > > # > > > > > > def removeHtmlFromFileContents(): > > > > > > TextOut = '' > > > > > > > > > > > > parser = MyHTMLParser() > > > > > > parser.feed(urllib2.urlopen('http://nl.linkedin.com/in/bobaalsma').read()) > > > > > > > > > > > > return TextOut > > > > > > # > > > > > > # --------------------------------------------------------------------- > > > > > > # > > > > > > if __name__ == '__main__': > > > > > > TextOut = removeHtmlFromFileContents() > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Part of the output: > > > > > > End tag : > > > > > > script > > > > > > Start tag: > > > > > > title > > > > > > Data : Bob Aalsma - Nederland | LinkedIn > > > > > > End tag : > > > > > > title > > > > > > Start tag: > > > > > > script > > > > > > attr: ('type', 'text/javascript') > > > > > > attr: ('src', 'http://www.linkedin.com/uas/authping?url=http%3A%2F%2Fnl%2Elinkedin%2Ecom%2Fin%2Fbobaalsma') > > > > > > End tag : > > > > > > script > > > > > > Start tag: > > > > > > link > > > > > > attr: ('rel', 'stylesheet') > > > > > > attr: ('type', 'text/css') > > > > > > attr: ('href', 'http://s3.licdn.com/scds/concat/common/css?h=5v4lkweptdvona6w56qelodrj-7pfvsr76gzb22ys278pbj80xm-b1io9ndljf1bvpack85gyxhv4-5xxmkfcm1ny97biv0pwj7ch69') > > > > > > Start tag: > > > > > > script > > > > > > attr: ('type', 'text/javascript') > > > > > > attr: ('src', 'http://s4.licdn.com/scds/concat/common/js?h=7nhn6ycbvnz80dydsu88wbuk-1kjdwxpxv0c3z97afuz9dlr9g-dlsf699o6xkxgppoxivctlunb-8v6o0480wy5u6j7f3sh92hzxo') > > > > > > End tag : > > > > > > script > > > > > > End tag : > > > > > > head > > > > > > > > > > > > > > > > > > > > > > > > But the source text for this is [and all of the " seem to go missing: > > > > > > > > > > > > Bob Aalsma | LinkedIn > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Hmm, OK, Peter, thanks. I didn't consider the effect of logging in, that could certainly be a reason. So how could I have the script log in? > > > > [Didn't understand the bit about the kittens, though. How about that?] Oops, sorry, found that bit about logging in - asked too soon; still wonder about the kittens ;) From invalid at invalid.invalid Wed Sep 5 13:47:10 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 5 Sep 2012 17:47:10 +0000 (UTC) Subject: python docs search for 'print' References: Message-ID: On 2012-09-05, Terry Reedy wrote: > On 9/4/2012 11:22 PM, Ramchandra Apte wrote: > >> I was actually planning to write a bug on this. > > If you do, find the right place to submit it. > bugs.python.org is for issues relating to the cpython repository.' > I fairly sure that the website search code is not there. > > If you do find the right place, you should contribute something to an > improvement. The current search performance is not a secret, so mere > complaints are useless. Making the site's "search" box use Google or somesuch is probably the simplest solution. I'm not enough of a web guy to know how to do that, but I do know that some sites do handle site search that way. -- Grant Edwards grant.b.edwards Yow! I like the way ONLY at their mouths move ... They gmail.com look like DYING OYSTERS From __peter__ at web.de Wed Sep 5 14:04:00 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 05 Sep 2012 20:04 +0200 Subject: HTMLParser skipping HTML? [newbie] References: <80d8623b-bb08-415c-900b-4a56556435ae@googlegroups.com> <0ac33349-4938-41a6-a129-05d676a5819f@googlegroups.com> <6f152539-4028-41ae-9520-f1c77ba55432@googlegroups.com> Message-ID: BobAalsma wrote: > [Didn't understand the bit about the kittens, though. How about that?] > > Oops, sorry, found that bit about logging in - asked too soon; still > wonder about the kittens ;) I just wanted to tell you not to mark the end of an if-suite with an "# end if" comment. As soon as you become familiar with the language that will look like noise that detracts from the actual code. In an attempt to make this advice appear less patronizing I wrapped it into a lame joke by alluding to http://en.wikipedia.org/wiki/Every_time_you_masturbate..._God_kills_a_kitten Sorry for the confusion -- I hope you aren't offended. From d at davea.name Wed Sep 5 14:13:32 2012 From: d at davea.name (Dave Angel) Date: Wed, 05 Sep 2012 14:13:32 -0400 Subject: python docs search for 'print' In-Reply-To: References: Message-ID: <5047964C.5020106@davea.name> On 09/05/2012 01:47 PM, Grant Edwards wrote: > On 2012-09-05, Terry Reedy wrote: >> On 9/4/2012 11:22 PM, Ramchandra Apte wrote: >> >>> I was actually planning to write a bug on this. >> If you do, find the right place to submit it. >> bugs.python.org is for issues relating to the cpython repository.' >> I fairly sure that the website search code is not there. >> >> If you do find the right place, you should contribute something to an >> improvement. The current search performance is not a secret, so mere >> complaints are useless. > Making the site's "search" box use Google or somesuch is probably the > simplest solution. I'm not enough of a web guy to know how to do > that, but I do know that some sites do handle site search that way. > And google has some API's to make it relatively painless. And a license form to fill in and send, along with your check. -- DaveA From invalid at invalid.invalid Wed Sep 5 14:24:17 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 5 Sep 2012 18:24:17 +0000 (UTC) Subject: python docs search for 'print' References: Message-ID: On 2012-09-05, Dave Angel wrote: > On 09/05/2012 01:47 PM, Grant Edwards wrote: > >> Making the site's "search" box use Google or somesuch is probably the >> simplest solution. I'm not enough of a web guy to know how to do >> that, but I do know that some sites do handle site search that way. >> > And google has some API's to make it relatively painless. And a > license form to fill in and send, along with your check. I just saw the posting mentioning the pricing. So it is a simple simple solution, but it's probably not cheap enough... -- Grant Edwards grant.b.edwards Yow! Yes, but will I at see the EASTER BUNNY in gmail.com skintight leather at an IRON MAIDEN concert? From tjreedy at udel.edu Wed Sep 5 14:27:44 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 05 Sep 2012 14:27:44 -0400 Subject: is implemented with id ? In-Reply-To: References: <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/5/2012 8:48 AM, Ramchandra Apte wrote: > Seeing this thread, I think the is statment should be removed. > It has a replacement syntax of id(x) == id(y) The thread is wrong then. If the implementation reuses ids, which CPython does, is must be implemented as internal-tem1 = internal-tem2 = id(internal-tem1) == id(internal-tem2) in order to ensure that the two objects exist simultaneously, so that the id comparison is valid. > and "a==True" should be automatically changed into memory comparison. I have no idea what that means. -- Terry Jan Reedy From tjreedy at udel.edu Wed Sep 5 14:31:08 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 05 Sep 2012 14:31:08 -0400 Subject: is implemented with id ? In-Reply-To: <5047648f$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <5047648f$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/5/2012 10:41 AM, Steven D'Aprano wrote: > True. In principle, some day there might be a version of Python that runs > on some exotic quantum computer where the very concept of "physical > address" is meaningless. You mean like the human brain? When people execute Python code, does 0 have an address? -- Terry Jan Reedy From d at davea.name Wed Sep 5 14:40:06 2012 From: d at davea.name (Dave Angel) Date: Wed, 05 Sep 2012 14:40:06 -0400 Subject: is implemented with id ? In-Reply-To: References: <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50479C86.8080702@davea.name> On 09/05/2012 02:27 PM, Terry Reedy wrote: > On 9/5/2012 8:48 AM, Ramchandra Apte wrote: > >> Seeing this thread, I think the is statment should be removed. >> It has a replacement syntax of id(x) == id(y) > > The thread is wrong then. > > If the implementation reuses ids, which CPython does, > is > must be implemented as > > internal-tem1 = > internal-tem2 = > id(internal-tem1) == id(internal-tem2) > > in order to ensure that the two objects exist simultaneously, > so that the id comparison is valid. > > > and "a==True" should be automatically changed into memory comparison. > > I have no idea what that means. > It's probably a response to Steve's comment """ In general, you almost never need to care about IDs and object identity. The main exception is testing for None, which should always be written as: if x is None """ Somehow he substituted True for None. Anyway, if one eliminates "is" then Steve's comment wouldn't apply. -- DaveA From PointedEars at web.de Wed Sep 5 14:42:18 2012 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 05 Sep 2012 20:42:18 +0200 Subject: Mailergate (was: python docs search for 'print') References: <2142958.VIB8zyE3RV@PointedEars.de> <504649ea$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <12378564.Q0WjZv560K@PointedEars.de> Stephen D'Aprano wrote: > On Tue, 04 Sep 2012 20:27:38 +0200, Thomas 'PointedEars' Lahn wrote: >> ? The other mess they created (or allowed to be created) is this mashup >> of newsgroup and mailing list, neither of which works properly, > > In what way do they not work properly? Most prominently, threads are completely and utterly borken. >> because the underlying protocols are not compatible. > > What? > > That is rather like saying that you can't read email via a web interface > because the http protocol is not compatible with the smtp protocol. Apples and oranges. The problem is gating messages from a mail server to a news server and vice-versa without regard to the differences between the underlying protocols. Netnews User Agents (NUAs, newsreaders), are currently based on [RFC3977] and [RFC5536]. In a Netnews article, a References header field is mandatory for a posting that is a follow-up. (Threading by Subject and Date works poorly, if at all, so the Specification does not suggest that.) The last element of the References header field value has to be a Message-ID specifiying the article's precursor. That Message-ID has to match the Message-ID header field value of an existing posting, unless it has expired on the target newsserver or was canceled (with Supersedes being a special case). The In-Reply-To header field (see below) is not allowed there, but it is set by some hybrid MUA/NUAs like Mozilla Thunderbird anyway?. Mail User Agents (MUAs, mailreaders), on the other hand, are currently based on [RFC5321], [RFC1939], IMAP4 (various RFCs, starting with [RFC1730]), and last but not least [RFC5322]. There are two possible header fields to build a thread of e-mail messages: In-Reply-To, and References. Whereas the first header field's value is supposed to be a Message-ID and the second one's as described in [RFC5536]. Few MUAs set both, some set the first one, and many set none of them at all, because there is no absolute requirement to set any of them (see [RFC5322], section 3.6.4.) And then there is utterly borken software ? or shall we say utterly borken approaches? Consider for example the recent thread with Subject "simple client data base" started by Mark R Rivet. The original posting has: | User-Agent: ForteAgent/7.00.32.1200 (posted using a newsreader) | [?] | Message-ID: Chris Angelico's follow-up to that has | In-Reply-To: | References: | [?] | Message-ID: | [?] | X-Mailman-Version: 2.1.15 (apparently posted using a mailreader, gated by python.org's mail software) So far, so good. But Peter Otten's follow-up to Chris Angelico's posting has | References: | | [?] | User-Agent: KNode/4.7.3 (posted using a newsreader) | [?] | Message-ID: As you can see, the Message-ID of Chris' posting does not occur in the References header field value of Peter's posting, which is caused by python.org's SMTP-to-NNTP gating program to set its own Message-ID, ignoring the Message-ID of the server where the message was injected. Therefore, although it is a followup to Chris' posting, Peter's posting has no *technical* (metadata) relation to Chris' posting. Instead, it should have | References: | | [?] or, better: Chris' posting should have had the original | [?] | Message-ID: | | [?] (no word-wrap), then the header fields of Peter's posting can stay as they are. My newsreader (KNode/4.4.11) tries its best to resolve this (short of threading by Subject and Date, which does not work; see above) which causes Peter's posting to end up as a follow-up to *Mark's* posting instead (specified by the only valid Message-ID in the References header). Only when you read Peter's posting you realize that it is not a follow-up to Mark's at all. Confusion ensues. There are a lot of similar examples here. As a result of the Message-ID rewriting, in several cases a follow-up even appears as if it was an original posting, without any technical (and therefore without any obvious visual) relation to the thread it actually belongs to at all, even though the precursor has not expired. For example, | [?] | X-Original-To: python-list at python.org | Delivered-To: python-list at mail.python.org | [?] | In-Reply-To: <50464153.5090402 at gmail.com> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | References: <50464153.5090402 at gmail.com> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | Date: Tue, 4 Sep 2012 14:27:35 -0400 | Subject: Re: python docs search for 'print' | From: Joel Goldstick | To: David Hoese | Content-Type: text/plain; charset=UTF-8 | Cc: python-list at python.org | [?] | Newsgroups: comp.lang.python | Message-ID: | [?] | | On Tue, Sep 4, 2012 at 1:58 PM, David Hoese wrote: | > [?] There is no message with Message-ID <50464153.5090402 at gmail.com> (at least not on the newsserver that I use), because that header field value was overwritten by the borken gating software that python.org uses. The actual message posted by that software is: | [?] | X-Original-To: python-list at python.org | Delivered-To: python-list at mail.python.org | [?] | Date: Tue, 04 Sep 2012 13:58:43 -0400 | From: David Hoese | User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; | rv:15.0) Gecko/20120824 Thunderbird/15.0 | [?] | To: python-list at python.org | Subject: python docs search for 'print' | [?] | Newsgroups: comp.lang.python | Message-ID: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To further show that this is not a coincidence, and that I am not imagining things here, the same problems started to occur when some people of the German-speaking Python mailing list at python.org thought it would be a good idea to merge that mailing list and the German-speaking newsgroup de.comp.lang.python not so long ago, using the same software. As a result, that Python newsgroup is a complete mess now, too. >> Add to that the abomination that Google Groups has become. > > It's always been an abomination, After they took over the Dejanews archive it was rather OK. You could use it with the keyboard, lines were at least automatically wrapped at 80 columns (but unfortunately, only when sending and there was no preview [AFAIK it still isn't]), they removed postings reported as spam, and so forth. > although I understand it is much, much worse now. Now you cannot even use it with the keyboard, the postings are not properly word-wrapped when typing or submitting (resulting in lines of 200 characters and more). The spam is not removed at all, but only hidden from *Google* *Groups* users, which causes it to be distributed on Usenet unchecked unless the closest peers of the Google Groups servers happen to employ a suitable spam filter, or have at least one dedicated user who runs a killbot. > Blame Google for that. I do, and I have UDP'd Google Groups since April for that (except follow-ups to my postings). However, I am also blaming the people still using it without complaining sufficiently, because if they would not use it or would complain more often and louder, Google would have to fix it. Unfortunately, most people do not even know where they are posting to when they access Usenet via Google Groups, so there is little hope for improvement of the situation. But that is another can of worms entirely. __________ ? Recent example: References: [RFC1730] Crispin, M. "INTERNET MESSAGE ACCESS PROTOCOL - VERSION 4" (IMAP4). December 1994. [RFC1939] Myers, J. and Rose, M. "Post Office Protocol - Version 3". May 1996. [RFC3977] Feather, C. "Network News Transfer Protocol (NNTP)". October 2006. [RFC5321] Klensin, J. "Simple Mail Transfer Protocol" (SMTP). October 2008. [RFC5322] Resnick, P. (ed.) "Internet Message Format". October 2008. [RFC5536] Murchison, K., Lindsey, C., and Kohn, D. "Netnews Article Format". November 2009. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail. From tjreedy at udel.edu Wed Sep 5 15:03:16 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 05 Sep 2012 15:03:16 -0400 Subject: python docs search for 'print' In-Reply-To: References: <9b4e3057-30a0-4731-95d2-131bfa495904@googlegroups.com> Message-ID: On 9/5/2012 8:45 AM, Ramchandra Apte wrote: > On Wednesday, 5 September 2012 15:03:56 UTC+5:30, Terry Reedy wrote: >> On 9/5/2012 1:22 AM, Ramchandra Apte wrote: >> >>> On Wednesday, 5 September 2012 09:35:43 UTC+5:30, Terry Reedy wrote: >> >> >> >>>> If you do find the right place, you should contribute something to an >> >>>> improvement. The current search performance is not a secret, so mere >> >>>> complaints are useless. These ever increasing extra blank lines with each quote are obnoxious. Consider using a news reader with news.gmane.org instead of google crap. Or snip heavily. > Google site search costs 2000$ for 500,000 searches per year and 750$ for 150,000 searches so its quite expensive. > Also the print function only comes in the third result (python 3.2) > if you search for "site:docs.python.org/release/3.2 print" the print function is not found at all. > I think a specialized algorithm would work better. > I'm going to code an program for this. A simple algorithm would be to present index search results first, if there are any, and then page search results. Then searching print would return "Index entries for print:" Builtin-functions page a couple of others... Pages containing print: I would not worry about duplication. Labeling index results as such would clue people in to the fact that they could have looked for the object name in the index. People names like 'Lundh' that are not indexed but which appear on several pages would give the same result as before. Looking at the web page (which I do not normally use), I see that the problem is deeper. The left margin of every page have an inviting "Quick search" box with text "Enter search terms or a module, class or function name." But it does not currently work very well for such object names. The index is only available from the main contents page. This contrasts with the Windows docs which has an index tab, making the index directly available from *anywhere*. (There is also a separate text search tab.) I think an index search box should be added above the text search box. I will ask on pydev where the suggestion should go. -- Terry Jan Reedy From walterhurry at lavabit.com Wed Sep 5 16:24:45 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Wed, 5 Sep 2012 20:24:45 +0000 (UTC) Subject: python docs search for 'print' References: <9b4e3057-30a0-4731-95d2-131bfa495904@googlegroups.com> Message-ID: On Wed, 05 Sep 2012 15:03:16 -0400, Terry Reedy wrote: > On 9/5/2012 8:45 AM, Ramchandra Apte wrote: > These ever increasing extra blank lines with each quote are obnoxious. > Consider using a news reader with news.gmane.org instead of google crap. > Or snip heavily. +1. And the duplicated posts. Enough of him. Bozo bin it is. From cornelius.koelbel at lsexperts.de Wed Sep 5 16:41:05 2012 From: cornelius.koelbel at lsexperts.de (=?ISO-8859-15?Q?Cornelius_K=F6lbel?=) Date: Wed, 05 Sep 2012 22:41:05 +0200 Subject: ctypes, strange structures of PKCS11 Message-ID: <5047B8E1.4030505@lsexperts.de> Hi there, I am trying to use a pkcs11 library (with python 2.7) and address this library with ctypes. Alas, I am neither the python black belt guru and C is not my preferred language. Till now, I do not want to use pykcs11, since I want to keep my dependencies low. I initialized the library, logged in to the token and got a session (self.hSession). Now I try to create an AES key using C_CreateKey. --snip-- def createAES(self, ks=32): rv=0 mechanism = CK_MECHANISM(CKM_AES_KEY_GEN, NULL, 0) print "Mech:",mechanism.mechanism print "Mech:",mechanism.pParameter print "Mech:",mechanism.usParameterLen keysize = c_ulong(ks) klass = CKO_SECRET_KEY keytype = CKK_AES label = "testAES" ck_true = c_ubyte(1) ck_false = c_ubyte(0) objHandle = CK_OBJECT_HANDLE() size=7 CK_TEMPLATE = CK_ATTRIBUTE * 6 template = CK_TEMPLATE( CK_ATTRIBUTE(CKA_KEY_TYPE, c_void_p(keytype),0), CK_ATTRIBUTE(CKA_LABEL, cast( label, c_void_p), len( label )), CK_ATTRIBUTE(CKA_VALUE_LEN, cast(byref(keysize),c_void_p), sizeof(keysize) ), CK_ATTRIBUTE(CKA_PRIVATE, cast(byref(ck_false),c_void_p), sizeof(ck_false)), CK_ATTRIBUTE(CKA_TOKEN, cast(byref(ck_true),c_void_p), sizeof(ck_true)), CK_ATTRIBUTE(CKA_SENSITIVE, cast(byref(ck_true),c_void_p), sizeof(ck_true)) ) template_len = c_ulong(size) print "Template: ", template print "Template: ", len(template) print "Handle:", objHandle print "Handle:", type(addressof(objHandle)) rv = self.etpkcs11.C_GenerateKey(self.hSession, addressof(mechanism), addressof(template), template_len, objHandle) print "rv=",rv print "handle=",objHandle if rv: if self.debug: print "Failed to create key: " , rv raise Exception("createAES - Failed to C_GenerateKey (%s): %s" % (rv, pkcs11error(rv)) ) else: if self.debug: print "created key successfully: %s" % str(handle) --snap-- Unfortunately I end up with a return value of 32, which means invalid data -- I guess my template is not that, what is should be. Any hint on this is highly appreciated. Kind regards Cornelius -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 259 bytes Desc: OpenPGP digital signature URL: From nesaro at gmail.com Wed Sep 5 17:04:16 2012 From: nesaro at gmail.com (Nestor Arocha) Date: Wed, 5 Sep 2012 14:04:16 -0700 (PDT) Subject: Language workbench written in python3 Message-ID: <1ed391c3-8fcf-4a3f-8ad7-0a2cf913b6cc@googlegroups.com> I'm developing a language workbench written in Python. The idea is to create an environment where grammars and translators can interact easily. https://github.com/nesaro/pydsl any comments, feedback or ideas? :) From 19mani.sh19 at gmail.com Wed Sep 5 18:08:02 2012 From: 19mani.sh19 at gmail.com (manish gupta) Date: Thu, 6 Sep 2012 03:38:02 +0530 Subject: webkit related problems Message-ID: What should I do in order to install Webkit for Official Python (not MacPorts Python) ? INVOKER, from INDIA -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Sep 5 18:13:44 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Sep 2012 08:13:44 +1000 Subject: Python Interview Questions In-Reply-To: References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: On Thu, Sep 6, 2012 at 2:40 AM, Ian Kelly wrote: > On Wed, Sep 5, 2012 at 9:34 AM, Chris Angelico wrote: >> On Thu, Sep 6, 2012 at 1:22 AM, Ian Kelly wrote: >>> The lack of an ORDER BY is the least of the problems with that SQL. >>> He's also using LIMIT without OFFSET, so the only thing that the >>> 'item' argument changes is how many rows are returned (all but one of >>> which are ignored), not which one is actually fetched. >> >> No, he's using the two-arg form of LIMIT. > > My mistake. I didn't even know there was a two-arg form of LIMIT. > Must be a MySQL thing. :-) Yeah, it's not something I've used, but when my current job started, we were using MySQL and I used to eyeball the logs to see what queries were performing most suboptimally. (There were some pretty egregious ones. Most memorable was rewriting a TEXT field several times a second with several KB of PHP serialized array with status/statistical information. Structured information, yes. Stored as a clob.) My first databasing experience was DB2, with the uber-verbose "FETCH FIRST n ROW[S] ONLY", but now I'm happily on Postgres. Everyone who wants to use LIMIT without ORDER BY should try their code on Postgres. You'll quickly discover the problem. ChrisA From oscar.j.benjamin at gmail.com Wed Sep 5 18:47:14 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 5 Sep 2012 22:47:14 +0000 (UTC) Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: In news.gmane.comp.python.general, you wrote: > On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote: > [...] >>> You are making unjustified assumptions about the distribution of >>> letters in the words. This might be a list of long chemical compounds >>> where the words typically differ only in their suffix. It might be a >>> list of people with titles: >> >> Actually, I'm not. I'm stating exactly what assumptions I'm making to >> get my calculation. I'm comparing *random* character strings or >> bitstrings. > > Excuse me, you are not. You are comparing English words which are highly > non-random. Evidently we have different understandings of what 'random' means. I don't think it's unreasonable to say that strings drawn uniformly from the set of all strings in the English language (having a given number of characters) is random. The distribution is not uniform over the set of all possible character strings but it is still random. I think Johannes deliberately chose these strings to emulate a particular kind of 'real' distribution of strings that might occur in practise. > > >> You, on the other hand, are making vague assumptions which you do not >> care for formalize and yet you claim that "the number of comparisons is >> equally likely to be 1, 2, 3, ..., N. The average then is". Without any >> explanation for this. At all. > > I will accept that my explanation was not good enough, but I strongly > disagree that I gave no explanation at all. > > >>> Herr Professor Frederick Schmidt >>> Herr Professor Frederick Wagner >>> ... >> >> Is your assumtion that we're comparing words that have the common prefix >> "Herr Professor Frederick "? > > No, I am pointing out that *your* assumption that most string comparisons > will halt close to the beginning of the string is an invalid assumption. > Your assumption only holds for some non-random strings. I think you have this backwards. The case where this assumption is provably true is precisely for random strings. To be clear, when I say 'random' in this context I mean that each character is chosen independently from the same probability distribution over the possible characters regardless of which index it has in the string and regardless of what the other characters are (IID). In this case the probability that comparison terminates at the jth character decreases exponentially with j. This means that for large strings the expected number of character comparisons is independent of the number of characters in the string as the probability of reaching the later parts of the string is too small for them to have any significant effect. This is provable and applies regardless of how many possible characters there are and whether or not each character is equally likely (except for the pathological case where one character has a probability of 1). For strings from 'real' distributions it is harder to make statements about the 'average case' and it is possible to construct situations where the comparison would regularly need to compare a common prefix. However, to get asymptotic performance worse than O(1) it is not sufficient to say that there may be a common prefix such as 'Herr' in the distribution of strings. It is necessary that, somehow, the common prefix is likely to grow as the size of the strings grows. For example, the set of all strings of length N whose first N//2 characters are always 'a' and whose remaining characters are chosen IID would lead to O(N) performance. This is why the file paths example chosen at the start of this thread is a good one. If a program is dealing with a number of large strings representing file paths then it is not uncommon that many of those paths would refer to files in the same deeply nested directory and hence compare equal for a significant number of characters. This could lead to average case O(N) performance. I think it's appropriate to compare string comparison with dict insertion: Best case O(1) (no hash collisions) Worst case O(N) (collides with every key) Average case O(1) (as long as you don't use pathological data) The only difference with string comparison is that there are some conceivable, non-malicious cases where the pathological data can occur (such as with file paths). However, I suspect that out of all the different uses of python strings these cases are a small minority. In saying that, it's not inconceivable that someone could exploit string comparison by providing pathological data to make normally O(1) operations behave as O(N). If I understand correctly it was precisely this kind of problem with dict insertion/lookup that lead to the recent hash-seed security update. Oscar From breamoreboy at yahoo.co.uk Wed Sep 5 19:11:07 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 06 Sep 2012 00:11:07 +0100 Subject: webkit related problems In-Reply-To: References: Message-ID: On 05/09/2012 23:08, manish gupta wrote: > What should I do in order to install Webkit for Official Python (not > MacPorts Python) ? > > > INVOKER, > from INDIA > > > I'd start with your favourite search engine, type something like "install webkit official python" into the box, hit return, see what comes back and follow an appropriate link. Probably faster than asking here. -- Cheers. Mark Lawrence. From solipsis at pitrou.net Wed Sep 5 20:34:56 2012 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 6 Sep 2012 00:34:56 +0000 (UTC) Subject: The opener parameter of Python 3 open() built-in References: <504555a5$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico gmail.com> writes: > > On Wed, Sep 5, 2012 at 5:16 AM, Terry Reedy udel.edu> wrote: > > io.open depends on a function the returns an open file descriptor. opener > > exposes that dependency so it can be replaced. > > I skimmed the bug report comments but didn't find an answer to this: > Why not just monkey-patch? When a module function calls on a support > function and you want to change that support function's behaviour, > isn't monkey-patching the most usual? Monkey-patching globals is not thread-safe: other threads will see your modification, which is risky and fragile. Regards Antoine. -- Software development and contracting: http://pro.pitrou.net From kushal.kumaran+python at gmail.com Thu Sep 6 00:24:46 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Thu, 6 Sep 2012 09:54:46 +0530 Subject: Python Interview Questions In-Reply-To: References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: On Wed, Sep 5, 2012 at 3:11 PM, Stephen Anto wrote: > On Wed, Sep 5, 2012 at 2:10 PM, Kushal Kumaran > wrote: >> >> On Wed, Sep 5, 2012 at 12:20 PM, wrote: >> > On Tuesday, October 30, 2007 11:44:01 PM UTC+5:30, Krypto wrote: >> >> Hi, >> >> >> >> I have used Python for a couple of projects last year and I found it >> >> extremely useful. I could write two middle size projects in 2-3 months >> >> (part time). Right now I am a bit rusty and trying to catch up again >> >> with Python. >> >> >> >> I am now appearing for Job Interviews these days and I am wondering if >> >> anybody of you appeared for a Python Interview. Can you please share >> >> the questions you were asked. That will be great help to me. >> >> >> > >> > Finally I have decided to put best interview question and answers. >> > >> > Please visit http://www.f2finterview.com/web/CorePython/ for core python >> > and http://www.f2finterview.com/web/PythonAdvanced/ for advanced python >> > >> >> As I see from a quick glance, several of your answers seem to be >> copied from the python faq at http://docs.python.org/faq/. The >> copyright notice for the python.org website seems to be at >> http://docs.python.org/copyright.html. Do you have the Python >> Software Foundation's permission to copy large chunks of the >> python.org website and claim it as your own content? >> > > Thank you for your information, I really sorry for this, if possible could > you note which are the questions taken from faq, we will remove it as early > as possible. > Since your website's Terms of Use state that you own the content, it is your problem to make sure whatever's there is there legally. Here's one example, though, to get you started: See the entry "Why can?t I use an assignment in an expression?" at http://docs.python.org/faq/design.html, and compare with the content under the identical heading on page 3 of the CorePython section. -- regards, kushal From stefan_ml at behnel.de Thu Sep 6 01:27:39 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 06 Sep 2012 07:27:39 +0200 Subject: RPython, static type annotations, SafePython project (was: PhD Python & Smalltalk grant possibility (Lille/INRIA)) In-Reply-To: References: Message-ID: Mariano Reingart, 05.09.2012 18:53, on python-announce-list: > Context: Dynamically-typed languages cannot take advantage of static > type information. In this context we would like to study > the benefit of the introduction of static types *annotations* on > library design and general robustness. Works to a certain extent, but won't get you very far. You'll notice that static types don't have all that rich semantics, so you'll eventually end up wanting to extend the type declarations into contract specifications, and then you'll end up duplicating half of your code to describe the interface at some point. Has been done, IMHO not worth doing. > The benefits can be at the level of the robustness (bug > identification), but also tools (IDE) and support for assembly > generation/c in case of JIT. As the PyPy people keep reiterating, JITs (read: their JIT) don't need static type declarations. IDEs can benefit from them a bit (not much, just a bit - guessing usually works quite well here), but I'd hate to change my code only to make my IDE happy. Static compilers obviously benefit from them, so you should take a look at Cython if you are interested in a Python based type system with optional static type declarations and how people use them in real code. (There's definitely a lot more Cython code out there than RPython code...) > The PhD grant is financed in the context of the Safe Python project > therefore the Ph.D. will have to work in contact > do we with the project partners and help in the context of some deliverables. > > The following tasks have to be done: > > - RPython is not formally defined. One of the first task will > be to define the formal semantic of RPython. Just to be sure: you are talking about RPython, the language that PyPy is (mostly) written in, right? Why would you want to restrict yourself to that instead of looking at general Python code? Is that due to those who pay the project or because it's really of interest all by itself? > One approach is to write a RPython interpreter based on an > operational semantics and to compare the output > with the RPython interpreter. We will certainly use PLT redex > which is a domain-specific language to specify > and debug operational semantics. Sounds like a research-only project to me. From what I hear, RPython isn't really an interesting programming language. It's very restrictive and easy to get wrong. That might be related to the fact that the only definition of the language is the only existing (incomplete) implementation, but maybe not. (Sounds like some research could help to decide that at least). There's also ShedSkin, which, I believe, has its own definition of an "RPython", again based on what it understands and can statically analyse. > - We may use the abstract syntax tree of PyLint and use the > Frama-C infrastructure. We will also consider to > build a Python parser based on petitParser. My advice: skip the parser part, use the existing AST that Python provides. That's the only sane way to integrate with other tools that process Python code. > - Define of some default metrics may also be necessary for the > SafePython project. Their definition should > be trivial on ASTs. Not sure what you mean with "default metrics" here. > - Analysis of the benefits of static typing for RPython. One > idea is to study the existing python libraries > and analyze the "distance" to the RPython subset. That might be an interesting study in its own right: how static is real-world Python code? > - Exploring type checking in presence of inconsistent type annotations. Yep, that's only one of the problems you'll run into. > - Since we are developing Pharo Which, if I searched correcly, is a Smalltalk IDE? > and that static type annotation are important to > support C or assembly generation, we would like to apply the > same technique to Pharo: > - define a syntax to support type annotation (reuse > the one developed by Pleaid team member) > - perform some analysis of existing library. I don't know Smalltalk well enough to comment on this. > About Lille and INRIA: > > Lille is located in the north of france at the border to Belgium > one hour from Paris, 1h20 from London, 35 min from Brussels, by train. And the most important thing (which you forgot to mention): a nice place to live. > French food, combined with belgian beer. Well, yes, but it's still a nice place to live. Stefan From mikepittenson85 at gmail.com Thu Sep 6 01:56:20 2012 From: mikepittenson85 at gmail.com (mike pittenson) Date: Wed, 5 Sep 2012 22:56:20 -0700 (PDT) Subject: ===== Soft Skills Training In Chennai ====== Message-ID: <4131defd-fb7b-407f-b45d-cbf0ab7fa23f@googlegroups.com> Ayus Technologies offers Dot net training in chennai,java/j2ee training in chennai,SEO training in chennai,web designing training in chennai,soft skills training in chennai,Software Testing training in chennai. ================================================ http://www.ayustechnologies.com/ ================================================ More Information contact Mr, Jana 9080140107 From dieter at handshake.de Thu Sep 6 02:07:46 2012 From: dieter at handshake.de (Dieter Maurer) Date: Thu, 06 Sep 2012 08:07:46 +0200 Subject: [web] Long-running process: FCGI? SCGI? WSGI? References: <4ofe485b0m50fi2qa7sk8d01369g2lo5el@4ax.com> Message-ID: <87vcfrptu5.fsf@handshake.de> Gilles writes: > To write a long-running web application, I'd like to some feedback > about which option to choose. > > Apparently, the choice boilds down to this: > - FastCGI > - SCGI > - WSGI > > It seems like FCGI and SCGI are language-neutral, while WSGI is > Python-specific. > > Besides that, how to make an informed choice about which option to > choose? Obviously, this depends on your environment. Some hosters, web servers, applications may directly support one interface and not others. If you control your whole environment, I would look for a newer approach. I do not know "SCGI" but I know that "WSGI" is fairly recent. This means that during its design, "FastCGI" was already known and not deemed to be sufficient. Thus, you can expect more features (more modularisation, in this case) in "WSGI". From amangill.coldfire at gmail.com Thu Sep 6 02:21:37 2012 From: amangill.coldfire at gmail.com (coldfire) Date: Wed, 5 Sep 2012 23:21:37 -0700 (PDT) Subject: Dynamically scheduling Cron Jobs for Python Scripts. Message-ID: <1c24b34d-774f-4613-b6a9-f6f19fb24acb@googlegroups.com> I have a web scrapper script which run every day at 0100 hrs using cron Job over a shell account. Now what I am looking for is to re run the same script. 1> The script goes online to scrape some data including a schedule time for my meeting. I want to re run the script at that schedule time to send me a email. How can I do that? Plz Help From steve+comp.lang.python at pearwood.info Thu Sep 6 02:34:24 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Sep 2012 06:34:24 GMT Subject: The opener parameter of Python 3 open() built-in References: <504555a5$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <504843f0$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 06 Sep 2012 00:34:56 +0000, Antoine Pitrou wrote: > Chris Angelico gmail.com> writes: >> >> On Wed, Sep 5, 2012 at 5:16 AM, Terry Reedy udel.edu> >> wrote: >> > io.open depends on a function the returns an open file descriptor. >> > opener exposes that dependency so it can be replaced. >> >> I skimmed the bug report comments but didn't find an answer to this: >> Why not just monkey-patch? When a module function calls on a support >> function and you want to change that support function's behaviour, >> isn't monkey-patching the most usual? > > Monkey-patching globals is not thread-safe: other threads will see your > modification, which is risky and fragile. Isn't that assuming that you don't intend the other threads to see the modification? If I have two functions in my module that call "open", and I monkey-patch the global (module-level) name "open" to intercept that call, I don't see that there is more risk of breakage just because one function is called from a thread. Obviously monkey-patching the builtin module itself is much riskier, because it doesn't just effect code in my module, it affects *everything*. -- Steven From steve+comp.lang.python at pearwood.info Thu Sep 6 02:44:19 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Sep 2012 06:44:19 GMT Subject: is implemented with id ? References: <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50484643$0$29977$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Sep 2012 14:27:44 -0400, Terry Reedy wrote: > On 9/5/2012 8:48 AM, Ramchandra Apte wrote: > > > and "a==True" should be automatically changed into memory comparison. > > I have no idea what that means. I interpret this as meaning that "a == True" should be special-cased by the interpreter as "a is True" instead of calling a.__eq__. -- Steven From timothy.c.delaney at gmail.com Thu Sep 6 02:52:55 2012 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Thu, 6 Sep 2012 16:52:55 +1000 Subject: The opener parameter of Python 3 open() built-in In-Reply-To: <504843f0$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <504555a5$0$29978$c3e8da3$5496439d@news.astraweb.com> <504843f0$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 6 September 2012 16:34, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Thu, 06 Sep 2012 00:34:56 +0000, Antoine Pitrou wrote: > > Monkey-patching globals is not thread-safe: other threads will see your > > modification, which is risky and fragile. > > Isn't that assuming that you don't intend the other threads to see the > modification? > > If I have two functions in my module that call "open", and I monkey-patch > the global (module-level) name "open" to intercept that call, I don't see > that there is more risk of breakage just because one function is called > from a thread. > > Obviously monkey-patching the builtin module itself is much riskier, > because it doesn't just effect code in my module, it affects *everything*. It's not as though the option to monkey-patch has been taken away. But hopefully there is now less of a need for it. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Thu Sep 6 04:24:20 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 6 Sep 2012 01:24:20 -0700 (PDT) Subject: is implemented with id ? In-Reply-To: <50484643$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com> <50484643$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, 6 September 2012 12:14:19 UTC+5:30, Steven D'Aprano wrote: > On Wed, 05 Sep 2012 14:27:44 -0400, Terry Reedy wrote: > > > > > On 9/5/2012 8:48 AM, Ramchandra Apte wrote: > > > > > > > and "a==True" should be automatically changed into memory comparison. > > > > > > I have no idea what that means. > > > > I interpret this as meaning that "a == True" should be special-cased by > > the interpreter as "a is True" instead of calling a.__eq__. > > > > > > > > -- > > Steven Steven you are right. From maniandram01 at gmail.com Thu Sep 6 04:26:21 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 6 Sep 2012 01:26:21 -0700 (PDT) Subject: is implemented with id ? In-Reply-To: <50475e0a$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com> <50475e0a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, 5 September 2012 19:43:30 UTC+5:30, Steven D'Aprano wrote: > On Wed, 05 Sep 2012 05:48:26 -0700, Ramchandra Apte wrote: > > > > > Seeing this thread, I think the is statment should be removed. It has a > > > replacement syntax of id(x) == id(y) > > > > A terrible idea. > > > > Because "is" is a keyword, it is implemented as a fast object comparison > > directly in C (for CPython) or Java (for Jython). In the C implementation > > "x is y" is *extremely* fast because it is just a pointer comparison > > performed directly by the interpreter. > > > > Because id() is a function, it is much slower. And because it is not a > > keyword, Python needs to do a name look-up for it, then push the argument > > on the stack, call the function (which may not even be the built-in id() > > any more!) and then pop back to the caller. > > > > And worst, *it doesn't even do what you think it does*. In some Python > > implementations, IDs can be reused. That leads to code like this, from > > CPython 2.7: > > > > py> id("spam ham"[1:]) == id("foo bar"[1:]) > > True > > > > You *cannot* replace is with id() except when the objects are guaranteed > > to both be alive at the same time, and even then you *shouldn't* replace > > is with id() because that is a pessimation (the opposite of an > > optimization -- something that makes code run slower, not faster). > > > > > > > and "a==True" should be automatically changed into memory comparison. > > > > Absolutely not. That would be a backward-incompatible change that would > > break existing programs: > > > > py> 1.0 == True > > True > > py> from decimal import Decimal > > py> Decimal("1.0000") == True > > True > > > > > > > > -- > > Steven the is statement could be made into a function From maniandram01 at gmail.com Thu Sep 6 04:30:02 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 6 Sep 2012 01:30:02 -0700 (PDT) Subject: python docs search for 'print' In-Reply-To: References: <9b4e3057-30a0-4731-95d2-131bfa495904@googlegroups.com> Message-ID: <7dfdb57f-76bc-4701-99d3-489bd3df0dca@googlegroups.com> On Thursday, 6 September 2012 01:54:45 UTC+5:30, Walter Hurry wrote: > On Wed, 05 Sep 2012 15:03:16 -0400, Terry Reedy wrote: > > > > > On 9/5/2012 8:45 AM, Ramchandra Apte wrote: > > > > > > > These ever increasing extra blank lines with each quote are obnoxious. > > > Consider using a news reader with news.gmane.org instead of google crap. > > > Or snip heavily. > > > > +1. And the duplicated posts. Enough of him. Bozo bin it is. I really don't know why Google Groups is double-posting. From steve+comp.lang.python at pearwood.info Thu Sep 6 04:33:14 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Sep 2012 08:33:14 GMT Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Sep 2012 22:47:14 +0000, Oscar Benjamin wrote: > In news.gmane.comp.python.general, you wrote: >> On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote: [...] >>>> You are making unjustified assumptions about the distribution of >>>> letters in the words. This might be a list of long chemical compounds >>>> where the words typically differ only in their suffix. It might be a >>>> list of people with titles: >>> >>> Actually, I'm not. I'm stating exactly what assumptions I'm making to >>> get my calculation. I'm comparing *random* character strings or >>> bitstrings. >> >> Excuse me, you are not. You are comparing English words which are >> highly non-random. > > Evidently we have different understandings of what 'random' means. I > don't think it's unreasonable to say that strings drawn uniformly from > the set of all strings in the English language (having a given number of > characters) is random. The distribution is not uniform over the set of > all possible character strings but it is still random. I think Johannes > deliberately chose these strings to emulate a particular kind of 'real' > distribution of strings that might occur in practise. Of course for some "real" applications, your strings being compared will be English words. And for other applications, they will be strings of numeric digits uniformly distributed between 20000 and 30000. Or taken from a Gaussian distribution centered around 7000. Or strings made up of deeply nested sets of parentheses (((((( ... )))))). Whichever special distribution of strings you pick, I don't think calling them "random" is terribly useful in context, even if they are generated randomly from some non-uniform distribution. But you know, it really doesn't make a difference. Equality testing will *still* be O(N) since the asymptomatic behaviour for sufficiently large string comparisons will be bounded by O(N). Multiplicative constants ("half the string" versus "0.001 of the string") do not matter. I may have been overly-conservative earlier when I said that on average string equality has to compare half the characters. I thought I had remembered that from a computer science textbook, but I can't find that reference now, so possibly I was thinking of something else. (String searching perhaps?). In any case, the *worst* case for string equality testing is certainly O(N) (every character must be looked at), and the *best* case is O(1) obviously (the first character fails to match). But I'm not so sure about the average case. Further thought is required. -- Steven From overhaalsgang_24_bob at me.com Thu Sep 6 04:46:34 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Thu, 6 Sep 2012 01:46:34 -0700 (PDT) Subject: HTMLParser skipping HTML? [newbie] In-Reply-To: <80d8623b-bb08-415c-900b-4a56556435ae@googlegroups.com> References: <80d8623b-bb08-415c-900b-4a56556435ae@googlegroups.com> Message-ID: <90f4a3c6-ee1d-4d28-a0a1-fdfa6657e944@googlegroups.com> Op woensdag 5 september 2012 14:57:05 UTC+2 schreef BobAalsma het volgende: > I'm trying to understand the HTMLParser so I've copied some code from http://docs.python.org/library/htmlparser.html?highlight=html#HTMLParser and tried that on my LinkedIn page. > > No errors, but some of the tags seem to go missing for no apparent reason - any advice? > > I have searched extensively for this, but seem to be the only one with missing data from HTMLParser :( > > > > Code: > > import urllib2 > > from HTMLParser import HTMLParser > > > > from GetHttpFileContents import getHttpFileContents > > > > # create a subclass and override the handler methods > > class MyHTMLParser(HTMLParser): > > def handle_starttag(self, tag, attrs): > > print "Start tag:\n\t", tag > > for attr in attrs: > > print "\t\tattr:", attr > > # end for attr in attrs: > > # > > def handle_endtag(self, tag): > > print "End tag :\n\t", tag > > # > > def handle_data(self, data): > > if data != '\n\n': > > if data != '\n': > > print "Data :\t\t", data > > # end if 1 > > # end if 2 > > # > > # > > # --------------------------------------------------------------------- > > # > > def removeHtmlFromFileContents(): > > TextOut = '' > > > > parser = MyHTMLParser() > > parser.feed(urllib2.urlopen('http://nl.linkedin.com/in/bobaalsma').read()) > > > > return TextOut > > # > > # --------------------------------------------------------------------- > > # > > if __name__ == '__main__': > > TextOut = removeHtmlFromFileContents() > > > > > > > > > > > > Part of the output: > > End tag : > > script > > Start tag: > > title > > Data : Bob Aalsma - Nederland | LinkedIn > > End tag : > > title > > Start tag: > > script > > attr: ('type', 'text/javascript') > > attr: ('src', 'http://www.linkedin.com/uas/authping?url=http%3A%2F%2Fnl%2Elinkedin%2Ecom%2Fin%2Fbobaalsma') > > End tag : > > script > > Start tag: > > link > > attr: ('rel', 'stylesheet') > > attr: ('type', 'text/css') > > attr: ('href', 'http://s3.licdn.com/scds/concat/common/css?h=5v4lkweptdvona6w56qelodrj-7pfvsr76gzb22ys278pbj80xm-b1io9ndljf1bvpack85gyxhv4-5xxmkfcm1ny97biv0pwj7ch69') > > Start tag: > > script > > attr: ('type', 'text/javascript') > > attr: ('src', 'http://s4.licdn.com/scds/concat/common/js?h=7nhn6ycbvnz80dydsu88wbuk-1kjdwxpxv0c3z97afuz9dlr9g-dlsf699o6xkxgppoxivctlunb-8v6o0480wy5u6j7f3sh92hzxo') > > End tag : > > script > > End tag : > > head > > > > > > > > But the source text for this is [and all of the " seem to go missing: > > > > Bob Aalsma | LinkedIn > > > > > > > > > > > > > > > > No offense and thanks for the reminder. My background is software packages in 3GL, where different platforms mean different editors which mean it is sometimes difficult to recognize the end of blocks, especially when nested. No need for that here, no. I think it also means I'm still not really satisfied with my commenting in Python... From bryanjugglercryptographer at yahoo.com Thu Sep 6 04:57:04 2012 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Thu, 6 Sep 2012 01:57:04 -0700 (PDT) Subject: simple client data base References: Message-ID: <9543c9b1-d3ea-4930-af73-6659878e0077@qa3g2000pbc.googlegroups.com> Mark R Rivet wrote: > Hello all, I am learning to program in python. I have a need to make a > program that can store, retrieve, add, and delete client data such as > name, address, social, telephone number and similar information. This > would be a small client database for my wife who has a home accounting > business. Among programming languages Python is exceptionally easy to learn, and rocks for the kind of app you describe, but your goal is not realistic. Simple is better than complex, but what you can build at this point is far from what a professional accountant with her own business needs from a client database manager. > I have been reading about lists, tuples, and dictionary data > structures in python and I am confused as to which would be more > appropriate for a simple database. Those are good classes to read about, and I dare say that most Pythoneers at some time faced confusion as to which were most appropriate for the problem at hand. You'd need of all them and more, a whole freak'in bunch more, to build a professional quality contact manager app. > I know that python has real database capabilities but I'm not there > yet and would like to proceed with as simple a structure as possible. > > Can anyone give me some idea's or tell me which structure would be > best to use? > > Maybe its a combination of structures? I need some help. comp.lang.python tries to be friendly and helpful, and to that end responders have read and answered your question as directly as possible. There's good stuff available for Python. Mark, there is absolutely no chance, no how, no way, that your stated plan is a good idea. Fine CRM apps are available for free; excellent ones for a few dollars. You're reading about lists, tuples, and dictionary data? Great, but other home accounting businesses have their client databases automatically synced with their smart-phones and their time-charging and their invoicing. -Bryan From overhaalsgang_24_bob at me.com Thu Sep 6 05:01:42 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Thu, 6 Sep 2012 02:01:42 -0700 (PDT) Subject: HTMLParser skipping HTML? [newbie] In-Reply-To: <80d8623b-bb08-415c-900b-4a56556435ae@googlegroups.com> References: <80d8623b-bb08-415c-900b-4a56556435ae@googlegroups.com> Message-ID: <63adb7c0-f558-4f21-a49c-729bdb4e536a@googlegroups.com> Op woensdag 5 september 2012 14:57:05 UTC+2 schreef BobAalsma het volgende: > I'm trying to understand the HTMLParser so I've copied some code from http://docs.python.org/library/htmlparser.html?highlight=html#HTMLParser and tried that on my LinkedIn page. > > No errors, but some of the tags seem to go missing for no apparent reason - any advice? > > I have searched extensively for this, but seem to be the only one with missing data from HTMLParser :( > > > > Code: > > import urllib2 > > from HTMLParser import HTMLParser > > > > from GetHttpFileContents import getHttpFileContents > > > > # create a subclass and override the handler methods > > class MyHTMLParser(HTMLParser): > > def handle_starttag(self, tag, attrs): > > print "Start tag:\n\t", tag > > for attr in attrs: > > print "\t\tattr:", attr > > # end for attr in attrs: > > # > > def handle_endtag(self, tag): > > print "End tag :\n\t", tag > > # > > def handle_data(self, data): > > if data != '\n\n': > > if data != '\n': > > print "Data :\t\t", data > > # end if 1 > > # end if 2 > > # > > # > > # --------------------------------------------------------------------- > > # > > def removeHtmlFromFileContents(): > > TextOut = '' > > > > parser = MyHTMLParser() > > parser.feed(urllib2.urlopen('http://nl.linkedin.com/in/bobaalsma').read()) > > > > return TextOut > > # > > # --------------------------------------------------------------------- > > # > > if __name__ == '__main__': > > TextOut = removeHtmlFromFileContents() > > > > > > > > > > > > Part of the output: > > End tag : > > script > > Start tag: > > title > > Data : Bob Aalsma - Nederland | LinkedIn > > End tag : > > title > > Start tag: > > script > > attr: ('type', 'text/javascript') > > attr: ('src', 'http://www.linkedin.com/uas/authping?url=http%3A%2F%2Fnl%2Elinkedin%2Ecom%2Fin%2Fbobaalsma') > > End tag : > > script > > Start tag: > > link > > attr: ('rel', 'stylesheet') > > attr: ('type', 'text/css') > > attr: ('href', 'http://s3.licdn.com/scds/concat/common/css?h=5v4lkweptdvona6w56qelodrj-7pfvsr76gzb22ys278pbj80xm-b1io9ndljf1bvpack85gyxhv4-5xxmkfcm1ny97biv0pwj7ch69') > > Start tag: > > script > > attr: ('type', 'text/javascript') > > attr: ('src', 'http://s4.licdn.com/scds/concat/common/js?h=7nhn6ycbvnz80dydsu88wbuk-1kjdwxpxv0c3z97afuz9dlr9g-dlsf699o6xkxgppoxivctlunb-8v6o0480wy5u6j7f3sh92hzxo') > > End tag : > > script > > End tag : > > head > > > > > > > > But the source text for this is [and all of the " seem to go missing: > > > > Bob Aalsma | LinkedIn > > > > > > > > > > > > > > > > I can see that my Tester is not logging in: the reply from the site reads "Sign In | LinkedIn" rather than "Bob Aalsma | LinkedIn". How can I tell which part is not correct? From rosuav at gmail.com Thu Sep 6 05:07:31 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Sep 2012 19:07:31 +1000 Subject: is implemented with id ? In-Reply-To: References: <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com> <50475e0a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 6, 2012 at 6:26 PM, Ramchandra Apte wrote: > the is statement could be made into a function It's not a statement, it's an operator; and functions have far more overhead than direct operators. There's little benefit in making 'is' into a function, and high cost; unlike 'print', whose cost is dominated by the cost of producing output to a console or similar device, 'is' would be dominated by the cost of name lookups and function call overhead. ChrisA From gelonida at gmail.com Thu Sep 6 05:23:59 2012 From: gelonida at gmail.com (Gelonida N) Date: Thu, 06 Sep 2012 11:23:59 +0200 Subject: Looking for an IPC solution In-Reply-To: References: <50410AD6.7080003@shopzeus.com> Message-ID: On 08/31/2012 11:05 PM, Antoine Pitrou wrote: > Laszlo Nagy shopzeus.com> writes: > >> > > How about the standard multiprocessing module? It supports shared memory, remote > processes, and will most probably work under PyPy: > http://docs.python.org/library/multiprocessing.html I always thought, that the multiprocessing module does NOT use shared memory (at least not under windows) My understanding was, that it forks (or whateveri is closest to fork under windows) and uses sockets and pickle to communicate between the processes. I would be very interested in a cross platform shared mem solution for python. Could you please point me to the right section. From gelonida at gmail.com Thu Sep 6 05:25:34 2012 From: gelonida at gmail.com (Gelonida N) Date: Thu, 06 Sep 2012 11:25:34 +0200 Subject: Looking for an IPC solution In-Reply-To: References: <50410AD6.7080003@shopzeus.com> Message-ID: On 08/31/2012 11:05 PM, Antoine Pitrou wrote: > Laszlo Nagy shopzeus.com> writes: > >> > How about the standard multiprocessing module? It supports shared > memory, remote processes, and will most probably work under PyPy: > http://docs.python.org/library/multiprocessing.html > I always thought, that the multiprocessing module does NOT use shared memory (at least not under windows) My understanding was, that it forks (or whateveri is closest to fork under windows) and uses sockets and pickle to communicate between the processes. However perhap s I just misunderstood I never spent time to dive into the internals of multiprocessing. I would be very interested in a cross platform shared mem solution for python. Could you please point me to the right section. From duncan.booth at invalid.invalid Thu Sep 6 05:34:27 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 6 Sep 2012 09:34:27 GMT Subject: is implemented with id ? References: <5047648f$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > But less exotically, Frank isn't entirely wrong. With current day > computers, it is reasonable to say that any object has exactly one > physical location at any time. In Jython, objects can move around; in > CPython, they can't. But at any moment, any object has a specific > location, and no other object can have that same location. Two objects > cannot both be at the same memory address at the same time. > It is however perfectly possible for one object to be at two or more memory addresses at the same time. In fact some work being done in PyPy right now is doing exactly that as part of Armin Rigo's software transactional memory implementation: when a global object is mutated a new copy is made and some threads may see the new version while other threads continue to see the old version until their transactions are comitted (or aborted). This means that global objects can be safely read from multiple threads without any semaphore locking. See http://mail.python.org/pipermail/pypy-dev/2012-September/010513.html -- Duncan Booth http://kupuguy.blogspot.com From rosuav at gmail.com Thu Sep 6 05:50:04 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Sep 2012 19:50:04 +1000 Subject: is implemented with id ? In-Reply-To: References: <5047648f$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 6, 2012 at 7:34 PM, Duncan Booth wrote: > Steven D'Aprano wrote: > >> But at any moment, any object has a specific >> location, and no other object can have that same location. Two objects >> cannot both be at the same memory address at the same time. >> > > It is however perfectly possible for one object to be at two or more memory > addresses at the same time. And of course, memory addresses have to be taken as per-process, since it's entirely possible for two processes to reuse addresses. But I think all these considerations of object identity are made with the assumption that we're working within a single Python process. ChrisA From gelonida at gmail.com Thu Sep 6 05:59:35 2012 From: gelonida at gmail.com (Gelonida N) Date: Thu, 06 Sep 2012 11:59:35 +0200 Subject: Looking for an IPC solution In-Reply-To: References: <50410AD6.7080003@shopzeus.com> Message-ID: On 08/31/2012 11:05 PM, Antoine Pitrou wrote: > Laszlo Nagy shopzeus.com> writes: > >> > > How about the standard multiprocessing module? It supports shared memory, remote > processes, and will most probably work under PyPy: > http://docs.python.org/library/multiprocessing.html I always thought, that the multiprocessing module does NOT use shared memory (at least not under windows) My understanding was, that it forks (or whateveri is closest to fork under windows) and uses sockets and pickle to communicate between the processes. I would be very interested in a cross platform shared mem solution for Python. The intention would be to excahnge mutexes and ctypes kind of data structures Could you please point me to the right section. From gandalf at shopzeus.com Thu Sep 6 06:00:10 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 06 Sep 2012 12:00:10 +0200 Subject: Looking for an IPC solution In-Reply-To: <40ab9c6f-737e-47e3-950b-558472ad4a09@googlegroups.com> References: <40ab9c6f-737e-47e3-950b-558472ad4a09@googlegroups.com> Message-ID: <5048742A.2060201@shopzeus.com> > Hi Laszlo, > > There aren't a lot of ways to create a Python object in an "mmap" buffer. "mmap" is conducive to arrays of arrays. For variable-length structures like strings and lists, you need "dynamic allocation". The C functions "malloc" and "free" allocate memory space, and file creation and deletion routines operate on disk space. However "malloc" doesn't allow you to allocate memory space within memory that's already allocated. Operating systems don't provide that capability, and doing it yourself amounts to creating your own file system. If you did, you still might not be able to use existing libraries like the STL or Python, because one address might refer to different locations in different processes. > > One solution is to keep a linked list of free blocks within your "mmap" buffer. It is prone to slow access times and segment fragmentation. Another solution is to create many small files with fixed-length names. The minimum file size on your system might become prohibitive depending on your constraints, since a 4-byte integer could occupy 4096 bytes on disk or more. Or you can serialize the arguments and return values of your functions, and make requests to a central process. I'm not sure about the technical details, but I was said that multiprocessing module uses mmap() under windows. And it is faster than TCP/IP. So I guess the same thing could be used from zmq, under Windows. (It is not a big concern, I plan to operate server on Unix. Some clients might be running on Windows, but they will use TCP/IP.) From gandalf at shopzeus.com Thu Sep 6 06:04:21 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 06 Sep 2012 12:04:21 +0200 Subject: Looking for an IPC solution In-Reply-To: References: <50410AD6.7080003@shopzeus.com> Message-ID: <50487525.7080403@shopzeus.com> >>> >> How about the standard multiprocessing module? It supports shared >> memory, remote processes, and will most probably work under PyPy: >> http://docs.python.org/library/multiprocessing.html >> > I always thought, that the multiprocessing module does NOT use shared > memory (at least not under windows) It uses mmap() under windows. (I'm not an expert, but this is what I was said by others.) I did not know that multiprocessing can be used over TCP/IP. :) Probably I'll use zmq instead, because it has other nice features (auto reconnect, publisher/subscriber, multicast etc.) > > I would be very interested in a cross platform shared mem solution for > python. > Could you please point me to the right section. > > As far as I know, POSIX compatible shared memory does not exist on Windows. I remember a thread about this on the PostgreSQL mailing list - the Windows version of PostgreSQL somehow emulates shared memory too. I wanted to use shared memory because response times are much faster than TCP/IP. From d at davea.name Thu Sep 6 06:07:38 2012 From: d at davea.name (Dave Angel) Date: Thu, 06 Sep 2012 06:07:38 -0400 Subject: Comparing strings from the back? In-Reply-To: <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <504875EA.8000603@davea.name> On 09/06/2012 04:33 AM, Steven D'Aprano wrote: > > > I may have been overly-conservative earlier when I said that on > average string equality has to compare half the characters. I thought > I had remembered that from a computer science textbook, but I can't > find that reference now, so possibly I was thinking of something else. > (String searching perhaps?). In any case, the *worst* case for string > equality testing is certainly O(N) (every character must be looked > at), and the *best* case is O(1) obviously (the first character fails > to match). But I'm not so sure about the average case. Further thought > is required. For random strings (as defined below), the average compare time is effectively unrelated to the size of the string, once the size passes some point. Define random string as being a selection from a set of characters, with replacement. So if we pick some set of characters, say 10 (or 256, it doesn't really matter), the number of possible strings is 10**N. The likelihood of not finding a mismatch within k characters is (1/10)**k The likelihood of actually reaching the end of the random string is (1/10)**N. (which is the reciprocal of the number of strings, naturally) If we wanted an average number of comparisons, we'd have to calculate a series, where each term is a probability times a value for k. sum((k * 9*10**-k) for k in range(1, 10)) Those terms very rapidly approach 0, so it's safe to stop after a few. Looking at the first 9 items, I see a value of 1.1111111 This may not be quite right, but the value is certainly well under 2 for a population of 10 characters, chosen randomly. And notice that N doesn't really come into it. -- DaveA From gandalf at shopzeus.com Thu Sep 6 06:13:25 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 06 Sep 2012 12:13:25 +0200 Subject: Looking for an IPC solution In-Reply-To: <20120901145535.53fd8d7d2e71b880d107266b@gmx.net> References: <20120901145535.53fd8d7d2e71b880d107266b@gmx.net> Message-ID: <50487745.5050503@shopzeus.com> > Probably the fastest I/RPC implementation for Python should be > OmniOrbpy: > > http://omniorb.sourceforge.net/ > > It's cross-platform, language-independent and standard-(Corba-) > compliant. I don't want to use IDL though. Clients will be written in Python, and it would be a waste of time to write IDL files. > >> I have seen a stand alone cross platform IPC server before that could >> serve "channels", and send/receive messages using these channels. But >> I don't remember its name and now I cannot find it. Can somebody >> please help? > If it's just for "messaging", Spread should be interesting: > > http://www.spread.org/ > > Also cross-platform & language-independent. Looks promising. This is what I have found about it: http://stackoverflow.com/questions/35490/spread-vs-mpi-vs-zeromq > So, it really depends on whether you are trying to build a parallel > system or distributed system. They are related to each other, but the > implied connotations/goals are different. Parallel programming deals > with increasing computational power by using multiple computers > simultaneously. Distributed programming deals with reliable > (consistent, fault-tolerant and highly available) group of computers. I don't know the full theory behind distributed programming or parallel programming. ZMQ seems easier to use. From shaun.wiseman91 at gmail.com Thu Sep 6 06:45:19 2012 From: shaun.wiseman91 at gmail.com (shaun) Date: Thu, 6 Sep 2012 03:45:19 -0700 (PDT) Subject: Need help fixing this error please:NameError: global name is not defined Message-ID: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> Hi all, I have a class which I create an object from in a different script but when its run I get an error at the last part of this method: ////CODE/////////////////////////////// def databasebatchcall(self,tid, bid): con=cx_Oracle.connect('user/user123 at odb4.dcc.company/ODB4TEST.COMPANY.COM') cur = con.cursor() cur.execute("SELECT * FROM name) results = cur.fetchall() ////////////////////////////////////////// >From this last line I get the following error which I don't understand I'm very new to python and have no idea about this any help would be appreciated ////////////////////////////////////////////// File "/home/dcroke/mdcFDACStringCall.py", line 21, in fetchbatchdata results = cur.fetchall() NameError: global name 'cur' is not defined ////////////////////////////////////////////// Thanks all, Shaun From oscar.j.benjamin at gmail.com Thu Sep 6 07:04:19 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 06 Sep 2012 12:04:19 +0100 Subject: Comparing strings from the back? In-Reply-To: <504875EA.8000603@davea.name> References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504875EA.8000603@davea.name> Message-ID: On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: > For random strings (as defined below), the average compare time is > effectively unrelated to the size of the string, once the size passes > some point. > Define random string as being a selection from a set of characters, with > replacement. So if we pick some set of characters, say 10 (or 256, it > doesn't really matter), the number of possible strings is 10**N. > The likelihood of not finding a mismatch within k characters is > (1/10)**k The likelihood of actually reaching the end of the random > string is (1/10)**N. (which is the reciprocal of the number of strings, > naturally) > If we wanted an average number of comparisons, we'd have to calculate a > series, where each term is a probability times a value for k. > sum((k * 9*10**-k) for k in range(1, 10)) > Those terms very rapidly approach 0, so it's safe to stop after a few. > Looking at the first 9 items, I see a value of 1.1111111 > This may not be quite right, but the value is certainly well under 2 for > a population of 10 characters, chosen randomly. And notice that N > doesn't really come into it. It's exactly right. You can obtain this result analytically from Johannes' formula above. Just replace 256 with 10 to get that the expected number of comparisons is (10/9)*(1 - 10**(-N)) The last term shows the dependence on N and is tiny even for N=9. Oscar From rosuav at gmail.com Thu Sep 6 07:05:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Sep 2012 21:05:29 +1000 Subject: Need help fixing this error please:NameError: global name is not defined In-Reply-To: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> References: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> Message-ID: On Thu, Sep 6, 2012 at 8:45 PM, shaun wrote: > ////CODE/////////////////////////////// > > def databasebatchcall(self,tid, bid): > con=cx_Oracle.connect('user/user123 at odb4.dcc.company/ODB4TEST.COMPANY.COM') > cur = con.cursor() > cur.execute("SELECT * FROM name) > results = cur.fetchall() > ////////////////////////////////////////// > > From this last line I get the following error which I don't understand I'm very new to python and have no idea about this any help would be appreciated > > > ////////////////////////////////////////////// > > File "/home/dcroke/mdcFDACStringCall.py", line 21, in fetchbatchdata > results = cur.fetchall() > NameError: global name 'cur' is not defined > > ////////////////////////////////////////////// > Not quite, actually. The traceback names a different function. Look in your code for a 'fetchbatchdata' function; it looks like you need to pass the cursor from one function to the other. To further assist, we'd need to see more of the code; but for a guess, I would say that you either need to make cur a function argument, or else (since this is class) an instance member, which you'd reference as 'self.cur'. ChrisA From d at davea.name Thu Sep 6 07:05:43 2012 From: d at davea.name (Dave Angel) Date: Thu, 06 Sep 2012 07:05:43 -0400 Subject: Need help fixing this error please:NameError: global name is not defined In-Reply-To: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> References: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> Message-ID: <50488387.2070505@davea.name> On 09/06/2012 06:45 AM, shaun wrote: > Hi all, > > I have a class which I create an object from in a different script but when its run I get an error at the last part of this method: > > ////CODE/////////////////////////////// > > def databasebatchcall(self,tid, bid): > con=cx_Oracle.connect('user/user123 at odb4.dcc.company/ODB4TEST.COMPANY.COM') > cur = con.cursor() > cur.execute("SELECT * FROM name) > results = cur.fetchall() > ////////////////////////////////////////// > > >From this last line I get the following error which I don't understand I'm very new to python and have no idea about this any help would be appreciated > > > ////////////////////////////////////////////// > > File "/home/dcroke/mdcFDACStringCall.py", line 21, in fetchbatchdata > results = cur.fetchall() > NameError: global name 'cur' is not defined > > ////////////////////////////////////////////// > > > Thanks all, > Shaun is that really the function in line 21, or is it just a similar line? Notice the error gives you filename & line number. I have no way to check either of those, but you can and should. What really stands out is the function name the error occurs in: fetchbatchdata() You don't show us the source to that function. -- DaveA From __peter__ at web.de Thu Sep 6 07:07:28 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 06 Sep 2012 13:07:28 +0200 Subject: Need help fixing this error please:NameError: global name is not defined References: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> Message-ID: shaun wrote: > I have a class which I create an object from in a different script but when its run I get an error at the last part of this method: > def databasebatchcall(self,tid, bid): > con=cx_Oracle.connect( > 'user/user123 at odb4.dcc.company/ODB4TEST.COMPANY.COM') > cur = con.cursor() > cur.execute("SELECT * FROM name) > results = cur.fetchall() This is not your real code. The above would give you a SyntaxError in the line > cur.execute("SELECT * FROM name) > From this last line I get the following error which I don't understand I'm very new to python and have no idea about this any help would be appreciated > File "/home/dcroke/mdcFDACStringCall.py", line 21, in fetchbatchdata > results = cur.fetchall() > NameError: global name 'cur' is not defined The offending line may not be indented correctly: def databasebatchcall(...): ... cur = con.cursor() ... results = cur.fetchall() This may be obscured by mixing tabs and spaces. However, without the actual code this is nothing but a guess. From vincent.vandevyvre at swing.be Thu Sep 6 07:09:10 2012 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Thu, 06 Sep 2012 13:09:10 +0200 Subject: Dynamically scheduling Cron Jobs for Python Scripts. In-Reply-To: <1c24b34d-774f-4613-b6a9-f6f19fb24acb@googlegroups.com> References: <1c24b34d-774f-4613-b6a9-f6f19fb24acb@googlegroups.com> Message-ID: <50488456.6010404@swing.be> On 06/09/12 08:21, coldfire wrote: > I have a web scrapper script which run every day at 0100 hrs using cron Job over a shell account. > Now what I am looking for is to re run the same script. > 1> The script goes online to scrape some data including a schedule time for my meeting. > I want to re run the script at that schedule time to send me a email. > How can I do that? > > Plz Help Have a look at python-crontab http://pypi.python.org/pypi?name=python-crontab&:action=display -- Vincent V.V. Oqapy . Qarte . PaQager From shaun.wiseman91 at gmail.com Thu Sep 6 07:37:04 2012 From: shaun.wiseman91 at gmail.com (shaun) Date: Thu, 6 Sep 2012 04:37:04 -0700 (PDT) Subject: Need help fixing this error please:NameError: global name is not defined In-Reply-To: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> References: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> Message-ID: <42718e31-d77b-4c8a-ae48-1dae0a780585@googlegroups.com> Sorry guys here is the full code for the class: #!/usr/bin/python # Echo client program import cx_Oracle import socket import pprint from struct import * import sys from binascii import * import time import datetime class StringCall: results=[] def databasebatchcall(self,termid, batchid): con = cx_Oracle.connect('user/user123 at odb4.dcc.company.ie/ODB4TEST.COMPANY.IE') cur = con.cursor() cur.execute("SELECT * from name) results = cur.fetchall() def fetchbatchdata(self,results): for row in results: mer = row[0].ljust(25, ' ') mercity = row[1].ljust(13, ' ') mertype = row[2] merloc = row[3] mercount = row[4] mersec = row[5] acq = row[6] btime = row[7].strftime('%d%m') bmerch = str(row[8]).rjust(12, '0') termcur = row[9] acqbank = str(row[10]).rjust(24, '0') termtype = row[11] termsoftver = row[12] merbatch = str(row[13]).rjust(3, '0') reccount = str(row[14]).rjust(9, '0') amounttotal = str(row[15]).rjust(16, '0') cashback = str(row[16]).rjust(16, '0') deposit = str(row[17]).rjust(16, '0') def createbatchstrings(self): BatchHeaderPacket = "\x01000\x0251.520%s00000%s000006060001%s%s%s%s0003 \x03" % (btime, bmerch, termcur, acqbank, termtype, termsoftver); ParameterPacket = "\x01001\x0251.5300000401%s%sIE%s%s%s00000%s%s0%s \x03" % (mer, mercity, mertype, merloc, termid, mercount, mersec, acq); TrailerPacket = "\x01003\x0251.550%s00%s%s%s%s%s00000000000\x03" % (btime, merbatch, reccount, amounttotal, cashback, deposit); cur.close() def returnbatchheader(self): return BatchHeaderPacket def returnparameterpacket(self): return ParameterPacket def returntrailerpacket(self): return TrailerPacket From shaun.wiseman91 at gmail.com Thu Sep 6 07:37:47 2012 From: shaun.wiseman91 at gmail.com (shaun) Date: Thu, 6 Sep 2012 04:37:47 -0700 (PDT) Subject: Need help fixing this error please:NameError: global name is not defined In-Reply-To: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> References: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> Message-ID: <183d7cb4-d6d5-461d-b0d9-da20de720dc4@googlegroups.com> This is the code in the script im calling: batchObject=StringCall() batchObject.databasebatchcall(termid, batchid) batchObject.fetchbatchdata() batchObject.createbatchstrings() BatchHeaderPacket =batchObject.returnbatchheader() ParameterPacket =batchObject.returnparameterpacket() TrailerPacket =batchObject.returntrailerpacket() print BatchHeaderPacket print ParameterPacket print TrailerPacket From python at mrabarnett.plus.com Thu Sep 6 07:38:52 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 06 Sep 2012 12:38:52 +0100 Subject: Python Interview Questions In-Reply-To: References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: <50488B4C.2050907@mrabarnett.plus.com> On 06/09/2012 05:24, Kushal Kumaran wrote: > On Wed, Sep 5, 2012 at 3:11 PM, Stephen Anto wrote: >> On Wed, Sep 5, 2012 at 2:10 PM, Kushal Kumaran >> wrote: >>> >>> On Wed, Sep 5, 2012 at 12:20 PM, wrote: >>> > On Tuesday, October 30, 2007 11:44:01 PM UTC+5:30, Krypto wrote: >>> >> Hi, >>> >> >>> >> I have used Python for a couple of projects last year and I found it >>> >> extremely useful. I could write two middle size projects in 2-3 months >>> >> (part time). Right now I am a bit rusty and trying to catch up again >>> >> with Python. >>> >> >>> >> I am now appearing for Job Interviews these days and I am wondering if >>> >> anybody of you appeared for a Python Interview. Can you please share >>> >> the questions you were asked. That will be great help to me. >>> >> >>> > >>> > Finally I have decided to put best interview question and answers. >>> > >>> > Please visit http://www.f2finterview.com/web/CorePython/ for core python >>> > and http://www.f2finterview.com/web/PythonAdvanced/ for advanced python >>> > >>> >>> As I see from a quick glance, several of your answers seem to be >>> copied from the python faq at http://docs.python.org/faq/. The >>> copyright notice for the python.org website seems to be at >>> http://docs.python.org/copyright.html. Do you have the Python >>> Software Foundation's permission to copy large chunks of the >>> python.org website and claim it as your own content? >>> >> >> Thank you for your information, I really sorry for this, if possible could >> you note which are the questions taken from faq, we will remove it as early >> as possible. >> > > Since your website's Terms of Use state that you own the content, it > is your problem to make sure whatever's there is there legally. > > Here's one example, though, to get you started: See the entry "Why > can?t I use an assignment in an expression?" at > http://docs.python.org/faq/design.html, and compare with the content > under the identical heading on page 3 of the CorePython section. > The section below it comes from here: http://svn.effbot.org/public/stuff/sandbox/pyfaq/is-there-a-tool-to-help-find-bugs-or-perform-static-analysis.xml From rosuav at gmail.com Thu Sep 6 07:53:57 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Sep 2012 21:53:57 +1000 Subject: Need help fixing this error please:NameError: global name is not defined In-Reply-To: <42718e31-d77b-4c8a-ae48-1dae0a780585@googlegroups.com> References: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> <42718e31-d77b-4c8a-ae48-1dae0a780585@googlegroups.com> Message-ID: On Thu, Sep 6, 2012 at 9:37 PM, shaun wrote: > class StringCall: > results=[] > def databasebatchcall(self,termid, batchid): > con = cx_Oracle.connect('user/user123 at odb4.dcc.company.ie/ODB4TEST.COMPANY.IE') > cur = con.cursor() > cur.execute("SELECT * from name) > results = cur.fetchall() This actually never sets 'results', which is a class variable. You should probably be using 'self.results' here; Python does not include class/instance members in scope automatically. Try using 'self.' for everything that you need to be maintained as state, and see if that solves your problem. But this looks to me like a case where you may not really even need a class at all. ChrisA From shaun.wiseman91 at gmail.com Thu Sep 6 08:00:32 2012 From: shaun.wiseman91 at gmail.com (shaun) Date: Thu, 6 Sep 2012 05:00:32 -0700 (PDT) Subject: Setting up a class Message-ID: Hi all, So I'm trying to to OO a script which is currently in place on work. It connects to the database and makes multiple strings and sends them to a server. But I'm having major problems since I am new to python I keep trying to do it as I would do it in Java but classes seem to be very different. I was wondering could someone answer a few questions? 1) Is there anything I should know about passing in variables from another script to the class? 2) When I'm passing variables back to the script they seem to come back blank as if I haven't done it correctly (I declare the empty variable at the top of the class, I use the information I get from the database to fill it and I send it back) Is there anything I'm not doing right with this. 3)When I want to use a method from a class in another class method it never seems to work for me, I have a feeling this is to do with "self" but im not too sure?? Any help would be appreciated. Thanks, Shaun From shaun.wiseman91 at gmail.com Thu Sep 6 08:07:58 2012 From: shaun.wiseman91 at gmail.com (shaun) Date: Thu, 6 Sep 2012 05:07:58 -0700 (PDT) Subject: Need help fixing this error please:NameError: global name is not defined In-Reply-To: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> References: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> Message-ID: <1c670c04-4367-4518-aa50-cf9adad8f6d2@googlegroups.com> Hi Chris, I'm changing it into multiple classes because the script is going to get much larger its more for maintainability reasons rather than functionality reasons. Thanks so much man it was the "self" fix you stated above. I woe you a pint of Guinness :D Thanks again, Shaun From python at mrabarnett.plus.com Thu Sep 6 08:08:35 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 06 Sep 2012 13:08:35 +0100 Subject: Need help fixing this error please:NameError: global name is not defined In-Reply-To: <42718e31-d77b-4c8a-ae48-1dae0a780585@googlegroups.com> References: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> <42718e31-d77b-4c8a-ae48-1dae0a780585@googlegroups.com> Message-ID: <50489243.2080501@mrabarnett.plus.com> On 06/09/2012 12:37, shaun wrote: > Sorry guys here is the full code for the class: > > #!/usr/bin/python > # Echo client program > import cx_Oracle > import socket > import pprint > from struct import * > import sys > from binascii import * Don't use "from something import *". It'll import a whole load of names. Import only those names you wish to use. > import time > import datetime > > > class StringCall: > results=[] > def databasebatchcall(self,termid, batchid): > con = cx_Oracle.connect('user/user123 at odb4.dcc.company.ie/ODB4TEST.COMPANY.IE') > cur = con.cursor() > cur.execute("SELECT * from name) That line has an unterminated string literal (missing quote). That means that this file won't compile. > results = cur.fetchall() As you're binding to "results" in the method, Python will assume that that name is local to the method. The results will be discarded as soon as the method returns, which it does right after. > > > def fetchbatchdata(self,results): > > for row in results: > mer = row[0].ljust(25, ' ') > mercity = row[1].ljust(13, ' ') > mertype = row[2] > merloc = row[3] > mercount = row[4] > mersec = row[5] > acq = row[6] > btime = row[7].strftime('%d%m') > bmerch = str(row[8]).rjust(12, '0') > termcur = row[9] > acqbank = str(row[10]).rjust(24, '0') > termtype = row[11] > termsoftver = row[12] > merbatch = str(row[13]).rjust(3, '0') > reccount = str(row[14]).rjust(9, '0') > amounttotal = str(row[15]).rjust(16, '0') > cashback = str(row[16]).rjust(16, '0') > deposit = str(row[17]).rjust(16, '0') All of the names "mer", "mercity", etc, will be local to this method. > > def createbatchstrings(self): > BatchHeaderPacket = "\x01000\x0251.520%s00000%s000006060001%s%s%s%s0003 \x03" % (btime, bmerch, termcur, acqbank, termtype, termsoftver); > ParameterPacket = "\x01001\x0251.5300000401%s%sIE%s%s%s00000%s%s0%s \x03" % (mer, mercity, mertype, merloc, termid, mercount, mersec, acq); > TrailerPacket = "\x01003\x0251.550%s00%s%s%s%s%s00000000000\x03" % (btime, merbatch, reccount, amounttotal, cashback, deposit); > cur.close() Where do the names "btime", "bmerch", etc, come from? They are certainly not the same as those in "fetchbatchdata" because this is a separate method. > > def returnbatchheader(self): > return BatchHeaderPacket > def returnparameterpacket(self): > return ParameterPacket > def returntrailerpacket(self): > return TrailerPacket > From roy at panix.com Thu Sep 6 08:13:07 2012 From: roy at panix.com (Roy Smith) Date: Thu, 06 Sep 2012 08:13:07 -0400 Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <50485fca$0$29977$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > In any case, the *worst* case for string equality > testing is certainly O(N) (every character must be looked at), and the > *best* case is O(1) obviously (the first character fails to match). The best case is O(0), if either string is empty (ducking and running). From roy at panix.com Thu Sep 6 08:16:36 2012 From: roy at panix.com (Roy Smith) Date: Thu, 06 Sep 2012 08:16:36 -0400 Subject: is implemented with id ? References: <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com> <50484643$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <50484643$0$29977$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Wed, 05 Sep 2012 14:27:44 -0400, Terry Reedy wrote: > > > On 9/5/2012 8:48 AM, Ramchandra Apte wrote: > > > > > and "a==True" should be automatically changed into memory comparison. > > > > I have no idea what that means. > > I interpret this as meaning that "a == True" should be special-cased by > the interpreter as "a is True" instead of calling a.__eq__. That would break classes which provide their own __eq__() method. From joel.goldstick at gmail.com Thu Sep 6 08:16:58 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 6 Sep 2012 08:16:58 -0400 Subject: Setting up a class In-Reply-To: References: Message-ID: On Thu, Sep 6, 2012 at 8:00 AM, shaun wrote: > Hi all, > > So I'm trying to to OO a script which is currently in place on work. It connects to the database and makes multiple strings and sends them to a server. > > But I'm having major problems since I am new to python I keep trying to do it as I would do it in Java but classes seem to be very different. I was wondering could someone answer a few questions? > > 1) Is there anything I should know about passing in variables from another script to the class? > > 2) When I'm passing variables back to the script they seem to come back blank as if I haven't done it correctly (I declare the empty variable at the top of the class, I use the information I get from the database to fill it and I send it back) Is there anything I'm not doing right with this. > > 3)When I want to use a method from a class in another class method it never seems to work for me, I have a feeling this is to do with "self" but im not too sure?? > > Any help would be appreciated. > Thanks, > Shaun > -- > http://mail.python.org/mailman/listinfo/python-list You should take the smallest snippit of your code that shows your problem and copy it here along with traceback where it fails. Java is not python and vice versa, so some of your ideas will be confused for a while -- Joel Goldstick From python at mrabarnett.plus.com Thu Sep 6 08:20:24 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 06 Sep 2012 13:20:24 +0100 Subject: Setting up a class In-Reply-To: References: Message-ID: <50489508.2050001@mrabarnett.plus.com> On 06/09/2012 13:00, shaun wrote: > Hi all, > > So I'm trying to to OO a script which is currently in place on work. It connects to the database and makes multiple strings and sends them to a server. > > But I'm having major problems since I am new to python I keep trying to do it as I would do it in Java but classes seem to be very different. I was wondering could someone answer a few questions? > > 1) Is there anything I should know about passing in variables from another script to the class? > > 2) When I'm passing variables back to the script they seem to come back blank as if I haven't done it correctly (I declare the empty variable at the top of the class, I use the information I get from the database to fill it and I send it back) Is there anything I'm not doing right with this. > > 3)When I want to use a method from a class in another class method it never seems to work for me, I have a feeling this is to do with "self" but im not too sure?? > > Any help would be appreciated. > Thanks, > Shaun > You should have a look as a Python tutorial to help you get used to the language. It shouldn't take you long, provided that you remember that Python isn't Java and don't try to write Java in Python. :-) Here's one you could look at: Python for Java programmers http://python4java.necaiseweb.org/Main/TableOfContents From rosuav at gmail.com Thu Sep 6 08:29:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Sep 2012 22:29:09 +1000 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: n Thu, Sep 6, 2012 at 10:13 PM, Roy Smith wrote: > In article <50485fca$0$29977$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> In any case, the *worst* case for string equality >> testing is certainly O(N) (every character must be looked at), and the >> *best* case is O(1) obviously (the first character fails to match). > > The best case is O(0), if either string is empty (ducking and running). No, O(0) would be when the application decides not to compare at all. ChrisA (also ducking) From rosuav at gmail.com Thu Sep 6 09:16:26 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Sep 2012 23:16:26 +1000 Subject: Need help fixing this error please:NameError: global name is not defined In-Reply-To: <1c670c04-4367-4518-aa50-cf9adad8f6d2@googlegroups.com> References: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> <1c670c04-4367-4518-aa50-cf9adad8f6d2@googlegroups.com> Message-ID: On Thu, Sep 6, 2012 at 10:07 PM, shaun wrote: > Hi Chris, > > I'm changing it into multiple classes because the script is going to get much larger its more for maintainability reasons rather than functionality reasons. Doesn't necessarily have to be multiple classes. Python gives you the flexibility of dividing things in whatever way makes sense to your project. Maybe a class is right - I can't say without seeing all your code and knowing all your intentions - but if it's not, you don't have to feel constrained by it. This isn't Java where all code goes into a class! > Thanks so much man it was the "self" fix you stated above. I woe you a pint of Guinness :D You're welcome! I'm a non-drinker, though, so you can drink it and think of me. :) ChrisA From maniandram01 at gmail.com Thu Sep 6 09:30:13 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 6 Sep 2012 06:30:13 -0700 (PDT) Subject: is implemented with id ? In-Reply-To: References: <504717ee$0$29977$c3e8da3$5496439d@news.astraweb.com> <50484643$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9efd7a32-5b9e-45fe-92c0-154359511acb@googlegroups.com> On Thursday, 6 September 2012 17:46:38 UTC+5:30, Roy Smith wrote: > In article <50484643$0$29977$c3e8da3$5496439d at news.astraweb.com>, > > Steven D'Aprano wrote: > > > > > On Wed, 05 Sep 2012 14:27:44 -0400, Terry Reedy wrote: > > > > > > > On 9/5/2012 8:48 AM, Ramchandra Apte wrote: > > > > > > > > > and "a==True" should be automatically changed into memory comparison. > > > > > > > > I have no idea what that means. > > > > > > I interpret this as meaning that "a == True" should be special-cased by > > > the interpreter as "a is True" instead of calling a.__eq__. > > > > That would break classes which provide their own __eq__() method. There is a way of doing this: make True.__req__ = lambda other: self is other From maniandram01 at gmail.com Thu Sep 6 09:32:39 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 6 Sep 2012 06:32:39 -0700 (PDT) Subject: ===== Soft Skills Training In Chennai ====== In-Reply-To: <4131defd-fb7b-407f-b45d-cbf0ab7fa23f@googlegroups.com> References: <4131defd-fb7b-407f-b45d-cbf0ab7fa23f@googlegroups.com> Message-ID: On Thursday, 6 September 2012 11:26:21 UTC+5:30, mike pittenson wrote: > Ayus Technologies offers Dot net training in chennai,java/j2ee training in chennai,SEO training in chennai,web designing training in chennai,soft skills training in chennai,Software Testing training in chennai. > > > > ================================================ > > > > http://www.ayustechnologies.com/ > > > > ================================================ > > > > More Information contact Mr, Jana 9080140107 this is spam - this is not related to python From maniandram01 at gmail.com Thu Sep 6 09:34:36 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 6 Sep 2012 06:34:36 -0700 (PDT) Subject: Language workbench written in python3 In-Reply-To: <1ed391c3-8fcf-4a3f-8ad7-0a2cf913b6cc@googlegroups.com> References: <1ed391c3-8fcf-4a3f-8ad7-0a2cf913b6cc@googlegroups.com> Message-ID: <634287e3-12b3-4b47-8ad2-38c1bc76ff1a@googlegroups.com> On Thursday, 6 September 2012 02:34:17 UTC+5:30, Nestor Arocha wrote: > I'm developing a language workbench written in Python. The idea is to create an environment where grammars and translators can interact easily. > > > > https://github.com/nesaro/pydsl > > > > any comments, feedback or ideas? :) Translator means what precisely? From dfnsonfsduifb at gmx.de Thu Sep 6 09:37:23 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 06 Sep 2012 15:37:23 +0200 Subject: Comparing strings from the back? In-Reply-To: <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05.09.2012 18:24, Steven D'Aprano wrote: > On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote: > [...] >>> You are making unjustified assumptions about the distribution of >>> letters in the words. This might be a list of long chemical compounds >>> where the words typically differ only in their suffix. It might be a >>> list of people with titles: >> >> Actually, I'm not. I'm stating exactly what assumptions I'm making to >> get my calculation. I'm comparing *random* character strings or >> bitstrings. > > Excuse me, you are not. You are comparing English words which are highly > non-random. Not in my original post. If you read it again, you will clearly see that I was talking about purely random strings. And since you like to nitpick, I'll clarify further: I'm talking about bitstrings in which every bit of every character has the same probability of occurence, 50%. You then replied by mentioning probability distributions of characters in different languages/encodings, to which I tried giving a example as it might (and does) occur in the real world, like sorting a dictionary. But the original point is still valid: Sorting of randomized bitstrings is definitely not O(N), you got that wrong. >> You, on the other hand, are making vague assumptions which you do not >> care for formalize and yet you claim that "the number of comparisons is >> equally likely to be 1, 2, 3, ..., N. The average then is". Without any >> explanation for this. At all. > > I will accept that my explanation was not good enough, but I strongly > disagree that I gave no explanation at all. What possible explanation could there be that comparison of purely random bitstrings yields an equal amount of comparisons for its length? >>> Herr Professor Frederick Schmidt >>> Herr Professor Frederick Wagner >>> ... >> >> Is your assumtion that we're comparing words that have the common prefix >> "Herr Professor Frederick "? > > No, I am pointing out that *your* assumption that most string comparisons > will halt close to the beginning of the string is an invalid assumption. > Your assumption only holds for some non-random strings. Definitely not. It *especially* holds true for random strings. For random strings with an alphabet of size n, the probability that the first character needs to be compared is n^0, i.e. 1. The probability that the second character needs to be compared is n^(-1). For the xth character, it is n^(-x). This is due to the lazy abort in comparison and it results in the average number of comparisons being extremely short no matter the bitlength n, or O(log n). >> it's counting the number of character comparisons. > > Correct. But only out of an extremely limited subset of all possible > string comparisons, namely those very few that happen when sorting lists > of English words using a very specific algorithm, namely timsort. Yes, but this was to look at a real-world example (in which way more comparisons are needed than in the random case). You first were talking about randomized bitstrings (and so was I), then you brought up character sets and languages (which, for the original problem, are entirely irrelevant). > Whatever figure you have calculated by taking this non-random selection, > it is irrelevant to the question of the average performance of string > equality given random strings. Correct. I gave the estimate for random strings in my very first post. > For the sake of simple calculations, let's pretend that there are only > 1000 five-letter strings possible. We want to know how many character- > comparisons are done on average when testing two random five-letter > strings for equality. To calculate this average, you must compare every > string to every other string, *including* itself. > > This gives 1000*1000 = one million equality tests to be performed. For > each equality test, we count the number of character comparisons > performed, sum all those counts, and divide by 1e6. That is the average > number of char comparisons for random strings of five letters. Easy enough. Since you didn't look at my original equation, here are some numbers and the program attached: 64 combinations for length 6 Char comparisons: 8064 Comparison cnt : 4096 Avg comparison : 1.97 128 combinations for length 7 Char comparisons: 32512 Comparison cnt : 16384 Avg comparison : 1.98 256 combinations for length 8 Char comparisons: 130560 Comparison cnt : 65536 Avg comparison : 1.99 512 combinations for length 9 Char comparisons: 523264 Comparison cnt : 262144 Avg comparison : 2.00 1024 combinations for length 10 Char comparisons: 2095104 Comparison cnt : 1048576 Avg comparison : 2.00 2048 combinations for length 11 Char comparisons: 8384512 Comparison cnt : 4194304 Avg comparison : 2.00 4096 combinations for length 12 Char comparisons: 33546240 Comparison cnt : 16777216 Avg comparison : 2.00 Hopefully now you'll see that your assumption O(n) is dead wrong. > But that's not what you do. First you eliminate 900 out of the 1000 > possible strings by only sampling English words -- strings like "xxoij" > cannot possibly be selected. So you are left with the highly non-random > subset of 10000 equality tests. This is *exactly* what my original calculation did. Enumerate all possibilites and divide by the total number. Regards, Johannes #!/usr/bin/python3 import itertools import random alphabet = [ c for c in "01" ] def cmpstr(s1, s2): c = 0 for i in range(len(s1)): c += 1 if s1[i] != s2[i]: break return c for strlength in range(1, 16): combinations = list(itertools.product(*([ alphabet ] * strlength))) assert(len(combinations) == len(alphabet) ** strlength) print("%d combinations for length %d" % (len(combinations), strlength)) compcnt = 0 comparisons = 0 for c1 in combinations: for c2 in combinations: comparisons += cmpstr(c1, c2) compcnt += 1 print("Char comparisons: %d" % (comparisons)) print("Comparison cnt : %d" % (compcnt)) print("Avg comparison : %.2f" % (comparisons / compcnt)) -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From d at davea.name Thu Sep 6 09:41:33 2012 From: d at davea.name (Dave Angel) Date: Thu, 06 Sep 2012 09:41:33 -0400 Subject: Setting up a class In-Reply-To: References: Message-ID: <5048A80D.70506@davea.name> On 09/06/2012 08:00 AM, shaun wrote: > Hi all, > > So I'm trying to to OO a script which is currently in place on work. It connects to the database and makes multiple strings and sends them to a server. > > But I'm having major problems since I am new to python I keep trying to do it as I would do it in Java but classes seem to be very different. I was wondering could someone answer a few questions? > > 1) Is there anything I should know about passing in variables from another script to the class? Things don't get passed to a class. They get passed to an initializer (and to the constructor, but you've probably never used one of those), or to methods of the class. There's only one script in a given program, the other source files are modules. If code in one module wants to use code or data from another module, there are two general ways to do it. One is to use the "from module1 import global1, func2" syntax. In this case, they effectively become globals of the current file. And the other is to use module1.func2() syntax, where you qualify where to find the function. As others have pointed out to you, "from xxx import *" is very risky, as you make everything global, and the reader can no longer tell where a particular symbol comes from. Further, any name collisions are silently dealt with, on the assumption that you REALLY know what you're doing. > > 2) When I'm passing variables back to the script they seem to come back blank as if I haven't done it correctly (I declare the empty variable at the top of the class, I use the information I get from the database to fill it and I send it back) Is there anything I'm not doing right with this. You don't pass variables back to a script. If you mean return a value from a function, then say so. Note that a return statement takes a single object, but that object could very well be a tuple. So it's perfectly reasonable for a function to return as: return first, second And the caller might have done something like: a, b = myfunc() first will go into a,and second will go into b. This subtlety is because the expression first,second is a standard way to specify a tuple of size 2. And tuple unpacking can be done similarly with his, hers = expression. No restriction with size of 2, but you do want the same number of items in both places. There is no need to declare any variable, anywhere. If it needs an initial value, then assign it. Further, things 'at the top of the class' are class attributes, not just variables. How can you ask if there's anything you're not doing right when you post no code with your vague question? > 3)When I want to use a method from a class in another class method it never seems to work for me, I have a feeling this is to do with "self" but im not too sure?? If one class method needs to call another method of the same class, you'll usually want to use the self object: class .... def method1(self): arg1 = 42 self.method2(arg1) def method2(self, value); ...dosomething interesting... Naturally, when it's a method of some other class, or when you need a different instance of the same class, then you'd better have an instance to use with it. someinstance.method2(arg1) -- DaveA From cjw at ncf.ca Thu Sep 6 09:41:33 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Thu, 06 Sep 2012 09:41:33 -0400 Subject: Setting up a class In-Reply-To: References: Message-ID: On 06/09/2012 8:20 AM, MRAB wrote: > On 06/09/2012 13:00, shaun wrote: >> Hi all, >> >> So I'm trying to to OO a script which is currently in place on work. >> It connects to the database and makes multiple strings and sends them >> to a server. >> >> But I'm having major problems since I am new to python I keep trying >> to do it as I would do it in Java but classes seem to be very >> different. I was wondering could someone answer a few questions? >> >> 1) Is there anything I should know about passing in variables from >> another script to the class? >> >> 2) When I'm passing variables back to the script they seem to come >> back blank as if I haven't done it correctly (I declare the empty >> variable at the top of the class, I use the information I get from the >> database to fill it and I send it back) Is there anything I'm not >> doing right with this. >> >> 3)When I want to use a method from a class in another class method it >> never seems to work for me, I have a feeling this is to do with "self" >> but im not too sure?? >> >> Any help would be appreciated. >> Thanks, >> Shaun >> > You should have a look as a Python tutorial to help you get used to the > language. It shouldn't take you long, provided that you remember that > Python isn't Java and don't try to write Java in Python. :-) > > Here's one you could look at: > > Python for Java programmers > http://python4java.necaiseweb.org/Main/TableOfContents > The link given seems dated and incomplete - see "operator overloading". Sorry I can't assist the OP. Colin W. From foo at email.invalid Thu Sep 6 09:43:22 2012 From: foo at email.invalid (Alex) Date: Thu, 6 Sep 2012 13:43:22 +0000 (UTC) Subject: Is there a way to configure IDLE to use spaces instead of tabs for indenting? References: Message-ID: Ramchandra Apte wrote: > On Saturday, 25 August 2012 04:03:52 UTC+5:30, Alex wrote: > > I'm new to Python and have been using IDLE 3.2.3 to experiment with > > > > code as I learn. Despite being configured to use a 4 space > > indentation > > > > width, sometimes IDLE's "smart" indentation insists upon using > > width-8 > > > > tabs. > > > > > > > > From what I've been able to find on Google, this is due to a > > > > shortcoming in Tk. While it's not that big a deal in the grand > > scheme > > > > of things, I think it looks like poop, and I'd like to change IDLE > > to > > > > use 4-space indentation instead of tabs for all indentation levels. > > > > > > > > Is there any way for me to achieve what I want in IDLE, or do I > > have to > > > > start up my full-blown IDE if I want consistent 4-space indentation? > > > > > > > > Alex > > I think an IDE is better than IDLE. Try NINJA IDE. > http://ninja-ide.org Agreed. I like PyDev in Eclipse, but sometimes I just want to try out something quick in the interpreter, to ensure I understand it or do a quick experiment. Since indentation is syntactically significant in Python, I think fixing the interpreter to produce good, readable, cut-and-pasteable, and Pythonic code is more important than a cosmetic feature, but less important than true bugs. From dfnsonfsduifb at gmx.de Thu Sep 6 09:43:25 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 06 Sep 2012 15:43:25 +0200 Subject: Comparing strings from the back? In-Reply-To: <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06.09.2012 10:33, Steven D'Aprano wrote: > But you know, it really doesn't make a difference. Equality testing will > *still* be O(N) since the asymptomatic behaviour for sufficiently large > string comparisons will be bounded by O(N). Multiplicative constants > ("half the string" versus "0.001 of the string") do not matter. Wrong, at least for randomized strings (i.e. every character with the same probability). O(N) is worst-case, O(log N) is correct for randomized strings. Then again, since you were nitpicking about Landau notation earlier this thread, every function bound by O(log N) is also bound by O(N), since, as you correctly stated, it's only a upper bound. We should be talking about the asymptotic sharp bound, i.e. capital Theta. > I may have been overly-conservative earlier when I said that on average > string equality has to compare half the characters. I thought I had > remembered that from a computer science textbook, but I can't find that > reference now, so possibly I was thinking of something else. (String > searching perhaps?). In any case, the *worst* case for string equality > testing is certainly O(N) (every character must be looked at), and the > *best* case is O(1) obviously (the first character fails to match). But > I'm not so sure about the average case. Further thought is required. Yes, worst-case is O(N), best case O(1). Average is O(n log n). Best regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From d at davea.name Thu Sep 6 09:46:10 2012 From: d at davea.name (Dave Angel) Date: Thu, 06 Sep 2012 09:46:10 -0400 Subject: Language workbench written in python3 In-Reply-To: <634287e3-12b3-4b47-8ad2-38c1bc76ff1a@googlegroups.com> References: <1ed391c3-8fcf-4a3f-8ad7-0a2cf913b6cc@googlegroups.com> <634287e3-12b3-4b47-8ad2-38c1bc76ff1a@googlegroups.com> Message-ID: <5048A922.5060208@davea.name> On 09/06/2012 09:34 AM, Ramchandra Apte wrote: > Translator means what precisely? Examples of translators include compilers, assemblers, and interpreters. They also include implementations like cfront, which translates from one high-level language to another lower-level language. (high and low being relative) -- DaveA From maniandram01 at gmail.com Thu Sep 6 09:53:14 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 6 Sep 2012 06:53:14 -0700 (PDT) Subject: Language workbench written in python3 In-Reply-To: References: <1ed391c3-8fcf-4a3f-8ad7-0a2cf913b6cc@googlegroups.com> <634287e3-12b3-4b47-8ad2-38c1bc76ff1a@googlegroups.com> Message-ID: <314ae0e0-f38f-4cb9-944c-511343988f37@googlegroups.com> On Thursday, 6 September 2012 19:16:38 UTC+5:30, Dave Angel wrote: > On 09/06/2012 09:34 AM, Ramchandra Apte wrote: > > > Translator means what precisely? > > > > Examples of translators include compilers, assemblers, and > > interpreters. They also include implementations like cfront, which > > translates from one high-level language to another lower-level > > language. (high and low being relative) > > > > -- > > > > DaveA Is conversion from Python to C++ possible from this project? From maniandram01 at gmail.com Thu Sep 6 09:54:56 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 6 Sep 2012 06:54:56 -0700 (PDT) Subject: Is there a way to configure IDLE to use spaces instead of tabs for indenting? In-Reply-To: References: Message-ID: <085f6d52-9425-43c3-8d24-ee8bb66741ba@googlegroups.com> On Thursday, 6 September 2012 19:13:23 UTC+5:30, Alex wrote: > Ramchandra Apte wrote: > > > > > On Saturday, 25 August 2012 04:03:52 UTC+5:30, Alex wrote: > > > > I'm new to Python and have been using IDLE 3.2.3 to experiment with > > > > > > > > code as I learn. Despite being configured to use a 4 space > > > > indentation > > > > > > > > width, sometimes IDLE's "smart" indentation insists upon using > > > > width-8 > > > > > > > > tabs. > > > > > > > > > > > > > > > > From what I've been able to find on Google, this is due to a > > > > > > > > shortcoming in Tk. While it's not that big a deal in the grand > > > > scheme > > > > > > > > of things, I think it looks like poop, and I'd like to change IDLE > > > > to > > > > > > > > use 4-space indentation instead of tabs for all indentation levels. > > > > > > > > > > > > > > > > Is there any way for me to achieve what I want in IDLE, or do I > > > > have to > > > > > > > > start up my full-blown IDE if I want consistent 4-space indentation? > > > > > > > > > > > > > > > > Alex > > > > > > I think an IDE is better than IDLE. Try NINJA IDE. > > > http://ninja-ide.org > > > > Agreed. I like PyDev in Eclipse, but sometimes I just want to try out > > something quick in the interpreter, to ensure I understand it or do a > > quick experiment. Since indentation is syntactically significant in > > Python, I think fixing the interpreter to produce good, readable, > > cut-and-pasteable, and Pythonic code is more important than a cosmetic > > feature, but less important than true bugs. Agree. From dhoese at gmail.com Thu Sep 6 10:01:39 2012 From: dhoese at gmail.com (David Hoese) Date: Thu, 06 Sep 2012 10:01:39 -0400 Subject: python docs search for 'print' In-Reply-To: References: Message-ID: <5048ACC3.4060201@gmail.com> On 9/5/12 3:03 PM, Grant Edwards wrote: > On 2012-09-05, Dave Angel wrote: >> >On 09/05/2012 01:47 PM, Grant Edwards wrote: >> > >>> >>Making the site's "search" box use Google or somesuch is probably the >>> >>simplest solution. I'm not enough of a web guy to know how to do >>> >>that, but I do know that some sites do handle site search that way. >>> >> >> >And google has some API's to make it relatively painless. And a >> >license form to fill in and send, along with your check. > I just saw the posting mentioning the pricing. So it is a simple > simple solution, but it's probably not cheap enough... > > I followed the bug reporting instructions on the docs site and emailed docs at python.org and pointed them at this thread. I didn't catch if anyone else on this thread already did it. I guess we'll see what happens. -Dave From d at davea.name Thu Sep 6 10:23:45 2012 From: d at davea.name (Dave Angel) Date: Thu, 06 Sep 2012 10:23:45 -0400 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5048B1F1.7000301@davea.name> On 09/06/2012 09:43 AM, Johannes Bauer wrote: > > Yes, worst-case is O(N), best case O(1). Average is O(n log n). Can't see how you came up with an average of n log(n). Fourteen minutes before you made this post, you demonstrated it was less than 2 for any N. And I previously posted that for a character set of size 10, the average was 1.1111 -- DaveA From d at davea.name Thu Sep 6 10:25:35 2012 From: d at davea.name (Dave Angel) Date: Thu, 06 Sep 2012 10:25:35 -0400 Subject: Language workbench written in python3 In-Reply-To: <314ae0e0-f38f-4cb9-944c-511343988f37@googlegroups.com> References: <1ed391c3-8fcf-4a3f-8ad7-0a2cf913b6cc@googlegroups.com> <634287e3-12b3-4b47-8ad2-38c1bc76ff1a@googlegroups.com> <314ae0e0-f38f-4cb9-944c-511343988f37@googlegroups.com> Message-ID: <5048B25F.3010003@davea.name> On 09/06/2012 09:53 AM, Ramchandra Apte wrote: > On Thursday, 6 September 2012 19:16:38 UTC+5:30, Dave Angel wrote: >> On 09/06/2012 09:34 AM, Ramchandra Apte wrote: >> >>> Translator means what precisely? >> >> >> Examples of translators include compilers, assemblers, and >> >> interpreters. They also include implementations like cfront, which >> >> translates from one high-level language to another lower-level >> >> language. (high and low being relative) >> > Is conversion from Python to C++ possible from this project? I'll let the OP answer that. I don't know anything about it. -- DaveA From dfnsonfsduifb at gmx.de Thu Sep 6 10:33:04 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 06 Sep 2012 16:33:04 +0200 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06.09.2012 16:23, Dave Angel wrote: > On 09/06/2012 09:43 AM, Johannes Bauer wrote: >> >> Yes, worst-case is O(N), best case O(1). Average is O(n log n). > > Can't see how you came up with an average of n log(n). Fourteen minutes > before you made this post, you demonstrated it was less than 2 for any N. O(log n) is what I meant, sorry! Damnit. > And I previously posted that for a character set of size 10, the average > was 1.1111 For any given string n and and alphabet size l, the average is: sum(i = 0..n) (1 / (l ^ n)) So with larger word length, the total complexity constantly increases. The amount by which it increases however is shrinking exponentially with the word length. Therefore O(log n). Sorry about the n log n mistake, argh. Best regards & thanks for the correction, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From dfnsonfsduifb at gmx.de Thu Sep 6 10:34:10 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 06 Sep 2012 16:34:10 +0200 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06.09.2012 15:43, Johannes Bauer wrote: > Wrong, at least for randomized strings (i.e. every character with the > same probability). O(N) is worst-case, O(log N) is correct for > randomized strings. ^^ Here I write the right thing. Then further below... > Yes, worst-case is O(N), best case O(1). Average is O(n log n). ...I write the wrong thing. O(log n) is what I meant, as Dave correctly noticed. Best regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From rosuav at gmail.com Thu Sep 6 10:39:33 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Sep 2012 00:39:33 +1000 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 6, 2012 at 11:37 PM, Johannes Bauer wrote: > Not in my original post. If you read it again, you will clearly see that > I was talking about purely random strings. And since you like to > nitpick, I'll clarify further: I'm talking about bitstrings in which > every bit of every character has the same probability of occurence, 50%. That sort of string isn't a normal thing to be comparing, though. Here's an idea. Someone who's doing a lot of arguing in this thread should take Python, find the string comparison routine, and hack in some statistics-gathering. Then run *real code* on it. Maybe use this with one of those web frameworks and run your web site on it for an hour or two, or fire off some real scripts you really use. Then dump out the stats at the end. My guess: The bulk of string comparisons that get to actually comparing byte-for-byte will end up returning True. Most of the false comparisons will be proven earlier; if I understand correctly, Python will check for identity (easy true) and different lengths (easy false). But my guess could turn out to be flat wrong. In any case, it'll be far FAR more useful than arguing from totally random, or random word selection, or anything. Who's game? ChrisA From dfnsonfsduifb at gmx.de Thu Sep 6 10:42:54 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 06 Sep 2012 16:42:54 +0200 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06.09.2012 16:23, Dave Angel wrote: > On 09/06/2012 09:43 AM, Johannes Bauer wrote: >> >> Yes, worst-case is O(N), best case O(1). Average is O(n log n). > > Can't see how you came up with an average of n log(n). Fourteen minutes > before you made this post, you demonstrated it was less than 2 for any N. > > And I previously posted that for a character set of size 10, the average > was 1.1111 Again playing with the equations and thinking about it again. And I completely missed your point. It wasn't about n log n vs. log n. Both are wrong. This surprises me. I was somehow thinking about the limit of sum (1/n), n -> infty. But since the summands are shrinking exponentially, the limit is different. I think the limit of the average comparisons for a given wordlength n against infinity with alphabet size l is l / (l - 1) i.e. for bitstrings it's 2 and for bytestrings it's 256/255. This would mean string comparison of randomized strings is O(1). Can that really be true? It looks like it. Best regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From laddosingh at gmail.com Thu Sep 6 10:56:29 2012 From: laddosingh at gmail.com (Tigerstyle) Date: Thu, 6 Sep 2012 07:56:29 -0700 (PDT) Subject: Function for examine content of directory Message-ID: Hi guys, I'm trying to write a module containing a function to examine the contents of the current working directory and print out a count of how many files have each extension (".txt", ".doc", etc.) This is the code so far: -- import os path = "v:\\workspace\\Python2_Homework03\\src\\" dirs = os.listdir( path ) filenames = {"this.txt", "that.txt", "the_other.txt","this.doc","that.doc","this.pdf","first.txt","that.pdf"} extensions = [] for filename in filenames: f = open(filename, "w") f.write("Some text\n") f.close() name , ext = os.path.splitext(f.name) extensions.append(ext) # This would print all the files and directories for file in dirs: print(file) for ext in extensions: print("Count for %s: " %ext, extensions.count(ext)) -- When I'm trying to get the module to print how many files each extension has, it prints the count of each ext multiple times for each extension type. Like this: this.pdf the_other.txt this.doc that.txt this.txt that.pdf first.txt that.doc Count for .pdf: 2 Count for .txt: 4 Count for .doc: 2 Count for .txt: 4 Count for .txt: 4 Count for .pdf: 2 Count for .txt: 4 Count for .doc: 2 Any help is appreciated. T From ian at feete.org Thu Sep 6 11:06:35 2012 From: ian at feete.org (Ian Foote) Date: Thu, 06 Sep 2012 16:06:35 +0100 Subject: Function for examine content of directory In-Reply-To: References: Message-ID: <5048BBFB.6090209@feete.org> On 06/09/12 15:56, Tigerstyle wrote: > Hi guys, > > I'm trying to write a module containing a function to examine the contents of the current working directory and print out a count of how many files have each extension (".txt", ".doc", etc.) > > This is the code so far: > -- > import os > > path = "v:\\workspace\\Python2_Homework03\\src\\" > dirs = os.listdir( path ) > filenames = {"this.txt", "that.txt", "the_other.txt","this.doc","that.doc","this.pdf","first.txt","that.pdf"} > extensions = [] Try using a set here instead of a list: extensions = set() > for filename in filenames: > f = open(filename, "w") > f.write("Some text\n") > f.close() > name , ext = os.path.splitext(f.name) > extensions.append(ext) and use: extensions.add(ext) This should take care of duplicates for you. Regards, Ian From rrllff at yahoo.com Thu Sep 6 11:07:07 2012 From: rrllff at yahoo.com (Helpful person) Date: Thu, 6 Sep 2012 08:07:07 -0700 (PDT) Subject: Accessing dll Message-ID: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> I am a complete novice to Python. I wish to access a dll that has been written to be compatible with C and VB6. I have been told that after running Python I should enter "from ctypes import *" which allows Python to recognize the dll structure. I have placed the dll into my active directory (if that's the correct word, one on my path) for simplification. I tried: "import name.dll" but this just gave me an error telling me that there was no such module. Can someone please help? Richard From yoursurrogategod at gmail.com Thu Sep 6 11:08:38 2012 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Thu, 6 Sep 2012 11:08:38 -0400 Subject: A Python class Message-ID: Hi all, I'd like to know if there are any online Python classes offered online from reliable institutions that you would recommend. It's annual review time and my employer would like me to put something down that I could improve on. Any suggestions? I have been interested in learning more about Python, but that did not go over as well as I had hoped. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Sep 6 11:20:30 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 06 Sep 2012 16:20:30 +0100 Subject: Function for examine content of directory In-Reply-To: References: Message-ID: <5048BF3E.3020009@mrabarnett.plus.com> On 06/09/2012 15:56, Tigerstyle wrote: > Hi guys, > > I'm trying to write a module containing a function to examine the contents of the current working directory and print out a count of how many files have each extension (".txt", ".doc", etc.) > > This is the code so far: > -- > import os > > path = "v:\\workspace\\Python2_Homework03\\src\\" > dirs = os.listdir( path ) > filenames = {"this.txt", "that.txt", "the_other.txt","this.doc","that.doc","this.pdf","first.txt","that.pdf"} > extensions = [] > for filename in filenames: > f = open(filename, "w") > f.write("Some text\n") > f.close() > name , ext = os.path.splitext(f.name) > extensions.append(ext) > > # This would print all the files and directories > for file in dirs: > print(file) > > for ext in extensions: > print("Count for %s: " %ext, extensions.count(ext)) > > -- > > When I'm trying to get the module to print how many files each extension has, it prints the count of each ext multiple times for each extension type. Like this: > > this.pdf > the_other.txt > this.doc > that.txt > this.txt > that.pdf > first.txt > that.doc > Count for .pdf: 2 > Count for .txt: 4 > Count for .doc: 2 > Count for .txt: 4 > Count for .txt: 4 > Count for .pdf: 2 > Count for .txt: 4 > Count for .doc: 2 > That's because each extension can occur multiple times in the list. Try the Counter class: from collections import Counter for ext, count in Counter(extensions).items(): print("Count for %s: " % ext, count) From benjamin.kaplan at case.edu Thu Sep 6 11:26:23 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 6 Sep 2012 08:26:23 -0700 Subject: Accessing dll In-Reply-To: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> References: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> Message-ID: On Sep 6, 2012 8:15 AM, "Helpful person" wrote: > > I am a complete novice to Python. I wish to access a dll that has > been written to be compatible with C and VB6. I have been told that > after running Python I should enter "from ctypes import *" which > allows Python to recognize the dll structure. I have placed the dll > into my active directory (if that's the correct word, one on my path) > for simplification. > > I tried: "import name.dll" but this just gave me an error telling me > that there was no such module. > > Can someone please help? > > Richard > -- Two things: 1) you would never use import name.dll, just like you don't use "import math.py" you would just import name. But that only works for Python libraries, which brings us to number 2 2) importing ctypes doesn't work any magic. Your c library is still a c library, not a python library. Ctypes provides functions to let you load a dll and makes calls to it, but you can't interact with the dll like python code. Doing that takes a lot more work. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ulrich.eckhardt at dominolaser.com Thu Sep 6 11:28:09 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 06 Sep 2012 17:28:09 +0200 Subject: Accessing dll In-Reply-To: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> References: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> Message-ID: <91smh9-duc.ln1@satorlaser.homedns.org> Am 06.09.2012 17:07, schrieb Helpful person: > I am a complete novice to Python. Welcome! > I wish to access a dll that has > been written to be compatible with C and VB6. I have been told that > after running Python I should enter "from ctypes import *" which > allows Python to recognize the dll structure. I have placed the dll > into my active directory (if that's the correct word, one on my path) > for simplification. Using ctypes, you can indeed load DLLs. Take a look at http://docs.python.org, which includes the documentation for the ctypes module but also general documentation and tutorials, which should be a starting point for you. > I tried: "import name.dll" but this just gave me an error telling me > that there was no such module. Like in VB or C, things are not that easy. You will always have to write some code that informs Python about the names and parameters of the functions in that DLL. Good luck! Uli From malaclypse2 at gmail.com Thu Sep 6 11:30:27 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Thu, 6 Sep 2012 11:30:27 -0400 Subject: Accessing dll In-Reply-To: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> References: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> Message-ID: On Thu, Sep 6, 2012 at 11:07 AM, Helpful person wrote: > I am a complete novice to Python. I wish to access a dll that has > been written to be compatible with C and VB6. I have been told that > after running Python I should enter "from ctypes import *" which > allows Python to recognize the dll structure. I have placed the dll > into my active directory (if that's the correct word, one on my path) > for simplification. > > I tried: "import name.dll" but this just gave me an error telling me > that there was no such module. > > Can someone please help? You should start by reading the ctypes documentation, here: http://docs.python.org/library/ctypes.html . It has a lot of examples that ought to get you started. When you run into more specific problems, you're going to have to provide a lot more information before we can help you, including the specific documentation of the DLL you're trying to wrap, your platform, and python version. If you are not permitted to share those things, we may not be able to give you much help. Ctypes is very specific to the actual library you are accessing, and requires that you understand the requirements of the underlying DLL. -- Jerry From dfnsonfsduifb at gmx.de Thu Sep 6 11:36:39 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 06 Sep 2012 17:36:39 +0200 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06.09.2012 16:39, Chris Angelico wrote: > In any case, it'll be far FAR more useful than arguing from > totally random, or random word selection, or anything. > > Who's game? Okay, patched against Python 3.2.3: http://pastebin.com/PRRN53P6 To invoke display of the stats, compare the string "pleasedumpstats" as LHO, i.e.: "pleasedumpstats" < "" Just ran it against a big script of mine which takes the stringified IMDb text files, parses it and dumps it into a sqlite3 database. Surprisingly little string comparisons however (the sqlite module without doubt uses its own routines internally). Although the database in the end has about 2 million records, these were the stats: strCmpEq 1017 strCmpLt 2802 strCmpGt 1633 strCmpTc 16219 strCmpCc 8570 which means 5452 comparisons of which 19% were equal and the rest inequal. Average string length is about 2.97 characters and aborted was in average after 1.57 characters. Maybe someone has a test which makes heavier use of string comparison. I don't want to make up something, however, since this is (by definition) going to be artificial. Best regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From rrllff at yahoo.com Thu Sep 6 11:41:45 2012 From: rrllff at yahoo.com (Helpful person) Date: Thu, 6 Sep 2012 08:41:45 -0700 (PDT) Subject: Accessing dll References: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> Message-ID: On Sep 6, 8:30?am, Jerry Hill wrote: > You should start by reading the ctypes documentation, here:http://docs.python.org/library/ctypes.html. ?It has a lot of examples > that ought to get you started. > > When you run into more specific problems, you're going to have to > provide a lot more information before we can help you, including the > specific documentation of the DLL you're trying to wrap, your > platform, and python version. ?If you are not permitted to share those > things, we may not be able to give you much help. ?Ctypes is very > specific to the actual library you are accessing, and requires that > you understand the requirements of the underlying DLL. > > -- > Jerry Thanks Jerry, I'll read the reference you posted. Unfortunately I know almost nothing about the dll and Python is loaded in some strange framework. I'll post back after a thorough read about Ctypes. From dfnsonfsduifb at gmx.de Thu Sep 6 11:44:06 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 06 Sep 2012 17:44:06 +0200 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06.09.2012 17:36, Johannes Bauer wrote: > "pleasedumpstats" < "" And against a XML-reading C code generator that uses mako: strCmpEq 39670 strCmpLt 2766215 strCmpGt 2744002 strCmpTc 37430821 strCmpCc 14048656 Compared strings: 5549887 Equal: 0.7% Average wordlength: 6.74 chars Average comparelength: 2.53 chars Best regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From rrllff at yahoo.com Thu Sep 6 11:44:46 2012 From: rrllff at yahoo.com (Helpful person) Date: Thu, 6 Sep 2012 08:44:46 -0700 (PDT) Subject: Accessing dll References: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> Message-ID: <02c28de7-e672-4850-b684-d2cb4e3128b6@fm12g2000vbb.googlegroups.com> FYI My Python version is 2.5.4 From d at davea.name Thu Sep 6 11:54:58 2012 From: d at davea.name (Dave Angel) Date: Thu, 06 Sep 2012 11:54:58 -0400 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5048C752.6030608@davea.name> On 09/06/2012 10:42 AM, Johannes Bauer wrote: > On 06.09.2012 16:23, Dave Angel wrote: >> On 09/06/2012 09:43 AM, Johannes Bauer wrote: >>> >>> Yes, worst-case is O(N), best case O(1). Average is O(n log n). >> Can't see how you came up with an average of n log(n). Fourteen minutes >> before you made this post, you demonstrated it was less than 2 for any N. >> >> And I previously posted that for a character set of size 10, the average >> was 1.1111 > Again playing with the equations and thinking about it again. And I > completely missed your point. It wasn't about n log n vs. log n. Both > are wrong. This surprises me. I was somehow thinking about the limit of > sum (1/n), n -> infty. But since the summands are shrinking > exponentially, the limit is different. > > I think the limit of the average comparisons for a given wordlength n > against infinity with alphabet size l is > > l / (l - 1) > > i.e. for bitstrings it's 2 and for bytestrings it's 256/255. > > This would mean string comparison of randomized strings is O(1). Can > that really be true? It looks like it. > (Just lost the internet in a storm, so I'm not sure how long it'll be before this sends.) Thanks, that was exactly my point. Since el is at least 2, the average number of comparisons is no larger than 2, for any value of N. That's why, when I'm visually comparing MD5 values, I usually only look at the first few, and last few hex digits. However, Chris Angelico (at 10:39) pointed out again that totally random strings aren't real-world equivalent. He has now proposed that somebody measure real-world cases here, by patching the string comparison to gather statistics. I think that's beyond me at this point. I only joined this thread when the cases under study were well-defined random, and therefore predictable. -- DaveA From rrllff at yahoo.com Thu Sep 6 12:31:51 2012 From: rrllff at yahoo.com (Helpful person) Date: Thu, 6 Sep 2012 09:31:51 -0700 (PDT) Subject: Accessing dll References: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> <91smh9-duc.ln1@satorlaser.homedns.org> Message-ID: On Sep 6, 8:28?am, Ulrich Eckhardt wrote: > Am 06.09.2012 17:07, schrieb Helpful person: > > > I am a complete novice to Python. > > Welcome! > > > I wish to access a dll that has > > been written to be compatible with C and VB6. ?I have been told that > > after running Python I should enter ?"from ctypes import *" which > > allows Python to recognize the dll structure. ?I have placed the dll > > into my active directory (if that's the correct word, one on my path) > > for simplification. > > Using ctypes, you can indeed load DLLs. Take a look athttp://docs.python.org, which includes the documentation for the ctypes > module but also general documentation and tutorials, which should be a > starting point for you. > > > I tried: ? "import name.dll" but this just gave me an error telling me > > that there was no such module. > > Like in VB or C, things are not that easy. You will always have to write > some code that informs Python about the names and parameters of the > functions in that DLL. > > Good luck! > > Uli Thanks. I've been working my way through that page, so far without any luck. I'm still trying. It seems strange that there is no documented way to simply access the dll, even incorrectly! If I could get Python to recognize the dll as a module I would at least have a place to start debugging. From rrllff at yahoo.com Thu Sep 6 12:46:03 2012 From: rrllff at yahoo.com (Helpful person) Date: Thu, 6 Sep 2012 09:46:03 -0700 (PDT) Subject: Accessing dll References: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> Message-ID: <83536b03-64a5-4394-9d31-378b56f4fa27@x3g2000vbn.googlegroups.com> On Sep 6, 8:30?am, Jerry Hill wrote: > > You should start by reading the ctypes documentation, here:http://docs.python.org/library/ctypes.html. ?It has a lot of examples > that ought to get you started. > The reference might help if I could get Python to recognize the dll as a module. From malaclypse2 at gmail.com Thu Sep 6 12:58:43 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Thu, 6 Sep 2012 12:58:43 -0400 Subject: Accessing dll In-Reply-To: <83536b03-64a5-4394-9d31-378b56f4fa27@x3g2000vbn.googlegroups.com> References: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> <83536b03-64a5-4394-9d31-378b56f4fa27@x3g2000vbn.googlegroups.com> Message-ID: On Thu, Sep 6, 2012 at 12:46 PM, Helpful person wrote: > The reference might help if I could get Python to recognize the dll as > a module. That's never going to happen. It's a DLL, not a python module. I think the documentation lays that out pretty explicitly. Have you experimented with the very first bit of example code in the documentation? What do you get if you do the following at the interactive interpreter? >>> from ctypes import * >>> print windll. -- Jerry From rrllff at yahoo.com Thu Sep 6 13:10:06 2012 From: rrllff at yahoo.com (Helpful person) Date: Thu, 6 Sep 2012 10:10:06 -0700 (PDT) Subject: Accessing dll References: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> <83536b03-64a5-4394-9d31-378b56f4fa27@x3g2000vbn.googlegroups.com> Message-ID: <088a3ea3-c9b6-47f0-a72c-2939174907a1@d7g2000vbv.googlegroups.com> On Sep 6, 9:58?am, Jerry Hill wrote: What do you get if you do the following at the > interactive interpreter? > > >>> from ctypes import * > >>> print windll. > > -- > Jerry I get: , handle 410000 at 2ace070> From python at mrabarnett.plus.com Thu Sep 6 13:17:58 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 06 Sep 2012 18:17:58 +0100 Subject: Accessing dll In-Reply-To: References: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> <83536b03-64a5-4394-9d31-378b56f4fa27@x3g2000vbn.googlegroups.com> Message-ID: <5048DAC6.4020207@mrabarnett.plus.com> On 06/09/2012 17:58, Jerry Hill wrote: > On Thu, Sep 6, 2012 at 12:46 PM, Helpful person wrote: >> The reference might help if I could get Python to recognize the dll as >> a module. > > That's never going to happen. It's a DLL, not a python module. I > think the documentation lays that out pretty explicitly. Have you > experimented with the very first bit of example code in the > documentation? What do you get if you do the following at the > interactive interpreter? > >>>> from ctypes import * >>>> print windll. > Or this: >>> import ctypes >>> dll_path = ... >>> libc = ctypes.CDLL(dll_path) >>> dir(libc) From tjreedy at udel.edu Thu Sep 6 13:30:57 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 06 Sep 2012 13:30:57 -0400 Subject: A Python class In-Reply-To: References: Message-ID: On 9/6/2012 11:08 AM, Yves S. Garret wrote: > I'd like to know if there are any online Python classes offered > online from reliable institutions that you would recommend. Google 'online programming course python' for taught courses. At least 2 of MIT's self-guided OpenCourseWare courses use Python. http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2011/ http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc-introduction-to-computer-science-and-programming-spring-2011/ If you wanted to do one of those, you might find a partner by asking here. There might be a matchmaking site, but I could not find one. -- Terry Jan Reedy From tinnews at isbd.co.uk Thu Sep 6 13:59:05 2012 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Thu, 6 Sep 2012 18:59:05 +0100 Subject: How to print something only if it exists? Message-ID: <9s4nh9-8dr.ln1@chris.zbmc.eu> I want to print a series of list elements some of which may not exist, e.g. I have a line:- print day, fld[1], balance, fld[2] fld[2] doesn't always exist (fld is the result of a split) so the print fails when it isn't set. I know I could simply use an if but ultimately there may be more elements of fld in the print and the print may well become more complex (most like will be formatted for example). Thus it would be good if there was some way to say "print this if it exists". -- Chris Green From tjreedy at udel.edu Thu Sep 6 14:11:26 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 06 Sep 2012 14:11:26 -0400 Subject: Is there a way to configure IDLE to use spaces instead of tabs for indenting? In-Reply-To: References: Message-ID: On 9/6/2012 9:43 AM, Alex wrote: >> On Saturday, 25 August 2012 04:03:52 UTC+5:30, Alex wrote: >>> I'm new to Python and have been using IDLE 3.2.3 to experiment with >>> code as I learn. Despite being configured to use a 4 space >>> indentation width, sometimes IDLE's "smart" indentation insists >>> upon using width-8 tabs. [snip] > Agreed. I like PyDev in Eclipse, but sometimes I just want to try out > something quick in the interpreter, to ensure I understand it or do a > quick experiment. You have two choices that come with the distribution: the console and IDLE. I prefer IDLE. IPython and other shells and IDEs are other choices. > Since indentation is syntactically significant in > Python, I think fixing the interpreter to produce good, readable, > cut-and-pasteable, and Pythonic code is more important than a cosmetic > feature, but less important than true bugs. IDLE is not the interpreter. As I said before, the IDLE editor *already* does what you want. The IDLE Shell is intended mainly for single-line inputs. For compound statements, it does automatic indenting, unlike the console (at least not on Windows). It uses a tab to guarantee that the code is visually indented. It does not use secondary prompts because a) they would not line up anyway with proportional fonts and b) they would appear in cut and paste copies. This probably count be improved, and has been discussed, but someone has to volunteer to write a patch that shows that it can be improved without introducing negative consequences. I would test one if one appears. For more than a three-line compound statement, I use the editor with a scratchpad file where editing is *much* easier. If the compound statement is a class or function definition, you need more statements anyway to actually exercise the definition. Hitting F5 to run is as easy as putting the cursor at the end of the statement and hitting Enter. And it runs multiple statements at once, not just one. -- Terry Jan Reedy From d at davea.name Thu Sep 6 14:18:05 2012 From: d at davea.name (Dave Angel) Date: Thu, 06 Sep 2012 14:18:05 -0400 Subject: How to print something only if it exists? In-Reply-To: <9s4nh9-8dr.ln1@chris.zbmc.eu> References: <9s4nh9-8dr.ln1@chris.zbmc.eu> Message-ID: <5048E8DD.7030301@davea.name> On 09/06/2012 01:59 PM, tinnews at isbd.co.uk wrote: > I want to print a series of list elements some of which may not exist, > e.g. I have a line:- > > print day, fld[1], balance, fld[2] > > fld[2] doesn't always exist (fld is the result of a split) so the > print fails when it isn't set. > > I know I could simply use an if but ultimately there may be more > elements of fld in the print and the print may well become more > complex (most like will be formatted for example). Thus it would be > good if there was some way to say "print this if it exists". > Would you like to define "exists" ? A list is not sparse, so all items exist if their subscript is less than the length of the list. So all you need to do is compare 2 to len(fld). But perhaps there's another approach. Just what DO you want to print if fld(1) exists, but fld(2) does not? Do you still want to print out day, fld(1), and balance? Or do you want to skip balance as well? if you literally want nothing printed for list elements beyond the end, then I'd add some extra empty-strings to the end of the list. fld.extend("" * 5) Now, subscripts 0 through 4 inclusive will work, as specified. Alternatively, perhaps there's some association between the day and the fld(1), and the balance and the fld(2). in that case, probably you want to make a loop out of it, and only print each pair if they're both available. Something like: for tag, value in zip((something, day, balance), fld): print tag, value, "" -- DaveA From emile at fenx.com Thu Sep 6 14:19:09 2012 From: emile at fenx.com (Emile van Sebille) Date: Thu, 06 Sep 2012 11:19:09 -0700 Subject: How to print something only if it exists? In-Reply-To: <9s4nh9-8dr.ln1@chris.zbmc.eu> References: <9s4nh9-8dr.ln1@chris.zbmc.eu> Message-ID: On 9/6/2012 10:59 AM tinnews at isbd.co.uk said... > I want to print a series of list elements some of which may not exist, > e.g. I have a line:- > > print day, fld[1], balance, fld[2] > > fld[2] doesn't always exist (fld is the result of a split) so the > print fails when it isn't set. > > I know I could simply use an if but ultimately there may be more > elements of fld in the print and the print may well become more > complex (most like will be formatted for example). Thus it would be > good if there was some way to say "print this if it exists". > You may be better off ensuring that fld is an appropriate length. One way may be tweaking the split to return the right numbers of elements: >>> T = "1,2,3" >>> flds = (T+","*5).split(",")[:5] >>> flds ['1', '2', '3', '', ''] Emile From breamoreboy at yahoo.co.uk Thu Sep 6 14:19:53 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 06 Sep 2012 19:19:53 +0100 Subject: python docs search for 'print' In-Reply-To: <5048ACC3.4060201@gmail.com> References: <5048ACC3.4060201@gmail.com> Message-ID: On 06/09/2012 15:01, David Hoese wrote: > On 9/5/12 3:03 PM, Grant Edwards wrote: >> On 2012-09-05, Dave Angel wrote: >>> >On 09/05/2012 01:47 PM, Grant Edwards wrote: >>> > >>>> >>Making the site's "search" box use Google or somesuch is probably the >>>> >>simplest solution. I'm not enough of a web guy to know how to do >>>> >>that, but I do know that some sites do handle site search that way. >>>> >> >>> >And google has some API's to make it relatively painless. And a >>> >license form to fill in and send, along with your check. >> I just saw the posting mentioning the pricing. So it is a simple >> simple solution, but it's probably not cheap enough... >> >> > I followed the bug reporting instructions on the docs site and emailed > docs at python.org and pointed them at this thread. I didn't catch if > anyone else on this thread already did it. I guess we'll see what happens. > > -Dave Say thanks to Terry Reedy for http://bugs.python.org/issue15871 -- Cheers. Mark Lawrence. From tjreedy at udel.edu Thu Sep 6 14:21:31 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 06 Sep 2012 14:21:31 -0400 Subject: python docs search for 'print' In-Reply-To: <5048ACC3.4060201@gmail.com> References: <5048ACC3.4060201@gmail.com> Message-ID: On 9/6/2012 10:01 AM, David Hoese wrote: > On 9/5/12 3:03 PM, Grant Edwards wrote: >> On 2012-09-05, Dave Angel wrote: >>> >On 09/05/2012 01:47 PM, Grant Edwards wrote: >>> > >>>> >>Making the site's "search" box use Google or somesuch is probably the >>>> >>simplest solution. I'm not enough of a web guy to know how to do >>>> >>that, but I do know that some sites do handle site search that way. >>>> >> >>> >And google has some API's to make it relatively painless. And a >>> >license form to fill in and send, along with your check. >> I just saw the posting mentioning the pricing. So it is a simple >> simple solution, but it's probably not cheap enough... >> >> > I followed the bug reporting instructions on the docs site and emailed > docs at python.org and pointed them at this thread. I didn't catch if > anyone else on this thread already did it. I guess we'll see what happens. I opened a tracker issue for a different solution. http://bugs.python.org/issue15871 -- Terry Jan Reedy From nagle at animats.com Thu Sep 6 15:27:19 2012 From: nagle at animats.com (John Nagle) Date: Thu, 06 Sep 2012 12:27:19 -0700 Subject: Parsing ISO date/time strings - where did the parser go? Message-ID: In Python 2.7: I want to parse standard ISO date/time strings such as 2012-09-09T18:00:00-07:00 into Python "datetime" objects. The "datetime" object offers an output method , datetimeobj.isoformat(), but not an input parser. There ought to be classmethod datetime.fromisoformat(s) but there isn't. I'd like to avoid adding a dependency on a third party module like "dateutil". The "Working with time" section of the Python wiki is so ancient it predates "datetime", and says so. There's an iso8601 module on PyPi, but it's abandoned; it hasn't been updated since 2007 and has many outstanding issues. There are mentions of "xml.utils.iso8601.parse" in various places, but the "xml" module that comes with Python 2.7 doesn't have xml.utils. http://www.seehuhn.de/pages/pdate says: "Unfortunately there is no easy way to parse full ISO 8601 dates using the Python standard library." It looks like this was taken out of "xml" at some point, but not moved into "datetime". John Nagle From tjreedy at udel.edu Thu Sep 6 15:34:13 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 06 Sep 2012 15:34:13 -0400 Subject: How to print something only if it exists? In-Reply-To: <9s4nh9-8dr.ln1@chris.zbmc.eu> References: <9s4nh9-8dr.ln1@chris.zbmc.eu> Message-ID: On 9/6/2012 1:59 PM, tinnews at isbd.co.uk wrote: > I want to print a series of list elements some of which may not exist, > e.g. I have a line:- > > print day, fld[1], balance, fld[2] > > fld[2] doesn't always exist (fld is the result of a split) so the > print fails when it isn't set. What fails is the indexing operation. You can prevent that by slicing rather than indexing: fld[1:2], fld[2:3]. These will give '' if there is no fld[1], fld[2]. Whether or not this is sensible depends on what you want the output to look like in these cases. -- Terry Jan Reedy From t at jollybox.de Thu Sep 6 15:44:13 2012 From: t at jollybox.de (Thomas Jollans) Date: Thu, 06 Sep 2012 21:44:13 +0200 Subject: Parsing ISO date/time strings - where did the parser go? In-Reply-To: References: Message-ID: <5048FD0D.1020400@jollybox.de> On 09/06/2012 09:27 PM, John Nagle wrote: > In Python 2.7: > > I want to parse standard ISO date/time strings such as > > 2012-09-09T18:00:00-07:00 > > into Python "datetime" objects. The "datetime" object offers > an output method , datetimeobj.isoformat(), but not an input > parser. There ought to be > > classmethod datetime.fromisoformat(s) http://docs.python.org/library/datetime.html#datetime.datetime.strptime The ISO date/time format is dead simple and well-defined. strptime is quite suitable. > > but there isn't. I'd like to avoid adding a dependency on > a third party module like "dateutil". > > The "Working with time" section of the Python wiki is so > ancient it predates "datetime", and says so. > > There's an iso8601 module on PyPi, but it's abandoned; it hasn't been > updated since 2007 and has many outstanding issues. > > There are mentions of "xml.utils.iso8601.parse" in > various places, but the "xml" module that comes > with Python 2.7 doesn't have xml.utils. > > http://www.seehuhn.de/pages/pdate > says: > > "Unfortunately there is no easy way to parse full ISO 8601 dates using > the Python standard library." > > It looks like this was taken out of "xml" at some point, > but not moved into "datetime". > > John Nagle > From nesaro at gmail.com Thu Sep 6 15:48:44 2012 From: nesaro at gmail.com (Nestor Arocha) Date: Thu, 6 Sep 2012 12:48:44 -0700 (PDT) Subject: Language workbench written in python3 In-Reply-To: <314ae0e0-f38f-4cb9-944c-511343988f37@googlegroups.com> References: <1ed391c3-8fcf-4a3f-8ad7-0a2cf913b6cc@googlegroups.com> <634287e3-12b3-4b47-8ad2-38c1bc76ff1a@googlegroups.com> <314ae0e0-f38f-4cb9-944c-511343988f37@googlegroups.com> Message-ID: On Thursday, September 6, 2012 2:53:15 PM UTC+1, Ramchandra Apte wrote: > On Thursday, 6 September 2012 19:16:38 UTC+5:30, Dave Angel wrote: > > > On 09/06/2012 09:34 AM, Ramchandra Apte wrote: > > > > > > > Translator means what precisely? > > > > > > > > > > > > Examples of translators include compilers, assemblers, and > > > > > > interpreters. They also include implementations like cfront, which > > > > > > translates from one high-level language to another lower-level > > > > > > language. (high and low being relative) > > > > > > > > > > > > -- > > > > > > > > > > > > DaveA > > > > Is conversion from Python to C++ possible from this project? No, it is not currently possible for several reasons: * current parser implementation is a recursive descent parser. I haven't implemented an LR parser yet, although PLY lexers and parsers are supported. * Syntax Directed Translator is not fully implemented either. * Parser Trees are supported, but there is no clear method defined for converting them into ASTs (like antlr grammars) * Even with AST and SDT support, a Python to C++ translator will require more complex tools and a lot of coding. This tool is oriented to small DSLs parsing and translation; grammars like Python or C++ are too complex for the current implementation From joshua.landau.ws at gmail.com Thu Sep 6 15:51:22 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Thu, 6 Sep 2012 20:51:22 +0100 Subject: How to print something only if it exists? In-Reply-To: <9s4nh9-8dr.ln1@chris.zbmc.eu> References: <9s4nh9-8dr.ln1@chris.zbmc.eu> Message-ID: On 6 September 2012 18:59, wrote: > I want to print a series of list elements some of which may not exist, > e.g. I have a line:- > > print day, fld[1], balance, fld[2] > > fld[2] doesn't always exist (fld is the result of a split) so the > print fails when it isn't set. > What I might do is simply make a class that wraps the list. class SafeIndex: def __init__(self, lst, safety=""): self.list = lst self.safety = "" def __getitem__(self, n): try: return self.list[n] except IndexError: return self.safety si = SafeIndex(range(20)) Then just index the SafeIndex with the print and abandon it after. -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Thu Sep 6 15:51:37 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 06 Sep 2012 12:51:37 -0700 Subject: Parsing ISO date/time strings - where did the parser go? References: Message-ID: <7xbohj3p6e.fsf@ruckus.brouhaha.com> John Nagle writes: > There's an iso8601 module on PyPi, but it's abandoned; it hasn't been > updated since 2007 and has many outstanding issues. Hmm, I have some code that uses ISO date/time strings and just checked to see how I did it, and it looks like it uses iso8601-0.1.4-py2.6.egg . I don't remember downloading that module (I must have done it and forgotten). I'm not sure what its outstanding issues are, as it works ok in the limited way I use it. I agree that this functionality ought to be in the stdlib. From d at davea.name Thu Sep 6 15:54:15 2012 From: d at davea.name (Dave Angel) Date: Thu, 06 Sep 2012 15:54:15 -0400 Subject: Parsing ISO date/time strings - where did the parser go? In-Reply-To: References: Message-ID: <5048FF67.3040808@davea.name> On 09/06/2012 03:27 PM, John Nagle wrote: > In Python 2.7: > > I want to parse standard ISO date/time strings such as > > 2012-09-09T18:00:00-07:00 > > into Python "datetime" objects. The "datetime" object offers > an output method , datetimeobj.isoformat(), but not an input > parser. There ought to be > > classmethod datetime.fromisoformat(s) > > but there isn't. I'd like to avoid adding a dependency on > a third party module like "dateutil". > > The "Working with time" section of the Python wiki is so > ancient it predates "datetime", and says so. > > There's an iso8601 module on PyPi, but it's abandoned; it hasn't been > updated since 2007 and has many outstanding issues. > > There are mentions of "xml.utils.iso8601.parse" in > various places, but the "xml" module that comes > with Python 2.7 doesn't have xml.utils. > > http://www.seehuhn.de/pages/pdate > says: > > "Unfortunately there is no easy way to parse full ISO 8601 dates using > the Python standard library." > > It looks like this was taken out of "xml" at some point, > but not moved into "datetime". > For working with datetime, see http://docs.python.org/library/datetime.html#datetime.datetime and look up datetime.strptime() Likewise for generalized output, check out datetime.strftime(). -- DaveA From miki.tebeka at gmail.com Thu Sep 6 16:17:51 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 6 Sep 2012 13:17:51 -0700 (PDT) Subject: Dynamically scheduling Cron Jobs for Python Scripts. In-Reply-To: <1c24b34d-774f-4613-b6a9-f6f19fb24acb@googlegroups.com> References: <1c24b34d-774f-4613-b6a9-f6f19fb24acb@googlegroups.com> Message-ID: <2702e6fc-a6f5-4bc1-9c47-216171506128@googlegroups.com> > I want to re run the script at that schedule time to send me a email. Calculate how much time until the meeting. And spawn the script that will sleep that amount of time and then send email. From tjandacw at cox.net Thu Sep 6 16:21:56 2012 From: tjandacw at cox.net (Tim Williams) Date: Thu, 6 Sep 2012 13:21:56 -0700 (PDT) Subject: Accessing dll In-Reply-To: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> References: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> Message-ID: On Thursday, September 6, 2012 11:07:07 AM UTC-4, Helpful person wrote: > I am a complete novice to Python. I wish to access a dll that has > > been written to be compatible with C and VB6. I have been told that > > after running Python I should enter "from ctypes import *" which > > allows Python to recognize the dll structure. I have placed the dll > > into my active directory (if that's the correct word, one on my path) > > for simplification. > > > > I tried: "import name.dll" but this just gave me an error telling me > > that there was no such module. > > > > Can someone please help? > > > > Richard I'm new to using the ctypes module also, but what I did to find the library was I appended the location of the dll to my PATH like so: (this is Windows) pth = os.environ['path'].split(';') pth.append(os.path.join(os.environ['userprofile'],'My Documents','DLLs')) os.environ['path'] = ';'.join(pth) From laddosingh at gmail.com Thu Sep 6 16:26:32 2012 From: laddosingh at gmail.com (Tigerstyle) Date: Thu, 6 Sep 2012 13:26:32 -0700 (PDT) Subject: Function for examine content of directory In-Reply-To: References: Message-ID: <08938014-e4e0-4f6d-b11a-e843ed4a0da3@googlegroups.com> Thanks, just what I was looking for :-) T kl. 17:20:27 UTC+2 torsdag 6. september 2012 skrev MRAB f?lgende: > On 06/09/2012 15:56, Tigerstyle wrote: > > > Hi guys, > > > > > > I'm trying to write a module containing a function to examine the contents of the current working directory and print out a count of how many files have each extension (".txt", ".doc", etc.) > > > > > > This is the code so far: > > > -- > > > import os > > > > > > path = "v:\\workspace\\Python2_Homework03\\src\\" > > > dirs = os.listdir( path ) > > > filenames = {"this.txt", "that.txt", "the_other.txt","this.doc","that.doc","this.pdf","first.txt","that.pdf"} > > > extensions = [] > > > for filename in filenames: > > > f = open(filename, "w") > > > f.write("Some text\n") > > > f.close() > > > name , ext = os.path.splitext(f.name) > > > extensions.append(ext) > > > > > > # This would print all the files and directories > > > for file in dirs: > > > print(file) > > > > > > for ext in extensions: > > > print("Count for %s: " %ext, extensions.count(ext)) > > > > > > -- > > > > > > When I'm trying to get the module to print how many files each extension has, it prints the count of each ext multiple times for each extension type. Like this: > > > > > > this.pdf > > > the_other.txt > > > this.doc > > > that.txt > > > this.txt > > > that.pdf > > > first.txt > > > that.doc > > > Count for .pdf: 2 > > > Count for .txt: 4 > > > Count for .doc: 2 > > > Count for .txt: 4 > > > Count for .txt: 4 > > > Count for .pdf: 2 > > > Count for .txt: 4 > > > Count for .doc: 2 > > > > > That's because each extension can occur multiple times in the list. > > > > Try the Counter class: > > > > from collections import Counter > > > > for ext, count in Counter(extensions).items(): > > print("Count for %s: " % ext, count) From laddosingh at gmail.com Thu Sep 6 16:26:32 2012 From: laddosingh at gmail.com (Tigerstyle) Date: Thu, 6 Sep 2012 13:26:32 -0700 (PDT) Subject: Function for examine content of directory In-Reply-To: References: Message-ID: <08938014-e4e0-4f6d-b11a-e843ed4a0da3@googlegroups.com> Thanks, just what I was looking for :-) T kl. 17:20:27 UTC+2 torsdag 6. september 2012 skrev MRAB f?lgende: > On 06/09/2012 15:56, Tigerstyle wrote: > > > Hi guys, > > > > > > I'm trying to write a module containing a function to examine the contents of the current working directory and print out a count of how many files have each extension (".txt", ".doc", etc.) > > > > > > This is the code so far: > > > -- > > > import os > > > > > > path = "v:\\workspace\\Python2_Homework03\\src\\" > > > dirs = os.listdir( path ) > > > filenames = {"this.txt", "that.txt", "the_other.txt","this.doc","that.doc","this.pdf","first.txt","that.pdf"} > > > extensions = [] > > > for filename in filenames: > > > f = open(filename, "w") > > > f.write("Some text\n") > > > f.close() > > > name , ext = os.path.splitext(f.name) > > > extensions.append(ext) > > > > > > # This would print all the files and directories > > > for file in dirs: > > > print(file) > > > > > > for ext in extensions: > > > print("Count for %s: " %ext, extensions.count(ext)) > > > > > > -- > > > > > > When I'm trying to get the module to print how many files each extension has, it prints the count of each ext multiple times for each extension type. Like this: > > > > > > this.pdf > > > the_other.txt > > > this.doc > > > that.txt > > > this.txt > > > that.pdf > > > first.txt > > > that.doc > > > Count for .pdf: 2 > > > Count for .txt: 4 > > > Count for .doc: 2 > > > Count for .txt: 4 > > > Count for .txt: 4 > > > Count for .pdf: 2 > > > Count for .txt: 4 > > > Count for .doc: 2 > > > > > That's because each extension can occur multiple times in the list. > > > > Try the Counter class: > > > > from collections import Counter > > > > for ext, count in Counter(extensions).items(): > > print("Count for %s: " % ext, count) From tjandacw at cox.net Thu Sep 6 16:27:42 2012 From: tjandacw at cox.net (Tim Williams) Date: Thu, 6 Sep 2012 13:27:42 -0700 (PDT) Subject: Accessing dll In-Reply-To: References: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> Message-ID: On Thursday, September 6, 2012 4:21:56 PM UTC-4, Tim Williams wrote: > On Thursday, September 6, 2012 11:07:07 AM UTC-4, Helpful person wrote: > > > I am a complete novice to Python. I wish to access a dll that has > > > > > > been written to be compatible with C and VB6. I have been told that > > > > > > after running Python I should enter "from ctypes import *" which > > > > > > allows Python to recognize the dll structure. I have placed the dll > > > > > > into my active directory (if that's the correct word, one on my path) > > > > > > for simplification. > > > > > > > > > > > > I tried: "import name.dll" but this just gave me an error telling me > > > > > > that there was no such module. > > > > > > > > > > > > Can someone please help? > > > > > > > > > > > > Richard > > > > I'm new to using the ctypes module also, but what I did to find the library was I appended the location of the dll to my PATH like so: (this is Windows) > > > > pth = os.environ['path'].split(';') > > pth.append(os.path.join(os.environ['userprofile'],'My Documents','DLLs')) > > os.environ['path'] = ';'.join(pth) I should have also mentioned to look at LoadLibrary in the ctypes module. e.g. mylib=cdll.LoadLibrary('mylib.dll') From nagle at animats.com Thu Sep 6 16:34:20 2012 From: nagle at animats.com (John Nagle) Date: Thu, 06 Sep 2012 13:34:20 -0700 Subject: Parsing ISO date/time strings - where did the parser go? In-Reply-To: <7xbohj3p6e.fsf@ruckus.brouhaha.com> References: <7xbohj3p6e.fsf@ruckus.brouhaha.com> Message-ID: On 9/6/2012 12:51 PM, Paul Rubin wrote: > John Nagle writes: >> There's an iso8601 module on PyPi, but it's abandoned; it hasn't been >> updated since 2007 and has many outstanding issues. > > Hmm, I have some code that uses ISO date/time strings and just checked > to see how I did it, and it looks like it uses iso8601-0.1.4-py2.6.egg . > I don't remember downloading that module (I must have done it and > forgotten). I'm not sure what its outstanding issues are, as it works > ok in the limited way I use it. > > I agree that this functionality ought to be in the stdlib. Yes, it should. There's no shortage of implementations. PyPi has four. Each has some defect. PyPi offers: iso8601 0.1.4 Simple module to parse ISO 8601 dates iso8601.py 0.1dev Parse utilities for iso8601 encoding. iso8601plus 0.1.6 Simple module to parse ISO 8601 dates zc.iso8601 0.2.0 ISO 8601 utility functions Unlike CPAN, PyPi has no quality control. Looking at the first one, it's in Google Code. http://code.google.com/p/pyiso8601/source/browse/trunk/iso8601/iso8601.py The first bug is at line 67. For a timestamp with a "Z" at the end, the offset should always be zero, regardless of the default timezone. See "http://en.wikipedia.org/wiki/ISO_8601". The code uses the default time zone in that case, which is wrong. So don't call that code with your local time zone as the default; it will return bad times. Looking at the second one, it's on github: https://github.com/accellion/iso8601.py/blob/master/iso8601.py Giant regular expressions! The code to handle the offset is present, but it doesn't make the datetime object a timezone-aware object. It returns a naive object in UTC. The third one is at https://github.com/jimklo/pyiso8601plus This is a fork of the first one, because the first one is abandonware. The bug in the first one, mentioned above, isn't fixed. However, if a time zone is present, it does return an "aware" datetime object. The fourth one is the Zope version. This brings in the pytz module, which brings in the Olsen database of named time zones and their historical conversion data. None of that information is used, or necessary, to parse ISO dates and times. Somebody just wanted the pytz.fixedOffset() function, which does something datetime already does. (For all the people who keep saying "use strptime", that doesn't handle time zone offsets at all.) John Nagle From d at davea.name Thu Sep 6 16:54:00 2012 From: d at davea.name (Dave Angel) Date: Thu, 06 Sep 2012 16:54:00 -0400 Subject: Looking for an IPC solution In-Reply-To: <2p0i489b5kq6ad2kc70r82ksjqpcatdsqu@invalid.netcom.com> References: <50410AD6.7080003@shopzeus.com> <2p0i489b5kq6ad2kc70r82ksjqpcatdsqu@invalid.netcom.com> Message-ID: <50490D68.1000305@davea.name> On 09/06/2012 04:33 PM, Dennis Lee Bieber wrote: > > Note that this difference mainly applies to how the processes are > themselves are created... How the library wraps shared data is > possibly different (I've never understood how a "fork" process can > avoid memory conflicts if it has write access to common virtual memory > blocks). Here's an approximate description of fork, at least for the memory aspects. During a fork, the virtual memory table is copied (that's descriptors for all mapped and allocated memory) but the memory itself is NOT. All the new descriptors are labeled "COW" (copy-on-write). As that process executes, the first time it writes in a particular memory block, the OS gets a memory fault, which it fixes by allocating a block of the same size, copying the memory block to the new one, and labeling it read/write. Subsequent accesses to the same block are normal, with no trace of the fork remaining. Now, there are lots of details that this blurs over, but it turns out that many times the new process doesn't change very much. For example, all the mappings to the executable and to shared libraries are theoretically readonly. In fact, they might have also been labeled COW even for the initial execution of the program. Another place that's blurry is just what the resolution of this table actually is. There are at least two levels of tables. The smallest increment on the Pentium family is 4k. -- DaveA From rosuav at gmail.com Thu Sep 6 17:30:45 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Sep 2012 07:30:45 +1000 Subject: A Python class In-Reply-To: References: Message-ID: On Fri, Sep 7, 2012 at 3:30 AM, Terry Reedy wrote: > On 9/6/2012 11:08 AM, Yves S. Garret wrote: > >> I'd like to know if there are any online Python classes offered >> online from reliable institutions that you would recommend. > > Google 'online programming course python' for taught courses. > At least 2 of MIT's self-guided OpenCourseWare courses use Python. Note this subtle distinction. A Python course will (theoretically, at least!) teach you how to write Python code. A Python class is a collection of methods and stuff. A trivial and petty distinction, perhaps, but when you go searching the web, you'll get better results with the right word. ChrisA From rosuav at gmail.com Thu Sep 6 17:48:27 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Sep 2012 07:48:27 +1000 Subject: Function for examine content of directory In-Reply-To: References: Message-ID: On Fri, Sep 7, 2012 at 12:56 AM, Tigerstyle wrote: > I'm trying to write a module containing a function to examine the contents of the current working directory and print out a count of how many files have each extension (".txt", ".doc", etc.) If you haven't already, look into the Python 'dict' type; you may find it easier to work with for this sort of job. You can map an extension ("txt") to its count (4) directly. ChrisA From bbeacham at desanasystems.com Thu Sep 6 18:12:14 2012 From: bbeacham at desanasystems.com (bbeacham at desanasystems.com) Date: Thu, 6 Sep 2012 15:12:14 -0700 (PDT) Subject: HP Quality Center only works with ActiveState Python 2.5 Message-ID: Does anyone know why this is? I cannot find anything via Google about this, but HP says it is so. Of course it is now impossible to get ActiveState Python 2.5 for free. You can spend a $1000 for a copy. :) Anyway, it is irritating me that we are starting a new automation environment in Python, but we are being restricted to version 2.5 From miki.tebeka at gmail.com Thu Sep 6 19:27:49 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 6 Sep 2012 16:27:49 -0700 (PDT) Subject: Parsing ISO date/time strings - where did the parser go? In-Reply-To: References: <7xbohj3p6e.fsf@ruckus.brouhaha.com> Message-ID: <230a7cda-f5e4-4062-9085-1db6795a453e@googlegroups.com> I'd look also into dateutil.parser.parse and feedparser._parse_date On Thursday, September 6, 2012 1:34:18 PM UTC-7, John Nagle wrote: > On 9/6/2012 12:51 PM, Paul Rubin wrote: > > > John Nagle writes: > > >> There's an iso8601 module on PyPi, but it's abandoned; it hasn't been > > >> updated since 2007 and has many outstanding issues. > > > > > > Hmm, I have some code that uses ISO date/time strings and just checked > > > to see how I did it, and it looks like it uses iso8601-0.1.4-py2.6.egg . > > > I don't remember downloading that module (I must have done it and > > > forgotten). I'm not sure what its outstanding issues are, as it works > > > ok in the limited way I use it. > > > > > > I agree that this functionality ought to be in the stdlib. > > > > Yes, it should. There's no shortage of implementations. > > PyPi has four. Each has some defect. > > > > PyPi offers: > > > > iso8601 0.1.4 Simple module to parse ISO 8601 dates > > iso8601.py 0.1dev Parse utilities for iso8601 encoding. > > iso8601plus 0.1.6 Simple module to parse ISO 8601 dates > > zc.iso8601 0.2.0 ISO 8601 utility functions > > > > Unlike CPAN, PyPi has no quality control. > > > > Looking at the first one, it's in Google Code. > > > > http://code.google.com/p/pyiso8601/source/browse/trunk/iso8601/iso8601.py > > > > The first bug is at line 67. For a timestamp with a "Z" > > at the end, the offset should always be zero, regardless of the default > > timezone. See "http://en.wikipedia.org/wiki/ISO_8601". > > The code uses the default time zone in that case, which is wrong. > > So don't call that code with your local time zone as the default; > > it will return bad times. > > > > Looking at the second one, it's on github: > > > > https://github.com/accellion/iso8601.py/blob/master/iso8601.py > > > > Giant regular expressions! The code to handle the offset > > is present, but it doesn't make the datetime object a > > timezone-aware object. It returns a naive object in UTC. > > > > The third one is at > > > > https://github.com/jimklo/pyiso8601plus > > > > This is a fork of the first one, because the first one is abandonware. > > The bug in the first one, mentioned above, isn't fixed. However, if > > a time zone is present, it does return an "aware" datetime object. > > > > The fourth one is the Zope version. This brings in the pytz > > module, which brings in the Olsen database of named time zones and > > their historical conversion data. None of that information is > > used, or necessary, to parse ISO dates and times. Somebody > > just wanted the pytz.fixedOffset() function, which does something > > datetime already does. > > > > (For all the people who keep saying "use strptime", that doesn't > > handle time zone offsets at all.) > > > > John Nagle From roy at panix.com Thu Sep 6 19:34:22 2012 From: roy at panix.com (Roy Smith) Date: Thu, 06 Sep 2012 19:34:22 -0400 Subject: Parsing ISO date/time strings - where did the parser go? References: Message-ID: In article , John Nagle wrote: > In Python 2.7: > > I want to parse standard ISO date/time strings such as > > 2012-09-09T18:00:00-07:00 > > into Python "datetime" objects. The "datetime" object offers > an output method , datetimeobj.isoformat(), but not an input > parser. There ought to be > > classmethod datetime.fromisoformat(s) > > but there isn't. I'd like to avoid adding a dependency on > a third party module like "dateutil". I'm curious why? I really think dateutil is the way to go. It's really amazing (and unfortunate) that datetime has isoformat(), but no way to go in the other direction. From roy at panix.com Thu Sep 6 19:44:38 2012 From: roy at panix.com (Roy Smith) Date: Thu, 06 Sep 2012 19:44:38 -0400 Subject: Parsing ISO date/time strings - where did the parser go? References: Message-ID: In article , Dave Angel wrote: > For working with datetime, see > http://docs.python.org/library/datetime.html#datetime.datetime > > and look up datetime.strptime() strptime has two problems. One is that it's a pain to use (you have to look up all those inscrutable %-thingies every time). The second is that it doesn't always work. To correctly parse an ISO-8601 string, you need '%z', which isn't supported on all platforms. The third is that I never use methods I can't figure out how to pronounce. From dwightdhutto at gmail.com Thu Sep 6 19:53:07 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Thu, 6 Sep 2012 19:53:07 -0400 Subject: HP Quality Center only works with ActiveState Python 2.5 In-Reply-To: References: Message-ID: On Thu, Sep 6, 2012 at 6:12 PM, wrote: > Does anyone know why this is? I cannot find anything via Google about > this, but HP says it is so. Of course it is now impossible to get > ActiveState Python 2.5 for free. You can spend a $1000 for a copy. :) > > Anyway, it is irritating me that we are starting a new automation > environment in Python, but we are being restricted to version 2.5 > -- > http://mail.python.org/mailman/listinfo/python-list > These might help: http://www.activestate.com/activepython/downloads http://docs.activestate.com/activepython/2.5/installnotes.html -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jimmyli1528 at gmail.com Thu Sep 6 20:01:12 2012 From: jimmyli1528 at gmail.com (jimbo1qaz) Date: Thu, 6 Sep 2012 17:01:12 -0700 (PDT) Subject: Bitshifts and "And" vs Floor-division and Modular Message-ID: Is it faster to use bitshifts or floor division? And which is better, & or %? All divisors and mods are power of 2, so are binary operations faster? And are they considered bad style? From contropinion at gmail.com Thu Sep 6 20:21:53 2012 From: contropinion at gmail.com (contro opinion) Date: Thu, 6 Sep 2012 20:21:53 -0400 Subject: lxml can't output right unicode result Message-ID: i eidt a file and save it in gbk encode named test. my system is :debian,locale,en.utf-8;python2.6,locale,utf-8.

?

in terminal i input: xxd test 0000000: 3c68 746d 6c3e 0a3c 703e c4e3 3c2f 703e .

..

0000010: 0a3c 2f68 746d 6c3e 0a .. ? is you in english, "\xc4\xe3" is the gbk encode of it. "\xe4\xbd\xe3" is the utf-8 encode of it. "u\x4f\x60" is the unicode encode of it. now i parse it in lxml >>> "?" '\xe4\xbd\xa0' >>> "?".decode("utf-8") u'\u4f60' >>> "?".decode("utf-8").encode("gbk") '\xc4\xe3' >>> code1: >>> import lxml.html >>> root=lxml.html.parse("test") >>> d=root.xpath("//p") >>> d[0].text_content() u'\xc4\xe3' in material ,lxml parse file to output the unicode form. why the d[0].text_content() can not output u'\x4f\x60'? code2: import codecs import lxml.html f = codecs.open('test', 'r', 'gbk') root=lxml.html.parse(f) d=root.xpath("//p") d[0].text_content() u'\xe4\xbd\xa0' why the d[0].text_content() can not output u'\x4f\x60'? i am confused by this problem for two days. -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Thu Sep 6 20:30:41 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 07 Sep 2012 01:30:41 +0100 Subject: Bitshifts and "And" vs Floor-division and Modular In-Reply-To: References: Message-ID: On 07/09/2012 01:01, jimbo1qaz wrote: > Is it faster to use bitshifts or floor division? And which is better, & or %? > All divisors and mods are power of 2, so are binary operations faster? And are they considered bad style? > Why don't you use the timeit module and find out for yourself? -- Cheers. Mark Lawrence. From john.ruckstuhl at gmail.com Thu Sep 6 20:55:02 2012 From: john.ruckstuhl at gmail.com (ruck) Date: Thu, 6 Sep 2012 17:55:02 -0700 (PDT) Subject: os.stat() distorts filenames that end with period (nt.stat()) Message-ID: (This with Python 2.7.2 on Windows 7) os.stat() won't recognize a filename ending in period. It will ignore trailing periods. If you ask it about file 'goo...' it will report on file 'goo' And if 'goo' doesn't exist, os.stat will complain. create file goo, then >>> os.stat('goo') nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) >>> os.stat('goo...') nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) rename goo to "goo...", then, >>> os.stat('goo...') Traceback (most recent call last): File "", line 1, in os.stat('goo...') WindowsError: [Error 2] The system cannot find the file specified: 'goo...' Puzzling, to me at least. Any comments? This with Python 2.7.2 on Windows 7. Is there a workaround? Thanks, John From jimmyli1528 at gmail.com Thu Sep 6 21:05:41 2012 From: jimmyli1528 at gmail.com (jimbo1qaz) Date: Thu, 6 Sep 2012 18:05:41 -0700 (PDT) Subject: Bitshifts and "And" vs Floor-division and Modular In-Reply-To: References: Message-ID: On Thursday, September 6, 2012 5:30:05 PM UTC-7, Mark Lawrence wrote: > On 07/09/2012 01:01, jimbo1qaz wrote: > > > Is it faster to use bitshifts or floor division? And which is better, & or %? > > > All divisors and mods are power of 2, so are binary operations faster? And are they considered bad style? > > > > > > > Why don't you use the timeit module and find out for yourself? > > > > -- > > Cheers. > > > > Mark Lawrence. How do I use it? timeit.timer is not defined. From jimmyli1528 at gmail.com Thu Sep 6 21:05:41 2012 From: jimmyli1528 at gmail.com (jimbo1qaz) Date: Thu, 6 Sep 2012 18:05:41 -0700 (PDT) Subject: Bitshifts and "And" vs Floor-division and Modular In-Reply-To: References: Message-ID: On Thursday, September 6, 2012 5:30:05 PM UTC-7, Mark Lawrence wrote: > On 07/09/2012 01:01, jimbo1qaz wrote: > > > Is it faster to use bitshifts or floor division? And which is better, & or %? > > > All divisors and mods are power of 2, so are binary operations faster? And are they considered bad style? > > > > > > > Why don't you use the timeit module and find out for yourself? > > > > -- > > Cheers. > > > > Mark Lawrence. How do I use it? timeit.timer is not defined. From cs at zip.com.au Thu Sep 6 21:08:30 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 7 Sep 2012 11:08:30 +1000 Subject: Bitshifts and "And" vs Floor-division and Modular In-Reply-To: References: Message-ID: <20120907010830.GA25508@cskk.homeip.net> On 07Sep2012 01:30, Mark Lawrence wrote: | On 07/09/2012 01:01, jimbo1qaz wrote: | > Is it faster to use bitshifts or floor division? And which is better, & or %? | > All divisors and mods are power of 2, so are binary operations faster? And are they considered bad style? | | Why don't you use the timeit module and find out for yourself? Because timeit doesn't output style advice? Because timeit won't offer even a short single parapgraph description of how python ints (even just in CPython) are implemented and how that may affect performance in general? To the OP: personally, I would suggest using % when I am thinking of division and a bit shift when I am thinking of a bitshift, and only reach for timeit when performance becomes an issue. Code for the algoritm, and only optimise later. Of course only a well run benchmark will measure the real world, but it possible to address his other questions in a helpful fashion and address the benchmark question in a less offputting tone. If you can't be bothered, please don't. (Especially since these irritating posts from you are usually in response to a post you feel could have used more effort from the OP.) Nobody answers all performance considerations or design choices with an exhaustive timeit benchmark, and it is silly to suggest so. It is helpful for people to have a mental model of the python internals so they can make often-sensible choices from the start. So try being helpful instead of slapping people down when they haven't reached your private bar. Cheers, -- Cameron Simpson Microsoft: Where do you want to go today? UNIX: Been there, done that! From python at mrabarnett.plus.com Thu Sep 6 21:14:06 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 07 Sep 2012 02:14:06 +0100 Subject: lxml can't output right unicode result In-Reply-To: References: Message-ID: <50494A5E.5010602@mrabarnett.plus.com> On 07/09/2012 01:21, contro opinion wrote: > i eidt a file and save it in gbk encode named test. my system is > :debian,locale,en.utf-8;python2.6,locale,utf-8. > > >

?

> > > in terminal i input: > > xxd test > > 0000000: 3c68 746d 6c3e 0a3c 703e c4e3 3c2f 703e .

..

> 0000010: 0a3c 2f68 746d 6c3e 0a .. > > ? is you in english, > "\xc4\xe3" is the gbk encode of it. > "\xe4\xbd\xe3" is the utf-8 encode of it. > "u\x4f\x60" is the unicode encode of it. > now i parse it in lxml > > >>> "?" > '\xe4\xbd\xa0' > >>> "?".decode("utf-8") > u'\u4f60' > >>> "?".decode("utf-8").encode("gbk") > '\xc4\xe3' > >>> > > code1: > > >>> import lxml.html > >>> root=lxml.html.parse("test") > >>> d=root.xpath("//p") > >>> d[0].text_content() > u'\xc4\xe3' > > in material ,lxml parse file to output the unicode form. > why the d[0].text_content() can not output u'\x4f\x60'? > > code2: > > import codecs > import lxml.html > f = codecs.open('test', 'r', 'gbk') > root=lxml.html.parse(f) > d=root.xpath("//p") > d[0].text_content() > u'\xe4\xbd\xa0' > > why the d[0].text_content() can not output u'\x4f\x60'? > > i am confused by this problem for two days. > You can't just put some text into a file and expect it to know "magically" what the encoding is. You have to specify that the encoding is GBK, something like this (in a file actually encoded as GBK, of course):

?

I hope there's a good reason why you're using that encoding and not UTF-8. From d at davea.name Thu Sep 6 21:18:28 2012 From: d at davea.name (Dave Angel) Date: Thu, 06 Sep 2012 21:18:28 -0400 Subject: os.stat() distorts filenames that end with period (nt.stat()) In-Reply-To: References: Message-ID: <50494B64.7090308@davea.name> On 09/06/2012 08:55 PM, ruck wrote: > (This with Python 2.7.2 on Windows 7) > > os.stat() won't recognize a filename ending in period. > It will ignore trailing periods. > If you ask it about file 'goo...' it will report on file 'goo' > And if 'goo' doesn't exist, os.stat will complain. > > create file goo, then > > >>> os.stat('goo') > nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) > >>> os.stat('goo...') > nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) > > rename goo to "goo...", then, > > >>> os.stat('goo...') > > Traceback (most recent call last): > File "", line 1, in > os.stat('goo...') > WindowsError: [Error 2] The system cannot find the file specified: 'goo...' > > Puzzling, to me at least. > Any comments? > This with Python 2.7.2 on Windows 7. > Is there a workaround? > Thanks, > John FWIW, it seems to work okay here in Linux 11.04, both Python 2.7 and 3.2 -- DaveA From dwightdhutto at gmail.com Thu Sep 6 21:22:36 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Thu, 6 Sep 2012 21:22:36 -0400 Subject: os.stat() distorts filenames that end with period (nt.stat()) In-Reply-To: References: Message-ID: On Thu, Sep 6, 2012 at 8:55 PM, ruck wrote: > (This with Python 2.7.2 on Windows 7) > > os.stat() won't recognize a filename ending in period. > It will ignore trailing periods. > If you ask it about file 'goo...' it will report on file 'goo' > And if 'goo' doesn't exist, os.stat will complain. > > create file goo, then > > >>> os.stat('goo') > nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, > st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, > st_ctime=1346978160L) > >>> os.stat('goo...') > nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, > st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, > st_ctime=1346978160L) > > rename goo to "goo...", then, > > >>> os.stat('goo...') > > Traceback (most recent call last): > File "", line 1, in > os.stat('goo...') > WindowsError: [Error 2] The system cannot find the file specified: > 'goo...' > You can try: the other, then if not there except:mkdirgoo > and obviously, don't use ..., use ___, or something else. It also sems that the file must exist, so did you have a file named 'goo...'? If not, it wouldn't create one, so you would have to, either by manual, or coded by a try/except. Below is how it could go: import os try: os.stat('/home/david/whatever') except: os.mkdir('/home/david/whatever') -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jimmyli1528 at gmail.com Thu Sep 6 21:30:48 2012 From: jimmyli1528 at gmail.com (jimbo1qaz) Date: Thu, 6 Sep 2012 18:30:48 -0700 (PDT) Subject: Bitshifts and "And" vs Floor-division and Modular In-Reply-To: References: Message-ID: On Thursday, September 6, 2012 5:01:12 PM UTC-7, jimbo1qaz wrote: > Is it faster to use bitshifts or floor division? And which is better, & or %? > > All divisors and mods are power of 2, so are binary operations faster? And are they considered bad style? OK, I decided to change my code. Which raises a similar question: Which one is better for setting a bit of a byte: |= or +=, assuming each will only be run once? Intuitively, I think |=, but some timeits are inconclusive, mainly because I don't know how it works. From d at davea.name Thu Sep 6 21:36:54 2012 From: d at davea.name (Dave Angel) Date: Thu, 06 Sep 2012 21:36:54 -0400 Subject: Bitshifts and "And" vs Floor-division and Modular In-Reply-To: References: Message-ID: <50494FB6.7020203@davea.name> On 09/06/2012 08:01 PM, jimbo1qaz wrote: > Is it faster to use bitshifts or floor division? Yes, and yes. Without doing any measurement, I'd expect that in CPython, it makes negligible performance difference for ordinary ints (under 2**31, more or less). Ordinary ints can be done with single instructions, and any such instruction would be a tiny fraction of the opcode overhead. One place were there might be a difference would be for longs. The implementation of those would have to be a loop, and eventually one might be faster than the other. At that point, maybe you'd want to measure. > And which is better, & or %? > All divisors and mods are power of 2, so are binary operations faster? And are they considered bad style? The better way is not the faster one, but rather is the one that more clearly expresses the original problem. If the problem is a modulo one, use % (or frequently divmod). If the problem is a bit shift/masking one, then use such operators. BTW, '/' on integers is redefined for Python 3.x to give float results, and not to truncate. -- DaveA From foo at email.invalid Thu Sep 6 21:40:37 2012 From: foo at email.invalid (Alex) Date: Fri, 7 Sep 2012 01:40:37 +0000 (UTC) Subject: Is there a way to configure IDLE to use spaces instead of tabs for indenting? References: Message-ID: Terry Reedy wrote: [snip] > IDLE is not the interpreter. Fine, I meant shell. Thanks for fixing that for me. > The IDLE Shell is intended mainly for single-line inputs. Maybe it should be limited to that, then. That way stoopid noobs like me don't use it wrong and then use the wrong nomenclature to complain about it. > For more than a three-line compound statement, I use the editor with > a scratchpad file where editing is much easier. Great tip, thanks. That's how I'll do it from now on. From d at davea.name Thu Sep 6 21:46:12 2012 From: d at davea.name (Dave Angel) Date: Thu, 06 Sep 2012 21:46:12 -0400 Subject: Bitshifts and "And" vs Floor-division and Modular In-Reply-To: References: Message-ID: <504951E4.2020102@davea.name> On 09/06/2012 09:30 PM, jimbo1qaz wrote: > On Thursday, September 6, 2012 5:01:12 PM UTC-7, jimbo1qaz wrote: >> Is it faster to use bitshifts or floor division? And which is better, & or %? >> >> All divisors and mods are power of 2, so are binary operations faster? And are they considered bad style? > OK, I decided to change my code. Which raises a similar question: Which one is better for setting a bit of a byte: |= or +=, assuming each will only be run once? Intuitively, I think |=, but some timeits are inconclusive, mainly because I don't know how it works. Maybe i should have been clearer in my message. i don't think you'll find a meaningful difference unless you're doing longs of a few hundred digits. So if the algorithm is to OR on a bit, please use a |= augmented assignment. not only will it ward off probable bugs when you accidentally try to set the bit a second time, but it reads better for the reader of the program. The reader is more important than the compiler. -- DaveA From wuwei23 at gmail.com Thu Sep 6 21:49:43 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 6 Sep 2012 18:49:43 -0700 (PDT) Subject: os.stat() distorts filenames that end with period (nt.stat()) References: Message-ID: <38fdb970-1bf6-4059-9fa6-cf9cf0655aa4@wm7g2000pbc.googlegroups.com> On Sep 7, 10:55?am, ruck wrote: > (This with Python 2.7.2 on Windows 7) > rename goo to "goo...", then, I'm unable to rename any file to have a '...' suffix, are you certain the file exists in the form you think after the rename? From tjreedy at udel.edu Thu Sep 6 21:53:56 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 06 Sep 2012 21:53:56 -0400 Subject: Bitshifts and "And" vs Floor-division and Modular In-Reply-To: References: Message-ID: On 9/6/2012 8:01 PM, jimbo1qaz wrote: > Is it faster to use bitshifts or floor division? And which is better, > & or %? All divisors and mods are power of 2, so are binary > operations faster? And are they considered bad style? Yes, meaningless, yes, and no. I would do what seems sensible to you in the context. -- Terry Jan Reedy From john.ruckstuhl at gmail.com Thu Sep 6 21:54:19 2012 From: john.ruckstuhl at gmail.com (ruck) Date: Thu, 6 Sep 2012 18:54:19 -0700 (PDT) Subject: os.stat() distorts filenames that end with period (nt.stat()) In-Reply-To: References: Message-ID: <55758f3e-3bd5-4b0b-aeb1-6beaa66cd513@googlegroups.com> On Thursday, September 6, 2012 6:19:11 PM UTC-7, Dave Angel wrote: > On 09/06/2012 08:55 PM, ruck wrote: > > > (This with Python 2.7.2 on Windows 7) > > > > > > os.stat() won't recognize a filename ending in period. > > > It will ignore trailing periods. > > > If you ask it about file 'goo...' it will report on file 'goo' > > > And if 'goo' doesn't exist, os.stat will complain. > > > > > > create file goo, then > > > > > > >>> os.stat('goo') > > > nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) > > > >>> os.stat('goo...') > > > nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) > > > > > > rename goo to "goo...", then, > > > > > > >>> os.stat('goo...') > > > > > > Traceback (most recent call last): > > > File "", line 1, in > > > os.stat('goo...') > > > WindowsError: [Error 2] The system cannot find the file specified: 'goo...' > > > > > > Puzzling, to me at least. > > > Any comments? > > > This with Python 2.7.2 on Windows 7. > > > Is there a workaround? > > > Thanks, > > > John > > > > FWIW, it seems to work okay here in Linux 11.04, both Python 2.7 and 3.2 > > > > > > -- > > > > DaveA Thanks, I agree, I expect this is Windows 7 or win32 specific. Also, in creating a test case to demonstrate, I may have clouded my intent. I want to walk() a dir, reporting the output of os.stat() for files below the dir. One of the existing files happens to be named like "goo..." And os.stat('goo...') fails to see the file. I am not trying to rename the file, just hoping to stat an existing file. John From john.ruckstuhl at gmail.com Thu Sep 6 21:54:19 2012 From: john.ruckstuhl at gmail.com (ruck) Date: Thu, 6 Sep 2012 18:54:19 -0700 (PDT) Subject: os.stat() distorts filenames that end with period (nt.stat()) In-Reply-To: References: Message-ID: <55758f3e-3bd5-4b0b-aeb1-6beaa66cd513@googlegroups.com> On Thursday, September 6, 2012 6:19:11 PM UTC-7, Dave Angel wrote: > On 09/06/2012 08:55 PM, ruck wrote: > > > (This with Python 2.7.2 on Windows 7) > > > > > > os.stat() won't recognize a filename ending in period. > > > It will ignore trailing periods. > > > If you ask it about file 'goo...' it will report on file 'goo' > > > And if 'goo' doesn't exist, os.stat will complain. > > > > > > create file goo, then > > > > > > >>> os.stat('goo') > > > nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) > > > >>> os.stat('goo...') > > > nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) > > > > > > rename goo to "goo...", then, > > > > > > >>> os.stat('goo...') > > > > > > Traceback (most recent call last): > > > File "", line 1, in > > > os.stat('goo...') > > > WindowsError: [Error 2] The system cannot find the file specified: 'goo...' > > > > > > Puzzling, to me at least. > > > Any comments? > > > This with Python 2.7.2 on Windows 7. > > > Is there a workaround? > > > Thanks, > > > John > > > > FWIW, it seems to work okay here in Linux 11.04, both Python 2.7 and 3.2 > > > > > > -- > > > > DaveA Thanks, I agree, I expect this is Windows 7 or win32 specific. Also, in creating a test case to demonstrate, I may have clouded my intent. I want to walk() a dir, reporting the output of os.stat() for files below the dir. One of the existing files happens to be named like "goo..." And os.stat('goo...') fails to see the file. I am not trying to rename the file, just hoping to stat an existing file. John From steve+comp.lang.python at pearwood.info Thu Sep 6 22:00:54 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Sep 2012 02:00:54 GMT Subject: Bitshifts and "And" vs Floor-division and Modular References: Message-ID: <50495556$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 06 Sep 2012 17:01:12 -0700, jimbo1qaz wrote: > Is it faster to use bitshifts or floor division? Does it matter? If you ever find yourself writing an application where the difference between 0.0476 microseconds and 0.0473 microseconds matters to you, Python is probably the wrong language. py> from timeit import Timer py> min(Timer('456789 // 8').repeat(repeat=35)) 0.04760909080505371 py> min(Timer('456789 >> 3').repeat(repeat=35)) 0.047319889068603516 > And which is better, & or %? Depends what you want to do. If you want to perform bitwise-and, then I strongly recommend you use &, the bitwise-and operator. If you want to perform modulus, then the modulus operator % is usually better. > All divisors and mods are power of 2, so are binary operations > faster? As the MiddleMan says, "specificity is the soul of all good communication". Python has many binary operations, e.g.: + - * / // % == is < <= > >= ** & ^ | Some of them are faster than some other things, so would you like to be more specific? My *guess* is that you mean *bitwise* operators, compared to numeric operators like * and // (integer division). The runtime cost is mostly dominated by the object-oriented overhead -- Python is not C or assembly, and the integers are rich objects, not low-level bitfields, so the difference between division and bitshifting is much less than you might expect from assembly language. But, in principle at least, there *may* be some tiny advantage to the bitwise operators. I say "may" because the difference is so small that it is likely to be lost in the noise. I do not believe that there will be any real world applications where the difference between the two is significant enough to care about. But if you think different, feel free to use the profile module to profile your code and demonstrate that divisions are a significant bottleneck in your application. > And are they considered bad style? Absolutely. Using & when you mean to take the remainder is a dirty optimization hack only justified if you really, really, really need it. I'm pretty confident that you will never notice a speed-up of the order of 0.1 nanoseconds. "More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason ? including blind stupidity." ? W.A. Wulf "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%. A good programmer will not be lulled into complacency by such reasoning, he will be wise to look carefully at the critical code; but only after that code has been identified" ? Donald Knuth "Bottlenecks occur in surprising places, so don't try to second guess and put in a speed hack until you have proven that's where the bottleneck is." ? Rob Pike "The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet." ? Michael A. Jackson -- Steven From tjreedy at udel.edu Thu Sep 6 22:05:13 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 06 Sep 2012 22:05:13 -0400 Subject: os.stat() distorts filenames that end with period (nt.stat()) In-Reply-To: References: Message-ID: On 9/6/2012 8:55 PM, ruck wrote: > (This with Python 2.7.2 on Windows 7) > > os.stat() won't recognize a filename ending in period. > It will ignore trailing periods. > If you ask it about file 'goo...' it will report on file 'goo' > And if 'goo' doesn't exist, os.stat will complain. > > create file goo, then > > >>> os.stat('goo') > nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) > >>> os.stat('goo...') > nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) > > rename goo to "goo...", then, > > >>> os.stat('goo...') > > Traceback (most recent call last): > File "", line 1, in > os.stat('goo...') > WindowsError: [Error 2] The system cannot find the file specified: 'goo...' > > Puzzling, to me at least. > Any comments? Windows have restrictions on filenames. The restrictions are not consistent in that some parts of Windows will let you make names that other parts do not recognize or regard as illegal. I ran into this some years ago and there may be a discussion on the tracker, but I have forgetten the details except that one of the 'parts' was Windows Explorer. This *might* be what you are running into. -- Terry Jan Reedy From tjreedy at udel.edu Thu Sep 6 22:12:35 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 06 Sep 2012 22:12:35 -0400 Subject: Parsing ISO date/time strings - where did the parser go? In-Reply-To: <5048FD0D.1020400@jollybox.de> References: <5048FD0D.1020400@jollybox.de> Message-ID: On 9/6/2012 3:44 PM, Thomas Jollans wrote: > On 09/06/2012 09:27 PM, John Nagle wrote: >> In Python 2.7: >> >> I want to parse standard ISO date/time strings such as >> >> 2012-09-09T18:00:00-07:00 >> >> into Python "datetime" objects. The "datetime" object offers >> an output method , datetimeobj.isoformat(), but not an input >> parser. There ought to be >> >> classmethod datetime.fromisoformat(s) > > http://docs.python.org/library/datetime.html#datetime.datetime.strptime > > The ISO date/time format is dead simple and well-defined. strptime is > quite suitable. I do not see any example formats. An example for ISO might be a good one. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Thu Sep 6 22:23:51 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Sep 2012 02:23:51 GMT Subject: Bitshifts and "And" vs Floor-division and Modular References: Message-ID: <50495ab6$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 06 Sep 2012 18:30:48 -0700, jimbo1qaz wrote: > OK, I decided to change my code. Which raises a similar question: Which > one is better for setting a bit of a byte: |= or +=, assuming each will > only be run once? Intuitively, I think |= Python (like most languages) doesn't have a "set this bit" operator, so the closest match is a bitwise-or. So to set a bit of a byte, the operation which most closely matches the programmer's intention is to use the bitwise operator. Even better would be to write a function called "setBit", and use that. > but some timeits are inconclusive, Timing results are usually inconclusive because the difference between the results are much smaller than that average random noise on any particular result. All modern computers, say for the last 20 or 30 years, have used multitasking operating systems. This means that at any time you could have dozens, even hundreds, of programs running at once, with the operating system switching between them faster than you can blink. In addition, the time taken by an operation can depend on dozens of external factors, such as whether the data is already in a CPU cache, whether CPU prediction has pre-fetched the instructions needed, pipelines, memory usage, latency when reading from disks, and many others. Consequently, timing results are very *noisy* -- the *exact* same operation can take different amount of time from one run to the next. Sometimes *large* differences. So any time you time a piece of code, what you are *actually* getting is not the amount of time that code takes to execute, but something slightly more. (And, occasionally, something a lot more.) Note that it is always slightly more -- by definition, it will never be less. So if you want a better estimate of the actual time taken to execute the code, you should repeat the measurement as many times as you can bear, and pick the smallest value. *Not* the average, since the errors are always positive. An average just gives you the "true" time plus some unknown average error, which may not be small. The minimum gives you the "true" time plus some unknown but hopefully small error. The smaller the amount of time you measure, the more likely that it will be disrupted by some external factor. So timeit takes a code snippet and runs it many times (by default, one million times), and returns the total time used. Even if one or two of those runs were blown out significantly, the total probably won't be. (Unless of course your anti-virus decided to start running, and *everything* slows down for 10 minutes, or something like that.) But even that total time returned by timeit is almost certainly wrong. So you should call the repeat method, with as many iterations as you can bear to wait for, and take the minimum, which will still be wrong but it will be less wrong. And remember, the result you get is only valid for *your* computer, running the specific version of Python you have, under the specific operating system. On another computer with a different CPU or a different OS, the results may be *completely* different. Are you still sure you care about shaving off every last nanosecond? > mainly because I don't know how it works. The internal details of how timeit works are complicated, but it is worth reading the comments and documentation, both in the Fine Manual and in the source code: http://docs.python.org/library/timeit.html http://hg.python.org/cpython/file/2.7/Lib/timeit.py -- Steven From steve+comp.lang.python at pearwood.info Thu Sep 6 22:32:59 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Sep 2012 02:32:59 GMT Subject: os.stat() distorts filenames that end with period (nt.stat()) References: Message-ID: <50495cdb$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 06 Sep 2012 17:55:02 -0700, ruck wrote: > (This with Python 2.7.2 on Windows 7) > > os.stat() won't recognize a filename ending in period. It will ignore > trailing periods. > If you ask it about file 'goo...' it will report on file 'goo' And if > 'goo' doesn't exist, os.stat will complain. I don't have access to a Windows machine to test this, but I suspect that you have found a side-effect of a Windows bug. http://answers.microsoft.com/en-us/windows/forum/windows_7-files/files-disappear-when-you-append-a-period-to-a/4329b1f1-746e-4c45-9c32-75622b6ab526 http://support.microsoft.com/kb/115827 -- Steven From john.ruckstuhl at gmail.com Thu Sep 6 22:46:13 2012 From: john.ruckstuhl at gmail.com (ruck) Date: Thu, 6 Sep 2012 19:46:13 -0700 (PDT) Subject: os.stat() distorts filenames that end with period (nt.stat()) In-Reply-To: <38fdb970-1bf6-4059-9fa6-cf9cf0655aa4@wm7g2000pbc.googlegroups.com> References: <38fdb970-1bf6-4059-9fa6-cf9cf0655aa4@wm7g2000pbc.googlegroups.com> Message-ID: <1bedf267-e265-4fd6-aaa6-e8643c0bf1fa@googlegroups.com> On Thursday, September 6, 2012 6:49:43 PM UTC-7, alex23 wrote: > On Sep 7, 10:55?am, ruck wrote: > > > (This with Python 2.7.2 on Windows 7) > > > rename goo to "goo...", then, > > > > I'm unable to rename any file to have a '...' suffix, are you certain > > the file exists in the form you think after the rename? I see your point. Using cygwin bash, I have no problem naming files with '...' suffix. But I see you're right, it seems I cannot do so from Windows Explorer or from cmd shell. FWIW, Windows Explorer displays to me that the file is named with '...' suffix. John From ian.g.kelly at gmail.com Thu Sep 6 23:12:01 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 6 Sep 2012 21:12:01 -0600 Subject: os.stat() distorts filenames that end with period (nt.stat()) In-Reply-To: References: Message-ID: On Thu, Sep 6, 2012 at 6:55 PM, ruck wrote: > (This with Python 2.7.2 on Windows 7) > > os.stat() won't recognize a filename ending in period. > It will ignore trailing periods. > If you ask it about file 'goo...' it will report on file 'goo' > And if 'goo' doesn't exist, os.stat will complain. Due to the weirdness of Windows filename extensions, these names refer to the same file. C:\Users\Ian>echo hello > goo C:\Users\Ian>type goo hello C:\Users\Ian>type goo. hello C:\Users\Ian>type goo.. hello C:\Users\Ian>type goo... hello C:\Users\Ian>echo world > goo... C:\Users\Ian>dir goo* Volume in drive C is OS Volume Serial Number is 9881-66F0 Directory of C:\Users\Ian 09/06/2012 09:10 PM 8 goo 1 File(s) 8 bytes 0 Dir(s) 8,884,142,080 bytes free C:\Users\Ian>type goo world From rustompmody at gmail.com Thu Sep 6 23:38:16 2012 From: rustompmody at gmail.com (rusi) Date: Thu, 6 Sep 2012 20:38:16 -0700 (PDT) Subject: Bitshifts and "And" vs Floor-division and Modular References: Message-ID: On Sep 7, 5:01?am, jimbo1qaz wrote: > Is it faster to use bitshifts or floor division? And which is better, & or %? > All divisors and mods are power of 2, so are binary operations faster? And are they considered bad style? On an 8086/8088 a MUL (multiply) instruction was of the order of 100 clocks and a DIV nearly 200 compared to ADD, OR etc which were something like 8 (IIRC -- this is decades-stale knowledge) On most modern processors (after the pentium) the difference has mostly vanished. I cant find a good data sheet to quote though -- one of the sad things about modern processors is that the clocks which were politely offered by intel earlier have now stopped presumably because cache-(in)coherence, pipelining etc are more likely to dominate the number of clocks than the specific instruction. This question is interesting to a programmer but meaningless at the python level (as others have pointed out). If it still interests you, work at the C (or still better assembly) level and use a more finegrained timer measure -- the finest being the RDTSC instruction. From steve+comp.lang.python at pearwood.info Fri Sep 7 00:06:42 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Sep 2012 04:06:42 GMT Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: > On 09/06/2012 04:33 AM, Steven D'Aprano wrote: >> >> >> I may have been overly-conservative earlier when I said that on average >> string equality has to compare half the characters. I thought I had >> remembered that from a computer science textbook, but I can't find that >> reference now, so possibly I was thinking of something else. (String >> searching perhaps?). In any case, the *worst* case for string equality >> testing is certainly O(N) (every character must be looked at), and the >> *best* case is O(1) obviously (the first character fails to match). But >> I'm not so sure about the average case. Further thought is required. > > For random strings (as defined below), the average compare time is > effectively unrelated to the size of the string, once the size passes > some point. Okay, I've spent some time looking for the reference, and can't find it, so I'm now sure I must have been conflating it with something else. After further thought, and giving consideration to the arguments given by people here, I'm now satisfied to say that for equal-length strings, string equality is best described as O(N). 1) If the strings are equal, a == b will always compare all N characters in each string. 2) If the strings are unequal, a == b will *at worst* compare all N characters. 3) Following usual practice in this field, worst case is the one which conventionally is meant when discussing Big Oh behaviour. See, for example, "Introduction To Algorithms" by Cormen, Leiserson and Rivest. Also of some interest is the best case: O(1) for unequal strings (they differ at the first character) and O(N) for equal strings. Also of interest is the case that has caused the majority of the discussion, the average case. I am now satisfied that the average number of comparisons for unequal strings is O(1). To be precise, it is bounded below by 1 comparison (you always have to compare at least one pair of characters) and bounded above by 2 comparisons. (I'm talking about the average here -- the actual number of comparisons can range all the way up to N, but the average is <= 2.) If I've done the maths right, the exact value for the average is: ((M-1)*sum( (N-i)*M**i for i in range(0, N) ) + N)/(M**N) for random strings of length N taken from an alphabet of size M. For M = 2, that average approaches but never exceeds 2 as N increases; for M = 3, the average approaches 1.5, for M = 4 it approaches 1.333... and so forth. Thanks to all who contributed. -- Steven From steve+comp.lang.python at pearwood.info Fri Sep 7 00:07:23 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Sep 2012 04:07:23 GMT Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <504972fb$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 07 Sep 2012 00:39:33 +1000, Chris Angelico wrote: > On Thu, Sep 6, 2012 at 11:37 PM, Johannes Bauer > wrote: >> Not in my original post. If you read it again, you will clearly see >> that I was talking about purely random strings. And since you like to >> nitpick, I'll clarify further: I'm talking about bitstrings in which >> every bit of every character has the same probability of occurence, >> 50%. > > That sort of string isn't a normal thing to be comparing, though. > > Here's an idea. Someone who's doing a lot of arguing in this thread > should take Python, find the string comparison routine, and hack in some > statistics-gathering. Then run *real code* on it. Where's the fun in that? :-P -- Steven From no.email at nospam.invalid Fri Sep 7 00:32:27 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 06 Sep 2012 21:32:27 -0700 Subject: Bitshifts and "And" vs Floor-division and Modular References: Message-ID: <7xwr065u78.fsf@ruckus.brouhaha.com> rusi writes: > On an 8086/8088 a MUL (multiply) instruction was of the order of 100 > clocks ... On most modern processors (after the pentium) the > difference has mostly vanished. I cant find a good data sheet to > quote though See http://www.agner.org/optimize/ : 4. Instruction tables: Lists of instruction latencies, throughputs and micro-operation breakdowns for Intel, AMD and VIA CPUs Multiplication is now fast but DIV is still generally much slower. There are ways to make fast parallel dividers that I think nobody bothers with, because of chip area and because one can often optimize division out of algorithms, replacing most of it with multiplication. Worrying about this sort of micro-optimization in CPython is almost always misplaced, since the interpreter overhead generally swamps any slowness of the machine arithmetic. From john.ruckstuhl at gmail.com Fri Sep 7 01:54:17 2012 From: john.ruckstuhl at gmail.com (ruck) Date: Thu, 6 Sep 2012 22:54:17 -0700 (PDT) Subject: os.stat() distorts filenames that end with period (nt.stat()) In-Reply-To: References: Message-ID: <7b4abe23-d2fc-4497-ac8f-c63bad4e2ac5@googlegroups.com> On Thursday, September 6, 2012 7:05:39 PM UTC-7, Terry Reedy wrote: > On 9/6/2012 8:55 PM, ruck wrote: > > > (This with Python 2.7.2 on Windows 7) > > > > > > os.stat() won't recognize a filename ending in period. > > > It will ignore trailing periods. > > > If you ask it about file 'goo...' it will report on file 'goo' > > > And if 'goo' doesn't exist, os.stat will complain. > > > > > > create file goo, then > > > > > > >>> os.stat('goo') > > > nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) > > > >>> os.stat('goo...') > > > nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) > > > > > > rename goo to "goo...", then, > > > > > > >>> os.stat('goo...') > > > > > > Traceback (most recent call last): > > > File "", line 1, in > > > os.stat('goo...') > > > WindowsError: [Error 2] The system cannot find the file specified: 'goo...' > > > > > > Puzzling, to me at least. > > > Any comments? > > > > Windows have restrictions on filenames. The restrictions are not > > consistent in that some parts of Windows will let you make names that > > other parts do not recognize or regard as illegal. I ran into this some > > years ago and there may be a discussion on the tracker, but I have > > forgetten the details except that one of the 'parts' was Windows > > Explorer. This *might* be what you are running into. > > > > -- > > Terry Jan Reedy Summary: I was complaining that >>> os.stat('goo...') Traceback (most recent call last): File "", line 1, in os.stat('goo...') WindowsError: [Error 2] The system cannot find the file specified: 'goo...' is actually looking for file 'goo' instead of the existing file 'goo...' -- that's why it errors. (Python 2.7.2, Windows 7) Here's a workaround. >>> os.stat('\\\\?\\' + os.getcwd() + '\\' + 'goo...') nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) In other words, prefix the path (full path?) with \\?\ to disable the Windows API filename interceptions. Detail: "Naming Files, Paths, and Namespaces" ( http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx ) says Naming Conventions The following fundamental rules enable applications to create and process valid names for files and directories, regardless of the file system: * Do not end a file or directory name with a space or a period. Although the underlying file system may support such names, the Windows shell and user interface does not. In my case, the filesystem is NTFS and it does support filenames like 'goo...', and I'm not trying to use Windows shell or UI. So how do I get to the underlying filesystem without interference? Here (from the same reference) Namespaces There are two main categories of namespace conventions used in the Windows APIs, commonly referred to as NT namespaces and the Win32 namespaces. ... Win32 File Namespaces The Win32 namespace prefixing and conventions are summarized in this section and the following section, with descriptions of how they are used. Note that these examples are intended for use with the Windows API functions and do not all necessarily work with Windows shell applications such as Windows Explorer. For this reason there is a wider range of possible paths than is usually available from Windows shell applications, and Windows applications that take advantage of this can be developed using these namespace conventions. For file I/O, the "\\?\" prefix to a path string tells the Windows APIs to disable all string parsing and to send the string that follows it straight to the file system. For example, if the file system supports large paths and file names, you can exceed the MAX_PATH limits that are otherwise enforced by the Windows APIs. Thanks all for your comments and pointers. John From john.ruckstuhl at gmail.com Fri Sep 7 01:54:17 2012 From: john.ruckstuhl at gmail.com (ruck) Date: Thu, 6 Sep 2012 22:54:17 -0700 (PDT) Subject: os.stat() distorts filenames that end with period (nt.stat()) In-Reply-To: References: Message-ID: <7b4abe23-d2fc-4497-ac8f-c63bad4e2ac5@googlegroups.com> On Thursday, September 6, 2012 7:05:39 PM UTC-7, Terry Reedy wrote: > On 9/6/2012 8:55 PM, ruck wrote: > > > (This with Python 2.7.2 on Windows 7) > > > > > > os.stat() won't recognize a filename ending in period. > > > It will ignore trailing periods. > > > If you ask it about file 'goo...' it will report on file 'goo' > > > And if 'goo' doesn't exist, os.stat will complain. > > > > > > create file goo, then > > > > > > >>> os.stat('goo') > > > nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) > > > >>> os.stat('goo...') > > > nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) > > > > > > rename goo to "goo...", then, > > > > > > >>> os.stat('goo...') > > > > > > Traceback (most recent call last): > > > File "", line 1, in > > > os.stat('goo...') > > > WindowsError: [Error 2] The system cannot find the file specified: 'goo...' > > > > > > Puzzling, to me at least. > > > Any comments? > > > > Windows have restrictions on filenames. The restrictions are not > > consistent in that some parts of Windows will let you make names that > > other parts do not recognize or regard as illegal. I ran into this some > > years ago and there may be a discussion on the tracker, but I have > > forgetten the details except that one of the 'parts' was Windows > > Explorer. This *might* be what you are running into. > > > > -- > > Terry Jan Reedy Summary: I was complaining that >>> os.stat('goo...') Traceback (most recent call last): File "", line 1, in os.stat('goo...') WindowsError: [Error 2] The system cannot find the file specified: 'goo...' is actually looking for file 'goo' instead of the existing file 'goo...' -- that's why it errors. (Python 2.7.2, Windows 7) Here's a workaround. >>> os.stat('\\\\?\\' + os.getcwd() + '\\' + 'goo...') nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1346978160L, st_mtime=1346978160L, st_ctime=1346978160L) In other words, prefix the path (full path?) with \\?\ to disable the Windows API filename interceptions. Detail: "Naming Files, Paths, and Namespaces" ( http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx ) says Naming Conventions The following fundamental rules enable applications to create and process valid names for files and directories, regardless of the file system: * Do not end a file or directory name with a space or a period. Although the underlying file system may support such names, the Windows shell and user interface does not. In my case, the filesystem is NTFS and it does support filenames like 'goo...', and I'm not trying to use Windows shell or UI. So how do I get to the underlying filesystem without interference? Here (from the same reference) Namespaces There are two main categories of namespace conventions used in the Windows APIs, commonly referred to as NT namespaces and the Win32 namespaces. ... Win32 File Namespaces The Win32 namespace prefixing and conventions are summarized in this section and the following section, with descriptions of how they are used. Note that these examples are intended for use with the Windows API functions and do not all necessarily work with Windows shell applications such as Windows Explorer. For this reason there is a wider range of possible paths than is usually available from Windows shell applications, and Windows applications that take advantage of this can be developed using these namespace conventions. For file I/O, the "\\?\" prefix to a path string tells the Windows APIs to disable all string parsing and to send the string that follows it straight to the file system. For example, if the file system supports large paths and file names, you can exceed the MAX_PATH limits that are otherwise enforced by the Windows APIs. Thanks all for your comments and pointers. John From hansmu at xs4all.nl Fri Sep 7 05:37:28 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 07 Sep 2012 11:37:28 +0200 Subject: How to print something only if it exists? In-Reply-To: <9s4nh9-8dr.ln1@chris.zbmc.eu> References: <9s4nh9-8dr.ln1@chris.zbmc.eu> Message-ID: <5049c059$0$6936$e4fe514c@news2.news.xs4all.nl> On 6/09/12 19:59:05, tinnews at isbd.co.uk wrote: > I want to print a series of list elements some of which may not exist, > e.g. I have a line:- > > print day, fld[1], balance, fld[2] > > fld[2] doesn't always exist (fld is the result of a split) so the > print fails when it isn't set. How about: print day, fld[1], balance, fld[2] if len(fld) > 2 else '' If you really want to avoid the keyword 'if', then you'd have to do something like: print day, fld[1], balance, (fld[2:3] or [''])[0] That may be shorter, but it isn't very readable. Hope this helps, -- HansM From chandraganeshchowdary at gmail.com Fri Sep 7 08:05:29 2012 From: chandraganeshchowdary at gmail.com (chandraganeshchowdary at gmail.com) Date: Fri, 7 Sep 2012 05:05:29 -0700 (PDT) Subject: Python newbie here! No module named settings In-Reply-To: <1ce00c77-35ae-4499-adff-bafadab80aa5@x38g2000pri.googlegroups.com> References: <1ce00c77-35ae-4499-adff-bafadab80aa5@x38g2000pri.googlegroups.com> Message-ID: <983415eb-d238-439c-8640-eb95dce1814c@googlegroups.com> On Thursday, June 2, 2011 8:59:48 PM UTC+5:30, Neeraj Agarwal wrote: > Hello all, > > I'm a newbie to Python and its my 2nd day exploring it. > > I was trying to use Python wrapper for Google Charts API and was > tweaking the examples. > https://github.com/gak/pygooglechart/raw/master/examples/pie.py > > This is the script which I was trying. > > And the python interpreter gives the following error: > import settings > ImportError: No module named settings > > I installed Django as well before this (if its causing the problem, > dunno) > > Please help me. > > Thanks, > Neeraj hi neeraj, I am also experiencing the same problem and in my pygooglechart file i am not having both settings.py and __init__.py file so can you send me the link from where you downloaded api Best Regards, ganesh From rosuav at gmail.com Fri Sep 7 08:15:42 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Sep 2012 22:15:42 +1000 Subject: Accessing dll In-Reply-To: <02c28de7-e672-4850-b684-d2cb4e3128b6@fm12g2000vbb.googlegroups.com> References: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> <02c28de7-e672-4850-b684-d2cb4e3128b6@fm12g2000vbb.googlegroups.com> Message-ID: On Fri, Sep 7, 2012 at 1:44 AM, Helpful person wrote: > FYI > > My Python version is 2.5.4 You may wish to upgrade, that's quite an old version. Unless something's binding you to version 2.x, I would strongly recommend migrating to 3.2 or 3.3. ChrisA From ramyasri20 at gmail.com Fri Sep 7 08:53:04 2012 From: ramyasri20 at gmail.com (Ramyasri Dodla) Date: Fri, 7 Sep 2012 08:53:04 -0400 Subject: Division help in python Message-ID: Hi All, I am brand new to python. checking over basic stuff. I came across the problem while doing so. If any body aware of the problem, kindly respond me. >>> 5/10 0 >>> - 5/10 -1 The second case also should yield a 'zero' but it is giving a -1 some other examples for your review. >>> -10/5 -2 >>> -5/-5 1 >>> 1/2 0 >>> -1/2 -1 >>> -1 /4 -1 I would be thankful to you if i got through this. Ramya -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Sep 7 09:06:19 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Sep 2012 23:06:19 +1000 Subject: Division help in python In-Reply-To: References: Message-ID: On Fri, Sep 7, 2012 at 10:53 PM, Ramyasri Dodla wrote: > I am brand new to python. checking over basic stuff. I came across the > problem while doing so. If any body aware of the problem, kindly respond me. > >>>> 5/10 > 0 >>>> - 5/10 > -1 > > The second case also should yield a 'zero' but it is giving a -1 You're clearly using Python 2, because in Python 3, the / operator will return a float instead (so these would return 0.5 and -0.5 respectively). But it's helpful to mention what Python version you're using when you ask for help :) The reason for this is that / (or in Python 3, //) rounds toward negative infinity, not toward zero. This allows the modulo operator (%) to return a positive number, while still maintaining the normal expectation that: (x//y)*y + (x%y) == x for any two integers x and y. Hope that helps! ChrisA From roy at panix.com Fri Sep 7 09:16:55 2012 From: roy at panix.com (Roy Smith) Date: Fri, 07 Sep 2012 09:16:55 -0400 Subject: How to print something only if it exists? References: <9s4nh9-8dr.ln1@chris.zbmc.eu> Message-ID: In article <9s4nh9-8dr.ln1 at chris.zbmc.eu>, tinnews at isbd.co.uk wrote: > I want to print a series of list elements some of which may not exist, > e.g. I have a line:- > > print day, fld[1], balance, fld[2] > > fld[2] doesn't always exist (fld is the result of a split) so the > print fails when it isn't set. > > I know I could simply use an if but ultimately there may be more > elements of fld in the print and the print may well become more > complex (most like will be formatted for example). Thus it would be > good if there was some way to say "print this if it exists". One possible way is a trick I've used in the past. fld = split(...) + ['']*10 this guarantees that fld has at least 10 elements. If you want to guarantee that fld has *exactly* 10 elements, just take [0:10] of that. From breamoreboy at yahoo.co.uk Fri Sep 7 09:24:13 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 07 Sep 2012 14:24:13 +0100 Subject: Bitshifts and "And" vs Floor-division and Modular In-Reply-To: <20120907010830.GA25508@cskk.homeip.net> References: <20120907010830.GA25508@cskk.homeip.net> Message-ID: On 07/09/2012 02:08, Cameron Simpson wrote: > On 07Sep2012 01:30, Mark Lawrence wrote: > | On 07/09/2012 01:01, jimbo1qaz wrote: > | > Is it faster to use bitshifts or floor division? And which is better, & or %? > | > All divisors and mods are power of 2, so are binary operations faster? And are they considered bad style? > | > | Why don't you use the timeit module and find out for yourself? > > Because timeit doesn't output style advice? > Because timeit won't offer even a short single parapgraph description > of how python ints (even just in CPython) are implemented and how that > may affect performance in general? > > To the OP: personally, I would suggest using % when I am thinking of > division and a bit shift when I am thinking of a bitshift, and only reach > for timeit when performance becomes an issue. Code for the algoritm, > and only optimise later. > > Of course only a well run benchmark will measure the real world, but it > possible to address his other questions in a helpful fashion and address > the benchmark question in a less offputting tone. If you can't be > bothered, please don't. (Especially since these irritating posts from > you are usually in response to a post you feel could have used more > effort from the OP.) > > Nobody answers all performance considerations or design choices with an > exhaustive timeit benchmark, and it is silly to suggest so. It is > helpful for people to have a mental model of the python internals > so they can make often-sensible choices from the start. > > So try being helpful instead of slapping people down when they haven't > reached your private bar. > > Cheers, > I'm sorry but I refuse point blank to spoon feed, fit bibs and change nappies. I wouldn't do that on the tutor mailing list and I certainly wouldn't do it here. If any OP is too bone idle to do some research and then pose a sensible question relating to what they want to achieve, what they've done to achieve it and what issues they've got then I intend responding in the same way. Clearly your approach is different so we'll have to agree to disagree. -- Cheers. Mark Lawrence. From mgwhitman at gmail.com Fri Sep 7 09:42:20 2012 From: mgwhitman at gmail.com (M Whitman) Date: Fri, 7 Sep 2012 06:42:20 -0700 (PDT) Subject: Defining features in a list Message-ID: Good Morning, I have been recently trying to define all of the features in a list but have been running into errors. I would like to define the features similar to the following print statement. Any advice would be appreciated. I'm trying to transition my output from a text file to excel and if I can loop through my lists and define them that transition will be cleaner. Many Thanks, -Matt #Author: MGW #2012 import os, datetime, sys, arcpy, xlrd from arcpy import env submission = "Rev.mdb" env.workspace = "C:/temp/"+submission+"/Water" #Get Submission totals fclist = sorted(arcpy.ListFeatureClasses("*")) for fc in fclist: print fc+"="+str(arcpy.GetCount_management(fc).getOutput(0)) print "Complete" raw_input("Press ENTER to close this window") Output Generated WATER_Net_Junctions=312 WS_Hyd=484 WS_Mains=2752 WS_Node=4722 WS_Vlvs=1078 WS_WatLats=3661 WS_WatMtrs=3662 WTRPLANTS_points=0 WTRPUMPSTA_points=0 WTRTANKS=0 WTR_ARV=10 WTR_MISC=0 Complete Press ENTER to close this window #Get Submission totals fclist = sorted(arcpy.ListFeatureClasses("*")) for fc in fclist: fc=str(arcpy.GetCount_management(fc).getOutput(0)) #TEST print WS_Hyd print "Complete" raw_input("Press ENTER to close this window") Output Generated Traceback (most recent call last): File "C:\Documents and Settings\mattheww\Desktop\Copy of QAQCexce_2.py", line 14, in print WS_Hyd NameError: name 'WS_Hyd' is not defined From invalid at invalid.invalid Fri Sep 7 10:19:07 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 7 Sep 2012 14:19:07 +0000 (UTC) Subject: Bitshifts and "And" vs Floor-division and Modular References: <50495556$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-09-07, Steven D'Aprano wrote: > My *guess* is that you mean *bitwise* operators, compared to numeric > operators like * and // (integer division). The runtime cost is mostly > dominated by the object-oriented overhead -- Python is not C or assembly, > and the integers are rich objects, not low-level bitfields, so the > difference between division and bitshifting is much less than you might > expect from assembly language. I don't suppose there's much of a chance that the OP is running Python on a CPU that doesn't have an integer divide instruction? If that _were_ the case, the difference would be more noticable, but would still probably not worth worrying about unless a truely huge number of operations were being done in a very tight loop with no intervening I/O operations. -- Grant Edwards grant.b.edwards Yow! I have accepted at Provolone into my life! gmail.com From laddosingh at gmail.com Fri Sep 7 10:23:15 2012 From: laddosingh at gmail.com (Tigerstyle) Date: Fri, 7 Sep 2012 07:23:15 -0700 (PDT) Subject: Function for examine content of directory In-Reply-To: References: Message-ID: <1eb7dbea-cff5-4038-a441-d22707a4a7de@googlegroups.com> kl. 16:56:29 UTC+2 torsdag 6. september 2012 skrev Tigerstyle f?lgende: > Hi guys, > > > > I'm trying to write a module containing a function to examine the contents of the current working directory and print out a count of how many files have each extension (".txt", ".doc", etc.) > > > > This is the code so far: > > -- > > import os > > > > path = "v:\\workspace\\Python2_Homework03\\src\\" > > dirs = os.listdir( path ) > > filenames = {"this.txt", "that.txt", "the_other.txt","this.doc","that.doc","this.pdf","first.txt","that.pdf"} > > extensions = [] > > for filename in filenames: > > f = open(filename, "w") > > f.write("Some text\n") > > f.close() > > name , ext = os.path.splitext(f.name) > > extensions.append(ext) > > > > # This would print all the files and directories > > for file in dirs: > > print(file) > > > > for ext in extensions: > > print("Count for %s: " %ext, extensions.count(ext)) > > > > -- > > > > When I'm trying to get the module to print how many files each extension has, it prints the count of each ext multiple times for each extension type. Like this: > > > > this.pdf > > the_other.txt > > this.doc > > that.txt > > this.txt > > that.pdf > > first.txt > > that.doc > > Count for .pdf: 2 > > Count for .txt: 4 > > Count for .doc: 2 > > Count for .txt: 4 > > Count for .txt: 4 > > Count for .pdf: 2 > > Count for .txt: 4 > > Count for .doc: 2 > > > > Any help is appreciated. > > > > T From laddosingh at gmail.com Fri Sep 7 10:28:03 2012 From: laddosingh at gmail.com (Tigerstyle) Date: Fri, 7 Sep 2012 07:28:03 -0700 (PDT) Subject: Function for examine content of directory In-Reply-To: References: Message-ID: Ok I'm now totally stuck. This is the code: --- import os from collections import Counter path = ":c\\mypath\dir" dirs = os.listdir( path ) filenames = {"this.txt", "that.txt", "the_other.txt","this.doc","that.doc","this.pdf","first.txt","that.pdf"} extensions = [] for filename in filenames: f = open(filename, "w") f.write("Some text\n") f.close() name , ext = os.path.splitext(f.name) extensions.append(ext) # This would print all the files and directories for file in dirs: print(file) for ext, count in Counter(extensions).items(): print("Count for %s: " % ext, count) --- I need to make this module into a function and write a separate module to verify by testing that the function gives correct results. Help and pointers are much appreciated. T From d at davea.name Fri Sep 7 10:35:17 2012 From: d at davea.name (Dave Angel) Date: Fri, 07 Sep 2012 10:35:17 -0400 Subject: Defining features in a list In-Reply-To: References: Message-ID: <504A0625.1090403@davea.name> On 09/07/2012 09:42 AM, M Whitman wrote: > Good Morning, > > I have been recently trying to define all of the features in a list but have been running into errors. How proficient are you in Python? Could you possibly use terms which make sense to someone who doesn't know this arcGIS program? I'm just making a wild guess that that's what you're importing with the arcpy import. When I do an internet search on arcpy, I see lots of tutorials, training, etc. I didn't find a mailing list, but there probably is one. The term that needs translating is "feature.' > I would like to define the features similar to the following print statement. Any advice would be appreciated. I'm trying to transition my output from a text file to excel and if I can loop through my lists and define them that transition will be cleaner. > > Many Thanks, > > -Matt > > #Author: MGW > #2012 > import os, datetime, sys, arcpy, xlrd > from arcpy import env > submission = "Rev.mdb" > env.workspace = "C:/temp/"+submission+"/Water" > > #Get Submission totals > fclist = sorted(arcpy.ListFeatureClasses("*")) > for fc in fclist: > print fc+"="+str(arcpy.GetCount_management(fc).getOutput(0)) > > print "Complete" > raw_input("Press ENTER to close this window") > > Output Generated > WATER_Net_Junctions=312 > WS_Hyd=484 > WS_Mains=2752 > WS_Node=4722 > WS_Vlvs=1078 > WS_WatLats=3661 > WS_WatMtrs=3662 > WTRPLANTS_points=0 > WTRPUMPSTA_points=0 > WTRTANKS=0 > WTR_ARV=10 > WTR_MISC=0 > Complete > Press ENTER to close this window > > #Get Submission totals > fclist = sorted(arcpy.ListFeatureClasses("*")) > for fc in fclist: > fc=str(arcpy.GetCount_management(fc).getOutput(0)) > #TEST > print WS_Hyd > There's no variable WS_Hyd, so what did you expect it to do? Do you want to be able to fetch the values by name that were printed above? if so, I'd suggest a dict, not a list. Lists don't have names for each element, just indices. > > > print "Complete" > raw_input("Press ENTER to close this window") > > Output Generated > Traceback (most recent call last): > File "C:\Documents and Settings\mattheww\Desktop\Copy of QAQCexce_2.py", line 14, in > print WS_Hyd > NameError: name 'WS_Hyd' is not defined As a very rough start, perhaps you could try something like this. Remember i don't have the docs, so the only clue I've got is the stuff you printed from the first loop. table = {} fclist = sorted(arcpy.ListFeatureClasses("*")) for fc in fclist: table[fc] = +str(arcpy.GetCount_management(fc).getOutput(0)) Now, if you want to print the value for WS_Hyd, it should be available as print "value = ", table["WS_Hyd"] If you're sufficiently advanced, i could suggest a class-based solution where you'd access items by mytable.WS_Hyd But if you're not yet familiar with class definition and attributes and such, we'd better not go there. -- DaveA From mgwhitman at gmail.com Fri Sep 7 11:21:50 2012 From: mgwhitman at gmail.com (M Whitman) Date: Fri, 7 Sep 2012 08:21:50 -0700 (PDT) Subject: Defining features in a list In-Reply-To: References: Message-ID: Dave- By features I was refering to items in the list. For background the arcpy module is used for geoprocessing of geographic information. I'm using my script to get totals for features in a dataset that I receive on a regular basis- for example total number of hydrants, total number of hydrants with null or missing attributes, and total number of hydrants with outlining attributes. I am experienced particularly with the arcpy module and I am trying deligently to become more experienced with Python in general. My goal is to fetch values by name and then print output by name. print WS_Hyd and then see "484". I have some experience with class definition but a dictionary might be the way to go. I was understanding the response of the Arcpy module but hadn't understood why the list wasn't being defined in my previous loop statement. I appreciate the response. I will look into dict if you have a class definition suggestion I will run with that. Thanks From jeanmichel at sequans.com Fri Sep 7 11:47:28 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 07 Sep 2012 17:47:28 +0200 Subject: Defining features in a list In-Reply-To: References: Message-ID: <504A1710.4070800@sequans.com> M Whitman wrote: > Good Morning, > > I have been recently trying to define all of the features in a list but have been running into errors. I would like to define the features similar to the following print statement. Any advice would be appreciated. I'm trying to transition my output from a text file to excel and if I can loop through my lists and define them that transition will be cleaner. > > Many Thanks, > > -Matt > > #Author: MGW > #2012 > import os, datetime, sys, arcpy, xlrd > from arcpy import env > submission = "Rev.mdb" > env.workspace = "C:/temp/"+submission+"/Water" > > #Get Submission totals > fclist = sorted(arcpy.ListFeatureClasses("*")) > for fc in fclist: > print fc+"="+str(arcpy.GetCount_management(fc).getOutput(0)) > > print "Complete" > raw_input("Press ENTER to close this window") > > Output Generated > WATER_Net_Junctions=312 > WS_Hyd=484 > WS_Mains=2752 > WS_Node=4722 > WS_Vlvs=1078 > WS_WatLats=3661 > WS_WatMtrs=3662 > WTRPLANTS_points=0 > WTRPUMPSTA_points=0 > WTRTANKS=0 > WTR_ARV=10 > WTR_MISC=0 > Complete > Press ENTER to close this window > > #Get Submission totals > fclist = sorted(arcpy.ListFeatureClasses("*")) > for fc in fclist: > fc=str(arcpy.GetCount_management(fc).getOutput(0)) > #TEST > print WS_Hyd > > > print "Complete" > raw_input("Press ENTER to close this window") > > Output Generated > Traceback (most recent call last): > File "C:\Documents and Settings\mattheww\Desktop\Copy of QAQCexce_2.py", line 14, in > print WS_Hyd > NameError: name 'WS_Hyd' is not defined > I'm not sure I've understood everything, is this something you're searching for: fcDict = dict([(str(fc), str(arcpy.GetCount_management(fc).getOutput(0))) ) for fc in sorted(arcpy.ListFeatureClasses("*")) ]) print fcDict print fcDict['WS_Hyd'] This is difficult to read because of the online statement, but it does basically the following pseudo code: fcDict = dict([(feature.name, feature.value) for feature in featureList ]) Cheers, JM From d at davea.name Fri Sep 7 11:55:02 2012 From: d at davea.name (Dave Angel) Date: Fri, 07 Sep 2012 11:55:02 -0400 Subject: Defining features in a list In-Reply-To: References: Message-ID: <504A18D6.4020704@davea.name> On 09/07/2012 11:21 AM, M Whitman wrote: > Dave- By features I was refering to items in the list. For background the arcpy module is used for geoprocessing of geographic information. I'm using my script to get totals for features in a dataset that I receive on a regular basis- for example total number of hydrants, total number of hydrants with null or missing attributes, and total number of hydrants with outlining attributes. > > I am experienced particularly with the arcpy module and I am trying deligently to become more experienced with Python in general. My goal is to fetch values by name and then print output by name. print WS_Hyd and then see "484". I have some experience with class definition but a dictionary might be the way to go. I was understanding the response of the Arcpy module but hadn't understood why the list wasn't being defined in my previous loop statement. There is a list fclist being defined, just before the loop. But that list contains the names of the "features" not the values. So if you wanted, you could make a second list containing the values, or you could even make a list containing tuples with name & value. But assuming there's no particular ordering you care about, that's what a dictionary is good at. In either case that loop is not creating extra variables with names like WS_Hyd. Creating variables with arbitrary names from data can only be done with code that's dangerous and prone to injection attacks. You can avoid the problem by putting them in some namespace, either a dictionary, or a namedtuple, or a custom class. > I appreciate the response. I will look into dict if you have a class definition suggestion I will run with that. Thanks Anyway, once you have the dictionary, you can indeed work on the values in it, in various ways. table = {} fclist = sorted(arcpy.ListFeatureClasses("*")) for fc in fclist: table[fc] = +str(arcpy.GetCount_management(fc).getOutput(0)) Now you can use your captured data to do further processing. Simplest example printing. Suppose order doesn't matter: for key in table.iterkeys(): print key, "=", table[key] You could also do this as: for key, value in table.iteritems(): print key, "=", value If you want them in the original order, you can use your fclist, which is a list of keys: for key in fclist: print key, "=", table[key] And of course if you want any particular one, you can do print table["WS_hyd"] Note that in the last case, if you typed the literal key wrong, or if the arcpy removed or renamed one of the keys, you'd get an exception there. To avoid that, you might do something like: key = "WS_hyd" if key in table: print table[key] -- DaveA From jeanmichel at sequans.com Fri Sep 7 12:19:17 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 07 Sep 2012 18:19:17 +0200 Subject: Division help in python In-Reply-To: References: Message-ID: <504A1E85.6020508@sequans.com> Ramyasri Dodla wrote: > Hi All, > > I am brand new to python. checking over basic stuff. I came across the > problem while doing so. If any body aware of the problem, kindly > respond me. > > >>> 5/10 > 0 > >>> - 5/10 > -1 > > The second case also should yield a 'zero' but it is giving a -1 > Why should it yield 'zero' ? The definition of the euclidean division : (http://en.wikipedia.org/wiki/Euclidean_division) a = b*q +r with 0? r < |b| With the constraint of r being a positive integer, the couple (q, r) is unique: with a=-5, b=10 -5 = 10*-1 + 5 (q=-1, r=+5) Note that for the strict Euclidean division, I mean the one allowing r to be negative, then -5 = 10*0 - 5 (q=0, r=-5) is also valid, but I there's still no reason to state that it SHOULD be prefered over the other solution. The uniqueness of the solution for the 1st definition is probably what makes python yield -1 instead of 0. Cheers, JM From rustompmody at gmail.com Fri Sep 7 12:59:17 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 7 Sep 2012 09:59:17 -0700 (PDT) Subject: Bitshifts and "And" vs Floor-division and Modular References: <7xwr065u78.fsf@ruckus.brouhaha.com> Message-ID: <7295a1ce-f89b-4fba-bcc7-1e23135f25a7@v9g2000pbu.googlegroups.com> On Sep 7, 9:32?am, Paul Rubin wrote: > rusi writes: > > On an 8086/8088 a MUL (multiply) instruction was of the order of 100 > > clocks ... ?On most modern processors (after the pentium) the > > difference has mostly vanished. ?I cant find a good data sheet to > > quote though > > See http://www.agner.org/optimize/: Hey Thanks! Seems like a nice resource! How on earth does he come up with the data though, when Intel does not publish it? From d at davea.name Fri Sep 7 13:12:24 2012 From: d at davea.name (Dave Angel) Date: Fri, 07 Sep 2012 13:12:24 -0400 Subject: Bitshifts and "And" vs Floor-division and Modular In-Reply-To: <7295a1ce-f89b-4fba-bcc7-1e23135f25a7@v9g2000pbu.googlegroups.com> References: <7xwr065u78.fsf@ruckus.brouhaha.com> <7295a1ce-f89b-4fba-bcc7-1e23135f25a7@v9g2000pbu.googlegroups.com> Message-ID: <504A2AF8.4080909@davea.name> On 09/07/2012 12:59 PM, rusi wrote: > On Sep 7, 9:32 am, Paul Rubin wrote: >> rusi writes: >>> On an 8086/8088 a MUL (multiply) instruction was of the order of 100 >>> clocks ... On most modern processors (after the pentium) the >>> difference has mostly vanished. I cant find a good data sheet to >>> quote though >> See http://www.agner.org/optimize/: > Hey Thanks! Seems like a nice resource! How on earth does he come up > with the data though, when Intel does not publish it? As he says on the home page, he measured the data himself. Unclear how repeatable such data may be, either due to environment or to multiple versions of the processor, and from two vendors. -- DaveA From rrllff at yahoo.com Fri Sep 7 13:27:43 2012 From: rrllff at yahoo.com (Helpful person) Date: Fri, 7 Sep 2012 10:27:43 -0700 (PDT) Subject: Accessing dll References: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> <02c28de7-e672-4850-b684-d2cb4e3128b6@fm12g2000vbb.googlegroups.com> Message-ID: <5b2b86a1-7fb5-4db9-be6a-4b720af936f2@d7g2000vbv.googlegroups.com> On Sep 7, 5:16?am, Chris Angelico wrote: > On Fri, Sep 7, 2012 at 1:44 AM, Helpful person wrote: > > FYI > > > My Python version is 2.5.4 > > You may wish to upgrade, that's quite an old version. Unless > something's binding you to version 2.x, I would strongly recommend > migrating to 3.2 or 3.3. > > ChrisA Upgrading is not possible due to the large number of programs using the early version. From travisgriggs at gmail.com Fri Sep 7 13:56:15 2012 From: travisgriggs at gmail.com (Travis Griggs) Date: Fri, 7 Sep 2012 10:56:15 -0700 Subject: Reusable (local) Modules Message-ID: <01D5A43C-4E12-410C-9D40-7DDFCA0867E4@gmail.com> I'm relatively new to Python (coming from strong C and Smalltalk backgrounds). I've written a couple of relatively small apps (one or two .py files). I'm using PyCharm (I love it). I'm curious what the pythonic approach is to creating your own reusable modules. Any tutorials or high level explanations, or detailed, much appreciated. For example, I have a small module called valvenumbers.py. It's a family of functions that we use to do a variety of things with the serial numbers we attach to some of our products. Now I'm making a little desktop app using wxpython, and I want to use (import) that module. Using PyCharm, I have two separate projects in sibling directories. And there's another separate command line tool that wants to do the same. Currently, I just place a symlink to the valvenumbers.py, local to the directory of these apps. This seems like "the quickest thing that could possibly work", but I'm assuming there's a more pythonic way to approach this general problem. TIA! Travis Griggs "Simplicity is the ultimate sophistication." -- Leonardo Da Vinci From d at davea.name Fri Sep 7 14:09:30 2012 From: d at davea.name (Dave Angel) Date: Fri, 07 Sep 2012 14:09:30 -0400 Subject: Reusable (local) Modules In-Reply-To: <01D5A43C-4E12-410C-9D40-7DDFCA0867E4@gmail.com> References: <01D5A43C-4E12-410C-9D40-7DDFCA0867E4@gmail.com> Message-ID: <504A385A.50905@davea.name> On 09/07/2012 01:56 PM, Travis Griggs wrote: > I'm relatively new to Python (coming from strong C and Smalltalk backgrounds). I've written a couple of relatively small apps (one or two .py files). I'm using PyCharm (I love it). > > I'm curious what the pythonic approach is to creating your own reusable modules. Any tutorials or high level explanations, or detailed, much appreciated. > > For example, I have a small module called valvenumbers.py. It's a family of functions that we use to do a variety of things with the serial numbers we attach to some of our products. Now I'm making a little desktop app using wxpython, and I want to use (import) that module. Using PyCharm, I have two separate projects in sibling directories. And there's another separate command line tool that wants to do the same. Currently, I just place a symlink to the valvenumbers.py, local to the directory of these apps. This seems like "the quickest thing that could possibly work", but I'm assuming there's a more pythonic way to approach this general problem. > > TIA! > > Travis Griggs > "Simplicity is the ultimate sophistication." -- Leonardo Da Vinci > import sys print sys.path This will show you your path for imports. The actual directories change by default with different python versions, but one of them will be suitable for putting new modules to be imported. Naturally, you don't want to add to the place where the stdlib is placed, but some of those are normal writable directories. -- DaveA From d at davea.name Fri Sep 7 14:11:00 2012 From: d at davea.name (Dave Angel) Date: Fri, 07 Sep 2012 14:11:00 -0400 Subject: Reusable (local) Modules In-Reply-To: <01D5A43C-4E12-410C-9D40-7DDFCA0867E4@gmail.com> References: <01D5A43C-4E12-410C-9D40-7DDFCA0867E4@gmail.com> Message-ID: <504A38B4.3090304@davea.name> On 09/07/2012 01:56 PM, Travis Griggs wrote: > I'm relatively new to Python (coming from strong C and Smalltalk backgrounds). I've written a couple of relatively small apps (one or two .py files). I'm using PyCharm (I love it). > > I'm curious what the pythonic approach is to creating your own reusable modules. Any tutorials or high level explanations, or detailed, much appreciated. > > For example, I have a small module called valvenumbers.py. It's a family of functions that we use to do a variety of things with the serial numbers we attach to some of our products. Now I'm making a little desktop app using wxpython, and I want to use (import) that module. Using PyCharm, I have two separate projects in sibling directories. And there's another separate command line tool that wants to do the same. Currently, I just place a symlink to the valvenumbers.py, local to the directory of these apps. This seems like "the quickest thing that could possibly work", but I'm assuming there's a more pythonic way to approach this general problem. > > TIA! > > Travis Griggs > "Simplicity is the ultimate sophistication." -- Leonardo Da Vinci > import sys print sys.path This will show you your path for imports. The actual directories change by default with different python versions, but one of them will be suitable for putting new modules to be imported. Naturally, you don't want to add to the place where the stdlib is placed, but some of those are normal writable directories. There are also several ways to add your own directories to that path, but maybe you don't need that complexity yet. I'm sure others will be able to be more specific. -- DaveA From storchaka at gmail.com Fri Sep 7 14:17:40 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Fri, 07 Sep 2012 21:17:40 +0300 Subject: Division help in python In-Reply-To: References: Message-ID: On 07.09.12 15:53, Ramyasri Dodla wrote: > I am brand new to python. checking over basic stuff. I came across the > problem while doing so. If any body aware of the problem, kindly respond me. > > >>> 5/10 > 0 > >>> - 5/10 > -1 > > The second case also should yield a 'zero' but it is giving a -1 http://python-history.blogspot.com/2010/08/why-pythons-integer-division-floors.html From subhabangalore at gmail.com Fri Sep 7 15:02:04 2012 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Fri, 7 Sep 2012 12:02:04 -0700 (PDT) Subject: Using Raw Data in NLTK Message-ID: <8279abb2-269e-4b4f-ab95-7f0b5cb5c62c@googlegroups.com> Dear Group, I am trying to use NLTK and its statistical classifiers. The system is working fine but I am trying to use my own data, instead of things like, from nltk.corpus import brown from nltk.corpus import names If any one can kindly guide me up. Thanks in Advance, Regards, Subhabrata. From gordon at panix.com Fri Sep 7 15:04:13 2012 From: gordon at panix.com (John Gordon) Date: Fri, 7 Sep 2012 19:04:13 +0000 (UTC) Subject: ctypes - python2.7.3 vs python3.2.3 References: <18eb8025-7545-4d10-9e76-2e41deaadb69@googlegroups.com> <9a74$503e88dd$546bb230$30836@cache80.multikabel.net> Message-ID: In <9a74$503e88dd$546bb230$30836 at cache80.multikabel.net> Jan Kuiken writes: > >> uint32_t myfunction (char ** _mydata) > >> { > >> char mydata[16]; > > > >> strcpy(mydata, "Hello Dude!"); > > > >> *_mydata = mydata; > > > >> return 0; > >> } > > > > mydata is an auto variable, which goes out of scope when myfunction() > > exits. *_mydata ends up pointing to garbage. > I'm not completely sure, but i think this can be solved by using: > static char mydata[16]; That will solve the immediate problem, however it makes myfunction() non-reentrant. > (Btw.: I don't know why you use char ** _mydata, i would use > char * _mydata, but then again, i'm not very familiar with > ctypes) He uses char **_mydata because he wants myfunction()'s caller to see the new value of _mydata, which it wouldn't if it were just char *_mydata. -- 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 oscar.j.benjamin at gmail.com Fri Sep 7 15:10:16 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 7 Sep 2012 19:10:16 +0000 (UTC) Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-09-07, Steven D'Aprano wrote: > > > After further thought, and giving consideration to the arguments given by > people here, I'm now satisfied to say that for equal-length strings, > string equality is best described as O(N). > > 1) If the strings are equal, a == b will always compare all N > characters in each string. > > 2) If the strings are unequal, a == b will *at worst* compare > all N characters. > > 3) Following usual practice in this field, worst case is the > one which conventionally is meant when discussing Big Oh > behaviour. See, for example, "Introduction To Algorithms" > by Cormen, Leiserson and Rivest. Would you say, then, that dict insertion is O(N)? > > Also of some interest is the best case: O(1) for unequal strings (they > differ at the first character) and O(N) for equal strings. > > Also of interest is the case that has caused the majority of the > discussion, the average case. I am now satisfied that the average number > of comparisons for unequal strings is O(1). To be precise, it is bounded > below by 1 comparison (you always have to compare at least one pair of > characters) and bounded above by 2 comparisons. I find this idea of separating into the comparison of equal strings versus the comparison of unequal strings rather odd. If the strings you compare come from a distribution where they are guaranteed to be equal (or unequal) then you can just use the O(0) comparison method. Since string comparison is only useful if the strings can be equal or unequal, the average case depends on how often they are equal/unequal as well as the average complexity of both. For random strings the frequency of equal strings decreases very fast as N increases so that the comparison of random strings is O(1). > > (I'm talking about the average here -- the actual number of comparisons > can range all the way up to N, but the average is <= 2.) > > If I've done the maths right, the exact value for the average is: > > ((M-1)*sum( (N-i)*M**i for i in range(0, N) ) + N)/(M**N) I'm not sure where the extra N comes from --------^ but otherwise good. I would have written that as: (1 - p) * sum(i * p**(i-1) for i in range(1, N+1)) where p is the probability of a match (1/M for M equally likely characters) or in closed form: ? N ? ?1 - p ?(1 + N ?(1 - p))? ????????????????????????? 1 - p > > for random strings of length N taken from an alphabet of size M. > > For M = 2, that average approaches but never exceeds 2 as N increases; > for M = 3, the average approaches 1.5, for M = 4 it approaches 1.333... > and so forth. It approaches 1 / (1 - p) or, if you prefer: M / (M - 1) Oscar From oscar.j.benjamin at gmail.com Fri Sep 7 15:40:00 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 7 Sep 2012 19:40:00 +0000 (UTC) Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-09-07, Oscar Benjamin wrote: > On 2012-09-07, Steven D'Aprano wrote: >> > > Since string comparison is only useful if the strings can be equal or unequal, > the average case depends on how often they are equal/unequal as well as the > average complexity of both. For random strings the frequency of equal strings > decreases very fast as N increases so that the comparison of random strings is > O(1). > >> >> (I'm talking about the average here -- the actual number of comparisons >> can range all the way up to N, but the average is <= 2.) >> >> If I've done the maths right, the exact value for the average is: >> >> ((M-1)*sum( (N-i)*M**i for i in range(0, N) ) + N)/(M**N) > > I'm not sure where the extra N comes from --------^ but otherwise good. Ok, I see it's for the case where they're equal. Oscar From michael at stroeder.com Fri Sep 7 16:54:50 2012 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Fri, 07 Sep 2012 22:54:50 +0200 Subject: Dynamically scheduling Cron Jobs for Python Scripts. In-Reply-To: <2702e6fc-a6f5-4bc1-9c47-216171506128@googlegroups.com> References: <1c24b34d-774f-4613-b6a9-f6f19fb24acb@googlegroups.com> <2702e6fc-a6f5-4bc1-9c47-216171506128@googlegroups.com> Message-ID: Miki Tebeka wrote: >> I want to re run the script at that schedule time to send me a email. > > Calculate how much time until the meeting. And spawn the script that will > sleep that amount of time and then send email. And if the process gets interrupted in the meantime (e.g. because of reboot)? Ciao, Michael. From tjreedy at udel.edu Fri Sep 7 17:32:20 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 07 Sep 2012 17:32:20 -0400 Subject: Using Raw Data in NLTK In-Reply-To: <8279abb2-269e-4b4f-ab95-7f0b5cb5c62c@googlegroups.com> References: <8279abb2-269e-4b4f-ab95-7f0b5cb5c62c@googlegroups.com> Message-ID: On 9/7/2012 3:02 PM, subhabangalore at gmail.com wrote: > Dear Group, > I am trying to use NLTK and its statistical classifiers. The system is working fine but I am trying to use my own data, instead of things like, > > from nltk.corpus import brown > from nltk.corpus import names > > If any one can kindly guide me up. from mypack import mydata The important thing is that mydata have the proper format. I would think that the nltk docs have instructions for and examples of using personal data -- Terry Jan Reedy From dwightdhutto at gmail.com Fri Sep 7 17:59:14 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 7 Sep 2012 17:59:14 -0400 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: With unequal strings/lists to match, it would seem that one would regex through the larger string/list with the shorter string, and piece by piece begin to match for partial percentage matches in relation to the longer iterative item. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From gelonida at gmail.com Fri Sep 7 18:04:28 2012 From: gelonida at gmail.com (Gelonida N) Date: Sat, 08 Sep 2012 00:04:28 +0200 Subject: how to run python2.6 module with absolute imports stand alone Message-ID: Hi, many of my modules contain following section at the end def main(): do_something() if __name__ == '__main__': main() This allows me to run some basic example code or some small test in a stand alone mode. My new modules contain following line at the beginning: from __future__ import absolute_import I like this: - It can reduce import name conflicts - and second it allows 'relative' imports like from .othermodule import funcname from ..mod_one_level_higher import fdfsd However If I try to run such a script from the command line it will now complain with ValueError: Attempted relative import in non-package Any tricks to work around this ??? The only idea, that I have is to have a script, that would take my modulename or path name as parameter, and try to import it and then call the main function of the imported module. Not very elegant, but probably functional. Thanks in advance for any other suggestions / ideas. From dwightdhutto at gmail.com Fri Sep 7 18:08:11 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 7 Sep 2012 18:08:11 -0400 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 7, 2012 at 5:59 PM, Dwight Hutto wrote: > With unequal strings/lists to match, it would seem that one would regex > through the larger string/list with the shorter string, and piece by piece > begin to match for partial percentage matches in relation to the longer > iterative item. > While iterating through the larger list character/item, one at a time, or arranging them in certain instances. > > -- > Best Regards, > David Hutto > *CEO:* *http://www.hitwebdevelopment.com* > > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Fri Sep 7 20:13:02 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 08 Sep 2012 01:13:02 +0100 Subject: how to run python2.6 module with absolute imports stand alone In-Reply-To: References: Message-ID: On 07/09/2012 23:04, Gelonida N wrote: > Hi, > > many of my modules contain following section at the end > > > def main(): > do_something() > if __name__ == '__main__': > main() > > This allows me to run some basic example code > or some small test in a stand alone mode. > > > My new modules contain following line at the beginning: > > from __future__ import absolute_import > > > I like this: > - It can reduce import name conflicts > - and second it allows 'relative' imports like > from .othermodule import funcname > from ..mod_one_level_higher import fdfsd > > > However If I try to run such a script from the command line it will now > complain with > > ValueError: Attempted relative import in non-package > > Any tricks to work around this ??? > > The only idea, that I have is to have a script, that would take my > modulename or path name as parameter, and try to import it and then call > the main function of the imported module. > > > Not very elegant, but probably functional. > > Thanks in advance for any other suggestions / ideas. > I hope this helps http://stackoverflow.com/questions/3616952/how-to-properly-use-relative-or-absolute-imports-in-python-modules -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Fri Sep 7 20:55:34 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Sep 2012 00:55:34 GMT Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 07 Sep 2012 19:10:16 +0000, Oscar Benjamin wrote: > On 2012-09-07, Steven D'Aprano > wrote: >> >> >> After further thought, and giving consideration to the arguments given >> by people here, I'm now satisfied to say that for equal-length strings, >> string equality is best described as O(N). >> >> 1) If the strings are equal, a == b will always compare all N >> characters in each string. >> >> 2) If the strings are unequal, a == b will *at worst* compare >> all N characters. >> >> 3) Following usual practice in this field, worst case is the >> one which conventionally is meant when discussing Big Oh behaviour. >> See, for example, "Introduction To Algorithms" by Cormen, Leiserson >> and Rivest. > > Would you say, then, that dict insertion is O(N)? Pedantically, yes. But since we're allowed to state (or even imply *wink*) whatever assumptions we like, we're allowed to assume "in the absence of significant numbers of hash collisions" and come up with amortized O(1) for dict insertions and lookups. (Provided, of course, that your computer has an infinite amount of unfragmented memory and the OS never starts paging your dict to disk. Another unstated assumption that gets glossed over when we talk about complexity analysis -- on real world computers, for big enough N, *everything* is O(2**N) or worse.) Big Oh analysis, despite the formal mathematics used, is not an exact science. Essentially, it is a way of bringing some vague order to hand- wavy estimates of complexity, and the apparent mathematical rigour is built on some awfully shaky foundations. But despite that, it actually is useful. Coming back to strings... given that in any real-world application, you are likely to have some string comparisons on equal strings and some on unequal strings, and more importantly you don't know which are which ahead of time, which attitude is less likely to give you a nasty surprise when you run your code? "I have many millions of 100K strings to compare against other 100K strings, and string comparisons are O(1) so that will be fast." "I have many millions of 100K strings to compare against other 100K strings, and string comparisons are O(N) so that will be slow, better find another algorithm." Remember too that "for small enough N, everything is O(1)". Getting hung up on Big Oh is just as much a mistake as ignoring it completely. > I find this idea of separating into the comparison of equal strings > versus the comparison of unequal strings rather odd. If the strings you > compare come from a distribution where they are guaranteed to be equal > (or unequal) then you can just use the O(0) comparison method. If you know that they're (un)equal, you don't need to call == at all. If you know that "most" strings will be unequal, then you might be justified in treating comparisons as O(1) "most of the time" and not stress about the occasional slow call. But of course most of the time you don't know this, which is why it is appropriate to treat string comparisons as O(N) rather than O(1), since that's the upper bound. > Since string comparison is only useful if the strings can be equal or > unequal, the average case depends on how often they are equal/unequal as > well as the average complexity of both. For random strings the frequency > of equal strings decreases very fast as N increases so that the > comparison of random strings is O(1). But that is not an upper bound, and Big Oh analysis is strictly defined in terms of upper bounds. >> (I'm talking about the average here -- the actual number of comparisons >> can range all the way up to N, but the average is <= 2.) >> >> If I've done the maths right, the exact value for the average is: >> >> ((M-1)*sum( (N-i)*M**i for i in range(0, N) ) + N)/(M**N) > > I'm not sure where the extra N comes from --------^ but otherwise good. The extra N comes from the case where you compare string S with itself, which takes exactly N comparisons. -- Steven From dwightdhutto at gmail.com Fri Sep 7 21:36:21 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 7 Sep 2012 21:36:21 -0400 Subject: Comparing strings from the back? In-Reply-To: <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Why don' you just time it,eit lops through incrementing thmax input/ -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason at powerpull.net Sat Sep 8 00:16:20 2012 From: jason at powerpull.net (Jason Friedman) Date: Fri, 7 Sep 2012 22:16:20 -0600 Subject: Python newbie here! No module named settings In-Reply-To: <983415eb-d238-439c-8640-eb95dce1814c@googlegroups.com> References: <1ce00c77-35ae-4499-adff-bafadab80aa5@x38g2000pri.googlegroups.com> <983415eb-d238-439c-8640-eb95dce1814c@googlegroups.com> Message-ID: >> I was trying to use Python wrapper for Google Charts API and was >> tweaking the examples. >> https://github.com/gak/pygooglechart/raw/master/examples/pie.py >> >> This is the script which I was trying. >> >> And the python interpreter gives the following error: >> import settings >> ImportError: No module named settings >> >> I installed Django as well before this (if its causing the problem, >> dunno) I searched Google for "django import settings" and found a few links that might be helpful. From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sat Sep 8 03:03:12 2012 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sat, 8 Sep 2012 07:03:12 +0000 (UTC) Subject: Division help in python References: Message-ID: Chris Angelico wrote: > On Fri, Sep 7, 2012 at 10:53 PM, Ramyasri Dodla wrote: >> I am brand new to python. checking over basic stuff. I came across the >> problem while doing so. If any body aware of the problem, kindly respond me. >> >>>>> 5/10 >> 0 >>>>> - 5/10 >> -1 >> >> The second case also should yield a 'zero' but it is giving a -1 > > ... > The reason for this is that / (or in Python 3, //) rounds toward > negative infinity, not toward zero. This allows the modulo operator I think he means the non-obvious unary minus precedence. -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From hansmu at xs4all.nl Sat Sep 8 04:09:23 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 08 Sep 2012 10:09:23 +0200 Subject: Division help in python In-Reply-To: References: Message-ID: <504afd33$0$6846$e4fe514c@news2.news.xs4all.nl> On 8/09/12 09:03:12, garabik-news-2005-05 at kassiopeia.juls.savba.sk wrote: > Chris Angelico wrote: >> On Fri, Sep 7, 2012 at 10:53 PM, Ramyasri Dodla wrote: >>> I am brand new to python. checking over basic stuff. I came across the >>> problem while doing so. If any body aware of the problem, kindly respond me. >>> >>>>>> 5/10 >>> 0 >>>>>> - 5/10 >>> -1 >>> >>> The second case also should yield a 'zero' but it is giving a -1 >> > ... > >> The reason for this is that / (or in Python 3, //) rounds toward >> negative infinity, not toward zero. This allows the modulo operator > > I think he means the non-obvious unary minus precedence. That seems unlikely. Unary minus has lower precedence in Python than in most other programming languages, but its precedence is higher than division, so this example doesn't show the difference. For example, in C unary opeators have the highest precedence. Yet -5/10 returns 0, not because of precedence, but because C rounds towards zero. Hope this helps, -- HansM From tinnews at isbd.co.uk Sat Sep 8 06:02:46 2012 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Sat, 8 Sep 2012 11:02:46 +0100 Subject: How to print something only if it exists? References: <9s4nh9-8dr.ln1@chris.zbmc.eu> Message-ID: <6nhrh9-908.ln1@chris.zbmc.eu> Dave Angel wrote: > Would you like to define "exists" ? A list is not sparse, so all items > exist if their subscript is less than the length of the list. So all > you need to do is compare 2 to len(fld). > Yes, a I said a simple len(fld) will tell me if fld[2] 'exists' but it gets messy if I have to do it in the middle of the print sequence. > But perhaps there's another approach. Just what DO you want to print if > fld(1) exists, but fld(2) does not? Do you still want to print out day, > fld(1), and balance? Or do you want to skip balance as well? > Here's a sample of the file whose lines are being split() :- 01 JB 0.00 Start of 2012, Initial balance 02 BB 0.00 13 ZB 0.00 I want to print out everything, it's just that in some cases there's no descriptive text (the bit that ends up in fld[2]). > if you literally want nothing printed for list elements beyond the end, > then I'd add some extra empty-strings to the end of the list. > > fld.extend("" * 5) > > Now, subscripts 0 through 4 inclusive will work, as specified. > That's probably the simplest approach, thank you. -- Chris Green From d at davea.name Sat Sep 8 07:08:09 2012 From: d at davea.name (Dave Angel) Date: Sat, 08 Sep 2012 07:08:09 -0400 Subject: How to print something only if it exists? In-Reply-To: <6nhrh9-908.ln1@chris.zbmc.eu> References: <9s4nh9-8dr.ln1@chris.zbmc.eu> <6nhrh9-908.ln1@chris.zbmc.eu> Message-ID: <504B2719.4080506@davea.name> On 09/08/2012 06:02 AM, tinnews at isbd.co.uk wrote: > Dave Angel wrote: >> Would you like to define "exists" ? A list is not sparse, so all items >> exist if their subscript is less than the length of the list. So all >> you need to do is compare 2 to len(fld). >> > Yes, a I said a simple len(fld) will tell me if fld[2] 'exists' but it > gets messy if I have to do it in the middle of the print sequence. > > >> But perhaps there's another approach. Just what DO you want to print if >> fld(1) exists, but fld(2) does not? Do you still want to print out day, >> fld(1), and balance? Or do you want to skip balance as well? >> > Here's a sample of the file whose lines are being split() :- > > 01 JB 0.00 Start of 2012, Initial balance > 02 BB 0.00 > 13 ZB 0.00 > > I want to print out everything, it's just that in some cases there's > no descriptive text (the bit that ends up in fld[2]). > > >> if you literally want nothing printed for list elements beyond the end, >> then I'd add some extra empty-strings to the end of the list. >> >> fld.extend("" * 5) >> >> Now, subscripts 0 through 4 inclusive will work, as specified. >> > That's probably the simplest approach, thank you. > If there literally is only one missing field, and at the end, then you could use fld.append("") instead. Or better, you could do something like if len(fld) == 2 : fld.append(""") This may be longer, but at least it's in one place -- the place where the split is occurring. And it pretty much states that the fld2 is optional. You ought to consider what error to report if you encounter a line with missing fields that ARE required. -- DaveA From rosuav at gmail.com Sat Sep 8 07:21:04 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 8 Sep 2012 21:21:04 +1000 Subject: Accessing dll In-Reply-To: <5b2b86a1-7fb5-4db9-be6a-4b720af936f2@d7g2000vbv.googlegroups.com> References: <0e642403-36e9-4945-9efb-4d074d7d0eb2@s5g2000vbj.googlegroups.com> <02c28de7-e672-4850-b684-d2cb4e3128b6@fm12g2000vbb.googlegroups.com> <5b2b86a1-7fb5-4db9-be6a-4b720af936f2@d7g2000vbv.googlegroups.com> Message-ID: On Sat, Sep 8, 2012 at 3:27 AM, Helpful person wrote: > On Sep 7, 5:16 am, Chris Angelico wrote: >> On Fri, Sep 7, 2012 at 1:44 AM, Helpful person wrote: >> > FYI >> >> > My Python version is 2.5.4 >> >> You may wish to upgrade, that's quite an old version. Unless >> something's binding you to version 2.x, I would strongly recommend >> migrating to 3.2 or 3.3. >> >> ChrisA > > Upgrading is not possible due to the large number of programs using > the early version. Sure. At least you've considered it. :) Do look into moving up to 2.7, at least, though. And of course, you can have multiple Pythons installed simultaneously, allowing you to migrate only when you're ready. ChrisA From oscar.j.benjamin at gmail.com Sat Sep 8 07:53:13 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 8 Sep 2012 11:53:13 +0000 (UTC) Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-09-08, Steven D'Aprano wrote: > On Fri, 07 Sep 2012 19:10:16 +0000, Oscar Benjamin wrote: > >> On 2012-09-07, Steven D'Aprano >> wrote: >> >> >> Would you say, then, that dict insertion is O(N)? > > Pedantically, yes. > > But since we're allowed to state (or even imply *wink*) whatever > assumptions we like, we're allowed to assume "in the absence of > significant numbers of hash collisions" and come up with amortized O(1) > for dict insertions and lookups. > > (Provided, of course, that your computer has an infinite amount of > unfragmented memory and the OS never starts paging your dict to disk. > Another unstated assumption that gets glossed over when we talk about > complexity analysis -- on real world computers, for big enough N, > *everything* is O(2**N) or worse.) > > Big Oh analysis, despite the formal mathematics used, is not an exact > science. Essentially, it is a way of bringing some vague order to hand- > wavy estimates of complexity, and the apparent mathematical rigour is > built on some awfully shaky foundations. But despite that, it actually is > useful. > > Coming back to strings... given that in any real-world application, you > are likely to have some string comparisons on equal strings and some on > unequal strings, and more importantly you don't know which are which > ahead of time, which attitude is less likely to give you a nasty surprise > when you run your code? > > "I have many millions of 100K strings to compare against other 100K > strings, and string comparisons are O(1) so that will be fast." > > "I have many millions of 100K strings to compare against other 100K > strings, and string comparisons are O(N) so that will be slow, better > find another algorithm." True. I can't think of a situation where I've used string comparisons directly in any text heavy code. Rather, I would use a dict or a set (or a regex) and hash(str) is always O(N). > > > Remember too that "for small enough N, everything is O(1)". Getting hung > up on Big Oh is just as much a mistake as ignoring it completely. > > I can't think of a situation in my own work where O(N) vs O(1) string comparisons would cause a significant problem (except perhaps in libraries that I use but didn't write). However, I can find a number of cases where I compare numpy.ndarrays for equality. For example, I found if np.all(a == b): in some code that I recently wrote. Although np.all() short-circuits, a==b does not so that line forces O(N) behaviour onto a situation where the average case can be better. Unfortunately numpy doesn't seem to provide a short-circuit equals() function. array_equal() is what I want but it does the same as the above. In future, I'll consider using something like def cmparray(a, b): return a.shape == b.shape and a.dtype == b.dtype and buffer(a) == buffer(b) to take advantage of (what I assume are) short-circuit buffer comparisons. >> Since string comparison is only useful if the strings can be equal or >> unequal, the average case depends on how often they are equal/unequal as >> well as the average complexity of both. For random strings the frequency >> of equal strings decreases very fast as N increases so that the >> comparison of random strings is O(1). > > But that is not an upper bound, and Big Oh analysis is strictly defined > in terms of upper bounds. It is an upper bound, but it is an upper bound on the *expectation value* assuming a particular distribution of inputs, rather than an upper bound on all possible inputs. >>> (I'm talking about the average here -- the actual number of comparisons >>> can range all the way up to N, but the average is <= 2.) The average is actually bounded by 1 / (1 - p) where p is the probability that two characters match. This bound can be arbitrarily large as p approaches 1 as would be the case if, say, one character was much more likely than others. The particular assumption that you have made p = 1/M where M is the number of characters is actually the *smallest* possible value of p. For non-uniform real data (English words for example) p is significantly greater than 1/M but in a strict bounds sense we should say that 1/M <= p <= 1. Oscar From freebee007 at gmail.com Sat Sep 8 09:39:55 2012 From: freebee007 at gmail.com (freebee007 at gmail.com) Date: Sat, 8 Sep 2012 06:39:55 -0700 (PDT) Subject: PExpect Cross-Platform Alternative In-Reply-To: References: <348a45771002111147q534fba67m831fbf3961ea55d2@mail.gmail.com> Message-ID: <8d17a7f2-22e4-4af1-8537-f0690fb464b6@googlegroups.com> Hello Steve, I was wondering if you had working examples of your automated tasks in python ... I am asking because I am starting out in Python, and I believe I can save my company time and headaches by automating a lot of the tasks we have. I would like to study your code and see if I can use it in our environment. Basically, our tasks involve downloading the firmwares and then installing it, restarting the processes and making sure all the processes are running. Its on Linux servers and HP switches. I cannot seem to find any example code to learn from ... I have IT guys who know Perl, but I do not want to go down that route. Many thanks, Zac. On Thursday, February 11, 2010 8:57:39 PM UTC+1, Steve Holden wrote: > Nathan Farrar wrote: > > Hello Community, > > > > Recently I've been automating lots of network operations tasks via > > simple python scripts. Originally, I utilized paramiko but found that > > the module had issues working with cisco equipment. I switched to > > pexpect and things have worked wonderfully since (I've been running this > > scripts in a Linux environment). However, I was just tasked to get > > these scripts running in a windows environment and to my dismay very > > quickly realized that pexpect is not cross platform compatible. > > > > Am I stuck, or are there solutions out there? > > > It works pretty well under Cygwin (which also improves your Windows > scripting environment no end). Any chance you would be allowed to > install that? > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ > Holden Web LLC http://www.holdenweb.com/ > UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From freebee007 at gmail.com Sat Sep 8 09:39:55 2012 From: freebee007 at gmail.com (freebee007 at gmail.com) Date: Sat, 8 Sep 2012 06:39:55 -0700 (PDT) Subject: PExpect Cross-Platform Alternative In-Reply-To: References: <348a45771002111147q534fba67m831fbf3961ea55d2@mail.gmail.com> Message-ID: <8d17a7f2-22e4-4af1-8537-f0690fb464b6@googlegroups.com> Hello Steve, I was wondering if you had working examples of your automated tasks in python ... I am asking because I am starting out in Python, and I believe I can save my company time and headaches by automating a lot of the tasks we have. I would like to study your code and see if I can use it in our environment. Basically, our tasks involve downloading the firmwares and then installing it, restarting the processes and making sure all the processes are running. Its on Linux servers and HP switches. I cannot seem to find any example code to learn from ... I have IT guys who know Perl, but I do not want to go down that route. Many thanks, Zac. On Thursday, February 11, 2010 8:57:39 PM UTC+1, Steve Holden wrote: > Nathan Farrar wrote: > > Hello Community, > > > > Recently I've been automating lots of network operations tasks via > > simple python scripts. Originally, I utilized paramiko but found that > > the module had issues working with cisco equipment. I switched to > > pexpect and things have worked wonderfully since (I've been running this > > scripts in a Linux environment). However, I was just tasked to get > > these scripts running in a windows environment and to my dismay very > > quickly realized that pexpect is not cross platform compatible. > > > > Am I stuck, or are there solutions out there? > > > It works pretty well under Cygwin (which also improves your Windows > scripting environment no end). Any chance you would be allowed to > install that? > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ > Holden Web LLC http://www.holdenweb.com/ > UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From maniandram01 at gmail.com Sat Sep 8 11:09:59 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 8 Sep 2012 08:09:59 -0700 (PDT) Subject: Language workbench written in python3 In-Reply-To: References: <1ed391c3-8fcf-4a3f-8ad7-0a2cf913b6cc@googlegroups.com> <634287e3-12b3-4b47-8ad2-38c1bc76ff1a@googlegroups.com> <314ae0e0-f38f-4cb9-944c-511343988f37@googlegroups.com> Message-ID: <65cd713e-38cf-4897-8777-0f824503c193@googlegroups.com> On Friday, 7 September 2012 01:18:45 UTC+5:30, Nestor Arocha wrote: > On Thursday, September 6, 2012 2:53:15 PM UTC+1, Ramchandra Apte wrote: > > > On Thursday, 6 September 2012 19:16:38 UTC+5:30, Dave Angel wrote: > > > > > > > On 09/06/2012 09:34 AM, Ramchandra Apte wrote: > > > > > > > > > > > > > > > Translator means what precisely? > > > > > > > > > > > > > > > > > > > > > > > > > > > > Examples of translators include compilers, assemblers, and > > > > > > > > > > > > > > interpreters. They also include implementations like cfront, which > > > > > > > > > > > > > > translates from one high-level language to another lower-level > > > > > > > > > > > > > > language. (high and low being relative) > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > > > > > > > > > > > > > > > > > > DaveA > > > > > > > > > > > > Is conversion from Python to C++ possible from this project? > > > > No, it is not currently possible for several reasons: > > * current parser implementation is a recursive descent parser. I haven't implemented an LR parser yet, although PLY lexers and parsers are supported. > > * Syntax Directed Translator is not fully implemented either. > > * Parser Trees are supported, but there is no clear method defined for converting them into ASTs (like antlr grammars) > > * Even with AST and SDT support, a Python to C++ translator will require more complex tools and a lot of coding. > > > > This tool is oriented to small DSLs parsing and translation; grammars like Python or C++ are too complex for the current implementation I was thinking I could use it for my Python to C/C++ converter - py2c @ code.google.com/p/py2c (py2c would love a developer so join and contribute) From maniandram01 at gmail.com Sat Sep 8 11:11:48 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 8 Sep 2012 08:11:48 -0700 (PDT) Subject: Looking for an IPC solution In-Reply-To: References: <50410AD6.7080003@shopzeus.com> <2p0i489b5kq6ad2kc70r82ksjqpcatdsqu@invalid.netcom.com> Message-ID: <299a8013-fd2b-4d91-a5d8-f4d8732e7377@googlegroups.com> On Friday, 7 September 2012 02:25:15 UTC+5:30, Dave Angel wrote: > On 09/06/2012 04:33 PM, Dennis Lee Bieber wrote: > > > > > > > > Note that this difference mainly applies to how the processes are > > > themselves are created... How the library wraps shared data is > > > possibly different (I've never understood how a "fork" process can > > > avoid memory conflicts if it has write access to common virtual memory > > > blocks). > > Here's an approximate description of fork, at least for the memory > > aspects. During a fork, the virtual memory table is copied (that's > > descriptors for all mapped and allocated memory) but the memory itself > > is NOT. All the new descriptors are labeled "COW" (copy-on-write). As > > that process executes, the first time it writes in a particular memory > > block, the OS gets a memory fault, which it fixes by allocating a block > > of the same size, copying the memory block to the new one, and labeling > > it read/write. Subsequent accesses to the same block are normal, with no > > trace of the fork remaining. > > > > Now, there are lots of details that this blurs over, but it turns out > > that many times the new process doesn't change very much. For example, > > all the mappings to the executable and to shared libraries are > > theoretically readonly. In fact, they might have also been labeled COW > > even for the initial execution of the program. Another place that's > > blurry is just what the resolution of this table actually is. There are > > at least two levels of tables. The smallest increment on the Pentium > > family is 4k. > > > > > > -- > > > > DaveA >From my OS development experience, there are two sizes of pages - 4K and 1 byte From maniandram01 at gmail.com Sat Sep 8 11:11:48 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 8 Sep 2012 08:11:48 -0700 (PDT) Subject: Looking for an IPC solution In-Reply-To: References: <50410AD6.7080003@shopzeus.com> <2p0i489b5kq6ad2kc70r82ksjqpcatdsqu@invalid.netcom.com> Message-ID: <299a8013-fd2b-4d91-a5d8-f4d8732e7377@googlegroups.com> On Friday, 7 September 2012 02:25:15 UTC+5:30, Dave Angel wrote: > On 09/06/2012 04:33 PM, Dennis Lee Bieber wrote: > > > > > > > > Note that this difference mainly applies to how the processes are > > > themselves are created... How the library wraps shared data is > > > possibly different (I've never understood how a "fork" process can > > > avoid memory conflicts if it has write access to common virtual memory > > > blocks). > > Here's an approximate description of fork, at least for the memory > > aspects. During a fork, the virtual memory table is copied (that's > > descriptors for all mapped and allocated memory) but the memory itself > > is NOT. All the new descriptors are labeled "COW" (copy-on-write). As > > that process executes, the first time it writes in a particular memory > > block, the OS gets a memory fault, which it fixes by allocating a block > > of the same size, copying the memory block to the new one, and labeling > > it read/write. Subsequent accesses to the same block are normal, with no > > trace of the fork remaining. > > > > Now, there are lots of details that this blurs over, but it turns out > > that many times the new process doesn't change very much. For example, > > all the mappings to the executable and to shared libraries are > > theoretically readonly. In fact, they might have also been labeled COW > > even for the initial execution of the program. Another place that's > > blurry is just what the resolution of this table actually is. There are > > at least two levels of tables. The smallest increment on the Pentium > > family is 4k. > > > > > > -- > > > > DaveA >From my OS development experience, there are two sizes of pages - 4K and 1 byte From castironpi at gmail.com Sat Sep 8 11:42:56 2012 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 8 Sep 2012 08:42:56 -0700 (PDT) Subject: set and dict iteration In-Reply-To: <50456073$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> <1567e8c7-a2bb-41f4-9be8-18e9f4d063cb@googlegroups.com> <504558cb$0$29978$c3e8da3$5496439d@news.astraweb.com> <50456073$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87f103a7-2bbd-405f-8a5e-3aaf02c80fff@googlegroups.com> On Monday, September 3, 2012 8:59:16 PM UTC-5, Steven D'Aprano wrote: > On Mon, 03 Sep 2012 21:50:57 -0400, Dave Angel wrote: > > > > > On 09/03/2012 09:26 PM, Steven D'Aprano wrote: > > > > >> An unsigned C int can count up to 4,294,967,295. I propose that you say > > >> that is enough iterators for anyone, and use a single, simple, version > > >> counter in the dict and the iterator. If somebody exceeds that many > > >> iterators to a single dict or set, > > > > > > I think you have the count confused. it has to be a count of how many > > > changes have been made to the dict or set, not how many iterators exist. > > > > Oops, yes you are absolutely right. It's a version number, not a count of > > iterators. > > > > > > -- > > Steven Hello. We have a number of proposed solutions so far. 1) Collection of iterators a) Linked list i) Uncounted references ii) Counted references iii) Weak references b) Weak set 2) Serial index / timestamp a) No overflow - Python longs b) Overflow - C ints / shorts / chars c) Reset index if no iterators left 3) Iterator count - Raise exception on set modifications, not iteration Note, "2b" still leaves the possibility of missing a case and letting an error pass silently, as the current behavior does. The rest catch the error 100% of the time. Anyway, I plan to develop the above patch for the 'dict' class. Would anyone like to take over or help me do it? From guojunquan at gmail.com Sat Sep 8 11:50:06 2012 From: guojunquan at gmail.com (gjq) Date: Sat, 8 Sep 2012 23:50:06 +0800 Subject: How to install pyPgSQL on windows ? Message-ID: Hello,everyone, Anyone who know how to install pyPgSQL on windows in python2.7,Pleas help me. thanks. --- guojunquan{at}gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From gelonida at gmail.com Sat Sep 8 11:50:22 2012 From: gelonida at gmail.com (Gelonida N) Date: Sat, 08 Sep 2012 17:50:22 +0200 Subject: Comparing strings from the back? In-Reply-To: <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 09/06/2012 10:33 AM, Steven D'Aprano wrote: > On Wed, 05 Sep 2012 22:47:14 +0000, Oscar Benjamin wrote: > > I may have been overly-conservative earlier when I said that on average > string equality has to compare half the characters. I thought I had > remembered that from a computer science textbook, but I can't find that > reference now, so possibly I was thinking of something else. (String > searching perhaps?). Yeah I think you mixed it up with searching an entry in an unsorted list of length N That's one of the most common N/2 cases, that one hits daily with many straight forward implementations From gelonida at gmail.com Sat Sep 8 11:52:10 2012 From: gelonida at gmail.com (Gelonida N) Date: Sat, 08 Sep 2012 17:52:10 +0200 Subject: Comparing strings from the back? In-Reply-To: <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 09/07/2012 06:06 AM, Steven D'Aprano wrote: > On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: > > > Also of some interest is the best case: O(1) for unequal strings (they > differ at the first character) and O(N) for equal strings. The worst case is O(N) or N characters the average case is O(1) or two characters. For denial of service attacks or systems, that are NEVER allowed to fail the worst case is important. For most other cases the average complexity counts. However I still wonder for how many applications the complexity of string comparisons would be the limiting factor. From typetoken at gmail.com Sat Sep 8 13:13:21 2012 From: typetoken at gmail.com (Token Type) Date: Sat, 8 Sep 2012 10:13:21 -0700 (PDT) Subject: AttributeError: 'list' object has no attribute 'lower' Message-ID: On page 77 of the book natural language processing with Python, we have such an exercise: The polysemy of a word is the number of senses it has. Using WordNet, we can determine that the noun doghas seven senses with len(wn.synsets('dog', 'n')). Compute the average polysemy of nouns, verbs, adjectives, and adverbs according to WordNet.http://nltk.googlecode.com/svn/trunk/doc/book/ch02.html I wrote the following function to solve it. However, it pops up "AttributeError: 'list' object has no attribute 'lower'". Quite confused, I supposed [synset.lemma_names for synset in synset_list] has made all the lemma into a list, hasn't it? >>> def average_polysemy(pos): synset_list = list(wn.all_synsets(pos)) lemma_list = [synset.lemma_names for synset in synset_list] sense_number = 0 for lemma in lemma_list: sense_number_new = len(wn.synsets(lemma, pos)) sense_number = sense_number + sense_number_new return sense_number/len(synset_list) >>> average_polysemy('n') Traceback (most recent call last): File "", line 1, in average_polysemy('n') File "", line 6, in average_polysemy sense_number_new = len(wn.synsets(lemma, pos)) File "C:\Python27\lib\site-packages\nltk\corpus\reader\wordnet.py", line 1191, in synsets lemma = lemma.lower() AttributeError: 'list' object has no attribute 'lower' Thanks for your tips From typetoken at gmail.com Sat Sep 8 13:32:59 2012 From: typetoken at gmail.com (Token Type) Date: Sat, 8 Sep 2012 10:32:59 -0700 (PDT) Subject: =?UTF-8?Q?wordnet_NLTK=E3=80=80Re=3A_AttributeError=3A_=27list=27_object_has?= =?UTF-8?Q?_no_attribute_=27lower=27?= In-Reply-To: References: Message-ID: <1b672d8e-ea00-4280-a724-8650f5a005ae@googlegroups.com> I don't know why lemma_list = [synset.lemma_names for synset in synset_list] will lead to such an error. I have to use extend to solve the problem for lemma_list. The following codes are successful, take all the nouns as an example: >>> def average_polysemy(pos): synset_list = list(wn.all_synsets(pos)) sense_number = 0 lemma_list = [] for synset in synset_list: lemma_list.extend(synset.lemma_names) for lemma in lemma_list: sense_number_new = len(wn.synsets(lemma, pos)) sense_number = sense_number + sense_number_new return sense_number/len(synset_list) >>> average_polysemy('n') 3 > > I wrote the following function to solve it. However, it pops up "AttributeError: 'list' object has no attribute 'lower'". Quite confused, I supposed [synset.lemma_names for synset in synset_list] has made all the lemma into a list, hasn't it? > > > > >>> def average_polysemy(pos): > > synset_list = list(wn.all_synsets(pos)) > > lemma_list = [synset.lemma_names for synset in synset_list] > > sense_number = 0 > > for lemma in lemma_list: > > sense_number_new = len(wn.synsets(lemma, pos)) > > sense_number = sense_number + sense_number_new > > return sense_number/len(synset_list) > > > > >>> average_polysemy('n') > > > > Traceback (most recent call last): > > File "", line 1, in > > average_polysemy('n') > > File "", line 6, in average_polysemy > > sense_number_new = len(wn.synsets(lemma, pos)) > > File "C:\Python27\lib\site-packages\nltk\corpus\reader\wordnet.py", line 1191, in synsets > > lemma = lemma.lower() > > AttributeError: 'list' object has no attribute 'lower' > > > > Thanks for your tips From roy at panix.com Sat Sep 8 13:45:39 2012 From: roy at panix.com (Roy Smith) Date: Sat, 08 Sep 2012 13:45:39 -0400 Subject: AttributeError: 'list' object has no attribute 'lower' References: Message-ID: In article , Token Type wrote: > I wrote the following function to solve it. However, it pops up > "AttributeError: 'list' object has no attribute 'lower'". Quite confused, I > supposed [synset.lemma_names for synset in synset_list] has made all the > lemma into a list, hasn't it? I'm not familiar with that library, but here's a few general ideas to help you figure out what's going on. First, I don't understand this code: > synset_list = list(wn.all_synsets(pos)) > lemma_list = [synset.lemma_names for synset in synset_list] It looks like you're taking an iterable, converting it to a list, just so you can iterate over it again. Why not the simpler: > lemma_list = [synset.lemma_names for synset in wn.all_synsets(pos)] ? But, I'm also confused about what lemma_list is supposed to end up being. The name "lemma_names" is plural, making me think it returns a list of something. And then you build those up into a list of lists? In fact, I'm guessing that's your problem. I think you're ending up with a list of lists of strings, when you think you're getting a list of strings. My suggestion is to print out all the intermediate data structures (synset_list, lemma_list, etc) and see what they look like. If the structures are simple, just plain print will work, but for more complicated structures, pprint.pprint() is a life saver. Another possibility is to assert that things are what you expect them to be. Something like: assert isinstance(synset_list, list) assert isinstance(lemma_list, list) assert isinstance(lemma_list[0], str) and so on. > for lemma in lemma_list: > sense_number_new = len(wn.synsets(lemma, pos)) > sense_number = sense_number + sense_number_new > return sense_number/len(synset_list) > > >>> average_polysemy('n') > > Traceback (most recent call last): > File "", line 1, in > average_polysemy('n') > File "", line 6, in average_polysemy > sense_number_new = len(wn.synsets(lemma, pos)) > File "C:\Python27\lib\site-packages\nltk\corpus\reader\wordnet.py", line > 1191, in synsets > lemma = lemma.lower() > AttributeError: 'list' object has no attribute 'lower' > > Thanks for your tips From ndparker at gmail.com Sat Sep 8 14:12:46 2012 From: ndparker at gmail.com (=?UTF-8?B?QW5kcsOp?= Malo) Date: Sat, 08 Sep 2012 20:12:46 +0200 Subject: Parsing ISO date/time strings - where did the parser go? References: Message-ID: <2085311.RYDFQ4b6kj@news.perlig.de> * Roy Smith wrote: > The third is that I never use methods I can't figure out how to > pronounce. here: strip'time nd -- Flhacs wird im Usenet grunds?tzlich alsfhc geschrieben. Schreibt man lafhsc nicht slfach, so ist das schlichtweg hclafs. Hingegen darf man rihctig ruhig rhitcgi schreiben, weil eine shcalfe Schreibweise bei irhictg nicht als shflac angesehen wird. -- Hajo Pfl?ger in dnq From davidgshi at yahoo.co.uk Sat Sep 8 15:19:56 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Sat, 8 Sep 2012 20:19:56 +0100 (BST) Subject: Looking for download link for ArcPY In-Reply-To: References: Message-ID: <1347131996.708.YahooMailNeo@web133204.mail.ir2.yahoo.com> Hi, All, Can anyone send me the link for downloading ArcPY? I came across it before, but can not find it anymore. Regards. David -------------- next part -------------- An HTML attachment was scrubbed... URL: From markrrivet at aol.com Sat Sep 8 15:22:24 2012 From: markrrivet at aol.com (Mark R Rivet) Date: Sat, 08 Sep 2012 15:22:24 -0400 Subject: simple client data base References: Message-ID: <5l6n489vo896k565a4m5bjgl714qgickqg@4ax.com> On Mon, 03 Sep 2012 16:50:14 +0200, Peter Otten <__peter__ at web.de> wrote: >Chris Angelico wrote: > >> You may also be needlessly reinventing the wheel. Aren't there already >> several million basic contact databases around? Why roll your own? > >To learn a thing or two, and to stick it to the defeatists ;) Yes, that's the reason. I need to learn something. Without getting into the complexities of relational database's for now. From markrrivet at aol.com Sat Sep 8 15:40:47 2012 From: markrrivet at aol.com (Mark R Rivet) Date: Sat, 08 Sep 2012 15:40:47 -0400 Subject: simple client data base References: <1454469.9HWcpyvaek@PointedEars.de> Message-ID: On Tue, 04 Sep 2012 04:25:14 +0200, Thomas 'PointedEars' Lahn wrote: >Mark R Rivet wrote: > >> Hello all, I am learning to program in python. I have a need to make a >> program that can store, retrieve, add, and delete client data such as >> name, address, social, telephone number and similar information. This >> would be a small client database for my wife who has a home accounting >> business. >> >> I have been reading about lists, tuples, and dictionary data >> structures in python and I am confused as to which would be more >> appropriate for a simple database. >> >> I know that python has real database capabilities but I'm not there >> yet and would like to proceed with as simple a structure as possible. >> >> Can anyone give me some idea's or tell me which structure would be >> best to use? >> >> Maybe its a combination of structures? I need some help. > >The data types that would choose are defined by your requirements and how >well a data type meets your requirements. > >I can imagine: In a database you would want quick access to data. You would >want to access fields primarily by name. You would also want to filter data >by various criteria. > >Therefore, it appears to me that it would be best if your records were >dictionaries or dictionary-like objects, and your recordsets were lists of >records, like so > >#!/usr/bin/env python3 > >from datetime import date > >data = [ > { > 'lastname': 'Doe', > 'firstname': 'John', > 'sn': '123-451-671-890', > 'birthdata': date(2000, 1, 2) > }, > { > 'lastname': 'Doe', > 'firstname': 'Jane', > 'sn': '409-212-582-452', > 'birthdata': date(2001, 2, 3) > }, >] > >- You could quickly access the second record with data[1]. >- You could access the 'lastname' field of the second record with > data[1]['lastname'] >- You could get a list of records where the person is born before 2001 CE > with filter(lambda record: record['birthdate'] < date(2001, 1, 1), data) > >The advantage of dictionaries over dictionary-like objects is that they are >easily extensible and that the memory footprint is probably lower (CMIIW); >the disadvantage is slightly more complicated syntax and that you have to >keep track of the keys. Therefore, you might want to consider instantiating >a Record class instead; in its simplest form: > >class Record(object): > def __init__(self, lastname, firstname, sn=None, birthdate=None): > self.lastname = lastname > self.firstname = firstname > self.sn = str(sn) > self.birthdate = birthdate > >data = [ > Record(lastname='Doe', firstname='John', sn='123-451-671-890', > birthdate=date(2000, 1, 2)), > Record(lastname='Doe', firstname='Jane', sn='409-212-582-452', > birthdate=date(2001, 2, 3)) >] > >- You could access the 'lastname' property of the second record with > data[1].lastname >- You get a list of records where the person is born before 2001 CE with > list(filter(lambda record: record.birthdate < date(2001, 1, 1), data)) > (in Python 2.x without list()) > >However, if you want your program to manipulate the data *persistently*. as >it will probably be needed for business, you will need to also store it >somewhere else than in the volatile memory in which these data structures >are usually stored. The most simple way would be to store and parse the >string representation of the objects. > >Production-quality implementations of those and other concepts already >exist, of course, but using something finished and polished does not provide >as much learning experience. > >HTH Now this is the kind of answer I was hoping for. This gives me food for thought. Now I have some Ideas of how to appproach this thing. I know that there are solutions to this problem already but I need to do my own before I can really use anything better. Thanks for the help. I fully intend to go with a real realational database, but not now. My version 1 will be a console interface and dictionaries, lists and pickling. Version 2 will be with a GUI written in tkinter, and better and better. I just want to learn how to lay the bricks before I start using prefab walls. From markrrivet at aol.com Sat Sep 8 15:42:27 2012 From: markrrivet at aol.com (Mark R Rivet) Date: Sat, 08 Sep 2012 15:42:27 -0400 Subject: simple client data base References: <11edefc8-5594-4cc9-8d73-f24f39bf8e11@googlegroups.com> Message-ID: On Wed, 5 Sep 2012 05:57:24 -0700 (PDT), Ramchandra Apte wrote: >On Monday, 3 September 2012 19:42:21 UTC+5:30, Manatee wrote: >> Hello all, I am learning to program in python. I have a need to make a >> >> program that can store, retrieve, add, and delete client data such as >> >> name, address, social, telephone number and similar information. This >> >> would be a small client database for my wife who has a home accounting >> >> business. >> >> >> >> I have been reading about lists, tuples, and dictionary data >> >> structures in python and I am confused as to which would be more >> >> appropriate for a simple database. >> >> >> >> I know that python has real database capabilities but I'm not there >> >> yet and would like to proceed with as simple a structure as possible. >> >> >> >> Can anyone give me some idea's or tell me which structure would be >> >> best to use? >> >> >> >> Maybe its a combination of structures? I need some help. >> >> >> >> Thanks for your help. > >If there are not more than 1000 records you can just use `pickle` Yes, not more than a 1000. My wifes clients only number 300. So not much of a problem for now I guess. I can't see it growing to double that, because 300 clients takes alot of work as it is. From markrrivet at aol.com Sat Sep 8 15:47:28 2012 From: markrrivet at aol.com (Mark R Rivet) Date: Sat, 08 Sep 2012 15:47:28 -0400 Subject: simple client data base References: <9543c9b1-d3ea-4930-af73-6659878e0077@qa3g2000pbc.googlegroups.com> Message-ID: On Thu, 6 Sep 2012 01:57:04 -0700 (PDT), Bryan wrote: >Mark R Rivet wrote: >> Hello all, I am learning to program in python. I have a need to make a >> program that can store, retrieve, add, and delete client data such as >> name, address, social, telephone number and similar information. This >> would be a small client database for my wife who has a home accounting >> business. > >Among programming languages Python is exceptionally easy to learn, and >rocks for the kind of app you describe, but your goal is not >realistic. Simple is better than complex, but what you can build at >this point is far from what a professional accountant with her own >business needs from a client database manager. > >> I have been reading about lists, tuples, and dictionary data >> structures in python and I am confused as to which would be more >> appropriate for a simple database. > >Those are good classes to read about, and I dare say that most >Pythoneers at some time faced confusion as to which were most >appropriate for the problem at hand. You'd need of all them and more, >a whole freak'in bunch more, to build a professional quality contact >manager app. > >> I know that python has real database capabilities but I'm not there >> yet and would like to proceed with as simple a structure as possible. >> >> Can anyone give me some idea's or tell me which structure would be >> best to use? >> >> Maybe its a combination of structures? I need some help. > >comp.lang.python tries to be friendly and helpful, and to that end >responders have read and answered your question as directly as >possible. There's good stuff available for Python. > >Mark, there is absolutely no chance, no how, no way, that your stated >plan is a good idea. Fine CRM apps are available for free; excellent >ones for a few dollars. You're reading about lists, tuples, and >dictionary data? Great, but other home accounting businesses have >their client databases automatically synced with their smart-phones >and their time-charging and their invoicing. > >-Bryan Well I have to say that this is most discouraging. I should give up learning to program. I don't have a chance at all. Thanks. From d at davea.name Sat Sep 8 15:58:49 2012 From: d at davea.name (Dave Angel) Date: Sat, 08 Sep 2012 15:58:49 -0400 Subject: Looking for download link for ArcPY In-Reply-To: <1347131996.708.YahooMailNeo@web133204.mail.ir2.yahoo.com> References: <1347131996.708.YahooMailNeo@web133204.mail.ir2.yahoo.com> Message-ID: <504BA379.6060007@davea.name> On 09/08/2012 03:19 PM, David Shi wrote: > Hi, All, > > Can anyone send me the link for downloading ArcPY? > > I came across it before, but can not find it anymore. > > Regards. > > David > Try this link; it looks promising. http://www.arcgis.com/home/item.html?id=3a790cd717514f4689ae197c79205805 Or ask mgwhitman at gmail.com, who started a thread yesterday asking for help with what turned out to be arcpy. He didn't give a link in his question (subject: "Defining features in a list"), but if you emailed him, he'd probably help. -- DaveA From jason at powerpull.net Sat Sep 8 16:05:49 2012 From: jason at powerpull.net (Jason Friedman) Date: Sat, 8 Sep 2012 14:05:49 -0600 Subject: simple client data base In-Reply-To: References: <9543c9b1-d3ea-4930-af73-6659878e0077@qa3g2000pbc.googlegroups.com> Message-ID: >>Mark R Rivet wrote: >>> Hello all, I am learning to program in python. I have a need to make a >>> program that can store, retrieve, add, and delete client data such as >>> name, address, social, telephone number and similar information. This >>> would be a small client database for my wife who has a home accounting >>> business. >> >>Among programming languages Python is exceptionally easy to learn, and >>rocks for the kind of app you describe, but your goal is not >>realistic. Simple is better than complex, but what you can build at >>this point is far from what a professional accountant with her own >>business needs from a client database manager. I am married, and I wonder what his wife will think if she discovers that she could have had her solution yesterday. My wife would not tolerate the roll-your-own approach, but every marriage is different. From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sat Sep 8 16:06:08 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sat, 08 Sep 2012 22:06:08 +0200 Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 19.08.2012 00:14 schrieb MRAB: >> Can someone who is more familiar with the cycle detector and cycle >> breaker, help prove or disprove the above? >> > In simple terms, when you create an immutable object it can contain > only references to pre-existing objects, but in order to create a cycle > you need to make an object refer to another which is created later, so > it's not possible to create a cycle out of immutable objects. Yes, but if I add a list in-between, I can create a refcycle: a = [] b = (a,) a.append(b) So b is a tuple consisting of one list which in turn contains b. It is not a direct cycle, but an indirect one. Or would that be detected via the list? Thomas From dwightdhutto at gmail.com Sat Sep 8 16:06:59 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sat, 8 Sep 2012 16:06:59 -0400 Subject: Looking for download link for ArcPY In-Reply-To: <1347131996.708.YahooMailNeo@web133204.mail.ir2.yahoo.com> References: <1347131996.708.YahooMailNeo@web133204.mail.ir2.yahoo.com> Message-ID: Didn't see the download link, but a quick google search yielded this: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z00000008000000 It seems it's part of a larger program ArcGIS 10. These are the docs for it, and how to use it, so it should be in there somewhere. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Sat Sep 8 16:11:27 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 08 Sep 2012 13:11:27 -0700 Subject: simple client data base References: <9543c9b1-d3ea-4930-af73-6659878e0077@qa3g2000pbc.googlegroups.com> Message-ID: <7xd31wff68.fsf@ruckus.brouhaha.com> Mark R Rivet writes: >>ones for a few dollars. You're reading about lists, tuples, and >>dictionary data? Great, but other home accounting businesses have >>their client databases automatically synced with their smart-phones >>and their time-charging and their invoicing. > Well I have to say that this is most discouraging. I should give up > learning to program. I don't have a chance at all. Thanks. I think the idea is just to start with something simpler. If you are interested in mechanical engineering, then building an automobile from scratch, machining all the parts yourself etc., would be an ill-advised choice as a first project. It's the same way with programming. From matteo.g at gmx.net Sat Sep 8 16:31:45 2012 From: matteo.g at gmx.net (=?ISO-8859-1?Q?Matteo_Gr=E4mlin?=) Date: Sat, 08 Sep 2012 22:31:45 +0200 Subject: Initial pointers for web based LAMP installation Message-ID: Hi all This is what I want to do: On a LAMP server, people are able to request for an instance of a particular LAMP application by submitting a few options. That involves creating a couple of directories, getting the code, writing a config file, setting file permissions and creating a mysql user. I can do it except for the interface with a shell script. Because of the web interface I was told that python is the right language but I have no knowledge in python. Could you pl. give me the initial pointers for this scheme? Matteo From mymixedmess at gmail.com Sat Sep 8 16:32:31 2012 From: mymixedmess at gmail.com (Ian W) Date: Sat, 8 Sep 2012 15:32:31 -0500 Subject: simple client data base In-Reply-To: <7xd31wff68.fsf@ruckus.brouhaha.com> References: <9543c9b1-d3ea-4930-af73-6659878e0077@qa3g2000pbc.googlegroups.com> <7xd31wff68.fsf@ruckus.brouhaha.com> Message-ID: On Sat, Sep 8, 2012 at 3:11 PM, Paul Rubin wrote: > I think the idea is just to start with something simpler. If you are > interested in mechanical engineering, then building an automobile from > scratch, machining all the parts yourself etc., would be an ill-advised > choice as a first project. It's the same way with programming. I'm wondering what his backup plan is for the information, in case his database somehow messes things up. It's smarter to start with something that's not vital to the functioning of your wife's business. Ian From walterhurry at lavabit.com Sat Sep 8 16:39:44 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Sat, 8 Sep 2012 20:39:44 +0000 (UTC) Subject: simple client data base References: <9543c9b1-d3ea-4930-af73-6659878e0077@qa3g2000pbc.googlegroups.com> <7xd31wff68.fsf@ruckus.brouhaha.com> Message-ID: On Sat, 08 Sep 2012 13:11:27 -0700, Paul Rubin wrote: > Mark R Rivet writes: >>>ones for a few dollars. You're reading about lists, tuples, and >>>dictionary data? Great, but other home accounting businesses have their >>>client databases automatically synced with their smart-phones and their >>>time-charging and their invoicing. >> Well I have to say that this is most discouraging. I should give up >> learning to program. I don't have a chance at all. Thanks. > > I think the idea is just to start with something simpler. If you are > interested in mechanical engineering, then building an automobile from > scratch, machining all the parts yourself etc., would be an ill-advised > choice as a first project. It's the same way with programming. And he has it backwards anyway, IMHO. If he wants a client database and insists on building it himself, he should start with the relational database and work up; not from the GUI and try to work down with silly solutions like pickling. From grahn+nntp at snipabacken.se Sat Sep 8 17:03:34 2012 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 8 Sep 2012 21:03:34 GMT Subject: simple client data base References: <9543c9b1-d3ea-4930-af73-6659878e0077@qa3g2000pbc.googlegroups.com> Message-ID: On Sat, 2012-09-08, Mark R Rivet wrote: > On Thu, 6 Sep 2012 01:57:04 -0700 (PDT), Bryan > wrote: ... >>comp.lang.python tries to be friendly and helpful, and to that end >>responders have read and answered your question as directly as >>possible. There's good stuff available for Python. >> >>Mark, there is absolutely no chance, no how, no way, that your stated >>plan is a good idea. Fine CRM apps are available for free; excellent >>ones for a few dollars. You're reading about lists, tuples, and >>dictionary data? Great, but other home accounting businesses have >>their client databases automatically synced with their smart-phones >>and their time-charging and their invoicing. >> >>-Bryan > Well I have to say that this is most discouraging. I should give up > learning to program. I don't have a chance at all. Thanks. He's saying you don't have a chance, but he's *not* telling you to give up programming. Personal reflection: it's risky to make friends and relatives depend on the success of your hobby projects. I got away with it once or twice (under special circumstances) but it might equally well have ended with resentment. "Why did he sell this crap idea to me? Now I'm stuck with it." /Jorgen -- // Jorgen Grahn O o . From hansmu at xs4all.nl Sat Sep 8 17:18:29 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 08 Sep 2012 23:18:29 +0200 Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <504bb625$0$6904$e4fe514c@news2.news.xs4all.nl> On 8/09/12 22:06:08, Thomas Rachel wrote: > Am 19.08.2012 00:14 schrieb MRAB: > >>> Can someone who is more familiar with the cycle detector and cycle >>> breaker, help prove or disprove the above? >>> >> In simple terms, when you create an immutable object it can contain >> only references to pre-existing objects, but in order to create a cycle >> you need to make an object refer to another which is created later, so >> it's not possible to create a cycle out of immutable objects. > > Yes, but if I add a list in-between, I can create a refcycle: > > a = [] > b = (a,) > a.append(b) > > So b is a tuple consisting of one list which in turn contains b. > > It is not a direct cycle, but an indirect one. It's a cycle and it contains an immutable object, but it's not a cycle consisting of immutable objects only. As MRAB was arguing: it is not possbible to create a cycle consisting of immutable objects only (unless you do unspeakable things at the C level). -- HansM From python at mrabarnett.plus.com Sat Sep 8 17:22:55 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 08 Sep 2012 22:22:55 +0100 Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <504BB72F.5070702@mrabarnett.plus.com> On 08/09/2012 21:06, Thomas Rachel wrote: > Am 19.08.2012 00:14 schrieb MRAB: > >>> Can someone who is more familiar with the cycle detector and cycle >>> breaker, help prove or disprove the above? >>> >> In simple terms, when you create an immutable object it can contain >> only references to pre-existing objects, but in order to create a cycle >> you need to make an object refer to another which is created later, so >> it's not possible to create a cycle out of immutable objects. > > Yes, but if I add a list in-between, I can create a refcycle: > > a = [] > b = (a,) > a.append(b) > > So b is a tuple consisting of one list which in turn contains b. > > It is not a direct cycle, but an indirect one. > > Or would that be detected via the list? > The quote was: ''' ...The tuple type does not implement a tp_clear function, because it?s possible to prove that no reference cycle can be composed entirely of tuples. ''' Note: "composed entirely of tuples". Or, in general, composed entirely of immutables. Lists are not immutable, therefore the proof does not apply. From castironpi at gmail.com Sat Sep 8 18:07:19 2012 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 8 Sep 2012 15:07:19 -0700 (PDT) Subject: set and dict iteration In-Reply-To: <50367242$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> <50367242$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, August 23, 2012 1:11:14 PM UTC-5, Steven D'Aprano wrote: > On Thu, 23 Aug 2012 09:49:41 -0700, Aaron Brady wrote: > > > > [...] > > > The patch for the above is only 40-60 lines. However it introduces two > > > new concepts. > > > > > > The first is a "linked list", a classic dynamic data structure, first > > > developed in 1955, cf. http://en.wikipedia.org/wiki/Linked_list . > > > Linked lists are absent in Python > > > > They certainly are not. There's merely no named "linked list" class. > > > > Linked lists are used by collections.ChainMap, tracebacks, xml.dom, > > Abstract Syntax Trees, and probably many other places. (Well, technically > > some of these are trees rather than lists.) You can trivially create a > > linked list: > > > > x = [a, [b, [c, [d, [e, None]]]]] > > > > is equivalent to a singly-linked list with five nodes. Only less > > efficient. > [snip.] > > -- > > Steven That's not totally true. Your formulation is equivalent to a single-linked list, but a double-linked list can't be represented as an expression because it contains reference cycles. Single and double-linked lists have the same requirements for inserting a new node. For instance: [a, [b, [c, [d, [e, None]]]]] [a, [a2, [b, [c, [d, [e, None]]]]]] However, to remove a node, the single-linked list requires iterating over the entire list to find the predecessor of the target, whereas the double-linked list already contains that information. [a, [b, [c, [d, [e, None]]]]] [a, [b, [c, [e, None]]]] The difference might be moot in some applications, such as if we only remove nodes when we're already iterating. Memory constraints were more severe 50 years ago when the structure was developed. The difference between one pointer and two in a structure could have a big impact in repetition. The single-linked list admits more easily of recursive algorithms as well. From cs at zip.com.au Sat Sep 8 19:26:46 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 9 Sep 2012 09:26:46 +1000 Subject: AttributeError: 'list' object has no attribute 'lower' In-Reply-To: References: Message-ID: <20120908232646.GA3320@cskk.homeip.net> On 08Sep2012 13:45, Roy Smith wrote: | First, I don't understand this code: | | In article , | Token Type wrote: | > synset_list = list(wn.all_synsets(pos)) | > lemma_list = [synset.lemma_names for synset in synset_list] | | It looks like you're taking an iterable, converting it to a list, just | so you can iterate over it again. Why not the simpler: | | > lemma_list = [synset.lemma_names for synset in wn.all_synsets(pos)] Speaking for myself, when I write something like that it is because I need to iterate over it twice or more. Often I'll make a tuple instead of a list in that case, too, to avoid certain types of accidents. | ? But, I'm also confused about what lemma_list is supposed to end up | being. The name "lemma_names" is plural, making me think it returns a | list of something. And then you build those up into a list of lists? | | In fact, I'm guessing that's your problem. I think you're ending up | with a list of lists of strings, when you think you're getting a list of | strings. In my case, I have most often had this error (.lower or its equivalent) when I've accidentally converted a string into a list of characters; easy to do because strings are themselves iterables, yielding a sequence of single character strings:-) It is usually an accident from getting my nesting wrong somewhere. | My suggestion is to print out all the intermediate data structures | (synset_list, lemma_list, etc) and see what they look like. If the | structures are simple, just plain print will work, but for more | complicated structures, pprint.pprint() is a life saver. | | Another possibility is to assert that things are what you expect them to | be. Something like: | | assert isinstance(synset_list, list) | assert isinstance(lemma_list, list) | assert isinstance(lemma_list[0], str) | | and so on. +1 to all of this, too. Cheers, -- Cameron Simpson Too much of a good thing is never enough. - Luba From dwightdhutto at gmail.com Sat Sep 8 19:42:29 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sat, 8 Sep 2012 19:42:29 -0400 Subject: Initial pointers for web based LAMP installation In-Reply-To: References: Message-ID: On Sat, Sep 8, 2012 at 4:31 PM, Matteo Gr?mlin wrote: > Hi all > > This is what I want to do: On a LAMP server, people are able > to request for an instance of a particular LAMP application > by submitting a few options. That involves creating a couple > of directories, getting the code, writing a config file, > setting file permissions and creating a mysql user. > > I can do it except for the interface with a shell script. Because > of the web interface I was told that python is the right language > but I have no knowledge in python. > > Could you pl. give me the initial pointers for this scheme? > I haven't played with this part of that much of Linux yet. you give them group access, certain privileges, and shell access, then they sudo apt-get install, or you, and use it in usr/shr I think, but not from the admin, it becomes sandboxed. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Sat Sep 8 19:43:46 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sat, 8 Sep 2012 19:43:46 -0400 Subject: Initial pointers for web based LAMP installation In-Reply-To: References: Message-ID: On Sat, Sep 8, 2012 at 7:42 PM, Dwight Hutto wrote: > > > On Sat, Sep 8, 2012 at 4:31 PM, Matteo Gr?mlin wrote: > >> Hi all >> >> This is what I want to do: On a LAMP server, people are able >> to request for an instance of a particular LAMP application >> by submitting a few options. That involves creating a couple >> of directories, getting the code, writing a config file, >> setting file permissions and creating a mysql user. >> >> I can do it except for the interface with a shell script. Because >> of the web interface I was told that python is the right language >> but I have no knowledge in python. >> >> Could you pl. give me the initial pointers for this scheme? >> > I haven't played with this part of that much of Linux yet. > > you give them group access, certain privileges, and shell access, then > they sudo apt-get install, or yum(correction), etc., and use it in usr/shr > I think, but not from the admin, it becomes sandboxed. > > > -- > Best Regards, > David Hutto > *CEO:* *http://www.hitwebdevelopment.com* > > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Sat Sep 8 19:45:22 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sat, 8 Sep 2012 19:45:22 -0400 Subject: Initial pointers for web based LAMP installation In-Reply-To: References: Message-ID: On Sat, Sep 8, 2012 at 7:42 PM, Dwight Hutto wrote: > > > On Sat, Sep 8, 2012 at 4:31 PM, Matteo Gr?mlin wrote: > >> Hi all >> >> This is what I want to do: On a LAMP server, people are able >> to request for an instance of a particular LAMP application >> by submitting a few options. That involves creating a couple >> of directories, getting the code, writing a config file, >> setting file permissions and creating a mysql user. >> >> I can do it except for the interface with a shell script. Because >> of the web interface I was told that python is the right language >> but I have no knowledge in python. >> >> Could you pl. give me the initial pointers for this scheme? >> > I haven't played with this part of that much of Linux yet. > > you give them group access, certain privileges, and shell access, then > they sudo apt-get install, or yum,etc., and use it in usr/shr I think, but > not from the admin, it becomes sandboxed. > > > -- > Best Regards, > David Hutto > *CEO:* *http://www.hitwebdevelopment.com* > > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jdgleeson at mac.com Sat Sep 8 20:20:25 2012 From: jdgleeson at mac.com (John Gleeson) Date: Sat, 08 Sep 2012 18:20:25 -0600 Subject: Parsing ISO date/time strings - where did the parser go? In-Reply-To: References: <7xbohj3p6e.fsf@ruckus.brouhaha.com> Message-ID: On 2012-09-06, at 2:34 PM, John Nagle wrote: > Yes, it should. There's no shortage of implementations. > PyPi has four. Each has some defect. > > PyPi offers: > > iso8601 0.1.4 Simple module to parse ISO 8601 dates > iso8601.py 0.1dev Parse utilities for iso8601 encoding. > iso8601plus 0.1.6 Simple module to parse ISO 8601 dates > zc.iso8601 0.2.0 ISO 8601 utility functions Here are three more on PyPI you can try: iso-8601 0.2.3 Flexible ISO 8601 parser... PySO8601 0.1.7 PySO8601 aims to parse any ISO 8601 date... isodate 0.4.8 An ISO 8601 date/time/duration parser and formater All three have been updated this year. From gelonida at gmail.com Sat Sep 8 22:03:56 2012 From: gelonida at gmail.com (Gelonida N) Date: Sun, 09 Sep 2012 04:03:56 +0200 Subject: how to run python2.6 module with absolute imports stand alone In-Reply-To: References: Message-ID: On 09/08/2012 02:13 AM, Mark Lawrence wrote: > On 07/09/2012 23:04, Gelonida N wrote: >> Hi, >> >> many of my modules contain following section at the end >> >> >> def main(): >> do_something() >> if __name__ == '__main__': >> main() >> >> This allows me to run some basic example code >> or some small test in a stand alone mode. >> >> >> My new modules contain following line at the beginning: >> >> from __future__ import absolute_import >> >> >> I like this: >> - It can reduce import name conflicts >> - and second it allows 'relative' imports like >> from .othermodule import funcname >> from ..mod_one_level_higher import fdfsd >> >> >> However If I try to run such a script from the command line it will now >> complain with >> >> ValueError: Attempted relative import in non-package >> >> Any tricks to work around this ??? >> >> The only idea, that I have is to have a script, that would take my >> modulename or path name as parameter, and try to import it and then call >> the main function of the imported module. >> >> >> Not very elegant, but probably functional. >> >> Thanks in advance for any other suggestions / ideas. >> > > I hope this helps > http://stackoverflow.com/questions/3616952/how-to-properly-use-relative-or-absolute-imports-in-python-modules It seems the safest bet seems to be to not use relative imports. What I did in the end however is write a wrapper script, that takes another script as parameter, converts it's path name to a module name, imports it, adapts sys.path and calls main of the imported module. Perhaps a little overkill, but most convenient, as the script can even adapt sys.path prior to importing other files if required. > > From nagle at animats.com Sat Sep 8 23:51:03 2012 From: nagle at animats.com (John Nagle) Date: Sat, 08 Sep 2012 20:51:03 -0700 Subject: Parsing ISO date/time strings - where did the parser go? In-Reply-To: References: <7xbohj3p6e.fsf@ruckus.brouhaha.com> Message-ID: On 9/8/2012 5:20 PM, John Gleeson wrote: > > On 2012-09-06, at 2:34 PM, John Nagle wrote: >> Yes, it should. There's no shortage of implementations. >> PyPi has four. Each has some defect. >> >> PyPi offers: >> >> iso8601 0.1.4 Simple module to parse ISO 8601 dates >> iso8601.py 0.1dev Parse utilities for iso8601 encoding. >> iso8601plus 0.1.6 Simple module to parse ISO 8601 dates >> zc.iso8601 0.2.0 ISO 8601 utility functions > > > Here are three more on PyPI you can try: > > iso-8601 0.2.3 Flexible ISO 8601 parser... > PySO8601 0.1.7 PySO8601 aims to parse any ISO 8601 date... > isodate 0.4.8 An ISO 8601 date/time/duration parser and formater > > All three have been updated this year. There's another one inside feedparser, and there used to be one in the xml module. Filed issue 15873: "datetime" cannot parse ISO 8601 dates and times http://bugs.python.org/issue15873 This really should be handled in the standard library, instead of everybody rolling their own, badly. Especially since in Python 3.x, there's finally a useful "tzinfo" subclass for fixed time zone offsets. That provides a way to directly represent ISO 8601 date/time strings with offsets as "time zone aware" date time objects. John Nagle From typetoken at gmail.com Sun Sep 9 01:43:24 2012 From: typetoken at gmail.com (Token Type) Date: Sat, 8 Sep 2012 22:43:24 -0700 (PDT) Subject: Is there a unique method in python to unique a list? Message-ID: Is there a unique method in python to unique a list? thanks From donald.stufft at gmail.com Sun Sep 9 01:47:40 2012 From: donald.stufft at gmail.com (Donald Stufft) Date: Sun, 9 Sep 2012 01:47:40 -0400 Subject: Is there a unique method in python to unique a list? In-Reply-To: References: Message-ID: <60A480B7378343149401A424A682AF34@gmail.com> If you don't need to retain order you can just use a set, set([1, 1, 2, 3, 4]) = set([1, 2, 3, 4]) But set's don't retain order. On Sunday, September 9, 2012 at 1:43 AM, Token Type wrote: > Is there a unique method in python to unique a list? thanks > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Sep 9 01:48:35 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 9 Sep 2012 15:48:35 +1000 Subject: Is there a unique method in python to unique a list? In-Reply-To: References: Message-ID: On Sun, Sep 9, 2012 at 3:43 PM, Token Type wrote: > Is there a unique method in python to unique a list? thanks I don't believe there's a method for that, but if you don't care about order, try turning your list into a set and then back into a list. ChrisA From typetoken at gmail.com Sun Sep 9 02:29:02 2012 From: typetoken at gmail.com (John H. Li) Date: Sun, 9 Sep 2012 14:29:02 +0800 Subject: Is there a unique method in python to unique a list? In-Reply-To: References: <60A480B7378343149401A424A682AF34@gmail.com> Message-ID: Many thanks. I put all the set result into a list first . Then it will work and work without result displayed. >>> import nltk >>> from nltk.corpus import wordnet as wn >>> def average_polysemy(pos): synset_list = list(wn.all_synsets(pos)) sense_number = 0 lemma_list =[] for synset in synset_list: lemma_list.extend(synset.lemma_names) unqiue_lemma_list = list(set(lemma_list)) for lemma in unique_lemma_list: sense_number_new = len(wn.synsets(lemma, pos)) sense_number = sense_number + sense_number_new return sense_number/len(unique_lemma_list) >>> average_polysemy('n') However, if I don't put list(set(lemma_list)) to a variable name, it works much faster. Say: >>> def average_polysemy(pos): synset_list = list(wn.all_synsets(pos)) sense_number = 0 lemma_list = [] for synset in synset_list: lemma_list.extend(synset.lemma_names) for lemma in list(set(lemma_list)): sense_number_new = len(wn.synsets(lemma, pos)) sense_number = sense_number + sense_number_new return sense_number/len(set(lemma_list)) >>> average_polysemy('n') 1 Do you know why there is such a big difference? Does that mean set() will work slower if its value is given to a variable name? On Sun, Sep 9, 2012 at 1:59 PM, Donald Stufft wrote: > seen = set() > uniqued = [] > for x in original: > if not x in seen: > seen.add(x) > uniqued.append(x) > > or > > uniqued = [] > for x in oriignal: > if not x in uniqued: > uniqued.append(x) > > The difference between is option #1 is more efficient speed wise, but uses > more memory (extraneous set hanging around), whereas the second is slower > (``in`` is slower in lists than in sets) but uses less memory. > > On Sunday, September 9, 2012 at 1:56 AM, John H. Li wrote: > > Many thanks. If I want keep the order, how can I deal with it? > or we can list(set([1, 1, 2, 3, 4])) = [1,2,3,4] > > > On Sun, Sep 9, 2012 at 1:47 PM, Donald Stufft wrote: > > If you don't need to retain order you can just use a set, > > set([1, 1, 2, 3, 4]) = set([1, 2, 3, 4]) > > But set's don't retain order. > > On Sunday, September 9, 2012 at 1:43 AM, Token Type wrote: > > Is there a unique method in python to unique a list? thanks > -- > http://mail.python.org/mailman/listinfo/python-list > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From typetoken at gmail.com Sun Sep 9 02:31:45 2012 From: typetoken at gmail.com (John H. Li) Date: Sun, 9 Sep 2012 14:31:45 +0800 Subject: Is there a unique method in python to unique a list? In-Reply-To: References: <60A480B7378343149401A424A682AF34@gmail.com> Message-ID: Thanks first, I could understand the second approach easily. The first approach is a bit puzzling. Why are seen=set() and seen.add(x) still necessary there if we can use unique.append(x) alone? Thanks for your enlightenment. On Sun, Sep 9, 2012 at 1:59 PM, Donald Stufft wrote: > seen = set() > uniqued = [] > for x in original: > if not x in seen: > seen.add(x) > uniqued.append(x) > > or > > uniqued = [] > for x in oriignal: > if not x in uniqued: > uniqued.append(x) > > The difference between is option #1 is more efficient speed wise, but uses > more memory (extraneous set hanging around), whereas the second is slower > (``in`` is slower in lists than in sets) but uses less memory. > > On Sunday, September 9, 2012 at 1:56 AM, John H. Li wrote: > > Many thanks. If I want keep the order, how can I deal with it? > or we can list(set([1, 1, 2, 3, 4])) = [1,2,3,4] > > > On Sun, Sep 9, 2012 at 1:47 PM, Donald Stufft wrote: > > If you don't need to retain order you can just use a set, > > set([1, 1, 2, 3, 4]) = set([1, 2, 3, 4]) > > But set's don't retain order. > > On Sunday, September 9, 2012 at 1:43 AM, Token Type wrote: > > Is there a unique method in python to unique a list? thanks > -- > http://mail.python.org/mailman/listinfo/python-list > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Sep 9 02:32:48 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 9 Sep 2012 16:32:48 +1000 Subject: Is there a unique method in python to unique a list? In-Reply-To: References: <60A480B7378343149401A424A682AF34@gmail.com> Message-ID: On Sun, Sep 9, 2012 at 4:29 PM, John H. Li wrote: > However, if I don't put list(set(lemma_list)) to a variable name, it works > much faster. Try backdenting that statement. You're currently doing it at every iteration of the loop - that's why it's so much slower. But you'll probably find it better to work with the set directly, instead of uniquifying a list as a separate operation. ChrisA From donald.stufft at gmail.com Sun Sep 9 02:36:24 2012 From: donald.stufft at gmail.com (Donald Stufft) Date: Sun, 9 Sep 2012 02:36:24 -0400 Subject: Is there a unique method in python to unique a list? In-Reply-To: References: <60A480B7378343149401A424A682AF34@gmail.com> Message-ID: <8F6B0BD8CC404B72AE9D11573AD28569@gmail.com> For a short list the difference is going to be negligible. For a long list the difference is that checking if an item in a list requires iterating over the list internally to find it but checking if an item is inside of a set uses a faster method that doesn't require iterating over the list. This doesn't matter if you have 20 or 30 items, but imagine if instead you have 50 million items. Your going to be iterating over the list a lot and that can introduce significant slow dow. On the other hand using a set is faster in that case, but because you are storing an additional copy of the data you are using more memory to store extra copies of everything. On Sunday, September 9, 2012 at 2:31 AM, John H. Li wrote: > Thanks first, I could understand the second approach easily. The first approach is a bit puzzling. Why are seen=set() and seen.add(x) still necessary there if we can use unique.append(x) alone? Thanks for your enlightenment. > > On Sun, Sep 9, 2012 at 1:59 PM, Donald Stufft wrote: > > seen = set() > > uniqued = [] > > for x in original: > > if not x in seen: > > seen.add(x) > > uniqued.append(x) > > > > or > > > > uniqued = [] > > for x in oriignal: > > if not x in uniqued: > > uniqued.append(x) > > > > The difference between is option #1 is more efficient speed wise, but uses more memory (extraneous set hanging around), whereas the second is slower (``in`` is slower in lists than in sets) but uses less memory. > > > > On Sunday, September 9, 2012 at 1:56 AM, John H. Li wrote: > > > > > Many thanks. If I want keep the order, how can I deal with it? > > > or we can list(set([1, 1, 2, 3, 4])) = [1,2,3,4] > > > > > > > > > On Sun, Sep 9, 2012 at 1:47 PM, Donald Stufft wrote: > > > > If you don't need to retain order you can just use a set, > > > > > > > > set([1, 1, 2, 3, 4]) = set([1, 2, 3, 4]) > > > > > > > > But set's don't retain order. > > > > > > > > On Sunday, September 9, 2012 at 1:43 AM, Token Type wrote: > > > > > > > > > Is there a unique method in python to unique a list? thanks > > > > > -- > > > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From typetoken at gmail.com Sun Sep 9 02:44:59 2012 From: typetoken at gmail.com (Token Type) Date: Sat, 8 Sep 2012 23:44:59 -0700 (PDT) Subject: Is there a unique method in python to unique a list? In-Reply-To: References: <60A480B7378343149401A424A682AF34@gmail.com> Message-ID: <422330d0-d6d4-4626-8fb3-308e4f2e2a8a@googlegroups.com> > Try backdenting that statement. You're currently doing it at every > > iteration of the loop - that's why it's so much slower. Thanks. I works now. >>> def average_polysemy(pos): synset_list = list(wn.all_synsets(pos)) sense_number = 0 lemma_list = [] for synset in synset_list: lemma_list.extend(synset.lemma_names) for lemma in list(set(lemma_list)): sense_number_new = len(wn.synsets(lemma, pos)) sense_number = sense_number + sense_number_new return sense_number/len(set(lemma_list)) >>> average_polysemy('n') 1 > But you'll probably find it better to work with the set directly, > > instead of uniquifying a list as a separate operation. Yes, the following second methods still runs faster if I don't give a separate variable name to list(set(lemma_list)). Why will this happen? >>> def average_polysemy(pos): synset_list = list(wn.all_synsets(pos)) sense_number = 0 lemma_list = [] for synset in synset_list: lemma_list.extend(synset.lemma_names) for lemma in list(set(lemma_list)): sense_number_new = len(wn.synsets(lemma, pos)) sense_number = sense_number + sense_number_new return sense_number/len(set(lemma_list)) >>> average_polysemy('n') 1 From typetoken at gmail.com Sun Sep 9 02:44:59 2012 From: typetoken at gmail.com (Token Type) Date: Sat, 8 Sep 2012 23:44:59 -0700 (PDT) Subject: Is there a unique method in python to unique a list? In-Reply-To: References: <60A480B7378343149401A424A682AF34@gmail.com> Message-ID: <422330d0-d6d4-4626-8fb3-308e4f2e2a8a@googlegroups.com> > Try backdenting that statement. You're currently doing it at every > > iteration of the loop - that's why it's so much slower. Thanks. I works now. >>> def average_polysemy(pos): synset_list = list(wn.all_synsets(pos)) sense_number = 0 lemma_list = [] for synset in synset_list: lemma_list.extend(synset.lemma_names) for lemma in list(set(lemma_list)): sense_number_new = len(wn.synsets(lemma, pos)) sense_number = sense_number + sense_number_new return sense_number/len(set(lemma_list)) >>> average_polysemy('n') 1 > But you'll probably find it better to work with the set directly, > > instead of uniquifying a list as a separate operation. Yes, the following second methods still runs faster if I don't give a separate variable name to list(set(lemma_list)). Why will this happen? >>> def average_polysemy(pos): synset_list = list(wn.all_synsets(pos)) sense_number = 0 lemma_list = [] for synset in synset_list: lemma_list.extend(synset.lemma_names) for lemma in list(set(lemma_list)): sense_number_new = len(wn.synsets(lemma, pos)) sense_number = sense_number + sense_number_new return sense_number/len(set(lemma_list)) >>> average_polysemy('n') 1 From typetoken at gmail.com Sun Sep 9 03:18:54 2012 From: typetoken at gmail.com (John H. Li) Date: Sun, 9 Sep 2012 15:18:54 +0800 Subject: Is there a unique method in python to unique a list? In-Reply-To: <8F6B0BD8CC404B72AE9D11573AD28569@gmail.com> References: <60A480B7378343149401A424A682AF34@gmail.com> <8F6B0BD8CC404B72AE9D11573AD28569@gmail.com> Message-ID: Thanks again. What you explain is reasonable. I try to the second method to unique the list. It does turn out that python just works and works without result. Maybe because it do iterate a long list in my example and slow. >>> def average_polysemy(pos): synset_list = list(wn.all_synsets(pos)) sense_number = 0 lemma_list = [] for synset in synset_list: lemma_list.extend(synset.lemma_names) unique_lemma_list = [] for w in lemma_list: if not w in unique_lemma_list: unique_lemma_list.append(w) return unique_lemma_list for lemma in unique_lemma_list: sense_number_new = len(wn.synsets(lemma, pos)) sense_number = sense_number + sense_number_new return sense_number/len(unique_lemma_list) >>> average_polysemy('n') On Sun, Sep 9, 2012 at 2:36 PM, Donald Stufft wrote: > For a short list the difference is going to be negligible. > > For a long list the difference is that checking if an item in a list > requires iterating over the list internally to find it but checking if an > item is inside of a set uses a faster method that doesn't require iterating > over the list. This doesn't matter if you have 20 or 30 items, but imagine > if instead you have 50 million items. Your going to be iterating over the > list a lot and that can introduce significant slow dow. > > On the other hand using a set is faster in that case, but because you are > storing an additional copy of the data you are using more memory to store > extra copies of everything. > > On Sunday, September 9, 2012 at 2:31 AM, John H. Li wrote: > > Thanks first, I could understand the second approach easily. The first > approach is a bit puzzling. Why are seen=set() and seen.add(x) still > necessary there if we can use unique.append(x) alone? Thanks for your > enlightenment. > > On Sun, Sep 9, 2012 at 1:59 PM, Donald Stufft wrote: > > seen = set() > uniqued = [] > for x in original: > if not x in seen: > seen.add(x) > uniqued.append(x) > > or > > uniqued = [] > for x in oriignal: > if not x in uniqued: > uniqued.append(x) > > The difference between is option #1 is more efficient speed wise, but uses > more memory (extraneous set hanging around), whereas the second is slower > (``in`` is slower in lists than in sets) but uses less memory. > > On Sunday, September 9, 2012 at 1:56 AM, John H. Li wrote: > > Many thanks. If I want keep the order, how can I deal with it? > or we can list(set([1, 1, 2, 3, 4])) = [1,2,3,4] > > > On Sun, Sep 9, 2012 at 1:47 PM, Donald Stufft wrote: > > If you don't need to retain order you can just use a set, > > set([1, 1, 2, 3, 4]) = set([1, 2, 3, 4]) > > But set's don't retain order. > > On Sunday, September 9, 2012 at 1:43 AM, Token Type wrote: > > Is there a unique method in python to unique a list? thanks > -- > http://mail.python.org/mailman/listinfo/python-list > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From typetoken at gmail.com Sun Sep 9 03:29:45 2012 From: typetoken at gmail.com (John H. Li) Date: Sun, 9 Sep 2012 15:29:45 +0800 Subject: Is there a unique method in python to unique a list? In-Reply-To: References: <60A480B7378343149401A424A682AF34@gmail.com> <8F6B0BD8CC404B72AE9D11573AD28569@gmail.com> Message-ID: One more test result to add, if I use your first method to unique: seen = set() uniqued = [] for x in original: if not x in seen: seen.add(x) uniqued.append(x) The results pops up in a few seconds. It makes a dramatic difference. Thanks. See the following fasted codes? >>> import nltk >>> from nltk.corpus import wordnet as wn >>> def average_polysemy(pos): synset_list = list(wn.all_synsets(pos)) sense_number = 0 lemma_list = [] for synset in synset_list: lemma_list.extend(synset.lemma_names) unique_lemma_list = [] seen = set() for w in lemma_list: if not w in seen: seen.add(w) unique_lemma_list.append(w) for lemma in unique_lemma_list: sense_number_new = len(wn.synsets(lemma, pos)) sense_number = sense_number + sense_number_new return sense_number/len(unique_lemma_list) >>> average_polysemy('n') 1 On Sun, Sep 9, 2012 at 3:18 PM, John H. Li wrote: > Thanks again. What you explain is reasonable. I try to the second method > to unique the list. It does turn out that python just works and works > without result. Maybe because it do iterate a long list in my example and > slow. > > >>> def average_polysemy(pos): > synset_list = list(wn.all_synsets(pos)) > sense_number = 0 > lemma_list = [] > for synset in synset_list: > lemma_list.extend(synset.lemma_names) > unique_lemma_list = [] > for w in lemma_list: > if not w in unique_lemma_list: > unique_lemma_list.append(w) > return unique_lemma_list > for lemma in unique_lemma_list: > sense_number_new = len(wn.synsets(lemma, pos)) > sense_number = sense_number + sense_number_new > return sense_number/len(unique_lemma_list) > > >>> average_polysemy('n') > > On Sun, Sep 9, 2012 at 2:36 PM, Donald Stufft wrote: > >> For a short list the difference is going to be negligible. >> >> For a long list the difference is that checking if an item in a list >> requires iterating over the list internally to find it but checking if an >> item is inside of a set uses a faster method that doesn't require iterating >> over the list. This doesn't matter if you have 20 or 30 items, but imagine >> if instead you have 50 million items. Your going to be iterating over the >> list a lot and that can introduce significant slow dow. >> >> On the other hand using a set is faster in that case, but because you are >> storing an additional copy of the data you are using more memory to store >> extra copies of everything. >> >> On Sunday, September 9, 2012 at 2:31 AM, John H. Li wrote: >> >> Thanks first, I could understand the second approach easily. The first >> approach is a bit puzzling. Why are seen=set() and seen.add(x) still >> necessary there if we can use unique.append(x) alone? Thanks for your >> enlightenment. >> >> On Sun, Sep 9, 2012 at 1:59 PM, Donald Stufft wrote: >> >> seen = set() >> uniqued = [] >> for x in original: >> if not x in seen: >> seen.add(x) >> uniqued.append(x) >> >> or >> >> uniqued = [] >> for x in oriignal: >> if not x in uniqued: >> uniqued.append(x) >> >> The difference between is option #1 is more efficient speed wise, but >> uses more memory (extraneous set hanging around), whereas the second is >> slower (``in`` is slower in lists than in sets) but uses less memory. >> >> On Sunday, September 9, 2012 at 1:56 AM, John H. Li wrote: >> >> Many thanks. If I want keep the order, how can I deal with it? >> or we can list(set([1, 1, 2, 3, 4])) = [1,2,3,4] >> >> >> On Sun, Sep 9, 2012 at 1:47 PM, Donald Stufft wrote: >> >> If you don't need to retain order you can just use a set, >> >> set([1, 1, 2, 3, 4]) = set([1, 2, 3, 4]) >> >> But set's don't retain order. >> >> On Sunday, September 9, 2012 at 1:43 AM, Token Type wrote: >> >> Is there a unique method in python to unique a list? thanks >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> >> >> >> >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From storchaka at gmail.com Sun Sep 9 04:36:43 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sun, 09 Sep 2012 11:36:43 +0300 Subject: Is there a unique method in python to unique a list? In-Reply-To: <60A480B7378343149401A424A682AF34@gmail.com> References: <60A480B7378343149401A424A682AF34@gmail.com> Message-ID: On 09.09.12 08:47, Donald Stufft wrote: > If you don't need to retain order you can just use a set, Only if elements are hashable. From no.email at nospam.invalid Sun Sep 9 04:41:09 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 09 Sep 2012 01:41:09 -0700 Subject: Is there a unique method in python to unique a list? References: <60A480B7378343149401A424A682AF34@gmail.com> Message-ID: <7xwr03oafu.fsf@ruckus.brouhaha.com> Token Type writes: >>>> def average_polysemy(pos): > synset_list = list(wn.all_synsets(pos)) > sense_number = 0 > lemma_list = [] > for synset in synset_list: > lemma_list.extend(synset.lemma_names) > for lemma in list(set(lemma_list)): > sense_number_new = len(wn.synsets(lemma, pos)) > sense_number = sense_number + sense_number_new > return sense_number/len(set(lemma_list)) I think you mean (untested): synsets = wn.all_synsets(pos) sense_number = 0 lemma_set = set() for synset in synsets: lemma_set.add(synset.lemma_names) for lemma in lemma_set: sense_number += len(wn.synsets(lemma,pos)) return sense_number / len(lemma_set) From no.email at nospam.invalid Sun Sep 9 05:06:49 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 09 Sep 2012 02:06:49 -0700 Subject: Is there a unique method in python to unique a list? References: <60A480B7378343149401A424A682AF34@gmail.com> <7xwr03oafu.fsf@ruckus.brouhaha.com> Message-ID: <7x7gs34lau.fsf@ruckus.brouhaha.com> Paul Rubin writes: > I think you mean (untested): > > synsets = wn.all_synsets(pos) > sense_number = 0 > lemma_set = set() > for synset in synsets: > lemma_set.add(synset.lemma_names) > for lemma in lemma_set: > sense_number += len(wn.synsets(lemma,pos)) > return sense_number / len(lemma_set) Or even: lemma_set = set(synset for synset in wn.all_synsets(pos)) sense_number = sum(len(wn.synsets(lemma, pos)) for lemma in lemma_set) return sense_number / len(lemma_set) From georg at python.org Sun Sep 9 05:25:39 2012 From: georg at python.org (Georg Brandl) Date: Sun, 09 Sep 2012 11:25:39 +0200 Subject: [RELEASED] Python 3.3.0 release candidate 2 Message-ID: <504C6093.7060304@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm delighted to announce the second release candidate of Python 3.3.0. This is a preview release, and its use is not recommended in production settings. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. Major new features and changes in the 3.3 release series are: * PEP 380, syntax for delegating to a subgenerator ("yield from") * PEP 393, flexible string representation (doing away with the distinction between "wide" and "narrow" Unicode builds) * A C implementation of the "decimal" module, with up to 80x speedup for decimal-heavy applications * The import system (__import__) now based on importlib by default * The new "lzma" module with LZMA/XZ support * PEP 397, a Python launcher for Windows * PEP 405, virtual environment support in core * PEP 420, namespace package support * PEP 3151, reworking the OS and IO exception hierarchy * PEP 3155, qualified name for classes and functions * PEP 409, suppressing exception context * PEP 414, explicit Unicode literals to help with porting * PEP 418, extended platform-independent clocks in the "time" module * PEP 412, a new key-sharing dictionary implementation that significantly saves memory for object-oriented code * PEP 362, the function-signature object * The new "faulthandler" module that helps diagnosing crashes * The new "unittest.mock" module * The new "ipaddress" module * The "sys.implementation" attribute * A policy framework for the email package, with a provisional (see PEP 411) policy that adds much improved unicode support for email header parsing * A "collections.ChainMap" class for linking mappings to a single unit * Wrappers for many more POSIX functions in the "os" and "signal" modules, as well as other useful functions such as "sendfile()" * Hash randomization, introduced in earlier bugfix releases, is now switched on by default In total, almost 500 API items are new or improved in Python 3.3. For a more extensive list of changes in 3.3.0, see http://docs.python.org/3.3/whatsnew/3.3.html To download Python 3.3.0 visit: http://www.python.org/download/releases/3.3.0/ Please consider trying Python 3.3.0 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAlBMYJMACgkQN9GcIYhpnLCc5ACfcufn57tkNBPFU7qCpZ74GzjW msMAn3sIwWHLdqixypnnyMBOw1ijILjo =+e0e -----END PGP SIGNATURE----- From roy at panix.com Sun Sep 9 06:15:38 2012 From: roy at panix.com (Roy Smith) Date: Sun, 09 Sep 2012 06:15:38 -0400 Subject: Parsing ISO date/time strings - where did the parser go? References: <7xbohj3p6e.fsf@ruckus.brouhaha.com> Message-ID: In article , John Nagle wrote: > This really should be handled in the standard library, instead of > everybody rolling their own, badly. +1 From aaronpil at gmail.com Sun Sep 9 07:03:40 2012 From: aaronpil at gmail.com (StarPilgrim) Date: Sun, 9 Sep 2012 04:03:40 -0700 (PDT) Subject: Beginner Q: What does the double underscore __ mean? Message-ID: <3dcd70d0-17b5-40a4-803a-eed66639b6e7@googlegroups.com> Hi all, Brand new to python. I was wondering what the __ underscore means? For example, there is a line of code: __name__=='__main__' and I don't know what the double underscore is used for. From breamoreboy at yahoo.co.uk Sun Sep 9 07:20:44 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 09 Sep 2012 12:20:44 +0100 Subject: Parsing ISO date/time strings - where did the parser go? In-Reply-To: References: <7xbohj3p6e.fsf@ruckus.brouhaha.com> Message-ID: On 09/09/2012 11:15, Roy Smith wrote: > In article , John Nagle > wrote: > >> This really should be handled in the standard library, instead of >> everybody rolling their own, badly. > > +1 > I'll second that given "There should be one-- and preferably only one --obvious way to do it". -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Sun Sep 9 07:23:55 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 09 Sep 2012 12:23:55 +0100 Subject: Beginner Q: What does the double underscore __ mean? In-Reply-To: <3dcd70d0-17b5-40a4-803a-eed66639b6e7@googlegroups.com> References: <3dcd70d0-17b5-40a4-803a-eed66639b6e7@googlegroups.com> Message-ID: On 09/09/2012 12:03, StarPilgrim wrote: > Hi all, > Brand new to python. I was wondering what the __ underscore means? > For example, there is a line of code: > > __name__=='__main__' > > > and I don't know what the double underscore is used for. > Start here http://docs.python.org/reference/datamodel.html#specialnames -- Cheers. Mark Lawrence. From roy at panix.com Sun Sep 9 08:14:30 2012 From: roy at panix.com (Roy Smith) Date: Sun, 09 Sep 2012 08:14:30 -0400 Subject: Parsing ISO date/time strings - where did the parser go? References: Message-ID: In article , Thomas Jollans wrote: > The ISO date/time format is dead simple and well-defined. Well defined, perhaps. But nobody who has read the standard could call it "dead simple". ISO-8601-2004(E) is 40 pages long. Of course, that fact that it's complicated enough to generate 40 pages worth of standards document just argues that much more strongly for it being in the standard lib (so there can be one canonical, well-tested, way to do it). From davea at dejaviewphoto.com Sun Sep 9 08:39:00 2012 From: davea at dejaviewphoto.com (Dave Angel) Date: Sun, 09 Sep 2012 08:39:00 -0400 Subject: Beginner Q: What does the double underscore __ mean? In-Reply-To: <3dcd70d0-17b5-40a4-803a-eed66639b6e7@googlegroups.com> References: <3dcd70d0-17b5-40a4-803a-eed66639b6e7@googlegroups.com> Message-ID: <504C8DE4.9020803@dejaviewphoto.com> See the identical thread you posted on tutor, where it was a better match. -- DaveA From redstone-cold at 163.com Sun Sep 9 09:22:09 2012 From: redstone-cold at 163.com (iMath) Date: Sun, 9 Sep 2012 06:22:09 -0700 (PDT) Subject: Does os.getcwd() and os.curdir have the same effect ? Message-ID: <12b64802-d598-441b-b3cd-87ec17bba514@googlegroups.com> Does os.getcwd() and os.curdir have the same effect ? From redstone-cold at 163.com Sun Sep 9 09:23:37 2012 From: redstone-cold at 163.com (iMath) Date: Sun, 9 Sep 2012 06:23:37 -0700 (PDT) Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: <645baeaa-438e-4d30-a559-0db4231ede9c@googlegroups.com> ? 2012?3?26????UTC+8??7?45?26??iMath??? > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? thx everyone From redstone-cold at 163.com Sun Sep 9 09:27:53 2012 From: redstone-cold at 163.com (iMath) Date: Sun, 9 Sep 2012 06:27:53 -0700 (PDT) Subject: =?windows-1252?Q?Re=3A_What=92s_the_differences_between_these_two__piec?= =?windows-1252?Q?es_of_code_=3F?= In-Reply-To: <48fbfc85-c495-4131-a18a-1ebb94e7ce20@googlegroups.com> References: <48fbfc85-c495-4131-a18a-1ebb94e7ce20@googlegroups.com> Message-ID: <874765ea-d1cd-40cc-ac8c-ff694648cfae@googlegroups.com> ? 2012?7?7????UTC+8??12?56?35??iMath??? > What?s the differences between these two pieces of code ? > > (1) > > for i in range(1, 7): > > print(2 * i, end=' ') > > > > thx everyone > > (2) > > for i in range(1, 7): > > print(2 * i, end=' ') > > print() > > > > > > when executed both respectively in Python shell ,I get the same effect . Who can tell me why ? From steve+comp.lang.python at pearwood.info Sun Sep 9 09:38:16 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Sep 2012 13:38:16 GMT Subject: Does os.getcwd() and os.curdir have the same effect ? References: <12b64802-d598-441b-b3cd-87ec17bba514@googlegroups.com> Message-ID: <504c9bc8$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sun, 09 Sep 2012 06:22:09 -0700, iMath wrote: > Does os.getcwd() and os.curdir have the same effect ? You could answer that yourself with two seconds experimentation at the interactive prompt. py> os.getcwd() '/home/steve' py> os.curdir '.' For more information, you can try reading the Fine Manual: http://docs.python.org/library/os.html#os.getcwd http://docs.python.org/library/os.html#os.curdir In case it isn't obvious: no, they are completely different. os.getcwd is a function which returns the path of the current working directory. os.curdir is a string which the operating system will understand to mean "this directory". -- Steven From t at jollybox.de Sun Sep 9 09:39:12 2012 From: t at jollybox.de (Thomas Jollans) Date: Sun, 09 Sep 2012 15:39:12 +0200 Subject: Does os.getcwd() and os.curdir have the same effect ? In-Reply-To: <12b64802-d598-441b-b3cd-87ec17bba514@googlegroups.com> References: <12b64802-d598-441b-b3cd-87ec17bba514@googlegroups.com> Message-ID: <504C9C00.3010403@jollybox.de> On 09/09/2012 03:22 PM, iMath wrote: > Does os.getcwd() and os.curdir have the same effect ? > Python 3.2.3 (default, May 3 2012, 15:51:42) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.getcwd() '/home/tjol' >>> os.curdir '.' >>> No. Both refer to the current directory, but os.curdir is not an absolute path, so you can't chdir() to it later and expect to land it the original directory. From typetoken at gmail.com Sun Sep 9 09:44:53 2012 From: typetoken at gmail.com (Token Type) Date: Sun, 9 Sep 2012 06:44:53 -0700 (PDT) Subject: Is there a unique method in python to unique a list? In-Reply-To: <7xwr03oafu.fsf@ruckus.brouhaha.com> References: <60A480B7378343149401A424A682AF34@gmail.com> <7xwr03oafu.fsf@ruckus.brouhaha.com> Message-ID: Thanks. I try to use set() suggested by you. However, not successful. Please see: >>> synsets = list(wn.all_synsets('n')) >>> synsets[:5] [Synset('entity.n.01'), Synset('physical_entity.n.01'), Synset('abstraction.n.06'), Synset('thing.n.12'), Synset('object.n.01')] >>> lemma_set = set() >>> for synset in synsets: lemma_set.add(synset.lemma_names) Traceback (most recent call last): File "", line 2, in lemma_set.add(synset.lemma_names) TypeError: unhashable type: 'list' >>> for synset in synsets: lemma_set.add(set(synset.lemma_names)) Traceback (most recent call last): File "", line 2, in lemma_set.add(set(synset.lemma_names)) TypeError: unhashable type: 'set' From typetoken at gmail.com Sun Sep 9 09:50:16 2012 From: typetoken at gmail.com (Token Type) Date: Sun, 9 Sep 2012 06:50:16 -0700 (PDT) Subject: AttributeError: 'list' object has no attribute 'lower' In-Reply-To: References: Message-ID: <43a68990-d6cf-4362-8c47-b13ce780b068@googlegroups.com> Thanks very much for all of your tips. Take noun as an example. First, I need find all the lemma_names in all the synsets whose pos is 'n'. Second, for each lemma_name, I will check all their sense number. 1) Surely,we can know the number of synset whose pos is noun by >>> len([synset for synset in wn.all_synsets('n')]) 82115 However, confusingly it is unsuccessful to get a list of lemma names of these synsets by >>> lemma_list = [synset.lemma_names for synset in wn.all_synsets('n')] >>> lemma_list[:20] [['entity'], ['physical_entity'], ['abstraction', 'abstract_entity'], ['thing'], ['object', 'physical_object'], ['whole', 'unit'], ['congener'], ['living_thing', 'animate_thing'], ['organism', 'being'], ['benthos'], ['dwarf'], ['heterotroph'], ['parent'], ['life'], ['biont'], ['cell'], ['causal_agent', 'cause', 'causal_agency'], ['person', 'individual', 'someone', 'somebody', 'mortal', 'soul'], ['animal', 'animate_being', 'beast', 'brute', 'creature', 'fauna'], ['plant', 'flora', 'plant_life']] >>> type(lemma_list) Though the lemma_list is a list in the above codes, it contains so many unnecessary [ and ]. How come it is like this? But what we desire and expect is a list without this brackets. Confused, I am really curious to know why. 2) Then I have to use a loop and extend to get all the lemma_names from synset: >>> synset_list = list(wn.all_synsets('n')) >>> lemma_list = [] >>> for synset in synset_list: lemma_list.extend(synset.lemma_names) >>> lemma_list[:20] ['entity', 'physical_entity', 'abstraction', 'abstract_entity', 'thing', 'object', 'physical_object', 'whole', 'unit', 'congener', 'living_thing', 'animate_thing', 'organism', 'being', 'benthos', 'dwarf', 'heterotroph', 'parent', 'life', 'biont'] 3) In this case, I have to use loop to get all the lemma_names instead of [synset.lemma_names for synset in wn.all_synsets('n')]. The following is a working solution: >>> def average_polysemy(pos): synset_list = list(wn.all_synsets(pos)) sense_number = 0 lemma_list = [] for synset in synset_list: lemma_list.extend(synset.lemma_names) for lemma in lemma_list: sense_number_new = len(wn.synsets(lemma, pos)) sense_number = sense_number + sense_number_new return sense_number/len(synset_list) >>> average_polysemy('n') 3 Thanks again. From typetoken at gmail.com Sun Sep 9 10:00:34 2012 From: typetoken at gmail.com (Token Type) Date: Sun, 9 Sep 2012 07:00:34 -0700 (PDT) Subject: AttributeError: 'list' object has no attribute 'lower' In-Reply-To: References: Message-ID: <113e44c3-cd53-4536-a60c-0363bf83a8ec@googlegroups.com> > In fact, I'm guessing that's your problem. I think you're ending up > > with a list of lists of strings, when you think you're getting a list of > > strings. > Thanks. You guess right. It turns out that lemma_list is a list of list, as I tested in the previous post. From rosuav at gmail.com Sun Sep 9 10:13:17 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 10 Sep 2012 00:13:17 +1000 Subject: Is there a unique method in python to unique a list? In-Reply-To: References: <60A480B7378343149401A424A682AF34@gmail.com> <7xwr03oafu.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Sep 9, 2012 at 11:44 PM, Token Type wrote: > lemma_set.add(synset.lemma_names) That tries to add the whole list as a single object, which doesn't work because lists can't go into sets. There are two solutions, depending on what you want to do. 1) If you want each addition to remain discrete, make a tuple instead: lemma_set.add(tuple(synset.lemma_names)) 2) If you want to add the elements of that list individually into the set, use update: lemma_set.update(synset.lemma_names) I'm thinking you probably want option 2 here. ChrisA From typetoken at gmail.com Sun Sep 9 10:19:42 2012 From: typetoken at gmail.com (Token Type) Date: Sun, 9 Sep 2012 07:19:42 -0700 (PDT) Subject: AttributeError: 'list' object has no attribute 'lower' In-Reply-To: References: Message-ID: > structures are simple, just plain print will work, but for more > > complicated structures, pprint.pprint() is a life saver. > I did try . However, >>> pprint.pprint(lemma_list) Traceback (most recent call last): File "", line 1, in pprint.pprint(lemma_list) NameError: name 'pprint' is not defined >>> pprint.pprint(synset_list) Traceback (most recent call last): File "", line 1, in pprint.pprint(synset_list) NameError: name 'pprint' is not defined >>> From overhaalsgang_24_bob at me.com Sun Sep 9 10:28:55 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Sun, 9 Sep 2012 07:28:55 -0700 (PDT) Subject: Newbie: where's the new python gone? Message-ID: I think I've installed Python 2.7.3 according to the instructions in the README, and now want to use that version. However, when typing "python" in Terminal, I get "Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) ". So: (1) I can't seem to find where the new software has gone and (2) can't seem to find how to point to this new versoin. I've searched Python.org and with Google but :( [I'm on Mac OS X 10.7.4] Please help. From roy at panix.com Sun Sep 9 10:29:11 2012 From: roy at panix.com (Roy Smith) Date: Sun, 09 Sep 2012 10:29:11 -0400 Subject: AttributeError: 'list' object has no attribute 'lower' References: <43a68990-d6cf-4362-8c47-b13ce780b068@googlegroups.com> Message-ID: In article <43a68990-d6cf-4362-8c47-b13ce780b068 at googlegroups.com>, Token Type wrote: > Thanks very much for all of your tips. Take noun as an example. First, I need > find all the lemma_names in all the synsets whose pos is 'n'. Second, for > each lemma_name, I will check all their sense number. > > 1) Surely,we can know the number of synset whose pos is noun by > >>> len([synset for synset in wn.all_synsets('n')]) > 82115 > > However, confusingly it is unsuccessful to get a list of lemma names of these > synsets by > >>> lemma_list = [synset.lemma_names for synset in wn.all_synsets('n')] > >>> lemma_list[:20] > [['entity'], ['physical_entity'], ['abstraction', 'abstract_entity'], > ['thing'], ['object', 'physical_object'], ['whole', 'unit'], ['congener'], > ['living_thing', 'animate_thing'], ['organism', 'being'], ['benthos'], > ['dwarf'], ['heterotroph'], ['parent'], ['life'], ['biont'], ['cell'], > ['causal_agent', 'cause', 'causal_agency'], ['person', 'individual', > 'someone', 'somebody', 'mortal', 'soul'], ['animal', 'animate_being', > 'beast', 'brute', 'creature', 'fauna'], ['plant', 'flora', 'plant_life']] > >>> type(lemma_list) > > > Though the lemma_list is a list in the above codes, it contains so many > unnecessary [ and ]. How come it is like this? But what we desire and expect > is a list without this brackets. Confused, I am really curious to know why. It looks like synset.lemma_names gets you a list. And then you're taking all those lists and forming them into a list of lists: >>> lemma_list = [synset.lemma_names for synset in wn.all_synsets('n')] I think what you want to study is the difference between list.append() and list.extend(). When you use the list builder syntax, you're essentially writing a loop which does append operations. The above is the same as if you wrote: lemma_list = list() for synset in wn.all_synsets('n'): lemma_list.append(synset.lemma_names) and I think what you're looking for is: lemma_list = list() for synset in wn.all_synsets('n'): lemma_list.extend(synset.lemma_names) From roy at panix.com Sun Sep 9 10:32:33 2012 From: roy at panix.com (Roy Smith) Date: Sun, 09 Sep 2012 10:32:33 -0400 Subject: AttributeError: 'list' object has no attribute 'lower' References: Message-ID: In article , Token Type wrote: > > structures are simple, just plain print will work, but for more > > > > complicated structures, pprint.pprint() is a life saver. > > > > I did try . However, > > >>> pprint.pprint(lemma_list) > > Traceback (most recent call last): > File "", line 1, in > pprint.pprint(lemma_list) > NameError: name 'pprint' is not defined > >>> pprint.pprint(synset_list) > > Traceback (most recent call last): > File "", line 1, in > pprint.pprint(synset_list) > NameError: name 'pprint' is not defined > >>> OK, I can see how this can be confusing. In "pprint.pprint()", the two "pprint"s mean different things. The first one is the name of a module. The second one is the name of a function in that module. In general, I dislike this style of naming since it just leads to this kind of confusion. In any case, you need to do one of two things. Style 1: import pprint pprint.pprint(foo) Style 2: from pprint import pprint pprint(foo) From ian at feete.org Sun Sep 9 10:41:46 2012 From: ian at feete.org (Ian Foote) Date: Sun, 09 Sep 2012 15:41:46 +0100 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <645baeaa-438e-4d30-a559-0db4231ede9c@googlegroups.com> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> <645baeaa-438e-4d30-a559-0db4231ede9c@googlegroups.com> Message-ID: <504CAAAA.3090905@feete.org> On 09/09/12 14:23, iMath wrote: > ? 2012?3?26????UTC+8??7?45?26??iMath??? >> I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? > thx everyone The difference is that 3 is an integer whereas '3' is a string. The print statement (function in python 3) converts any object to a string before displaying it on the screen, so print 3 and print '3' both display the same result. Ian F From steve+comp.lang.python at pearwood.info Sun Sep 9 10:50:23 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Sep 2012 14:50:23 GMT Subject: Newbie: where's the new python gone? References: Message-ID: <504cacae$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sun, 09 Sep 2012 07:28:55 -0700, BobAalsma wrote: > I think I've installed Python 2.7.3 according to the instructions in the > README, and now want to use that version. However, when typing "python" > in Terminal, I get "Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) ". Did you run "make altinstall"? You should, because it is a bad idea to replace the system Python with a newer (or worse, older) version. You can break things. > So: > (1) I can't seem to find where the new software has gone Just enter "python2.7" instead of "python" and it should work perfectly. > and (2) can't > seem to find how to point to this new versoin. I've searched Python.org You won't find it there *wink* At the terminal, enter: which python2.7 which should return the full path to the executable, e.g.: [steve at ando ~]$ which python2.7 /usr/local/bin/python2.7 My system uses Python 2.4 as the system Python, but I prefer to use Python 2.7 as my default. So I have this command in my .bashrc file: alias python='python2.7' which means that *for me*, "python" launches Python 2.7, but when system tools call "python" they still see the version they are expecting. If your shell is something other than bash, you may need to use a different rc file. Did any of this make sense to you? If anything was unclear, please don't hesitate to ask. -- Steven From overhaalsgang_24_bob at me.com Sun Sep 9 11:36:52 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Sun, 9 Sep 2012 08:36:52 -0700 (PDT) Subject: Newbie: where's the new python gone? In-Reply-To: References: Message-ID: <9fcf4eb6-1ea3-4f75-bf2a-031b754a2c89@googlegroups.com> Op zondag 9 september 2012 16:28:55 UTC+2 schreef BobAalsma het volgende: > I think I've installed Python 2.7.3 according to the instructions in the README, and now want to use that version. > > However, when typing "python" in Terminal, I get "Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) ". > > So: > > (1) I can't seem to find where the new software has gone and > > (2) can't seem to find how to point to this new versoin. > > I've searched Python.org and with Google but :( > > [I'm on Mac OS X 10.7.4] > > > > Please help. Thanks Steven! Most of what you wrote made very good sense, yes. Umm, I didn't usa altinstall - should I (and can I) go back? [In hindsight I do like your solution to the versopns a lot more, yes] Umm2, as said, I think I've installed (at least downloaded) 2.7.3 (note the three there) and with "python2.7" I now see "Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)" From ben+python at benfinney.id.au Sun Sep 9 11:50:09 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 10 Sep 2012 01:50:09 +1000 Subject: Newbie: where's the new python gone? References: Message-ID: <87ligjqjpq.fsf@benfinney.id.au> BobAalsma writes: > I think I've installed Python 2.7.3 according to the instructions in > the README, and now want to use that version. > However, when typing "python" in Terminal, I get "Python 2.6.4 > (r264:75821M, Oct 27 2009, 19:48:32) ". I think you might have made a mistake. Without more detail about what you did ? detail which you perhaps can't provide, since it's like asking ?where did you last see the thing you lost? ? there's not much more we can do but guess. You could try following the install instructions again, paying careful attention to what might go wrong. Either something will go wrong, and you'll be paying close enough attention to report it; or nothing will go wrong, and you'll be able to use the version you want. Good hunting. -- \ ?The most dangerous man to any government is the man who is | `\ able to think things out for himself, without regard to the | _o__) prevailing superstitions and taboos.? ?Henry L. Mencken | Ben Finney From hamilton at nothere.com Sun Sep 9 12:04:18 2012 From: hamilton at nothere.com (hamilton) Date: Sun, 09 Sep 2012 10:04:18 -0600 Subject: Beginner Q: What does the double underscore __ mean? In-Reply-To: References: <3dcd70d0-17b5-40a4-803a-eed66639b6e7@googlegroups.com> Message-ID: On 9/9/2012 6:39 AM, Dave Angel wrote: > See the identical thread you posted on tutor, where it was a better match. > > > Would you please post that link for those of us that did not see that one. Thanks From bryanjugglercryptographer at yahoo.com Sun Sep 9 12:06:14 2012 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Sun, 9 Sep 2012 09:06:14 -0700 (PDT) Subject: simple client data base References: <9543c9b1-d3ea-4930-af73-6659878e0077@qa3g2000pbc.googlegroups.com> Message-ID: Mark R Rivet wrote: > Well I have to say that this is most discouraging. Sorry to to be a drag, but the thread needed a bit a realism. From kwpolska at gmail.com Sun Sep 9 13:07:06 2012 From: kwpolska at gmail.com (Kwpolska) Date: Sun, 9 Sep 2012 19:07:06 +0200 Subject: =?UTF-8?Q?Re=3A_What=E2=80=99s_the_differences_between_these_two_piece?= =?UTF-8?Q?s_of_code_=3F?= In-Reply-To: <874765ea-d1cd-40cc-ac8c-ff694648cfae@googlegroups.com> References: <48fbfc85-c495-4131-a18a-1ebb94e7ce20@googlegroups.com> <874765ea-d1cd-40cc-ac8c-ff694648cfae@googlegroups.com> Message-ID: On Sun, Sep 9, 2012 at 3:27 PM, iMath wrote: > ? 2012?7?7????UTC+8??12?56?35??iMath??? >> What?s the differences between these two pieces of code ? >> >> (1) >> >> for i in range(1, 7): >> >> print(2 * i, end=' ') >> >> >> >> thx everyone >> >> (2) >> >> for i in range(1, 7): >> >> print(2 * i, end=' ') >> >> print() >> >> >> >> >> >> when executed both respectively in Python shell ,I get the same effect . Who can tell me why ? > > -- > http://mail.python.org/mailman/listinfo/python-list Well, (2) is inserting an additional newline, and (1) isn?t. The shell might not show that, but try running this as a standalone script. -- Kwpolska stop html mail | always bottom-post www.asciiribbon.org | www.netmeister.org/news/learn2quote.html GPG KEY: 5EAAEA16 From mok-kong.shen at t-online.de Sun Sep 9 13:26:25 2012 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Sun, 09 Sep 2012 19:26:25 +0200 Subject: Symbolic computations Message-ID: I heard of names of two systems for Python users to do symbolic computations: SymPy and Sage. Could someone say a few lines from experiences about their comparisons? Thanks in advance. M. K. Shen From nad at acm.org Sun Sep 9 13:41:16 2012 From: nad at acm.org (Ned Deily) Date: Sun, 09 Sep 2012 10:41:16 -0700 Subject: Newbie: where's the new python gone? References: <9fcf4eb6-1ea3-4f75-bf2a-031b754a2c89@googlegroups.com> Message-ID: In article <9fcf4eb6-1ea3-4f75-bf2a-031b754a2c89 at googlegroups.com>, BobAalsma wrote: > Umm2, as said, I think I've installed (at least downloaded) 2.7.3 (note the > three there) and with "python2.7" I now see "Python 2.7.1 (r271:86832, Jun 16 > 2011, 16:59:05)" Did you use a binary installer from python.org or did you build it yourself from source? In the former case, you should find the newer python2.7 at /usr/local/bin/python2.7. Also, the installer by default should have added the framework bin directory to your shell PATH. Try opening a new terminal window and typing python2.7. In any case, as suggested: which python should tell you the path to the python you are invoking. It doesn't appear to be an Apple-supplied one or a python.org one, BTW. -- Ned Deily, nad at acm.org From hansmu at xs4all.nl Sun Sep 9 13:44:20 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sun, 09 Sep 2012 19:44:20 +0200 Subject: Newbie: where's the new python gone? In-Reply-To: References: Message-ID: <504cd574$0$6990$e4fe514c@news2.news.xs4all.nl> On 9/09/12 16:28:55, BobAalsma wrote: > I think I've installed Python 2.7.3 according to the instructions in the README, and now want to use that version. > However, when typing "python" in Terminal, I get "Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) ". Was that a freshly opened Terminal window, or one that was open before the install? The installers from python.org by default modify your .bashrc file to put /Library/Frameworks/Python.framework/Versions/2.7/bin at the front of your shell's search path. However, that only affects windows opened after the install (unless you use "source ~/.bashrc" to read the new setting into a pre-existing window). What happens if you type: /Library/Frameworks/Python.framework/Versions/2.7/bin/python ? > So: > (1) I can't seem to find where the new software has gone and > (2) can't seem to find how to point to this new versoin. > I've searched Python.org and with Google but :( > [I'm on Mac OS X 10.7.4] I'm on MacOS 10.5.0, and my default Python is /Library/Frameworks/Python.framework/Versions/2.7/bin/python If yours isn't, you could try looking in finder at the disk you installed Python to, and see if it has a top-level folder named "Library", containing "Frameworks", etc. If you find a "Python.framework" under /System/Library that's the one that ships with MacOS. Hope this helps, -- HansM From python.list at tim.thechases.com Sun Sep 9 14:27:14 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 09 Sep 2012 13:27:14 -0500 Subject: simple client data base In-Reply-To: References: <9543c9b1-d3ea-4930-af73-6659878e0077@qa3g2000pbc.googlegroups.com> Message-ID: <504CDF82.5060800@tim.thechases.com> On 09/08/12 14:47, Mark R Rivet wrote: > Well I have to say that this is most discouraging. I should give > up learning to program. I don't have a chance at all. Thanks. I think the intent is not to deter you from learning to program, but rather to urge you in a direction less fraught with peril. Rather than starting by duplicating existing functionality of a complex domain, you may find it easier to start by aiming for something in a less-complex domain, or tackle a project that doesn't already exist but scratches your personal itch. As you succeed at smaller projects, you'll have a better idea of how to tackle larger projects in the future. -tkc From piet at vanoostrum.org Sun Sep 9 14:29:57 2012 From: piet at vanoostrum.org (Piet van Oostrum) Date: Sun, 09 Sep 2012 20:29:57 +0200 Subject: =?utf-8?Q?What=E2=80=99s?= the differences between these two pieces of code ? References: <48fbfc85-c495-4131-a18a-1ebb94e7ce20@googlegroups.com> Message-ID: iMath writes: > What?s the differences between these two pieces of code ? > (1) > for i in range(1, 7): > print(2 * i, end=' ') > > > (2) > for i in range(1, 7): > print(2 * i, end=' ') > print() > > > when executed both respectively in Python shell ,I get the same effect . Who can tell me why ? The first one gives a syntax error (IndentationError: expected an indented block) -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From no.email at nospam.invalid Sun Sep 9 14:55:55 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 09 Sep 2012 11:55:55 -0700 Subject: simple client data base References: <9543c9b1-d3ea-4930-af73-6659878e0077@qa3g2000pbc.googlegroups.com> Message-ID: <7xmx0zc9fo.fsf@ruckus.brouhaha.com> Tim Chase writes: > urge you in a direction less fraught with peril. Rather than starting > by duplicating existing functionality of a complex domain More importantly, as others have mentioned, the main peril comes from having someone else relying on the success of the program. If you want to learn to play the violin, that's great. Just don't book a recital in Carnegie Hall until you've practiced for a while in private to get your skills in order. From amc96 at cam.ac.uk Sun Sep 9 15:14:41 2012 From: amc96 at cam.ac.uk (Andrew Cooper) Date: Sun, 09 Sep 2012 20:14:41 +0100 Subject: Looking for an IPC solution In-Reply-To: <299a8013-fd2b-4d91-a5d8-f4d8732e7377@googlegroups.com> References: <50410AD6.7080003@shopzeus.com> <2p0i489b5kq6ad2kc70r82ksjqpcatdsqu@invalid.netcom.com> <299a8013-fd2b-4d91-a5d8-f4d8732e7377@googlegroups.com> Message-ID: On 08/09/2012 16:11, Ramchandra Apte wrote: > On Friday, 7 September 2012 02:25:15 UTC+5:30, Dave Angel wrote: >> On 09/06/2012 04:33 PM, Dennis Lee Bieber wrote: >> >>> >> >> >> >>> Note that this difference mainly applies to how the processes are >> >>> themselves are created... How the library wraps shared data is >> >>> possibly different (I've never understood how a "fork" process can >> >>> avoid memory conflicts if it has write access to common virtual memory >> >>> blocks). >> >> Here's an approximate description of fork, at least for the memory >> >> aspects. During a fork, the virtual memory table is copied (that's >> >> descriptors for all mapped and allocated memory) but the memory itself >> >> is NOT. All the new descriptors are labeled "COW" (copy-on-write). As >> >> that process executes, the first time it writes in a particular memory >> >> block, the OS gets a memory fault, which it fixes by allocating a block >> >> of the same size, copying the memory block to the new one, and labeling >> >> it read/write. Subsequent accesses to the same block are normal, with no >> >> trace of the fork remaining. >> >> >> >> Now, there are lots of details that this blurs over, but it turns out >> >> that many times the new process doesn't change very much. For example, >> >> all the mappings to the executable and to shared libraries are >> >> theoretically readonly. In fact, they might have also been labeled COW >> >> even for the initial execution of the program. Another place that's >> >> blurry is just what the resolution of this table actually is. There are >> >> at least two levels of tables. The smallest increment on the Pentium >> >> family is 4k. >> >> >> >> >> >> -- >> >> >> >> DaveA > > From my OS development experience, there are two sizes of pages - 4K and 1 byte > No - pages are always 4k (or bigger given superpage support). You are probably thinking about the granularity bit in descriptor entries, which is relevant for segmentation. The granularity bit changes the limit between 1 byte or 4K chunks, as there are only 20 bits of limit space in a 32bit {L,G}DT entry. However, in the modern days of paging, segmentation support is only for legacy compatibility. ~Andrew From steve+comp.lang.python at pearwood.info Sun Sep 9 16:27:00 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Sep 2012 20:27:00 GMT Subject: Symbolic computations References: Message-ID: <504cfb94$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sun, 09 Sep 2012 19:26:25 +0200, Mok-Kong Shen wrote: > I heard of names of two systems for Python users to do symbolic > computations: SymPy and Sage. Could someone say a few lines from > experiences about their comparisons? Thanks in advance. Sage includes and is compatible with sympy. See for example: http://www.sagemath.org/doc/reference/sage/calculus/test_sympy.html -- Steven From d at davea.name Sun Sep 9 16:54:20 2012 From: d at davea.name (Dave Angel) Date: Sun, 09 Sep 2012 16:54:20 -0400 Subject: Beginner Q: What does the double underscore __ mean? In-Reply-To: References: <3dcd70d0-17b5-40a4-803a-eed66639b6e7@googlegroups.com> Message-ID: <504D01FC.2040005@davea.name> On 09/09/2012 12:04 PM, hamilton wrote: > On 9/9/2012 6:39 AM, Dave Angel wrote: >> See the identical thread you posted on tutor, where it was a better >> match. >> >> >> > Would you please post that link for those of us that did not see that > one. > > Thanks > it's a mailing list. There's no links to the mail in my folder. Googling shows me: http://code.activestate.com/lists/python-tutor/90564/ -- DaveA From steve+comp.lang.python at pearwood.info Sun Sep 9 18:05:56 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Sep 2012 22:05:56 GMT Subject: Beginner Q: What does the double underscore __ mean? References: <3dcd70d0-17b5-40a4-803a-eed66639b6e7@googlegroups.com> Message-ID: <504d12c4$0$29890$c3e8da3$5496439d@news.astraweb.com> On Sun, 09 Sep 2012 10:04:18 -0600, hamilton wrote: > On 9/9/2012 6:39 AM, Dave Angel wrote: >> See the identical thread you posted on tutor, where it was a better >> match. >> >> >> > Would you please post that link for those of us that did not see that > one. http://mail.python.org/pipermail/tutor/2012-September/091388.html You can see the tutor archives, or subscribe to the list, from here: http://mail.python.org/mailman/listinfo/tutor -- Steven From dustin at v.igoro.us Sun Sep 9 20:07:51 2012 From: dustin at v.igoro.us (Dustin J. Mitchell) Date: Sun, 9 Sep 2012 20:07:51 -0400 Subject: Standard Asynchronous Python Message-ID: After seeing David Mertz's talk at PyCon 2012, "Coroutines, event loops, and the history of Python generators" [1], I got thinking again about Python's expressive power for asynchronous programming. Generators, particularly with the addition of 'yield from' and 'return' in PEP 380 [2], allow us to write code that is executed "bit by bit" but still reads naturally. There are a number of frameworks that take advantage of this ability, but each is a little different -- enough so that there's negligible code re-use between these frameworks. I think that's a shame. I proposed a design PEP a while back [3] with the intent of defining a standard way of writing asynchronous code, with the goal of allowing code re-use and bringing users of the frameworks closer together. Ideally, we could have libraries to implement network protocols, database wrappers, subprocess execution, and so on, that would work in any of the available asynchronous frameworks. My proposal met with near-silence, and I didn't pursue it. Instead, I did what any self-respecting hacker would do - I wrote up a framework, uthreads [4], that implemented my idea. This was initially a simple trampoline scheduler, but I eventually refactored it to run atop Twisted, since that's what I use. To my knowledge, it's never been used. I'm considering re-drafting the PEP with the following changes: * De-emphasize the thread emulation aspects, and focus on code-portability issues: * callbacks vs. "blocking" calls (e.g., when accepting incoming connections on a socket, how is my code invoked?) * consistent access to primitives, regardless of framework (e.g., where's the function I call to branch execution?) * nested asynchronous methods * Account for PEP 380 (by making the StopIteration workarounds match PEP 380, and explicitly deprecating them after Python 3.3) * Look forward to a world with software transactional memory [5] by matching that API where appropriate As I get to work on the PEP, I'd like to hear any initial reactions to the idea. Dustin [1] https://us.pycon.org/2012/schedule/presentation/104/ [2] http://www.python.org/dev/peps/pep-0380 [3] http://code.google.com/p/uthreads/source/browse/trunk/microthreading-pep.txt [4] http://code.google.com/p/uthreads/ [5] https://bitbucket.org/pypy/pypy/raw/stm-thread/pypy/doc/stm.rst From steve+comp.lang.python at pearwood.info Sun Sep 9 23:38:19 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Sep 2012 03:38:19 GMT Subject: Standard Asynchronous Python References: Message-ID: <504d60ab$0$29890$c3e8da3$5496439d@news.astraweb.com> On Sun, 09 Sep 2012 20:07:51 -0400, Dustin J. Mitchell wrote: > After seeing David Mertz's talk at PyCon 2012, "Coroutines, event loops, > and the history of Python generators" [1], I got thinking again about > Python's expressive power for asynchronous programming. [...] > I'm considering re-drafting the PEP with the following changes: > > * De-emphasize the thread emulation aspects, and focus on > code-portability issues: > * callbacks vs. "blocking" calls (e.g., when accepting incoming > connections on a socket, how is my code invoked?) > * consistent access to primitives, regardless of framework (e.g., > where's the function I call to branch execution?) > * nested asynchronous methods > * Account for PEP 380 (by making the StopIteration workarounds match > PEP 380, and explicitly deprecating them after Python 3.3) > * Look forward to a world with software transactional memory [5] by > matching that API where appropriate > > As I get to work on the PEP, I'd like to hear any initial reactions to > the idea. My reaction is that until your framework gets some significant real-world use, it probably doesn't belong in the standard library. To some degree, the standard library is where good code goes to die -- the API should be mature and well-tested, not just the code, because we'll be stuck with the API (essentially) forever. Code can change, bugs can be fixed, but we're stuck with "referer" forever :) At least, you should be prepared to justified why your library uthreads should be considered mature enough for the std lib despite the lack of real-world use. -- Steven From bryanjugglercryptographer at yahoo.com Sun Sep 9 23:42:03 2012 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Sun, 9 Sep 2012 20:42:03 -0700 (PDT) Subject: Standard Asynchronous Python References: Message-ID: Dustin J. Mitchell wrote: > After seeing David Mertz's talk at PyCon 2012, "Coroutines, event > loops, and the history of Python generators" [1], I got thinking again > about Python's expressive power for asynchronous programming. I lament the confusion of generators and coroutines. Generators are no substitute for threads; they're a substitute for temporary memory- wasting lists and for those extraneous classes that just implement another class's __iter__. [big snip] > As I get to work on the PEP, I'd like to hear any initial reactions to the idea. Be warned that I'm frequently chastised for negativity... Your motivating examples motivate me in the opposite direction. Computing Fibonacci numbers with a generator? The problem with your first support app is that threads don't scale? I'm happy with the direction Python has chosen: real, platform- provided threads. There are some fine projects taking other courses, but most of the standard stuff is sequential code with some notion of thread-safety. In this area Python has benefited for free as the popular platforms have steadily improved. Properly exploiting event-drive would be a bigger change than you propose. Python tends to polymorphize I/O via "file like" objects, who's requirements have traditionally been under-specified and have never included event-driven behavior. Also, while Python is proudly cross-platform, Microsoft Windows has the edge on asynchronous facilities but Python treats Windows like a Unix wanna-be. -Bryan From bryanjugglercryptographer at yahoo.com Mon Sep 10 01:38:13 2012 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Sun, 9 Sep 2012 22:38:13 -0700 (PDT) Subject: Beginner Q: What does the double underscore __ mean? References: <3dcd70d0-17b5-40a4-803a-eed66639b6e7@googlegroups.com> Message-ID: <0cd34f31-6b7d-4ff2-b9dd-e711b1f88963@j2g2000pbg.googlegroups.com> StarPilgrim wrote: > Brand new to python. I was wondering what the __ underscore means? > For example, there is a line of code: > > __name__=='__main__' > > and I don't know what the double underscore is used for. Ah, tricky. That's not just double underscore; it's double ended double underscore. Double ended double underscore means that it invokes special behavior in the Python language. It means fair warning. Look this up. Never name your own variables with double ended double underscore. The one exception is if you are proposing a change to the Python language and seeking the blessing of our BDFL. Such names are reserved for the Python language. Leading double underscore without trailing double underscore means that the programmer knows and loves some other object-oriented language, and this other language has a notion of trying to enforce that this member variable is "private", and Python is meeting him half way. The programmer of the class advises you not to manipulate this member variable directly and Python has bowed to convention and done some name mangling. It's often useful, usually naive, fundamentally insecure, and tangential to the zen Python. A lesser known Python convention is the double ended single underscore. Whether it even rates as convention might be arguable, but it's there in the critical _fields_ member of the Structure and Union base classes in the standard ctypes module. It means special within the particular class. To the Python language it's just another name, but the authors of the class have coded it to look up that name and do something interesting with the associated value. -Bryan From dwightdhutto at gmail.com Mon Sep 10 01:54:47 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 10 Sep 2012 01:54:47 -0400 Subject: Beginner Q: What does the double underscore __ mean? In-Reply-To: <0cd34f31-6b7d-4ff2-b9dd-e711b1f88963@j2g2000pbg.googlegroups.com> References: <3dcd70d0-17b5-40a4-803a-eed66639b6e7@googlegroups.com> <0cd34f31-6b7d-4ff2-b9dd-e711b1f88963@j2g2000pbg.googlegroups.com> Message-ID: The very first few steps, are help(any_module), and google. Try looking at this first then, the google search term I used(or any you might come up with_ : double underscore python 2.7 yielding: https://isearch.avg.com/search?q=double+underscore+python+2.7&sap=ku&lang=en&mid=376c19fb27d247d0a284cd3c4e3199e1-2a42c7757f8323a601da41ed11055b4506e772ff&cid={f9f3e522-d7d6-4f0d-bfa5-e8ef583d0ff7}&v=12.2.0.5&ds=ft011&d=8%2F29%2F2012+7%3A54%3A48+AM&pr=sa&snd=hdr and usually any question you've wanted to ask, has already been asked, and answered, but if you can't find it, you're in the right place. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Mon Sep 10 02:10:53 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 10 Sep 2012 02:10:53 -0400 Subject: Newbie: where's the new python gone? In-Reply-To: <504cd574$0$6990$e4fe514c@news2.news.xs4all.nl> References: <504cd574$0$6990$e4fe514c@news2.news.xs4all.nl> Message-ID: I have several installations on my windows, so I use c:\python27_64\python.exe module_file.py or c:\python26\python.exe module_file.py in the command line. Not to show that this shouldn't be a discussion, but usually it's searching. Here's search term a link, and some python docs: install python windows command line or click: https://www.google.com/search?q=install+python+windows+command+line&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-ahere's and one of the better results: http://docs.python.org/faq/windows.html#how-do-i-run-a-python-program-under-windows -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Mon Sep 10 02:33:52 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 10 Sep 2012 02:33:52 -0400 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <504CAAAA.3090905@feete.org> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> <645baeaa-438e-4d30-a559-0db4231ede9c@googlegroups.com> <504CAAAA.3090905@feete.org> Message-ID: On Sun, Sep 9, 2012 at 10:41 AM, Ian Foote wrote: > On 09/09/12 14:23, iMath wrote: > >> ? 2012?3?26????UTC+8??7?45?26??**iMath??? >> >>> I know the print statement produces the same result when both of these >>> two instructions are executed ,I just want to know Is there any difference >>> between print 3 and print '3' in Python ? >>> >> thx everyone >> > > Here's a future import though I used,so I can use the planned 3 with a 2x python version in the command line interpreter: Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\david>c:\python26\python.exe Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> exit() C:\Users\david>c:\python27_64\python.exe Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> import __future__ >>> x = 3 >>> y = '3' >>> print(x) 3 >>> print(y) 3 >>> >>> type(x) >>> type(y) >>> z = '%i' % (3) >>> type(z) >>> In other words type(value), and find out the difference. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Sep 10 02:54:24 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 10 Sep 2012 07:54:24 +0100 Subject: Newbie: where's the new python gone? In-Reply-To: References: <504cd574$0$6990$e4fe514c@news2.news.xs4all.nl> Message-ID: On 10/09/2012 07:10, Dwight Hutto wrote: > I have several installations on my windows, so I use > c:\python27_64\python.exe module_file.py > > or > > c:\python26\python.exe module_file.py > > in the command line. > > > Not to show that this shouldn't be a discussion, but usually it's > searching. Here's search term a link, and some python docs: > > install python windows command line > > or click: > > https://www.google.com/search?q=install+python+windows+command+line&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-ahere's > > and one of the better results: > > http://docs.python.org/faq/windows.html#how-do-i-run-a-python-program-under-windows > > > > Why have you posted this seeing that the OP stated that they're on Mac OS X? The windows faq is outdated wrt PEP397. An up to date version is available here http://docs.python.org/dev/using/windows.html -- Cheers. Mark Lawrence. From benjamin.kaplan at case.edu Mon Sep 10 02:55:58 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 9 Sep 2012 23:55:58 -0700 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> <645baeaa-438e-4d30-a559-0db4231ede9c@googlegroups.com> <504CAAAA.3090905@feete.org> Message-ID: On Sun, Sep 9, 2012 at 11:33 PM, Dwight Hutto wrote: > > > On Sun, Sep 9, 2012 at 10:41 AM, Ian Foote wrote: >> >> On 09/09/12 14:23, iMath wrote: >>> >>> ? 2012?3?26????UTC+8??7?45?26??iMath??? >>>> >>>> I know the print statement produces the same result when both of these >>>> two instructions are executed ,I just want to know Is there any difference >>>> between print 3 and print '3' in Python ? >>> >>> thx everyone >> >> > > Here's a future import though I used,so I can use the planned 3 with a 2x > python version in the command line interpreter: > > Microsoft Windows [Version 6.1.7600] > Copyright (c) 2009 Microsoft Corporation. All rights reserved. > > C:\Users\david>c:\python26\python.exe > Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] > on > win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> exit() > > C:\Users\david>c:\python27_64\python.exe > Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on > win > 32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import __future__ >>>> x = 3 >>>> y = '3' >>>> print(x) > 3 >>>> print(y) > 3 >>>> >>>> type(x) > >>>> type(y) > > >>>> z = '%i' % (3) >>>> type(z) > >>>> > > In other words type(value), and find out the difference. > -- > Best Regards, > David Hutto > CEO: http://www.hitwebdevelopment.com > Somewhat OT, but __future__ doesn't work like that. You have to import the specific features you want to use. Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> print 3 3 >>> import __future__ >>> print 3 3 >>> from __future__ import print_function >>> print 3 File "", line 1 print 3 ^ SyntaxError: invalid syntax From benjamin.kaplan at case.edu Mon Sep 10 02:57:00 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 9 Sep 2012 23:57:00 -0700 Subject: Newbie: where's the new python gone? In-Reply-To: References: <504cd574$0$6990$e4fe514c@news2.news.xs4all.nl> Message-ID: On Sun, Sep 9, 2012 at 11:10 PM, Dwight Hutto wrote: > > I have several installations on my windows, so I use > c:\python27_64\python.exe module_file.py > > or > > c:\python26\python.exe module_file.py > > in the command line. > > > Not to show that this shouldn't be a discussion, but usually it's searching. > Here's search term a link, and some python docs: > > install python windows command line > > or click: > > https://www.google.com/search?q=install+python+windows+command+line&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-ahere's > > and one of the better results: > > http://docs.python.org/faq/windows.html#how-do-i-run-a-python-program-under-windows > > > -- > Best Regards, > David Hutto > CEO: http://www.hitwebdevelopment.com > The problem is related to Python on Mac, not on Windows. As was stated in the original post. From tjreedy at udel.edu Mon Sep 10 03:16:48 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 10 Sep 2012 03:16:48 -0400 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> <645baeaa-438e-4d30-a559-0db4231ede9c@googlegroups.com> <504CAAAA.3090905@feete.org> Message-ID: On 9/10/2012 2:33 AM, Dwight Hutto wrote: > > > On Sun, Sep 9, 2012 at 10:41 AM, Ian Foote > wrote: > > On 09/09/12 14:23, iMath wrote: > > ? 2012?3?26????UTC+8??7?45?26??__iMath??? > > I know the print statement produces the same result when > both of these two instructions are executed ,I just want to > know Is there any difference between print 3 and print '3' > in Python ? > > thx everyone > > > Here's a future import though I used,so I can use the planned 3 with a > 2x python version in the command line interpreter: > > Microsoft Windows [Version 6.1.7600] > Copyright (c) 2009 Microsoft Corporation. All rights reserved. > > C:\Users\david>c:\python26\python.exe > Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> exit() > > C:\Users\david>c:\python27_64\python.exe > Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit > (AMD64)] on win > 32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import __future__ > >>> x = 3 > >>> y = '3' > >>> print(x) > 3 > >>> print(y) > 3 > >>> > >>> type(x) > > >>> type(y) > > > >>> z = '%i' % (3) > >>> type(z) > > >>> > > In other words type(value), and find out the difference. print(x) prints str(x), which is meant to be a 'friendly' representation. To see a difference, >>> print(repr(3)) 3 >>> print(repr('3')) '3' -- Terry Jan Reedy From duncan.booth at invalid.invalid Mon Sep 10 04:59:37 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Sep 2012 08:59:37 GMT Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Gelonida N wrote: > On 09/07/2012 06:06 AM, Steven D'Aprano wrote: >> On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: >> >> >> Also of some interest is the best case: O(1) for unequal strings (they >> differ at the first character) and O(N) for equal strings. > > The worst case is O(N) or N characters > the average case is O(1) or two characters. > > For denial of service attacks or systems, that are NEVER allowed to fail > the worst case is important. > > For most other cases the average complexity counts. > > However I still wonder for how many applications the complexity of > string comparisons would be the limiting factor. > > and of course if you ever do find an application where that worst case matters there's an easy way round it: just call intern() on all the strings when they are created. For the comparison to be the limiting factor you have to be doing a lot of comparisons on the same string (otherwise creating the string would be the limiting factor), so at the expense of a single dictionary insertion when the string is created you can get guaranteed O(1) on all the comparisons. -- Duncan Booth http://kupuguy.blogspot.com From jrbjagger at googlemail.com Mon Sep 10 05:21:46 2012 From: jrbjagger at googlemail.com (jrbjagger at googlemail.com) Date: Mon, 10 Sep 2012 02:21:46 -0700 (PDT) Subject: Call for Papers: ACCU 2013 conference Message-ID: <74adc9c6-dfc8-4934-95cc-ad68cb0273e7@googlegroups.com> ACCU invites you to propose a session for its leading software development conference. The conference will be held in Bristol, England, from the 9th to the 13th April inclusive. Our opening keynote speakers will be Eben Upton, Mr Raspberry Pi. To propose a session please email the following information to conference at accu.org * Title (a working title if necessary) * Type (tutorial, case-study, workshop, etc.) * Duration (45/90 min) * Speaker name(s) * Speaker biography (max 150 words) * Description (approx 250 words) We have a long tradition of high quality sessions covering many aspects of software development, from programming languages (e.g., Java, C#, Python, Erlang, Haskell, Ruby, Groovy, C, C++, etc.), and technologies (libraries, frameworks, databases, etc.) to subjects about the wider development environment such as testing, architecture and design, development process, analysis, patterns, project management, and softer aspects such as team building, communication and leadership. Sessions are usually tutorial-based, presentations of case studies, or interactive workshops, but we are always open to novel formats. Most sessions are 90 minutes. To encourage less experienced speakers to speak without the pressure of filling a full 90 minutes, we reserve a number of shorter 45 minute sessions. Speakers running one or more full 90 minute sessions receive a special conference package including free attendance, and assistance with their travel and accommodation costs. Speakers filling a 45 minute slot qualify for free conference attendance on the day of their session. For more information about location, travel, fees, accommodation, restaurants, etc, please see http://www.cvent.com/events/save-the-date-/event-summary-8539404013564465b7aba6a2ce241323.aspx The conference has always benefited from the strength of its programme. Please help us make 2013 another successful event. Thank you Jon Jagger (ACCU conference chair) From jeanmichel at sequans.com Mon Sep 10 05:28:23 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 10 Sep 2012 11:28:23 +0200 Subject: how to run python2.6 module with absolute imports stand alone In-Reply-To: References: Message-ID: <504DB2B7.3070202@sequans.com> Gelonida N wrote: > On 09/08/2012 02:13 AM, Mark Lawrence wrote: >> [snip] >>> >> >> I hope this helps >> http://stackoverflow.com/questions/3616952/how-to-properly-use-relative-or-absolute-imports-in-python-modules >> > > It seems the safest bet seems to be to not use relative imports. That's what I figured as well. I may have been misusing relative imports, but I never found the solution for my problems. Absolute imports just solved everything. I think this is the way to go for anyone who does not want to spend too much brain on their import directives. JM From jeanmichel at sequans.com Mon Sep 10 05:52:34 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 10 Sep 2012 11:52:34 +0200 Subject: AttributeError: 'list' object has no attribute 'lower' In-Reply-To: <113e44c3-cd53-4536-a60c-0363bf83a8ec@googlegroups.com> References: <113e44c3-cd53-4536-a60c-0363bf83a8ec@googlegroups.com> Message-ID: <504DB862.9050908@sequans.com> Token Type wrote: >> In fact, I'm guessing that's your problem. I think you're ending up >> >> with a list of lists of strings, when you think you're getting a list of >> >> strings. >> >> > Thanks. You guess right. It turns out that lemma_list is a list of list, as I tested in the previous post. > I often noticed people around me that are not that familiar with python are dismissing the error stack so quickly ; they probably knows the machine is trying to communicate with them but they don't seem to understand the message. Error stacks may be difficult to read at first glance but you can solve a lot of problems just by reading it. So next time you see 'X' has no attribute 'Y', you'll know that you've accessed an attribute/method of an object that does not exist, either you made a typo in the attribute name, or you object is not actually what you think it is. Advice : if you have so time, install ipython and execute your scripts in an ipython shell with the %pdb faeture on. This will automatically call the debugger upon unhandled exceptions and you'll be able to inspect your objects live from the prompt. JM From dustin at v.igoro.us Mon Sep 10 07:36:11 2012 From: dustin at v.igoro.us (Dustin J. Mitchell) Date: Mon, 10 Sep 2012 07:36:11 -0400 Subject: Standard Asynchronous Python In-Reply-To: <504d60ab$0$29890$c3e8da3$5496439d@news.astraweb.com> References: <504d60ab$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: The responses have certainly highlighted some errors in emphasis in my approach. * My idea is to propose a design PEP. (Steven, Dennis) I'm not at *all* suggesting including uthreads in the standard library. It's a toy implementation I used to develop my ideas. I think of this as a much smaller idea in the same vein as the DBAPI (PEP 249): a common set of expectations that allows portability. * I'd like to set aside the issue of threads vs. event-driven programming. There are legitimate reasons to do both, and the healthy ecosystem of frameworks for the latter indicates at least some people are interested. My idea is to introduce a tiny bit of coherence across those frameworks. * (Bryan) The Fibonacci example is a simple example of, among other things, a CPU-bound, recursive task -- something that many async frameworks don't handle fairly right now. I will add some text to call that out explicitly. * Regarding generators vs. coroutines (Bryan), I use the terms generator and generator function in the PEP carefully, as that's what the syntactic and runtime concepts are called in Python. I will include a paragraph distinguishing the two. I will need to take up the details of the idea with the developers of the async frameworks themselves, and get some agreement before actually proposing the PEP. However, among this group I'm interested to know whether this is an appropriate use of a design PEP. That's why I posted my old and flawed PEP text, rather than re-drafting first. Thanks for the responses so far! Dustin From rolf.wester at ilt.fraunhofer.de Mon Sep 10 08:15:03 2012 From: rolf.wester at ilt.fraunhofer.de (Rolf Wester) Date: Mon, 10 Sep 2012 14:15:03 +0200 Subject: Compile python code into a dll Message-ID: <504dd9c6$1@news.fhg.de> Hi, I have Python code that I would like to compile into a dll (I have to deliver a C/C++ callable dll and I don't want to reimpelement the Python code in C/C++). It's not for extending Python but I want to call the Python functions and classes from C/C++. It's more like extending C/C++ with Python. I would be very appreciative for any help. Thank you in advance Regards Rolf From wrw at mac.com Mon Sep 10 09:04:24 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Mon, 10 Sep 2012 09:04:24 -0400 Subject: Newbie: where's the new python gone? In-Reply-To: References: Message-ID: <163755B1-D4FE-4660-B48B-91995D273231@mac.com> On Sep 9, 2012, at 10:28 AM, BobAalsma wrote: > I think I've installed Python 2.7.3 according to the instructions in the README, and now want to use that version. > However, when typing "python" in Terminal, I get "Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) ". > So: > (1) I can't seem to find where the new software has gone and > (2) can't seem to find how to point to this new versoin. > I've searched Python.org and with Google but :( > [I'm on Mac OS X 10.7.4] > > Please help. > -- > http://mail.python.org/mailman/listinfo/python-list Bob, I'm coming into this late, but it doesn't appear that you've gotten a satisfactory answer yet. Let's take it one step at a time. First, if none of the hints you've received earlier have gotten you going. Maybe the thing is to resort to a bigger hammer. In a terminal window: $sudo find / -name Python -print This will search the entire file system for all the files named Python and will ask for your admin password so it can search in directories owned by root. (It may also generate quite a bit of output, so you might want to capture it in a file.) In any case, this will take several minutes and while it is running, you can be checking a couple of other things. OS X doesn't use a .bashrc file by default (you can make it do so if you want, but that's extra work right now). It uses .login and then .profile to set up your python path _if_ you've used the installer from python.org. So, look to see if you have a .profile in your ~ directory. If so, then you're using (or have used at some point in the past) an installer from python.org. It should have an entry that looks something like the following: # Setting PATH for Python 2.7 # The orginal version is saved in .profile.pysave PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}" export PATH Note the distinction between this path and the one from Apple. The python that ships from Apple is in /System/Library/Frameworks? Do NOT touch the one from Apple. Apple uses it for some of its housekeeping operations and you want it to stay just as Apple installed it. When you finally find the Python 2.7 in the output from the "find" command, you can edit your .login (if you don't have a .profile) or edit .profile if you do. Good luck, Bill From maniandram01 at gmail.com Mon Sep 10 09:08:04 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Mon, 10 Sep 2012 06:08:04 -0700 (PDT) Subject: Compile python code into a dll In-Reply-To: <504dd9c6$1@news.fhg.de> References: <504dd9c6$1@news.fhg.de> Message-ID: <26783863-134f-4d58-a56f-a0a14ee0e15d@googlegroups.com> On Monday, 10 September 2012 17:45:11 UTC+5:30, Rolf Wester wrote: > Hi, > > > > I have Python code that I would like to compile into a dll (I have to > > deliver a C/C++ callable dll and I don't want to reimpelement the Python > > code in C/C++). It's not for extending Python but I want to call the > > Python functions and classes from C/C++. It's more like extending C/C++ > > with Python. I would be very appreciative for any help. > > > > Thank you in advance > > > > Regards > > Rolf http://docs.python.org/extending/embedding.html is the official docs for this thing Embedding is similar to extending. From miki.tebeka at gmail.com Mon Sep 10 09:11:02 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 10 Sep 2012 06:11:02 -0700 (PDT) Subject: Compile python code into a dll In-Reply-To: <504dd9c6$1@news.fhg.de> References: <504dd9c6$1@news.fhg.de> Message-ID: > I have Python code that I would like to compile into a dll (I have to See http://docs.python.org/extending/embedding.html. You can pack your code in a zip file and load it from the DLL entry point (something like what py2exe does). See also the Freeze tool - http://wiki.python.org/moin/Freeze. HTH, -- Miki (http://pythonwise.blogspot.com/) From suresh2.sancrosoft at gmail.com Mon Sep 10 09:21:10 2012 From: suresh2.sancrosoft at gmail.com (Suresh Kumar) Date: Mon, 10 Sep 2012 06:21:10 -0700 (PDT) Subject: SAP MM Cupertino, CA Message-ID: Hi, This is Girish, - IT Recruiter from SancroSoft USA Inc. Please respond with updated resume in MS-Word .doc Format with the following details to Girish at sancrosoftusa.com Full Name : Location : Contact Number : Email : Availability : Visa Status : SAP MM Location : Cupertino, CA Duration: 3+ Months Job Description: ? Candidate should possess excellent functional knowledge in SAP MM for about 4-5 yrs and have 2 years of implementation or Production support experience ? Should be strong in Procure to pay cycle covering the critical aspects of Purchasing, Inventory Management & Invoice Verification. ? Should be able to understand the client business process so as to map the requirements in SAP using standard solution methodology. ? Should be able to conduct Business workshops to drive the project implementation using SAP standard implementation methodologies. ? Should be strong in Special processes which include Consignment process, Subcontracting process & Batch Management. ? Should be comfortable in handling and preparation of Functional Specifications and to work with developer to achieve RICEF objects. ? Should have cross functional expertise and should be strong in integrating the system with other modules which includes SD, WM & FI. ? Should have worked and exposed to EDI Integration techniques along with Idoc monitoring process. ? Should be an excellent team player & good team builder. ? Should demonstrate excellent communication skills. Thanks & Regards, Girish IT Recruiter. The power of focus SancroSoft USA INC 4944 Sunrise Blvd, Suite B-4 || Fair Oaks, CA 95628 Phone : 916-671-5584|| Fax: 916-200-0305 E-Mail : girish at sancrosoftusa.com|| www.sancrosoftusa.com Stay Connected: The information contained in this email message is intended only for the personal and confidential use of the recipient(s) named above. The message may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by email and delete the original message. From steve+comp.lang.python at pearwood.info Mon Sep 10 09:24:10 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Sep 2012 13:24:10 GMT Subject: Standard Asynchronous Python References: <504d60ab$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: <504de9fa$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 10 Sep 2012 07:36:11 -0400, Dustin J. Mitchell wrote: > The responses have certainly highlighted some errors in emphasis in my > approach. > > * My idea is to propose a design PEP. (Steven, Dennis) I'm not at *all* > suggesting including uthreads in the standard library. It's a toy > implementation I used to develop my ideas. I think of this as a much > smaller idea in the same vein as the DBAPI (PEP 249): a common set of > expectations that allows portability. Okay, point taken, I misunderstood your proposal. But my point still stands: since nobody except (possibly) you has used your uthreads library, what gives you confidence that the API you suggest is any good? Not just good, but good enough to impose that API on every other async framework in the standard library and possibly beyond it? If you have a good answer to that question, then it might be appropriate to propose such an API. (For what it's worth, consensus among the major async frameworks that your approach was a good idea would be a pretty good answer to that question.) -- Steven From oscar.j.benjamin at gmail.com Mon Sep 10 09:40:37 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 10 Sep 2012 13:40:37 +0000 (UTC) Subject: Standard Asynchronous Python References: <5kuq48po3pnic4au2ivtikkihntu8pvk42@invalid.netcom.com> Message-ID: On 2012-09-10, Dennis Lee Bieber wrote: > On Sun, 9 Sep 2012 20:07:51 -0400, "Dustin J. Mitchell" > declaimed the following in > gmane.comp.python.general: > >> >> My proposal met with near-silence, and I didn't pursue it. Instead, I >> did what any self-respecting hacker would do - I wrote up a framework, >> uthreads [4], that implemented my idea. This was initially a simple >> trampoline scheduler, but I eventually refactored it to run atop >> Twisted, since that's what I use. To my knowledge, it's never been >> used. >> > So for your small attempt to hide an event-driven dispatcher, one > has to load a massive event-driven library. Some years ago I tried to > make sense of Twisted and failed badly. Maybe it makes sense to those > raised on UNIX style select() (where practically anything that involved > data transfer over some sort of channel could be tested -- but doesn't > work as such on Windows where only network sockets can be used, file i/o > needs to use a different call), >> I think the idea behind the PEP is to facilitate modularisation of event driven frameworks into dispatchers and libraries that are suitable for running within dispatchers. When you say a 'massive-event driven library' I guess you mean something liek Twisted. I don't have much experience with Twisted but having looked at it a bit my impression is that it is so large because it includes many components that are not essential for every user. I guess that the reason for keeping those components in Twisted rather than as separate projects is not so much because every user needs them but because many of them are implemented in a way that makes them not much use outside of Twisted. The idea that Dustin is proposing is that in the same way that a library might declare a subset of its API to be thread-safe, and so usable with threading frameworks, a library could expose a PEP-XXX compliant interface for use with a PEP-XXX compliant dispatcher. If implemented that should facilitate the creation of minimal dispatchers and minimal standard components that can run within those dispatchers. This would mean that it wouldn't be necessary to make massive event-driven libraries but rather smaller interchangeable libraries. For example, it might facilitate the creation of a Windows-specific dispatcher that would be able to use the best underlying Windows APIs while also benefitting from any PEP-XXX compliant libraries that would work with any other dispatcher. >> As I get to work on the PEP, I'd like to hear any initial reactions to the >> idea. I don't have much experience with the event-driven frameworks but having made a couple of simple scripts using gevent/Twisted my experience is that learning to use these frameworks is hard, largely because of the number of framework- specific concepts that are needed to make simple examples work. I would expect that giving each framework a relatively standardised interface would make them much easier to learn. Oscar From steve+comp.lang.python at pearwood.info Mon Sep 10 09:45:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Sep 2012 13:45:01 GMT Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <504deedc$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 10 Sep 2012 08:59:37 +0000, Duncan Booth wrote: > Gelonida N wrote: > >> On 09/07/2012 06:06 AM, Steven D'Aprano wrote: >>> On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: >>> >>> >>> Also of some interest is the best case: O(1) for unequal strings (they >>> differ at the first character) and O(N) for equal strings. >> >> The worst case is O(N) or N characters the average case is O(1) or two >> characters. >> >> For denial of service attacks or systems, that are NEVER allowed to >> fail the worst case is important. >> >> For most other cases the average complexity counts. >> >> However I still wonder for how many applications the complexity of >> string comparisons would be the limiting factor. >> >> > and of course if you ever do find an application where that worst case > matters there's an easy way round it: just call intern() on all the > strings when they are created. There are other good reasons for interning strings, but speeding up "astring == bstring" is not one of them. [steve at ando ~]$ python -m timeit -s "s = 'abc'*100000" -s \ > "t = s[:-1] + 'x'" "s == t" 1000 loops, best of 3: 910 usec per loop [steve at ando ~]$ python -m timeit -s "s = 'abc'*100000" -s \ > "t = s[:-1] + 'x'" -s "intern(s); intern(t)" "s == t" 1000 loops, best of 3: 914 usec per loop No significant difference. To state the bleedin' obvious, the computational effort required to *compare two strings* pre-supposes that those strings already exist, and is *completely independent* of the complexity of creating the strings. > For the comparison to be the limiting factor you have to be doing a lot > of comparisons Correct. > on the same string (otherwise creating the string would be the limiting > factor), Not necessarily. Look, it's really hard to come up with a realistic, non-contrived example where string comparisons are a significant bottleneck in a non-toy application. So let me first off say that *nearly always* you're not going to care whether "s == t" looks at all N characters or just the first 2 (or 20, or 100). This argument is rather academic (the best sort of argument!). Until you start getting up into truly huge strings, we're arguing about how many angels can dance on a CPU cache. But for the record, in principle string comparisons *could* be the bottleneck. Example: you have 10000 strings, which are each created once and stored in a list. Then you iterate over the list, comparing every string against every other string. And due to some weird vagary of the data, the strings are nearly all equal. (Why would you do this? I don't know, maybe it's a programmers' challenge found on the Internet, make up your own scenario...) Total number of strings created: 10000. Total number of strings compared: 100000000. The overhead of creating the strings is trivial compared to the overhead of comparing them, and since each string is only created once anyway, interning them is just a waste of time. > so at the expense of a single dictionary > insertion when the string is created you can get guaranteed O(1) on all > the comparisons. What interning buys you is that "s == t" is an O(1) pointer compare if they are equal. But if s and t differ in the last character, __eq__ will still inspect every character. There is no way to tell Python "all strings are interned, if s is not t then s != t as well". -- Steven From oscar.j.benjamin at gmail.com Mon Sep 10 10:06:16 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 10 Sep 2012 14:06:16 +0000 (UTC) Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504deedc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-09-10, Steven D'Aprano wrote: > On Mon, 10 Sep 2012 08:59:37 +0000, Duncan Booth wrote: > >> Gelonida N wrote: >> >> so at the expense of a single dictionary >> insertion when the string is created you can get guaranteed O(1) on all >> the comparisons. > > What interning buys you is that "s == t" is an O(1) pointer compare if > they are equal. But if s and t differ in the last character, __eq__ will > still inspect every character. There is no way to tell Python "all > strings are interned, if s is not t then s != t as well". > I thought that if *both* strings were interned then a pointer comparison could decide if they were unequal without needing to check the characters. Have I misunderstood how intern() works? Oscar From rosuav at gmail.com Mon Sep 10 10:26:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Sep 2012 00:26:29 +1000 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504deedc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 11, 2012 at 12:06 AM, Oscar Benjamin wrote: > On 2012-09-10, Steven D'Aprano wrote: >> What interning buys you is that "s == t" is an O(1) pointer compare if >> they are equal. But if s and t differ in the last character, __eq__ will >> still inspect every character. There is no way to tell Python "all >> strings are interned, if s is not t then s != t as well". >> > > I thought that if *both* strings were interned then a pointer comparison could > decide if they were unequal without needing to check the characters. > > Have I misunderstood how intern() works? In a language where _all_ strings are guaranteed to be interned (such as Lua, I think), you do indeed gain this. Pointer inequality implies string inequality. But when interning is optional (as in Python), you cannot depend on that, unless there's some way of recognizing interned strings. Of course, that may indeed be the case; a simple bit flag "this string has been interned" would suffice, and if both strings are interned AND their pointers differ, THEN you can be sure the strings differ. I have no idea whether or not CPython version X.Y.Z does this. The value of such an optimization really depends on how likely strings are to be interned; for instance, if the compiler automatically interns all the names of builtins, this could be quite beneficial. Otherwise, probably not; most Python scripts don't bother interning anything. ChrisA From oscar.j.benjamin at gmail.com Mon Sep 10 10:32:22 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 10 Sep 2012 14:32:22 +0000 (UTC) Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504deedc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-09-10, Chris Angelico wrote: > On Tue, Sep 11, 2012 at 12:06 AM, Oscar Benjamin > wrote: >> On 2012-09-10, Steven D'Aprano wrote: >>> What interning buys you is that "s == t" is an O(1) pointer compare if >>> they are equal. But if s and t differ in the last character, __eq__ will >>> still inspect every character. There is no way to tell Python "all >>> strings are interned, if s is not t then s != t as well". >>> >> >> I thought that if *both* strings were interned then a pointer comparison >> could decide if they were unequal without needing to check the characters. >> >> Have I misunderstood how intern() works? > > In a language where _all_ strings are guaranteed to be interned (such > as Lua, I think), you do indeed gain this. Pointer inequality implies > string inequality. But when interning is optional (as in Python), you > cannot depend on that, unless there's some way of recognizing interned > strings. Of course, that may indeed be the case; a simple bit flag > "this string has been interned" would suffice, and if both strings are > interned AND their pointers differ, THEN you can be sure the strings > differ. > > I have no idea whether or not CPython version X.Y.Z does this. The > value of such an optimization really depends on how likely strings are > to be interned; for instance, if the compiler automatically interns > all the names of builtins, this could be quite beneficial. Otherwise, > probably not; most Python scripts don't bother interning anything. > I haven't looked at the source but my understanding was precisely that there is an intern() bit and that not only the builtins module but all the literals in any byte-compiled module are interned. Oscar From oscar.j.benjamin at gmail.com Mon Sep 10 10:43:34 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 10 Sep 2012 14:43:34 +0000 (UTC) Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504deedc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-09-10, Oscar Benjamin wrote: > On 2012-09-10, Chris Angelico wrote: >> On Tue, Sep 11, 2012 at 12:06 AM, Oscar Benjamin >> wrote: >>> On 2012-09-10, Steven D'Aprano wrote: >>>> What interning buys you is that "s == t" is an O(1) pointer compare if >>>> they are equal. But if s and t differ in the last character, __eq__ will >>>> still inspect every character. There is no way to tell Python "all >>>> strings are interned, if s is not t then s != t as well". >>>> >>> >>> I thought that if *both* strings were interned then a pointer comparison >>> could decide if they were unequal without needing to check the characters. >>> >>> Have I misunderstood how intern() works? >> >> In a language where _all_ strings are guaranteed to be interned (such >> as Lua, I think), you do indeed gain this. Pointer inequality implies >> string inequality. But when interning is optional (as in Python), you >> cannot depend on that, unless there's some way of recognizing interned >> strings. Of course, that may indeed be the case; a simple bit flag >> "this string has been interned" would suffice, and if both strings are >> interned AND their pointers differ, THEN you can be sure the strings >> differ. >> >> I have no idea whether or not CPython version X.Y.Z does this. The >> value of such an optimization really depends on how likely strings are >> to be interned; for instance, if the compiler automatically interns >> all the names of builtins, this could be quite beneficial. Otherwise, >> probably not; most Python scripts don't bother interning anything. >> > > I haven't looked at the source but my understanding was precisely that there > is an intern() bit and that not only the builtins module but all the literals > in any byte-compiled module are interned. > s/literals/identifiers/ You can see the interned flag in the PyUnicodeObject struct here: http://hg.python.org/cpython/file/3ffd6ad93fe4/Include/unicodeobject.h#l303 Oscar From desolatechair at gmail.com Mon Sep 10 10:55:58 2012 From: desolatechair at gmail.com (james simpson) Date: Mon, 10 Sep 2012 07:55:58 -0700 (PDT) Subject: PYODBC Print Cursor Output Question Message-ID: <4a3619f2-721a-4aca-9a97-f90aaf6a1346@u15g2000yql.googlegroups.com> I think there's a simple answer but displaying my ignorance here. I'm using Python 2.7.3 IDLW with pydoc 3x I think I've connected to my SQL Server 2005 and my SQL is good. How do I display the actual data returned from my fetch? Been searching for several hours but no joy... Thanks. Jamie =============================================== >>> cursor.execute("select * from project") row = cursor.fetchone() if row: print row I'd like to actually see SQL output here?) From rosuav at gmail.com Mon Sep 10 10:56:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Sep 2012 00:56:09 +1000 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504deedc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 11, 2012 at 12:43 AM, Oscar Benjamin wrote: > On 2012-09-10, Oscar Benjamin wrote: >> I haven't looked at the source but my understanding was precisely that there >> is an intern() bit and that not only the builtins module but all the literals >> in any byte-compiled module are interned. >> > > s/literals/identifiers/ > > You can see the interned flag in the PyUnicodeObject struct here: > http://hg.python.org/cpython/file/3ffd6ad93fe4/Include/unicodeobject.h#l303 Ah, yep, so that's there. In that case, it's possible to have that optimization. However, I may be misreading this, but it seems the only Unicode comparison function is a rich compare, which is unable to take advantage of a known difference: http://hg.python.org/cpython/file/b48ef168d8c5/Objects/unicodeobject.c#l6114 Different pointers prove the strings differ, but don't tell you which is to be sorted earlier. You could use this if you roll your own comparison in C; or, if you already know the strings are interned, you can use 'is' / 'is not'. But that seems to be the extent of it. ChrisA From maniandram01 at gmail.com Mon Sep 10 10:58:03 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Mon, 10 Sep 2012 07:58:03 -0700 (PDT) Subject: SAP MM Cupertino, CA In-Reply-To: References: Message-ID: On Monday, 10 September 2012 18:51:10 UTC+5:30, Suresh Kumar wrote: > Hi, > > > > This is Girish, - IT Recruiter from SancroSoft USA Inc. > > > > Please respond with updated resume in MS-Word .doc Format with the > > following details to Girish at sancrosoftusa.com > > > > Full Name : > > Location : > > Contact Number : > > Email : > > Availability : > > Visa Status : > > > > SAP MM > > Location : Cupertino, CA > > Duration: 3+ Months > > > > Job Description: > > > > ? Candidate should possess excellent functional knowledge in SAP MM > > for about 4-5 yrs and have 2 years of implementation or Production > > support experience > > ? Should be strong in Procure to pay cycle covering the critical > > aspects of Purchasing, Inventory Management & Invoice Verification. > > ? Should be able to understand the client business process so as to > > map the requirements in SAP using standard solution methodology. > > ? Should be able to conduct Business workshops to drive the project > > implementation using SAP standard implementation methodologies. > > ? Should be strong in Special processes which include Consignment > > process, Subcontracting process & Batch Management. > > ? Should be comfortable in handling and preparation of Functional > > Specifications and to work with developer to achieve RICEF objects. > > ? Should have cross functional expertise and should be strong in > > integrating the system with other modules which includes SD, WM & FI. > > ? Should have worked and exposed to EDI Integration techniques along > > with Idoc monitoring process. > > ? Should be an excellent team player & good team builder. > > ? Should demonstrate excellent communication skills. > > > > > > > > Thanks & Regards, > > > > Girish > > IT Recruiter. > > > > > > The power of focus > > SancroSoft USA INC > > 4944 Sunrise Blvd, Suite B-4 || Fair Oaks, CA 95628 > > Phone : 916-671-5584|| Fax: 916-200-0305 > > E-Mail : girish at sancrosoftusa.com|| www.sancrosoftusa.com > > > > Stay Connected: > > > > The information contained in this email message is intended only for > > the personal and confidential use of the recipient(s) named above. The > > message may be privileged and confidential and protected from > > disclosure. If the reader of this message is not the intended > > recipient or an agent responsible for delivering it to the intended > > recipient, you are hereby notified that you have received this > > document in error and that any review, dissemination, distribution, > > copying of this message is strictly prohibited. If you have received > > this communication in error, please notify us immediately by email and > > delete the original message. Marking this as abusive in Google Groups - this seems like spam. Please explain what does this have to do with Python. From hansmu at xs4all.nl Mon Sep 10 11:22:12 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Mon, 10 Sep 2012 17:22:12 +0200 Subject: Newbie: where's the new python gone? In-Reply-To: References: Message-ID: <504e05a4$0$6966$e4fe514c@news2.news.xs4all.nl> On 10/09/12 15:04:24, William R. Wing (Bill Wing) wrote: > On Sep 9, 2012, at 10:28 AM, BobAalsma wrote: > >> I think I've installed Python 2.7.3 according to the instructions in the README, and now want to use that version. >> However, when typing "python" in Terminal, I get "Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) ". >> So: >> (1) I can't seem to find where the new software has gone and >> (2) can't seem to find how to point to this new versoin. >> I've searched Python.org and with Google but :( >> [I'm on Mac OS X 10.7.4] >> >> Please help. >> -- >> http://mail.python.org/mailman/listinfo/python-list > > Bob, I'm coming into this late, but it doesn't appear that you've < gotten a satisfactory answer yet. Let's take it one step at a time. > > First, if none of the hints you've received earlier have gotten you going. > Maybe the thing is to resort to a bigger hammer. In a terminal window: > > $sudo find / -name Python -print > > This will search the entire file system for all the files named Python Trouble is, the file you're looking for is named "python" and this command is case-sensitive. So the command you need would be: sudo find / -name python -print > and will ask for your admin password so it can search in directories > owned by root. The file you're looking for is in a directory that you can read with more mundane permissions, so you might want to leave off the "sudo" prefix. If you do, you'll get some message about permission problems. > (It may also generate quite a bit of output, so you might want > to capture it in a file.) For example: find / -name python > /tmp/pythons.txt 2> /dev/null The 2>/dev/null bit throws away warnings about permission problems and the like. Alternatively, you can cut down the output like so: find / -name python -print | grep bin/python That will only report pythons found in directories named "bin". On my laptop, that cuts the output down to: /Library/Frameworks/Python.framework/Versions/2.7/bin/python /opt/local/bin/python /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/python /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python /System/Library/Frameworks/Python.framework/Versions/2.6/bin/python /usr/bin/python /usr/local/bin/python Those are all valid python interpreters, or wrappers for same. > In any case, this will take several minutes and while it is running, > you can be checking a couple of other things. OS X doesn't use a > .bashrc file by default (you can make it do so if you want, but > that's extra work right now). It uses .login and then .profile > to set up your python path _if_ you've used the installer from python.org. I doubt it. What files are used, depends on which shell you use. Bash uses .profile; the C shell uses .login and .cshrc. I don't think there is a shell that can read both .login and .profile since .login typically uses C shell syntax and .profile uses Bourne shell syntax. If you're not sure which shell you have, type echo $SHELL at the shell prompt. > So, look to see if you have a .profile in your ~ directory. If so, > then you're using (or have used at some point in the past) an installer > from python.org. > It should have an entry that looks something like the following: > > # Setting PATH for Python 2.7 > # The original version is saved in .profile.pysave > PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}" > export PATH > > Note the distinction between this path and the one from Apple. > The python that ships from Apple is in /System/Library/Frameworks? > > Do NOT touch the one from Apple. Apple uses it for some of its > housekeeping operations and you want it to stay just as Apple > installed it. +1 > When you finally find the Python 2.7 in the output from the "find" > command, you can edit your .login (if you don't have a .profile) or > edit .profile if you do. Hope this helps, -- HansM From tjreedy at udel.edu Mon Sep 10 12:06:42 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 10 Sep 2012 12:06:42 -0400 Subject: Compile python code into a dll In-Reply-To: <504dd9c6$1@news.fhg.de> References: <504dd9c6$1@news.fhg.de> Message-ID: On 9/10/2012 8:15 AM, Rolf Wester wrote: > I have Python code that I would like to compile into a dll (I have to > deliver a C/C++ callable dll and I don't want to reimpelement the Python > code in C/C++). It's not for extending Python but I want to call the > Python functions and classes from C/C++. It's more like extending C/C++ > with Python. I would be very appreciative for any help. Cython compiles CPython to C which can be compiled by and c/c++ compiler. I believe it can do the above. "This makes Cython the ideal language for wrapping external C libraries, embedding CPython into existing applications, ". I think the latter is what you want to do. http:cython.org -- Terry Jan Reedy From dg.gmane at thesamovar.net Mon Sep 10 12:07:41 2012 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Mon, 10 Sep 2012 18:07:41 +0200 Subject: Comparing strings from the back? In-Reply-To: References: Message-ID: <504E104D.8090404@thesamovar.net> On 04/09/2012 03:54, Roy Smith wrote: > Let's assume you're testing two strings for equality. You've already > done the obvious quick tests (i.e they're the same length), and you're > down to the O(n) part of comparing every character. > > I'm wondering if it might be faster to start at the ends of the strings > instead of at the beginning? If the strings are indeed equal, it's the > same amount of work starting from either end. But, if it turns out that > for real-life situations, the ends of strings have more entropy than the > beginnings, the odds are you'll discover that they're unequal quicker by > starting at the end. From the rest of the thread, it looks like in most situations it won't make much difference as typically very few characters need to be compared if they are unequal. However, if you were in a situation with many strings which were almost equal, the most general way to improve the situation might be store a hash of the string along with the string, i.e. store (hash(x), x) and then compare equality of this tuple. Almost all of the time, if the strings are unequal the hash will be unequal. Or, as someone else suggested, use interned versions of the strings. This is basically the same solution but even better. In this case, your startup costs will be higher (creating the strings) but your comparisons will always be instant. Dan From dg.gmane at thesamovar.net Mon Sep 10 12:07:41 2012 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Mon, 10 Sep 2012 18:07:41 +0200 Subject: Comparing strings from the back? In-Reply-To: References: Message-ID: <504E104D.8090404@thesamovar.net> On 04/09/2012 03:54, Roy Smith wrote: > Let's assume you're testing two strings for equality. You've already > done the obvious quick tests (i.e they're the same length), and you're > down to the O(n) part of comparing every character. > > I'm wondering if it might be faster to start at the ends of the strings > instead of at the beginning? If the strings are indeed equal, it's the > same amount of work starting from either end. But, if it turns out that > for real-life situations, the ends of strings have more entropy than the > beginnings, the odds are you'll discover that they're unequal quicker by > starting at the end. From the rest of the thread, it looks like in most situations it won't make much difference as typically very few characters need to be compared if they are unequal. However, if you were in a situation with many strings which were almost equal, the most general way to improve the situation might be store a hash of the string along with the string, i.e. store (hash(x), x) and then compare equality of this tuple. Almost all of the time, if the strings are unequal the hash will be unequal. Or, as someone else suggested, use interned versions of the strings. This is basically the same solution but even better. In this case, your startup costs will be higher (creating the strings) but your comparisons will always be instant. Dan From python at mrabarnett.plus.com Mon Sep 10 12:19:09 2012 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 10 Sep 2012 17:19:09 +0100 Subject: PYODBC Print Cursor Output Question In-Reply-To: <4a3619f2-721a-4aca-9a97-f90aaf6a1346@u15g2000yql.googlegroups.com> References: <4a3619f2-721a-4aca-9a97-f90aaf6a1346@u15g2000yql.googlegroups.com> Message-ID: <504E12FD.2050906@mrabarnett.plus.com> On 10/09/2012 15:55, james simpson wrote: > I think there's a simple answer but displaying my ignorance here. > I'm > using Python 2.7.3 IDLW with pydoc 3x > > I think I've connected to my SQL Server 2005 and my SQL is good. > > How do I display the actual data returned from my fetch? Been > searching for several hours but no joy... > > Thanks. Jamie > > =============================================== >>>> cursor.execute("select * from project") > > row = cursor.fetchone() > if row: > print row > > I'd like to actually see SQL > output here?) > > Try this: >>> results = cursor.execute("select * from project") >>> row = results.fetchone() >>> print row From tjreedy at udel.edu Mon Sep 10 12:21:11 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 10 Sep 2012 12:21:11 -0400 Subject: Standard Asynchronous Python In-Reply-To: References: <504d60ab$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/10/2012 7:36 AM, Dustin J. Mitchell wrote: > The responses have certainly highlighted some errors in emphasis in my approach. > > * My idea is to propose a design PEP. (Steven, Dennis) I'm not at > *all* suggesting including uthreads in the standard library. It's a > toy implementation I used to develop my ideas. I think of this as a > much smaller idea in the same vein as the DBAPI (PEP 249): a common > set of expectations that allows portability. That has been very successful. > * I'd like to set aside the issue of threads vs. event-driven > programming. There are legitimate reasons to do both, and the healthy > ecosystem of frameworks for the latter indicates at least some people > are interested. My idea is to introduce a tiny bit of coherence > across those frameworks. I think many developers recognize that some improvment in coherence would be a good idea. I occasionally read that *someone* is working on common event loop approach, though it has not materialized yet. > I will need to take up the details of the idea with the developers of > the async frameworks themselves, and get some agreement before > actually proposing the PEP. However, among this group I'm interested > to know whether this is an appropriate use of a design PEP. I think so. > That's why I posted my old and flawed PEP text, rather than re-drafting > first. I think you should do a bit of editing now, even if not a full redraft. -- Terry Jan Reedy From emile at fenx.com Mon Sep 10 12:22:54 2012 From: emile at fenx.com (Emile van Sebille) Date: Mon, 10 Sep 2012 09:22:54 -0700 Subject: SAP MM Cupertino, CA In-Reply-To: References: Message-ID: On 9/10/2012 7:58 AM Ramchandra Apte said... > On Monday, 10 September 2012 18:51:10 UTC+5:30, Suresh Kumar wrote: >> delete the original message. > > Marking this as abusive in Google Groups - this seems like spam. > Please explain what does this have to do with Python. Please learn to trim -- your reposting of the entire 'abusive' post is in and of itself abusive. Emile From oscar.j.benjamin at gmail.com Mon Sep 10 12:33:47 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 10 Sep 2012 16:33:47 +0000 (UTC) Subject: Comparing strings from the back? References: <504E104D.8090404@thesamovar.net> Message-ID: On 2012-09-10, Dan Goodman wrote: > On 04/09/2012 03:54, Roy Smith wrote: >> Let's assume you're testing two strings for equality. You've already >> done the obvious quick tests (i.e they're the same length), and you're >> down to the O(n) part of comparing every character. >> >> I'm wondering if it might be faster to start at the ends of the strings >> instead of at the beginning? If the strings are indeed equal, it's the >> same amount of work starting from either end. But, if it turns out that >> for real-life situations, the ends of strings have more entropy than the >> beginnings, the odds are you'll discover that they're unequal quicker by >> starting at the end. > > From the rest of the thread, it looks like in most situations it won't > make much difference as typically very few characters need to be > compared if they are unequal. > > However, if you were in a situation with many strings which were almost > equal, the most general way to improve the situation might be store a > hash of the string along with the string, i.e. store (hash(x), x) and > then compare equality of this tuple. Almost all of the time, if the > strings are unequal the hash will be unequal. Or, as someone else > suggested, use interned versions of the strings. This is basically the > same solution but even better. In this case, your startup costs will be > higher (creating the strings) but your comparisons will always be instant. > Computing the hash always requires iterating over all characters in the string so is best case O(N) where string comparison is best case (and often average case) O(1). Also, so far as I know the hash value once computed is stored on the string object itself [1] and used for subsequent string comparisons so there's no need for you to do that in your code. Oscar [1] http://hg.python.org/cpython/file/71d94e79b0c3/Include/unicodeobject.h#l293 From invalid at invalid.invalid Mon Sep 10 13:21:52 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 10 Sep 2012 17:21:52 +0000 (UTC) Subject: How to timeout a recv() on an ssl connection? Message-ID: I can't figure out how to timeout a recv() on an SSLSocket -- I'm using Python 2.6 nad 2.7. Here's what I've got so far (it needs to work on either a plain or SSL socket): s.settimeout(timeout) try: b = ord(s.recv(1)) except socket.timeout: return None except ssl.SSLError as e: if e.message == 'The read operation timed out': return None else: raise finally: s.settimeout(None) It works fine on normal sockets. With an SSLSocket, it works the first time it's called with timeout set to something other than None (it times out properly). Subsequence reads with timeout set to None work, but then the second time it's called with a non-None timeout, it hangs for several minutes, and then the recv() returns an empty string. -- Grant Edwards grant.b.edwards Yow! This PORCUPINE knows at his ZIPCODE ... And he has gmail.com "VISA"!! From jayden.shui at gmail.com Mon Sep 10 13:24:00 2012 From: jayden.shui at gmail.com (jayden.shui at gmail.com) Date: Mon, 10 Sep 2012 10:24:00 -0700 (PDT) Subject: pyQT performance? Message-ID: <1fdd6c92-2eb9-41b6-9cdb-84bfb3a4ed75@googlegroups.com> Anybody has the experience of the performance of the program developed by pyQT? Is it much slower than the one made by QT, such as (20%)? From john.ruckstuhl at gmail.com Mon Sep 10 13:25:29 2012 From: john.ruckstuhl at gmail.com (ruck) Date: Mon, 10 Sep 2012 10:25:29 -0700 (PDT) Subject: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py Message-ID: In Python 2.7.2 on Windows 7, os.walk() uses isdir(), which comes from os.path, which really comes from ntpath.py, which really comes from genericpath.py I want os.walk() to use a modified isdir() on my Windows 7. Not knowing any better, it seems to me like ntpath.py would be a good place to intercept. When os.py does "import ntpath as path", how can I get python to process my customized ntpath.py instead of Lib/ntpath.py ? Thanks for any comments. John BTW, here's my mod to ntpath.py: $ diff ntpath.py.standard ntpath.py 14c14,19 < from genericpath import * --- > from genericpath import * > > def isdir(s): > return genericpath.isdir('\\\\?\\' + abspath(s + '\\')) > def isfile(s): > return genericpath.isfile('\\\\?\\' + abspath(s + '\\')) Why? Because the genericpath implementation relies on os.stat() which uses Windows API function that presumes or enforces some naming conventions like "doesn't end with a space or a period". But the NTFS actually supports such filenames and dirnames, and some sw (like cygwin) lets users make files & dirs without restricting. So, cygwin users like me may have file 'voo...\\doo' which os.walk() cannot ordinarily walk. That is, the isdir('voo...') returns false because the underlying os.stat is assessing 'voo' instead of 'voo...' . The workaround is to pass os.stat a fullpathname that is prefixed with r'\\?\' so the Windows API recognizes that you do NOT want the name filtered. Better said by Microsoft: "For file I/O, the "\\?\" prefix to a path string tells the Windows APIs to disable all string parsing and to send the string that follows it straight to the file system. For example, if the file system supports large paths and file names, you can exceed the MAX_PATH limits that are otherwise enforced by the Windows APIs." From dg.gmane at thesamovar.net Mon Sep 10 13:32:48 2012 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Mon, 10 Sep 2012 19:32:48 +0200 Subject: Comparing strings from the back? In-Reply-To: References: <504E104D.8090404@thesamovar.net> Message-ID: <504E2440.50805@thesamovar.net> On 10/09/2012 18:33, Oscar Benjamin wrote: > Computing the hash always requires iterating over all characters in the string > so is best case O(N) where string comparison is best case (and often average > case) O(1). Yep, but you already have O(N) costs just creating the strings in the first place, so it's absorbed into that. It's only worth doing if you do many comparisons. > Also, so far as I know the hash value once computed is stored on the string > object itself [1] and used for subsequent string comparisons so there's no > need for you to do that in your code. Cool, Python is very clever as always! :) Dan From dg.gmane at thesamovar.net Mon Sep 10 13:32:48 2012 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Mon, 10 Sep 2012 19:32:48 +0200 Subject: Comparing strings from the back? In-Reply-To: References: <504E104D.8090404@thesamovar.net> Message-ID: <504E2440.50805@thesamovar.net> On 10/09/2012 18:33, Oscar Benjamin wrote: > Computing the hash always requires iterating over all characters in the string > so is best case O(N) where string comparison is best case (and often average > case) O(1). Yep, but you already have O(N) costs just creating the strings in the first place, so it's absorbed into that. It's only worth doing if you do many comparisons. > Also, so far as I know the hash value once computed is stored on the string > object itself [1] and used for subsequent string comparisons so there's no > need for you to do that in your code. Cool, Python is very clever as always! :) Dan From invalid at invalid.invalid Mon Sep 10 13:37:37 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 10 Sep 2012 17:37:37 +0000 (UTC) Subject: How to timeout a recv() on an ssl connection? References: Message-ID: On 2012-09-10, Grant Edwards wrote: > I can't figure out how to timeout a recv() on an SSLSocket -- I'm using > Python 2.6 nad 2.7. Here's what I've got so far (it needs to work on > either a plain or SSL socket): > > s.settimeout(timeout) > try: > b = ord(s.recv(1)) > except socket.timeout: > return None > except ssl.SSLError as e: > if e.message == 'The read operation timed out': > return None > else: > raise > finally: > s.settimeout(None) > > > It works fine on normal sockets. With an SSLSocket, it works the > first time it's called with timeout set to something other than None > (it times out properly). Subsequence reads with timeout set to None > work, but then the second time it's called with a non-None timeout, it > hangs for several minutes, and then the recv() returns an empty > string. Doh! Never mind. The above code does appear to be working correctly. I had a different bug that was misleading me... -- Grant Edwards grant.b.edwards Yow! What GOOD is a at CARDBOARD suitcase ANYWAY? gmail.com From dg.gmane at thesamovar.net Mon Sep 10 13:44:46 2012 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Mon, 10 Sep 2012 19:44:46 +0200 Subject: Comparing strings from the back? In-Reply-To: <504E104D.8090404@thesamovar.net> References: <504E104D.8090404@thesamovar.net> Message-ID: <504E270E.70104@thesamovar.net> On 10/09/2012 18:07, Dan Goodman wrote: > On 04/09/2012 03:54, Roy Smith wrote: >> Let's assume you're testing two strings for equality. You've already >> done the obvious quick tests (i.e they're the same length), and you're >> down to the O(n) part of comparing every character. >> >> I'm wondering if it might be faster to start at the ends of the strings >> instead of at the beginning? If the strings are indeed equal, it's the >> same amount of work starting from either end. But, if it turns out that >> for real-life situations, the ends of strings have more entropy than the >> beginnings, the odds are you'll discover that they're unequal quicker by >> starting at the end. > > From the rest of the thread, it looks like in most situations it won't > make much difference as typically very few characters need to be > compared if they are unequal. > > However, if you were in a situation with many strings which were almost > equal, the most general way to improve the situation might be store a > hash of the string along with the string, i.e. store (hash(x), x) and > then compare equality of this tuple. Almost all of the time, if the > strings are unequal the hash will be unequal. Or, as someone else > suggested, use interned versions of the strings. This is basically the > same solution but even better. In this case, your startup costs will be > higher (creating the strings) but your comparisons will always be instant. Just had another thought about this. Although it's unlikely to be necessary in practice since (a) it's rarely necessary at all, and (b) when it is, hashing and optionally interning seems like the better approach, I had another idea that would be more general. Rather than starting from the beginning or the end, why not do something like: check the first and last character, then the len/2 character, then the len/4, then 3*len/4, then len/8, 3*len/8, etc. You'd need to be a bit clever about making sure you hit every character but I'm sure someone's already got an efficient algorithm for this. You could probably even make this cache efficient by working on cache line length blocks. Almost certainly entirely unnecessary, but I like the original question and it's a nice theoretical problem. Dan From dg.gmane at thesamovar.net Mon Sep 10 13:44:46 2012 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Mon, 10 Sep 2012 19:44:46 +0200 Subject: Comparing strings from the back? In-Reply-To: <504E104D.8090404@thesamovar.net> References: <504E104D.8090404@thesamovar.net> Message-ID: <504E270E.70104@thesamovar.net> On 10/09/2012 18:07, Dan Goodman wrote: > On 04/09/2012 03:54, Roy Smith wrote: >> Let's assume you're testing two strings for equality. You've already >> done the obvious quick tests (i.e they're the same length), and you're >> down to the O(n) part of comparing every character. >> >> I'm wondering if it might be faster to start at the ends of the strings >> instead of at the beginning? If the strings are indeed equal, it's the >> same amount of work starting from either end. But, if it turns out that >> for real-life situations, the ends of strings have more entropy than the >> beginnings, the odds are you'll discover that they're unequal quicker by >> starting at the end. > > From the rest of the thread, it looks like in most situations it won't > make much difference as typically very few characters need to be > compared if they are unequal. > > However, if you were in a situation with many strings which were almost > equal, the most general way to improve the situation might be store a > hash of the string along with the string, i.e. store (hash(x), x) and > then compare equality of this tuple. Almost all of the time, if the > strings are unequal the hash will be unequal. Or, as someone else > suggested, use interned versions of the strings. This is basically the > same solution but even better. In this case, your startup costs will be > higher (creating the strings) but your comparisons will always be instant. Just had another thought about this. Although it's unlikely to be necessary in practice since (a) it's rarely necessary at all, and (b) when it is, hashing and optionally interning seems like the better approach, I had another idea that would be more general. Rather than starting from the beginning or the end, why not do something like: check the first and last character, then the len/2 character, then the len/4, then 3*len/4, then len/8, 3*len/8, etc. You'd need to be a bit clever about making sure you hit every character but I'm sure someone's already got an efficient algorithm for this. You could probably even make this cache efficient by working on cache line length blocks. Almost certainly entirely unnecessary, but I like the original question and it's a nice theoretical problem. Dan From vincent.vandevyvre at swing.be Mon Sep 10 13:59:14 2012 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Mon, 10 Sep 2012 19:59:14 +0200 Subject: pyQT performance? In-Reply-To: <1fdd6c92-2eb9-41b6-9cdb-84bfb3a4ed75@googlegroups.com> References: <1fdd6c92-2eb9-41b6-9cdb-84bfb3a4ed75@googlegroups.com> Message-ID: <504E2A72.8000802@swing.be> Le 10/09/12 19:24, jayden.shui at gmail.com a ?crit : > Anybody has the experience of the performance of the program developed by pyQT? Is it much slower than the one made by QT, such as (20%)? > For my experience, 20% is really surestimated. I'm developping only with PyQt and essentially in the imaging domain (viewing, transformation) and I've never seen a difference of processing speed with the same applications written in C++. Qt + Python, a very good association. -- Vincent V.V. Oqapy . Qarte . PaQager From info at wingware.com Mon Sep 10 14:22:00 2012 From: info at wingware.com (Wingware) Date: Mon, 10 Sep 2012 14:22:00 -0400 Subject: Wing IDE 4.1.8 released Message-ID: <504E2FC8.80504@wingware.com> Hi, Wingware has released version 4.1.8 of Wing IDE, our integrated development environment designed specifically for the Python programming language. Wing IDE provides a professional quality code editor with vi, emacs, and other key bindings, auto-completion, call tips, refactoring, context-aware auto-editing, a powerful graphical debugger, version control, unit testing, search, and many other features. For details see http://wingware.com/ This minor release includes: Added How-Tos for The Foundry's NUKE/NUKEX and IDA Python Track file operations in Project at the revision control level Accept glob style wildcards for Filter in Search in Files Support analysis of extension modules within zip archives Fix searching of documentation Several VI mode files Several auto-editing and auto-completion fixes Fix excessive memory use by the Perforce integration Copy existing window's tool layout when creating new windows Less confusing auto-save recovery About 35 other bug fixes and minor improvements For a complete change log see http://wingware.com/pub/wingide/4.1.8/CHANGELOG.txt Free trial: http://wingware.com/wingide/trial Downloads: http://wingware.com/downloads Feature matrix: http://wingware.com/wingide/features More information: http://wingware.com/ Sales: http://wingware.com/store/purchase Upgrades: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at sales at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE Advancing Software Development www.wingware.com From jayden.shui at gmail.com Mon Sep 10 14:29:02 2012 From: jayden.shui at gmail.com (jayden.shui at gmail.com) Date: Mon, 10 Sep 2012 11:29:02 -0700 (PDT) Subject: pyQT performance? In-Reply-To: References: <1fdd6c92-2eb9-41b6-9cdb-84bfb3a4ed75@googlegroups.com> Message-ID: On Monday, September 10, 2012 2:06:59 PM UTC-4, Vincent Vande Vyvre wrote: > Le 10/09/12 19:24, jayden.shui at gmail.com a ?crit : > > > Anybody has the experience of the performance of the program developed by pyQT? Is it much slower than the one made by QT, such as (20%)? > > > > > For my experience, 20% is really surestimated. > > > > I'm developping only with PyQt and essentially in the imaging domain > > (viewing, transformation) > > and I've never seen a difference of processing speed with the same > > applications written in C++. > > > > Qt + Python, a very good association. > > > > -- > > Vincent V.V. > > Oqapy . Qarte > > . PaQager Have you ever used py2exe? After converting the python codes to executable, does it save the time of interpreting the script language? Thank a lot! From jayden.shui at gmail.com Mon Sep 10 14:29:02 2012 From: jayden.shui at gmail.com (jayden.shui at gmail.com) Date: Mon, 10 Sep 2012 11:29:02 -0700 (PDT) Subject: pyQT performance? In-Reply-To: References: <1fdd6c92-2eb9-41b6-9cdb-84bfb3a4ed75@googlegroups.com> Message-ID: On Monday, September 10, 2012 2:06:59 PM UTC-4, Vincent Vande Vyvre wrote: > Le 10/09/12 19:24, jayden.shui at gmail.com a ?crit : > > > Anybody has the experience of the performance of the program developed by pyQT? Is it much slower than the one made by QT, such as (20%)? > > > > > For my experience, 20% is really surestimated. > > > > I'm developping only with PyQt and essentially in the imaging domain > > (viewing, transformation) > > and I've never seen a difference of processing speed with the same > > applications written in C++. > > > > Qt + Python, a very good association. > > > > -- > > Vincent V.V. > > Oqapy . Qarte > > . PaQager Have you ever used py2exe? After converting the python codes to executable, does it save the time of interpreting the script language? Thank a lot! From andrea.crotti.0 at gmail.com Mon Sep 10 15:34:04 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Mon, 10 Sep 2012 20:34:04 +0100 Subject: pyQT performance? In-Reply-To: References: <1fdd6c92-2eb9-41b6-9cdb-84bfb3a4ed75@googlegroups.com> Message-ID: <504E40AC.6030402@gmail.com> On 09/10/2012 07:29 PM, jayden.shui at gmail.com wrote > Have you ever used py2exe? After converting the python codes to executable, does it save the time of interpreting the script language? Thank a lot! Py2exe normally never speeds up anything, simply because it doesn't convert to executable, but simply package everything together, so I haven't tried in this particular case but it shouldn't make a difference.. From wanderer at dialup4less.com Mon Sep 10 15:39:11 2012 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 10 Sep 2012 12:39:11 -0700 (PDT) Subject: Numpy combine channels Message-ID: I have an array generated by audiolab of left and right stereo channels. It looks like [[1,1],[1,2],[2,3]]. I would like to combine the left and right channels to get an array [2,3,5]. Is there a numpy command to do that? Thanks From nick.cash at npcinternational.com Mon Sep 10 15:50:09 2012 From: nick.cash at npcinternational.com (Nick Cash) Date: Mon, 10 Sep 2012 19:50:09 +0000 Subject: Numpy combine channels In-Reply-To: References: Message-ID: <846C3A8E860C4344B567D813B63AA51D3933B501@BY2PRD0611MB429.namprd06.prod.outlook.com> > I have an array generated by audiolab of left and right stereo > channels. It looks like [[1,1],[1,2],[2,3]]. I would like to combine > the left and right channels to get an array [2,3,5]. Is there a numpy > command to do that? You may be over-thinking this, and numpy might not be necessary. A simple solution would be just a quick list comprehension: stereo_array = [[1, 1], [1, 2], [2, 3]] mono_array = [l+r for (l, r) in stereo_array] Thanks, Nick Cash From wanderer at dialup4less.com Mon Sep 10 15:56:17 2012 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 10 Sep 2012 12:56:17 -0700 (PDT) Subject: Numpy combine channels In-Reply-To: References: Message-ID: On Monday, September 10, 2012 3:39:11 PM UTC-4, Wanderer wrote: > I have an array generated by audiolab of left and right stereo channels. It looks like [[1,1],[1,2],[2,3]]. I would like to combine the left and right channels to get an array [2,3,5]. Is there a numpy command to do that? > > > > Thanks I figured it out. numpy.sum(array, axis=1). From python at mrabarnett.plus.com Mon Sep 10 16:11:46 2012 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 10 Sep 2012 21:11:46 +0100 Subject: Numpy combine channels In-Reply-To: References: Message-ID: <504E4982.1000204@mrabarnett.plus.com> On 10/09/2012 20:39, Wanderer wrote: > I have an array generated by audiolab of left and right stereo > channels. It looks like [[1,1],[1,2],[2,3]]. I would like to combine > the left and right channels to get an array [2,3,5]. Is there a numpy > command to do that? > >>> import numpy >>> numpy.array([[1,1],[1,2],[2,3]], dtype="i") array([[1, 1], [1, 2], [2, 3]]) >>> a[:, 0] array([1, 1, 2]) >>> a[:, 1] array([1, 2, 3]) >>> a[:, 0] + a[:, 1] array([2, 3, 5]) But should they be added together to make mono? Suppose, for example, that both channels have a maximum value. Their sum would be _twice_ the maximum. Therefore, I think that it should probably be the average. >>> (a[:, 0] + a[:, 1]) / 2 array([1, 1, 2]) From wanderer at dialup4less.com Mon Sep 10 16:14:18 2012 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 10 Sep 2012 13:14:18 -0700 (PDT) Subject: Numpy combine channels In-Reply-To: References: Message-ID: <0d091492-39e0-42b3-a383-9853af33136f@googlegroups.com> On Monday, September 10, 2012 4:12:40 PM UTC-4, MRAB wrote: > On 10/09/2012 20:39, Wanderer wrote: > > > I have an array generated by audiolab of left and right stereo > > > channels. It looks like [[1,1],[1,2],[2,3]]. I would like to combine > > > the left and right channels to get an array [2,3,5]. Is there a numpy > > > command to do that? > > > > > >>> import numpy > > >>> numpy.array([[1,1],[1,2],[2,3]], dtype="i") > > array([[1, 1], > > [1, 2], > > [2, 3]]) > > >>> a[:, 0] > > array([1, 1, 2]) > > >>> a[:, 1] > > array([1, 2, 3]) > > >>> a[:, 0] + a[:, 1] > > array([2, 3, 5]) > > > > But should they be added together to make mono? > > > > Suppose, for example, that both channels have a maximum value. Their > > sum would be _twice_ the maximum. > > > > Therefore, I think that it should probably be the average. > > > > >>> (a[:, 0] + a[:, 1]) / 2 > > array([1, 1, 2]) I'm decoding morse code. So it's CV dots and dashes. From wanderer at dialup4less.com Mon Sep 10 16:14:18 2012 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 10 Sep 2012 13:14:18 -0700 (PDT) Subject: Numpy combine channels In-Reply-To: References: Message-ID: <0d091492-39e0-42b3-a383-9853af33136f@googlegroups.com> On Monday, September 10, 2012 4:12:40 PM UTC-4, MRAB wrote: > On 10/09/2012 20:39, Wanderer wrote: > > > I have an array generated by audiolab of left and right stereo > > > channels. It looks like [[1,1],[1,2],[2,3]]. I would like to combine > > > the left and right channels to get an array [2,3,5]. Is there a numpy > > > command to do that? > > > > > >>> import numpy > > >>> numpy.array([[1,1],[1,2],[2,3]], dtype="i") > > array([[1, 1], > > [1, 2], > > [2, 3]]) > > >>> a[:, 0] > > array([1, 1, 2]) > > >>> a[:, 1] > > array([1, 2, 3]) > > >>> a[:, 0] + a[:, 1] > > array([2, 3, 5]) > > > > But should they be added together to make mono? > > > > Suppose, for example, that both channels have a maximum value. Their > > sum would be _twice_ the maximum. > > > > Therefore, I think that it should probably be the average. > > > > >>> (a[:, 0] + a[:, 1]) / 2 > > array([1, 1, 2]) I'm decoding morse code. So it's CV dots and dashes. From dihedral88888 at googlemail.com Mon Sep 10 16:14:38 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 10 Sep 2012 13:14:38 -0700 (PDT) Subject: set and dict iteration In-Reply-To: <7xvcgi8h70.fsf@ruckus.brouhaha.com> References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502D7E17.1070103@dejaviewphoto.com> <7xvcgi8h70.fsf@ruckus.brouhaha.com> Message-ID: <753e4641-0c61-42c0-a87d-7826be736aa6@googlegroups.com> Paul Rubin? 2012?8?17????UTC+8??9?01?39???? > Ian Kelly writes: > > > With regard to key insertion and deletion while iterating over a dict > > > or set, though, there is just no good reason to be doing that > > > (especially as the result is very implementation-specific), and I > > > wouldn't mind a more complete low-level check against it as long as > > > it's not too expensive (which is not clearly the case with the current > > > suggestion at all). > > > > One possible approach is to freeze the dictionary against modification > > while any iterator is open on it. You could keep a count of active > > iterators in the dict structure, adjusting it whenever an iterator is > > created or closed/destroyed. If there is only one iterator of a frozen dictionary, then nothing is saved. But if there are manny iterators based on the same frozen dictionary, this approach saves a lot. From wanderer at dialup4less.com Mon Sep 10 16:15:54 2012 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 10 Sep 2012 13:15:54 -0700 (PDT) Subject: Numpy combine channels In-Reply-To: <0d091492-39e0-42b3-a383-9853af33136f@googlegroups.com> References: <0d091492-39e0-42b3-a383-9853af33136f@googlegroups.com> Message-ID: <45a73671-552e-491e-a1ff-27d7a3fde52e@googlegroups.com> On Monday, September 10, 2012 4:14:18 PM UTC-4, Wanderer wrote: > On Monday, September 10, 2012 4:12:40 PM UTC-4, MRAB wrote: > > > On 10/09/2012 20:39, Wanderer wrote: > > > > > > > I have an array generated by audiolab of left and right stereo > > > > > > > channels. It looks like [[1,1],[1,2],[2,3]]. I would like to combine > > > > > > > the left and right channels to get an array [2,3,5]. Is there a numpy > > > > > > > command to do that? > > > > > > > > > > > > > >>> import numpy > > > > > > >>> numpy.array([[1,1],[1,2],[2,3]], dtype="i") > > > > > > array([[1, 1], > > > > > > [1, 2], > > > > > > [2, 3]]) > > > > > > >>> a[:, 0] > > > > > > array([1, 1, 2]) > > > > > > >>> a[:, 1] > > > > > > array([1, 2, 3]) > > > > > > >>> a[:, 0] + a[:, 1] > > > > > > array([2, 3, 5]) > > > > > > > > > > > > But should they be added together to make mono? > > > > > > > > > > > > Suppose, for example, that both channels have a maximum value. Their > > > > > > sum would be _twice_ the maximum. > > > > > > > > > > > > Therefore, I think that it should probably be the average. > > > > > > > > > > > > >>> (a[:, 0] + a[:, 1]) / 2 > > > > > > array([1, 1, 2]) > > > > I'm decoding morse code. So it's CV dots and dashes. In case anyone is interested, here is the full code. # morsecode.py import numpy as np from scikits.audiolab import wavread from scipy.signal import decimate from pylab import plot from pylab import show import os def movingaverage(interval, window_size): window = np.ones(int(window_size)) / float(window_size) return np.convolve(interval, window, 'same') def wav2morse(resultDir, filename): """ Convert a wave file to morse code resultDir: directory for wave file and results filename: wave file name """ data, _fs, _enc = wavread(resultDir + '\\' + filename) data = np.sum(data, axis=1) data = np.fabs(data) data = movingaverage(data, 100) data = decimate(data, 2) highcount = 0 lowcount = 0 fileBase, _fileExt = os.path.splitext(filename) f = open(resultDir + '\\' + fileBase + '.txt', 'w') for d in data: if d > 0.3: if lowcount > 3000: f.write(' ') lowcount = 0 highcount += 1 else: if highcount > 3000: f.write('-') elif highcount > 1000: f.write('.') highcount = 0 lowcount += 1 f.close() From wanderer at dialup4less.com Mon Sep 10 16:15:54 2012 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 10 Sep 2012 13:15:54 -0700 (PDT) Subject: Numpy combine channels In-Reply-To: <0d091492-39e0-42b3-a383-9853af33136f@googlegroups.com> References: <0d091492-39e0-42b3-a383-9853af33136f@googlegroups.com> Message-ID: <45a73671-552e-491e-a1ff-27d7a3fde52e@googlegroups.com> On Monday, September 10, 2012 4:14:18 PM UTC-4, Wanderer wrote: > On Monday, September 10, 2012 4:12:40 PM UTC-4, MRAB wrote: > > > On 10/09/2012 20:39, Wanderer wrote: > > > > > > > I have an array generated by audiolab of left and right stereo > > > > > > > channels. It looks like [[1,1],[1,2],[2,3]]. I would like to combine > > > > > > > the left and right channels to get an array [2,3,5]. Is there a numpy > > > > > > > command to do that? > > > > > > > > > > > > > >>> import numpy > > > > > > >>> numpy.array([[1,1],[1,2],[2,3]], dtype="i") > > > > > > array([[1, 1], > > > > > > [1, 2], > > > > > > [2, 3]]) > > > > > > >>> a[:, 0] > > > > > > array([1, 1, 2]) > > > > > > >>> a[:, 1] > > > > > > array([1, 2, 3]) > > > > > > >>> a[:, 0] + a[:, 1] > > > > > > array([2, 3, 5]) > > > > > > > > > > > > But should they be added together to make mono? > > > > > > > > > > > > Suppose, for example, that both channels have a maximum value. Their > > > > > > sum would be _twice_ the maximum. > > > > > > > > > > > > Therefore, I think that it should probably be the average. > > > > > > > > > > > > >>> (a[:, 0] + a[:, 1]) / 2 > > > > > > array([1, 1, 2]) > > > > I'm decoding morse code. So it's CV dots and dashes. In case anyone is interested, here is the full code. # morsecode.py import numpy as np from scikits.audiolab import wavread from scipy.signal import decimate from pylab import plot from pylab import show import os def movingaverage(interval, window_size): window = np.ones(int(window_size)) / float(window_size) return np.convolve(interval, window, 'same') def wav2morse(resultDir, filename): """ Convert a wave file to morse code resultDir: directory for wave file and results filename: wave file name """ data, _fs, _enc = wavread(resultDir + '\\' + filename) data = np.sum(data, axis=1) data = np.fabs(data) data = movingaverage(data, 100) data = decimate(data, 2) highcount = 0 lowcount = 0 fileBase, _fileExt = os.path.splitext(filename) f = open(resultDir + '\\' + fileBase + '.txt', 'w') for d in data: if d > 0.3: if lowcount > 3000: f.write(' ') lowcount = 0 highcount += 1 else: if highcount > 3000: f.write('-') elif highcount > 1000: f.write('.') highcount = 0 lowcount += 1 f.close() From steve+comp.lang.python at pearwood.info Mon Sep 10 16:16:13 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Sep 2012 20:16:13 GMT Subject: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py References: Message-ID: <504e4a8d$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 10 Sep 2012 10:25:29 -0700, ruck wrote: > In Python 2.7.2 on Windows 7, > > os.walk() uses isdir(), > which comes from os.path, > which really comes from ntpath.py, > which really comes from genericpath.py > > I want os.walk() to use a modified isdir() on my Windows 7. Not knowing > any better, it seems to me like ntpath.py would be a good place to > intercept. > > When os.py does "import ntpath as path", how can I get python to process > my customized ntpath.py instead of Lib/ntpath.py ? import os os.path.isdir = my_isdir ought to do it. This general technique is called "monkey-patching". The Ruby community is addicted to it. Everybody else -- and a goodly number of the more sensible Ruby crowd -- consider it a risky, dirty hack that 99 times out of 100 will lead to blindness, moral degeneracy and subtle, hard-to-fix bugs. They are right to be suspicious of it. As a general rule, monkey-patching is not for production code. You have been warned. http://www.codinghorror.com/blog/2008/07/monkeypatching-for-humans.html [...] > Why? Because the genericpath implementation relies on os.stat() which > uses Windows API function that presumes or enforces some naming > conventions like "doesn't end with a space or a period". But the NTFS > actually supports such filenames and dirnames, and some sw (like cygwin) > lets users make files & dirs without restricting. So, cygwin users like > me may have file 'voo...\\doo' which os.walk() cannot ordinarily walk. > That is, the isdir('voo...') returns false because the underlying > os.stat is assessing 'voo' instead of 'voo...' . Please consider submitting a patch that adds support for cygwin paths to the standard library. You'll need to target 3.4 though, 2.7 is now a maintenance release with no new features allowed. > The workaround is to > pass os.stat a fullpathname that is prefixed with r'\\?\' so the Windows > API recognizes that you do NOT want the name filtered. > > Better said by Microsoft: > "For file I/O, the "\\?\" prefix to a path string tells the Windows APIs > to disable all string parsing and to send the string that follows it > straight to the file system. That's not so much a workaround as the officially supported API for dealing with the situation you are in. Why don't you just prepend a '?' to paths like they tell you to? -- Steven From wrw at mac.com Mon Sep 10 16:53:07 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Mon, 10 Sep 2012 16:53:07 -0400 Subject: Newbie: where's the new python gone? In-Reply-To: References: <163755B1-D4FE-4660-B48B-91995D273231@mac.com> Message-ID: On Sep 10, 2012, at 11:17 AM, Bob Aalsma wrote: > Well, Bill, better late than never - thanks for stepping in. > You are right, my problems are not yet solved ;) As Hans pointed out, you are looking for python, not Python (the frameworks are named Python, the executable is python). Sorry about that. To eliminate the output from TimeMachine (assuming it is using an external drive or a TimeCapsule), add one more option to the find command: $ sudo find -x / -name python -print (or follow his directions for piping to a file). The -x option prevents find from descending into a volume with a different device number from the one you started on. -Bill From jayden.shui at gmail.com Mon Sep 10 17:10:55 2012 From: jayden.shui at gmail.com (Jayden) Date: Mon, 10 Sep 2012 14:10:55 -0700 (PDT) Subject: python CAD libraries? Message-ID: Are there any python CAD libraries that can (1) build simple 3D primitives solids such as spheres, cylinders and so on (2) perform bool operations on 3D solids (3) better if it has some transformations such has scaling, sweeping, and lofting Please recommend some good ones for me? Thanks a lot!! From gherron at digipen.edu Mon Sep 10 17:24:35 2012 From: gherron at digipen.edu (Gary Herron) Date: Mon, 10 Sep 2012 14:24:35 -0700 Subject: python CAD libraries? In-Reply-To: References: Message-ID: <504E5A93.7020403@digipen.edu> On 09/10/2012 02:10 PM, Jayden wrote: > Are there any python CAD libraries that can > > (1) build simple 3D primitives solids such as spheres, cylinders and so on > (2) perform bool operations on 3D solids > (3) better if it has some transformations such has scaling, sweeping, and lofting > > Please recommend some good ones for me? Thanks a lot!! Try PythonCAD: http://sourceforge.net/projects/pythoncad/ (Google would have been faster. :-) ) Gary Herron -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From rhodri at wildebst.demon.co.uk Mon Sep 10 17:46:19 2012 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 10 Sep 2012 22:46:19 +0100 Subject: Parsing ISO date/time strings - where did the parser go? References: Message-ID: On Sun, 09 Sep 2012 13:14:30 +0100, Roy Smith wrote: > In article , > Thomas Jollans wrote: > >> The ISO date/time format is dead simple and well-defined. > Well defined, perhaps. But nobody who has read the standard could call > it "dead simple". ISO-8601-2004(E) is 40 pages long. A short standard, then :-) -- Rhodri James *-* Wildebeest Herder to the Masses From jayden.shui at gmail.com Mon Sep 10 17:50:11 2012 From: jayden.shui at gmail.com (Jayden) Date: Mon, 10 Sep 2012 14:50:11 -0700 (PDT) Subject: python CAD libraries? In-Reply-To: References: Message-ID: On Monday, September 10, 2012 5:30:08 PM UTC-4, Gary Herron wrote: > On 09/10/2012 02:10 PM, Jayden wrote: > > > Are there any python CAD libraries that can > > > > > > (1) build simple 3D primitives solids such as spheres, cylinders and so on > > > (2) perform bool operations on 3D solids > > > (3) better if it has some transformations such has scaling, sweeping, and lofting > > > > > > Please recommend some good ones for me? Thanks a lot!! > > > > Try PythonCAD: http://sourceforge.net/projects/pythoncad/ > > > > (Google would have been faster. :-) ) > > > > Gary Herron > > > > -- > > Dr. Gary Herron > > Department of Computer Science > > DigiPen Institute of Technology > > (425) 895-4418 Thank you. But this is for 2D. From jayden.shui at gmail.com Mon Sep 10 17:50:11 2012 From: jayden.shui at gmail.com (Jayden) Date: Mon, 10 Sep 2012 14:50:11 -0700 (PDT) Subject: python CAD libraries? In-Reply-To: References: Message-ID: On Monday, September 10, 2012 5:30:08 PM UTC-4, Gary Herron wrote: > On 09/10/2012 02:10 PM, Jayden wrote: > > > Are there any python CAD libraries that can > > > > > > (1) build simple 3D primitives solids such as spheres, cylinders and so on > > > (2) perform bool operations on 3D solids > > > (3) better if it has some transformations such has scaling, sweeping, and lofting > > > > > > Please recommend some good ones for me? Thanks a lot!! > > > > Try PythonCAD: http://sourceforge.net/projects/pythoncad/ > > > > (Google would have been faster. :-) ) > > > > Gary Herron > > > > -- > > Dr. Gary Herron > > Department of Computer Science > > DigiPen Institute of Technology > > (425) 895-4418 Thank you. But this is for 2D. From oscar.j.benjamin at gmail.com Mon Sep 10 17:52:47 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 10 Sep 2012 21:52:47 +0000 (UTC) Subject: Comparing strings from the back? References: <504E104D.8090404@thesamovar.net> <504E270E.70104@thesamovar.net> Message-ID: On 2012-09-10, Dan Goodman wrote: > On 10/09/2012 18:07, Dan Goodman wrote: >> On 04/09/2012 03:54, Roy Smith wrote: >>> Let's assume you're testing two strings for equality. You've already >>> done the obvious quick tests (i.e they're the same length), and you're >>> down to the O(n) part of comparing every character. >>> >>> I'm wondering if it might be faster to start at the ends of the strings >>> instead of at the beginning? If the strings are indeed equal, it's the >>> same amount of work starting from either end. But, if it turns out that >>> for real-life situations, the ends of strings have more entropy than the >>> beginnings, the odds are you'll discover that they're unequal quicker by >>> starting at the end. >> >> From the rest of the thread, it looks like in most situations it won't >> make much difference as typically very few characters need to be >> compared if they are unequal. >> >> However, if you were in a situation with many strings which were almost >> equal, the most general way to improve the situation might be store a >> hash of the string along with the string, i.e. store (hash(x), x) and >> then compare equality of this tuple. Almost all of the time, if the >> strings are unequal the hash will be unequal. Or, as someone else >> suggested, use interned versions of the strings. This is basically the >> same solution but even better. In this case, your startup costs will be >> higher (creating the strings) but your comparisons will always be instant. > > Just had another thought about this. Although it's unlikely to be > necessary in practice since (a) it's rarely necessary at all, and (b) > when it is, hashing and optionally interning seems like the better > approach, I had another idea that would be more general. Rather than > starting from the beginning or the end, why not do something like: check > the first and last character, then the len/2 character, then the len/4, > then 3*len/4, then len/8, 3*len/8, etc. You'd need to be a bit clever > about making sure you hit every character but I'm sure someone's already > got an efficient algorithm for this. You could probably even make this > cache efficient by working on cache line length blocks. Almost certainly > entirely unnecessary, but I like the original question and it's a nice > theoretical problem. It's not totally theoretical in the sense that the reasoning applies to all sequence comparisons. If you needed to compare lists of objects where the comparison of each pair of elements was an expensive operation then you would want to think carefully about what order you used. Also in general you can't hash/intern all sequences. If I was going to change the order of comparisons for all strings then I would use a random order. This is essentially how dict gets away with claiming to have O(1) lookup. There are sequences of inputs that can cause every possible hash collision to occur but because the hash function acts as a kind of randomisation filter the pathological sequences are very unlikely to occur unless someone is going out of their way. The clever way that Python 3.3 prevents someone from even doing this on purpose is just to introduce additional per-process randomisation. The difference between dict lookup and string comparison is that string comparison always compares the characters in the same order and it corresponds to the natural ordering of the data. This means that some pefectly natural use cases like comparing file-paths can have close to worst case behaviour. If string/sequence comparison occurs in a random order then there can be no use case where the likely strings would induce close to worst case behaviour unless you really are just comparing lots of almost identical sequences. Oscar From john.ruckstuhl at gmail.com Mon Sep 10 18:22:05 2012 From: john.ruckstuhl at gmail.com (ruck) Date: Mon, 10 Sep 2012 15:22:05 -0700 (PDT) Subject: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py In-Reply-To: <504e4a8d$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <504e4a8d$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <83af64e3-bc26-4217-8afa-e4f6d45b604d@googlegroups.com> On Monday, September 10, 2012 1:16:13 PM UTC-7, Steven D'Aprano wrote: > On Mon, 10 Sep 2012 10:25:29 -0700, ruck wrote: > > > > > In Python 2.7.2 on Windows 7, > > > > > > os.walk() uses isdir(), > > > which comes from os.path, > > > which really comes from ntpath.py, > > > which really comes from genericpath.py > > > > > > I want os.walk() to use a modified isdir() on my Windows 7. Not knowing > > > any better, it seems to me like ntpath.py would be a good place to > > > intercept. > > > > > > When os.py does "import ntpath as path", how can I get python to process > > > my customized ntpath.py instead of Lib/ntpath.py ? > > > > import os > > os.path.isdir = my_isdir > > > > ought to do it. > > > > This general technique is called "monkey-patching". The Ruby community is > > addicted to it. Everybody else -- and a goodly number of the more > > sensible Ruby crowd -- consider it a risky, dirty hack that 99 times out > > of 100 will lead to blindness, moral degeneracy and subtle, hard-to-fix > > bugs. > > > > They are right to be suspicious of it. As a general rule, monkey-patching > > is not for production code. You have been warned. > > > > http://www.codinghorror.com/blog/2008/07/monkeypatching-for-humans.html > > > > > > [...] > > > Why? Because the genericpath implementation relies on os.stat() which > > > uses Windows API function that presumes or enforces some naming > > > conventions like "doesn't end with a space or a period". But the NTFS > > > actually supports such filenames and dirnames, and some sw (like cygwin) > > > lets users make files & dirs without restricting. So, cygwin users like > > > me may have file 'voo...\\doo' which os.walk() cannot ordinarily walk. > > > That is, the isdir('voo...') returns false because the underlying > > > os.stat is assessing 'voo' instead of 'voo...' . > > > > Please consider submitting a patch that adds support for cygwin paths to > > the standard library. You'll need to target 3.4 though, 2.7 is now a > > maintenance release with no new features allowed. > > > > > > > The workaround is to > > > pass os.stat a fullpathname that is prefixed with r'\\?\' so the Windows > > > API recognizes that you do NOT want the name filtered. > > > > > > Better said by Microsoft: > > > "For file I/O, the "\\?\" prefix to a path string tells the Windows APIs > > > to disable all string parsing and to send the string that follows it > > > straight to the file system. > > > > That's not so much a workaround as the officially supported API for > > dealing with the situation you are in. Why don't you just prepend a '?' > > to paths like they tell you to? > > > > > > -- > > Steven Steven says: That's not so much a workaround as the officially supported API for dealing with the situation you are in. Why don't you just prepend a '?' to paths like they tell you to? Good idea, but the first thing os.walk() does is a listdir(), and os.listdir() does not like the r'\\?\' prefix. In other words, os.walk(r'\\?\C:Users\john\Desktop\sandbox\goo') does not work. Also, your recipe worked for me -- I'm walking 'goo' which contains 'voo.../doo' import os import genericpath def my_isdir(s): return genericpath.isdir('\\\\?\\' + os.path.abspath(s + '\\')) print 'os.walk(\'goo\') with standard isdir()' for root, dirs, files in os.walk('goo'): print root, dirs, files print 'os.walk(\'goo\') with modified isdir()' os.path.isdir = my_isdir for root, dirs, files in os.walk('goo'): print root, dirs, files yields os.walk('goo') with standard isdir() goo [] ['voo...'] os.walk('goo') with modified isdir() goo ['voo...'] [] goo\voo... [] ['doo'] About monkeypatching, generally -- thanks for the pointer to that discussion. That sounded like a lot of wisdom and lessons learned being shared. About me suggesting a patch -- I'll sleep on that :) Thanks Steven! John From krecoun at gmail.com Mon Sep 10 18:25:13 2012 From: krecoun at gmail.com (=?UTF-8?B?Vm9qdMSbY2ggUG9sw6HFoWVr?=) Date: Tue, 11 Sep 2012 00:25:13 +0200 Subject: delay on windows when processing Pygame events Message-ID: <504E68C9.60009@gmail.com> Greetings, I am writing a simple game for visually impaired in pygame. I use this construction: while running == True: for event in pygame.event.get(): if event.type == blahblahblah, #processing various events blahblahblah, contiuing the code after events are analysed I am looking mainly for keyboard events. I notice a quite nonnegligible lag when running this under Windows XP, when compared to the same code on Ubuntu 12.04. Python and pygame version should be the same: Python 2.7.3 pygame 1.9.1 Can anyone please help me? Thank you, Vojta From rosuav at gmail.com Mon Sep 10 18:51:02 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Sep 2012 08:51:02 +1000 Subject: Parsing ISO date/time strings - where did the parser go? In-Reply-To: References: Message-ID: On Tue, Sep 11, 2012 at 7:46 AM, Rhodri James wrote: > On Sun, 09 Sep 2012 13:14:30 +0100, Roy Smith wrote: > >> In article , >> Thomas Jollans wrote: >> >>> The ISO date/time format is dead simple and well-defined. > > >> Well defined, perhaps. But nobody who has read the standard could call >> it "dead simple". ISO-8601-2004(E) is 40 pages long. > > > A short standard, then :-) What is it that takes up forty pages? RFC 2822 describes a date/time stamp in about two pages. In fact, the whole RFC describes the Internet Message Format in not much more than 40 pages. Is ISO-language just bloated? *boggle* ChrisA From joshua.landau.ws at gmail.com Mon Sep 10 20:12:12 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Tue, 11 Sep 2012 01:12:12 +0100 Subject: delay on windows when processing Pygame events In-Reply-To: <504E68C9.60009@gmail.com> References: <504E68C9.60009@gmail.com> Message-ID: On 10 September 2012 23:25, Vojt?ch Pol??ek wrote: > while running == True: > for event in pygame.event.get(): > if event.type == blahblahblah, #processing various events > blahblahblah, contiuing the code after events are analysed > > I am looking mainly for keyboard events. I notice a quite nonnegligible > lag when running this under Windows XP, when compared to the same code > on Ubuntu 12.04. > I do not have WinXP available, but if you want the best help from this board you should post the *exact* code that you are running. I don't think anyone has ever complained of code lasting a page or so (although any more and it becomes a bit of a chore :P). It does help. How are you sure that it is pygame.event.get() that is lagging? Have you tried """ while True: for e in pygame.event.get(): pass """* or even "while True: pygame.event.get()"*? If you have not, would it not be something else? How are you measuring the lag and what type is it (late signals? program freezes?)? *Obviously you need to add code that tells you whether it's on time, but I'm not sure how you're doing that currently. I'm not saying this to be harsh and if I could I would look further into the question, but I am trying to ask what I would probably need to know if I did have a Windows installation. Or it could be a known bug. Eh. -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Mon Sep 10 21:12:09 2012 From: roy at panix.com (Roy Smith) Date: Mon, 10 Sep 2012 21:12:09 -0400 Subject: Parsing ISO date/time strings - where did the parser go? References: Message-ID: In article , Chris Angelico wrote: > On Tue, Sep 11, 2012 at 7:46 AM, Rhodri James > wrote: > > On Sun, 09 Sep 2012 13:14:30 +0100, Roy Smith wrote: > > > >> In article , > >> Thomas Jollans wrote: > >> > >>> The ISO date/time format is dead simple and well-defined. > > > > > >> Well defined, perhaps. But nobody who has read the standard could call > >> it "dead simple". ISO-8601-2004(E) is 40 pages long. > > > > > > A short standard, then :-) > > What is it that takes up forty pages? RFC 2822 describes a date/time > stamp in about two pages. In fact, the whole RFC describes the > Internet Message Format in not much more than 40 pages. Is > ISO-language just bloated? > > *boggle* You can find a copy at http://dotat.at/tmp/ISO_8601-2004_E.pdf From jayden.shui at gmail.com Mon Sep 10 22:58:21 2012 From: jayden.shui at gmail.com (Jayden) Date: Mon, 10 Sep 2012 19:58:21 -0700 (PDT) Subject: a python license problem? Message-ID: <2f6ddde4-cff2-4005-bda5-b251e9822aff@googlegroups.com> Python is under GPL compatible. If I develop a python code, convert it to executable and distribute the executable as a commercial software. May I need to make my source code open? If python is under GPL, is the answer different? Thanks a lot!! From benjamin.kaplan at case.edu Mon Sep 10 23:16:08 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 10 Sep 2012 20:16:08 -0700 Subject: a python license problem? In-Reply-To: <2f6ddde4-cff2-4005-bda5-b251e9822aff@googlegroups.com> References: <2f6ddde4-cff2-4005-bda5-b251e9822aff@googlegroups.com> Message-ID: On Mon, Sep 10, 2012 at 7:58 PM, Jayden wrote: > Python is under GPL compatible. If I develop a python code, convert it to executable and distribute the executable as a commercial software. May I need to make my source code open? > > If python is under GPL, is the answer different? Thanks a lot!! > -- > http://mail.python.org/mailman/listinfo/python-list "GPL compatible" is not a license. It's a quality of the license. Python's license is compatible with the GPL, which means that you can use Python in software licensed under the GPL Python's license (which is available at http://docs.python.org/license.html ) does not require Python code to be open source, nor does it prohibit commercial use. And even if Python was under the GPL, you would still be able to release your own programs without opening the source. You just wouldn't be able to modify Python without releasing your changes. That's how the userland in Mac OS X is still closed-source despite being compiled with GCC. From steve+comp.lang.python at pearwood.info Mon Sep 10 23:46:04 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Sep 2012 03:46:04 GMT Subject: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py References: <504e4a8d$0$29981$c3e8da3$5496439d@news.astraweb.com> <83af64e3-bc26-4217-8afa-e4f6d45b604d@googlegroups.com> Message-ID: <504eb3fc$0$29890$c3e8da3$5496439d@news.astraweb.com> On Mon, 10 Sep 2012 15:22:05 -0700, ruck wrote: > On Monday, September 10, 2012 1:16:13 PM UTC-7, Steven D'Aprano wrote: [...] > > That's not so much a workaround as the officially supported API for > > dealing with the situation you are in. Why don't you just prepend a > > '?' to paths like they tell you to? > > Good idea, but the first thing os.walk() does is a listdir(), and > os.listdir() does not like the r'\\?\' prefix. In other words, > os.walk(r'\\?\C:Users\john\Desktop\sandbox\goo') does not work. Now that sounds like a bug to me. If Microsoft officially support leading ? in file names, then so should Python on Windows. > Also, your recipe worked for me -- > I'm walking 'goo' which contains 'voo.../doo' Good for you. (Sorry, that comes across as more condescending than it is intended as.) Monkey-patching often gets used for quick scripts and tiny pieces of code because it works. Just beware that if you extend that technique to larger bodies of code, say when using a large framework, or multiple libraries, your experience may not be quite so good. Especially if *they* are monkey-patching too, as some very large frameworks sometimes do. (Or so I am lead to believe.) The point is not that monkey-patching is dangerous and should never be used, but that it is risky and should be used with caution. -- Steven From dhananjay.c.joshi at gmail.com Tue Sep 11 00:16:35 2012 From: dhananjay.c.joshi at gmail.com (Dhananjay) Date: Tue, 11 Sep 2012 12:16:35 +0800 Subject: submit jobs on multi-core Message-ID: Dear all, I have a python script in which I have a list of files to input one by one and for each file I get a number as an output. I used for loop to submit the file to script. My script uses one file at a time and returns the output. My computers has 8 cores. Is there any way that I could submit 8 jobs at a time and get all the output faster ? In other words, how can I modify my script so that I could submit 8 jobs together on 8 different processors ? I am bit new to this stuff, please suggest me some directions. Thank you. -- Joshi -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Tue Sep 11 01:53:47 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 11 Sep 2012 07:53:47 +0200 Subject: submit jobs on multi-core In-Reply-To: References: Message-ID: <504ED1EB.1080008@shopzeus.com> On 2012-09-11 06:16, Dhananjay wrote: > Dear all, > > I have a python script in which I have a list of files to input one by > one and for each file I get a number as an output. > I used for loop to submit the file to script. > My script uses one file at a time and returns the output. > > My computers has 8 cores. > Is there any way that I could submit 8 jobs at a time and get all the > output faster ? > In other words, how can I modify my script so that I could submit 8 > jobs together on 8 different processors ? > > I am bit new to this stuff, please suggest me some directions. You should first look at the multiprocessing module. It is part of the standard library. http://docs.python.org/library/multiprocessing.html From dwightdhutto at gmail.com Tue Sep 11 02:03:47 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 11 Sep 2012 02:03:47 -0400 Subject: python CAD libraries? In-Reply-To: References: Message-ID: On Mon, Sep 10, 2012 at 5:50 PM, Jayden wrote: > On Monday, September 10, 2012 5:30:08 PM UTC-4, Gary Herron wrote: > > On 09/10/2012 02:10 PM, Jayden wrote: > > > > > Are there any python CAD libraries that can > > > > > > > > > > (1) build simple 3D primitives solids such as spheres, cylinders and > so on > > > > > (2) perform bool operations on 3D solids > > > > > (3) better if it has some transformations such has scaling, sweeping, > and lofting > > > I've used maya(I think that was the name), and matplotlib, but Blender.org(open source) is great for 3d rendering/game engine, etc, and has a nice python API, with great tutorials everywhere. If you checkout my homepage in my sig, you can see a roughdraft of somethings I was working on for it. I'd say go with an earlier version(more tuts/examples), but they put them out pretty quick, so 2.6 my be best to start with, and it uses python 3.x. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Tue Sep 11 02:12:47 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 11 Sep 2012 02:12:47 -0400 Subject: python CAD libraries? In-Reply-To: References: Message-ID: > > > Are there any python CAD libraries that can > > > > > > > > > > (1) build simple 3D primitives solids such as spheres, cylinders and > so on > > > > > (2) perform bool operations on 3D solids > > > > > (3) better if it has some transformations such has scaling, sweeping, > and lofting > > > > > > > > > > Please recommend some good ones for me? Thanks a lot!! > > > > > > > > Try PythonCAD: http://sourceforge.net/projects/pythoncad/ > > > > > > > > (Google would have been faster. :-) ) > > > > > > > > Gary Herron > > > > > > > > -- > > > > Dr. Gary Herron > > > > Department of Computer Science > > > > DigiPen Institute of Technology > > > > (425) 895-4418 > > Thank you. But this is for 2D. > 3-d is just manipulating what's shown in x/y points(and not as easy as it sounds) . I went with cartesian coordinate, a 360x360 canvas(with 90x90 degree view port), and a little trig for front/back/left/right/up/down, and amplitude or z distance for my first attempt, and now porting it into the Blender game engine. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Tue Sep 11 02:21:13 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 11 Sep 2012 02:21:13 -0400 Subject: python CAD libraries? In-Reply-To: References: Message-ID: I've used maya(I think that was the name), and matplotlib, but Blender.org(open source) is great for 3d rendering/game engine, etc, and has a nice python API, with great tutorials everywhere. If you checkout my homepage in my sig, you can see a roughdraft of somethings I was working on for it. I'd say go with an earlier version(more tuts/examples), but they put them out pretty quick, so 2.6 my be best to start with, and it uses python 3.x. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Tue Sep 11 02:22:52 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 11 Sep 2012 02:22:52 -0400 Subject: python CAD libraries? In-Reply-To: References: Message-ID: On Mon, Sep 10, 2012 at 5:10 PM, Jayden wrote: > Are there any python CAD libraries that can > > (1) build simple 3D primitives solids such as spheres, cylinders and so on > (2) perform bool operations on 3D solids > (3) better if it has some transformations such has scaling, sweeping, and > lofting > > Please recommend some good ones for me? Thanks a lot!! > -- > http://mail.python.org/mailman/listinfo/python-list > 've used maya(I think that was the name), and matplotlib, but Blender.org(open source) is great for 3d rendering/game engine, etc, and has a nice python API, with great tutorials everywhere. If you checkout my homepage in my sig, you can see a roughdraft of somethings I was working on for it. I'd say go with an earlier version(more tuts/examples), but they put them out pretty quick, so 2.6 my be best to start with, and it uses python 3.x. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Tue Sep 11 02:28:28 2012 From: dwightdhutto at gmail.com (david) Date: Mon, 10 Sep 2012 23:28:28 -0700 (PDT) Subject: python CAD libraries? In-Reply-To: References: Message-ID: > Thank you. But this is for 2D. Thank you. But this is for 2D. 3-d is just manipulating what's shown in x/y points(and not as easy as it sounds) . I went with cartesian coordinate, a 360x360 canvas(with 90x90 degree view port), and a little trig for front/back/left/right/up/down, and amplitude or z distance for my first attempt, with a few others that locked a center of an object,and held point rotation, and now porting it into the Blender game engine. I've used maya(I think that was the name), and matplotlib, but Blender.org(open source) is great for 3d rendering/game engine, etc, and has a nice python API, with great tutorials everywhere. If you checkout my homepage in my sig, you can see a roughdraft of somethings I was working on for it. I'd say go with an earlier version(more tuts/examples), but they put them out pretty quick, so 2.6 my be best to start with, and it uses python 3.x. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Tue Sep 11 02:28:28 2012 From: dwightdhutto at gmail.com (david) Date: Mon, 10 Sep 2012 23:28:28 -0700 (PDT) Subject: python CAD libraries? In-Reply-To: References: Message-ID: > Thank you. But this is for 2D. Thank you. But this is for 2D. 3-d is just manipulating what's shown in x/y points(and not as easy as it sounds) . I went with cartesian coordinate, a 360x360 canvas(with 90x90 degree view port), and a little trig for front/back/left/right/up/down, and amplitude or z distance for my first attempt, with a few others that locked a center of an object,and held point rotation, and now porting it into the Blender game engine. I've used maya(I think that was the name), and matplotlib, but Blender.org(open source) is great for 3d rendering/game engine, etc, and has a nice python API, with great tutorials everywhere. If you checkout my homepage in my sig, you can see a roughdraft of somethings I was working on for it. I'd say go with an earlier version(more tuts/examples), but they put them out pretty quick, so 2.6 my be best to start with, and it uses python 3.x. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Tue Sep 11 02:32:37 2012 From: dwightdhutto at gmail.com (david) Date: Mon, 10 Sep 2012 23:32:37 -0700 (PDT) Subject: python CAD libraries? In-Reply-To: References: Message-ID: <47697953-443c-462b-b279-bd55befbc4aa@googlegroups.com> Thank you. But this is for 2D. 3-d is just manipulating what's shown in x/y points(and not as easy as it sounds) . I went with cartesian coordinate, a 360x360 canvas(with 90x90 degree view port), and a little trig for front/back/left/right/up/down, and amplitude or z distance for my first attempt, and now porting it into the Blender game engine. I've used maya(I think that was the name), and matplotlib, but Blender.org(open source) is great for 3d rendering/game engine, etc, and has a nice python API, with great tutorials everywhere. If you checkout my homepage in my sig, you can see a roughdraft of somethings I was working on for it. I'd say go with an earlier version(more tuts/examples), but they put them out pretty quick, so 2.6 my be best to start with, and it uses python 3.x. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Tue Sep 11 02:32:37 2012 From: dwightdhutto at gmail.com (david) Date: Mon, 10 Sep 2012 23:32:37 -0700 (PDT) Subject: python CAD libraries? In-Reply-To: References: Message-ID: <47697953-443c-462b-b279-bd55befbc4aa@googlegroups.com> Thank you. But this is for 2D. 3-d is just manipulating what's shown in x/y points(and not as easy as it sounds) . I went with cartesian coordinate, a 360x360 canvas(with 90x90 degree view port), and a little trig for front/back/left/right/up/down, and amplitude or z distance for my first attempt, and now porting it into the Blender game engine. I've used maya(I think that was the name), and matplotlib, but Blender.org(open source) is great for 3d rendering/game engine, etc, and has a nice python API, with great tutorials everywhere. If you checkout my homepage in my sig, you can see a roughdraft of somethings I was working on for it. I'd say go with an earlier version(more tuts/examples), but they put them out pretty quick, so 2.6 my be best to start with, and it uses python 3.x. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Tue Sep 11 02:39:02 2012 From: dwightdhutto at gmail.com (David Hutto) Date: Mon, 10 Sep 2012 23:39:02 -0700 (PDT) Subject: python CAD libraries? In-Reply-To: References: Message-ID: <57acc936-afd4-4562-98f3-ac030bfb3d66@googlegroups.com> Might have posted that too many times, I don't use the google groups that much. > > Best Regards, > > David Hutto > > CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Tue Sep 11 02:39:02 2012 From: dwightdhutto at gmail.com (David Hutto) Date: Mon, 10 Sep 2012 23:39:02 -0700 (PDT) Subject: python CAD libraries? In-Reply-To: References: Message-ID: <57acc936-afd4-4562-98f3-ac030bfb3d66@googlegroups.com> Might have posted that too many times, I don't use the google groups that much. > > Best Regards, > > David Hutto > > CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Tue Sep 11 02:41:29 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 11 Sep 2012 02:41:29 -0400 Subject: python CAD libraries? In-Reply-To: <47697953-443c-462b-b279-bd55befbc4aa@googlegroups.com> References: <47697953-443c-462b-b279-bd55befbc4aa@googlegroups.com> Message-ID: Apologies for the double posting. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Tue Sep 11 02:45:50 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 11 Sep 2012 02:45:50 -0400 Subject: python CAD libraries? In-Reply-To: References: Message-ID: Apologies for the multiple posts, it's been a long night, and I don't use the google groups that much I kept getting sent mail failure, I think because I didn't hit 'reply all'. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From rolf.wester at ilt.fraunhofer.de Tue Sep 11 03:05:00 2012 From: rolf.wester at ilt.fraunhofer.de (Rolf Wester) Date: Tue, 11 Sep 2012 09:05:00 +0200 Subject: Compile python code into a dll In-Reply-To: <504dd9c6$1@news.fhg.de> References: <504dd9c6$1@news.fhg.de> Message-ID: <504ee29a$1@news.fhg.de> Thank you all for your help. I'm going to try Cython. Regards Rolf On 10/09/12 14:15, Rolf Wester wrote: > Hi, > > I have Python code that I would like to compile into a dll (I have to > deliver a C/C++ callable dll and I don't want to reimpelement the Python > code in C/C++). It's not for extending Python but I want to call the > Python functions and classes from C/C++. It's more like extending C/C++ > with Python. I would be very appreciative for any help. > > Thank you in advance > > Regards > Rolf From dwightdhutto at gmail.com Tue Sep 11 03:14:44 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 11 Sep 2012 03:14:44 -0400 Subject: python CAD libraries? In-Reply-To: References: Message-ID: https://www.google.com/search?q=python+cad+3d+examples&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a First listing looks good, might look later on at it myself: http://www.pythonocc.org/ -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Tue Sep 11 03:18:19 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 11 Sep 2012 03:18:19 -0400 Subject: Compile python code into a dll In-Reply-To: <504ee29a$1@news.fhg.de> References: <504dd9c6$1@news.fhg.de> <504ee29a$1@news.fhg.de> Message-ID: import ctypes http://docs.python.org/library/ctypes.html#loading-dynamic-link-libraries -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue Sep 11 03:20:42 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 11 Sep 2012 08:20:42 +0100 Subject: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py In-Reply-To: <504eb3fc$0$29890$c3e8da3$5496439d@news.astraweb.com> References: <504e4a8d$0$29981$c3e8da3$5496439d@news.astraweb.com> <83af64e3-bc26-4217-8afa-e4f6d45b604d@googlegroups.com> <504eb3fc$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: <504EE64A.2090909@timgolden.me.uk> On 11/09/2012 04:46, Steven D'Aprano wrote: > On Mon, 10 Sep 2012 15:22:05 -0700, ruck wrote: > >> On Monday, September 10, 2012 1:16:13 PM UTC-7, Steven D'Aprano wrote: > [...] >>> That's not so much a workaround as the officially supported API for >>> dealing with the situation you are in. Why don't you just prepend a >>> '?' to paths like they tell you to? >> >> Good idea, but the first thing os.walk() does is a listdir(), and >> os.listdir() does not like the r'\\?\' prefix. In other words, >> os.walk(r'\\?\C:Users\john\Desktop\sandbox\goo') does not work. > > Now that sounds like a bug to me. If Microsoft officially support > leading ? in file names, then so should Python on Windows. And so it does, but you'll notice from the MSDN docs that the \\? syntax must be supplied as a Unicode string, which os.listdir will do if you pass it a Python unicode object and not otherwise: import os os.listdir(u"\\\\?\\c:\\users") # and consequently for p, ds, fs in os.walk(u"\\\\?\\c:\\users"): print p TJG From dwightdhutto at gmail.com Tue Sep 11 03:24:12 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 11 Sep 2012 03:24:12 -0400 Subject: Compile python code into a dll In-Reply-To: References: <504dd9c6$1@news.fhg.de> <504ee29a$1@news.fhg.de> Message-ID: Also, and sometimes google does kind of fail you, but straight from your question, I just type in this section of what you wrote: 'Python code that I would like to compile into a dll' Yours comes up as well within that search,but so do quite a few others related to it. > > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Tue Sep 11 03:33:33 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 11 Sep 2012 03:33:33 -0400 Subject: python CAD libraries? In-Reply-To: References: Message-ID: And just a little more for you from: http://wiki.python.org/moin/Applications#A3D_CAD.2FCAM This looked interesting: http://free-cad.sourceforge.net/ > > but I have to get to a few other things, so I hope this helps. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Tue Sep 11 03:36:57 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Tue, 11 Sep 2012 17:36:57 +1000 Subject: python CAD libraries? In-Reply-To: References: Message-ID: Blender is definitely the most popular open-source CAD software; it has even forked its own version of Python to make things run neatly :P On Tue, Sep 11, 2012 at 5:33 PM, Dwight Hutto wrote: > And just a little more for you from: > > http://wiki.python.org/moin/Applications#A3D_CAD.2FCAM > > This looked interesting: > http://free-cad.sourceforge.net/ >> >> > but I have to get to a few other things, so I hope this helps. > > > > -- > Best Regards, > David Hutto > CEO: http://www.hitwebdevelopment.com > > > -- > http://mail.python.org/mailman/listinfo/python-list > From dwightdhutto at gmail.com Tue Sep 11 03:43:11 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 11 Sep 2012 03:43:11 -0400 Subject: python CAD libraries? In-Reply-To: References: Message-ID: On Tue, Sep 11, 2012 at 3:36 AM, Alec Taylor wrote: > Blender is definitely the most popular open-source CAD software; it > has even forked its own version of Python to make things run neatly :P > I heard that they were going to change a few things a while back with the Python API(especially the switch to 3.0 in blender 2.5), but thought they were still using regular 3.x. I've been using the 2.49b, and just started using 2.6.2 when I upgraded my Ubuntu to 12.04. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Tue Sep 11 03:46:56 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 11 Sep 2012 03:46:56 -0400 Subject: python CAD libraries? In-Reply-To: References: Message-ID: > Blender is definitely the most popular open-source CAD software; it >> has even forked its own version of Python to make things run neatly :P >> > > Plus it never hurts to look around at some of the other interfaces,some of which might have just altered Blender, or something else, just to see which is more user friendly for the individual. But I am a huge Blender fan, so I'll probably not be changing that anytime soon. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From overhaalsgang_24_bob at me.com Tue Sep 11 03:52:46 2012 From: overhaalsgang_24_bob at me.com (Bob Aalsma) Date: Tue, 11 Sep 2012 09:52:46 +0200 Subject: Newbie: where's the new python gone? In-Reply-To: References: <163755B1-D4FE-4660-B48B-91995D273231@mac.com> Message-ID: <26C63E01-6D76-4922-85C3-5026BA8E6617@me.com> A non-text attachment was scrubbed... Name: c.c Type: application/octet-stream Size: 2335 bytes Desc: not available URL: -------------- next part -------------- Op 10 Sep 2012, om 22:53 heeft William R. Wing (Bill Wing) het volgende geschreven: > On Sep 10, 2012, at 11:17 AM, Bob Aalsma wrote: > >> Well, Bill, better late than never - thanks for stepping in. >> You are right, my problems are not yet solved ;) > > As Hans pointed out, you are looking for python, not Python (the frameworks are named Python, the executable is python). Sorry about that. > > To eliminate the output from TimeMachine (assuming it is using an external drive or a TimeCapsule), add one more option to the find command: > > $ sudo find -x / -name python -print (or follow his directions for piping to a file). > > The -x option prevents find from descending into a volume with a different device number from the one you started on. > > -Bill > From zig-zag at yahoo.com Tue Sep 11 05:17:31 2012 From: zig-zag at yahoo.com (zig-zag) Date: Tue, 11 Sep 2012 11:17:31 +0200 Subject: submit jobs on multi-core In-Reply-To: References: Message-ID: On 09/11/2012 07:53 AM, Laszlo Nagy wrote: > On 2012-09-11 06:16, Dhananjay wrote: >> Dear all, >> >> I have a python script in which I have a list of files to input one by >> one and for each file I get a number as an output. >> I used for loop to submit the file to script. >> My script uses one file at a time and returns the output. >> >> My computers has 8 cores. >> Is there any way that I could submit 8 jobs at a time and get all the >> output faster ? >> In other words, how can I modify my script so that I could submit 8 >> jobs together on 8 different processors ? >> >> I am bit new to this stuff, please suggest me some directions. > You should first look at the multiprocessing module. It is part of the > standard library. > > http://docs.python.org/library/multiprocessing.html > > Did anybody tried this on a cluster? From alec.taylor6 at gmail.com Tue Sep 11 05:23:00 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Tue, 11 Sep 2012 19:23:00 +1000 Subject: submit jobs on multi-core In-Reply-To: References: Message-ID: http://celeryproject.org/ Don't eat it all at once On Tue, Sep 11, 2012 at 2:16 PM, Dhananjay wrote: > Dear all, > > I have a python script in which I have a list of files to input one by one > and for each file I get a number as an output. > I used for loop to submit the file to script. > My script uses one file at a time and returns the output. > > My computers has 8 cores. > Is there any way that I could submit 8 jobs at a time and get all the output > faster ? > In other words, how can I modify my script so that I could submit 8 jobs > together on 8 different processors ? > > I am bit new to this stuff, please suggest me some directions. > > Thank you. > > -- Joshi > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From duncan.booth at invalid.invalid Tue Sep 11 05:41:50 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 11 Sep 2012 09:41:50 GMT Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504deedc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > But for the record, in principle string comparisons *could* be the > bottleneck. Example: you have 10000 strings, which are each created > once and stored in a list. Then you iterate over the list, comparing > every string against every other string. And due to some weird vagary > of the data, the strings are nearly all equal. > > (Why would you do this? I don't know, maybe it's a programmers' > challenge found on the Internet, make up your own scenario...) > > Total number of strings created: 10000. > Total number of strings compared: 100000000. which is exactly what I meant by doing a lot of comparisons (10000) on the same string. Perhaps if I'd phrased it more as "you have to be doing many more comparisons than string creation operations" it would have been clearer what I meant. > The overhead of creating the strings is trivial compared to the > overhead of comparing them, and since each string is only created once > anyway, interning them is just a waste of time. No, you created 10k strings many of which are equal and then did 10k comparisons on each most of which found 'yes' they are equal. Interning them would have reduced all the 'true' comparisons to an identity check at the cost of 1 hash and 1 full comparison per string. >> so at the expense of a single dictionary >> insertion when the string is created you can get guaranteed O(1) on >> all the comparisons. > > What interning buys you is that "s == t" is an O(1) pointer compare if > they are equal. But if s and t differ in the last character, __eq__ > will still inspect every character. There is no way to tell Python > "all strings are interned, if s is not t then s != t as well". Right if the strings differ only in the last character, but the rest of this thread has been about how, for random strings, the not-equal case is O(1) as well. -- Duncan Booth http://kupuguy.blogspot.com From duncan.booth at invalid.invalid Tue Sep 11 05:51:54 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 11 Sep 2012 09:51:54 GMT Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504deedc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Oscar Benjamin wrote: >> What interning buys you is that "s == t" is an O(1) pointer compare >> if they are equal. But if s and t differ in the last character, >> __eq__ will still inspect every character. There is no way to tell >> Python "all strings are interned, if s is not t then s != t as well". >> > > I thought that if *both* strings were interned then a pointer > comparison could decide if they were unequal without needing to check > the characters. > > Have I misunderstood how intern() works? > I don't think you've misunderstood how it work, but so far as I can see the code doesn't attempt to short circuit the "not equal but interned" case. The comparison code doesn't look at interning at all, it only looks for identity as a shortcut. -- Duncan Booth http://kupuguy.blogspot.com From oscar.j.benjamin at gmail.com Tue Sep 11 06:40:42 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 11 Sep 2012 11:40:42 +0100 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504deedc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 September 2012 10:51, Duncan Booth wrote: > Oscar Benjamin wrote: > > >> What interning buys you is that "s == t" is an O(1) pointer compare > >> if they are equal. But if s and t differ in the last character, > >> __eq__ will still inspect every character. There is no way to tell > >> Python "all strings are interned, if s is not t then s != t as well". > >> > > > > I thought that if *both* strings were interned then a pointer > > comparison could decide if they were unequal without needing to check > > the characters. > > > > Have I misunderstood how intern() works? > > > > I don't think you've misunderstood how it work, but so far as I can see the > code doesn't attempt to short circuit the "not equal but interned" case. > The comparison code doesn't look at interning at all, it only looks for > identity as a shortcut. It also doesn't seem to check if the hash values have been set. I guess the cached hash value is only used in contexts where the hash is explicitly desired. That makes two optimisations that can bring worst case string comparison down to O(1) in many contexts that are available to cpython but unused. But then if full string comparison is already on average O(1) then the cost of checking the interned and hash flags for every string comparison would outweigh the benefits of avoiding the rare worst case O(N) comparisons. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From PointedEars at web.de Tue Sep 11 07:28:00 2012 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Tue, 11 Sep 2012 13:28 +0200 Subject: simple client data base References: <1454469.9HWcpyvaek@PointedEars.de> Message-ID: <1697290.HfSm95OzvH@PointedEars.de> Mark R Rivet wrote: > Thomas 'PointedEars' Lahn wrote: >> Mark R Rivet wrote: >>> Hello all, I am learning to program in python. I have a need to make a >>> program that can store, retrieve, add, and delete client data such as >>> name, address, social, telephone number and similar information. This >>> would be a small client database for my wife who has a home accounting >>> business. >>> >>> I have been reading about lists, tuples, and dictionary data >>> structures in python and I am confused as to which would be more >>> appropriate for a simple database. >> >> [?] >> However, if you want your program to manipulate the data *persistently*. >> as it will probably be needed for business, you will need to also store >> it somewhere else than in the volatile memory in which these data >> structures are usually stored. The most simple way would be to store and >> parse the string representation of the objects. >> >> Production-quality implementations of those and other concepts already >> exist, of course, but using something finished and polished does not >> provide as much learning experience. > > Now this is the kind of answer I was hoping for. This gives me food > for thought. Now I have some Ideas of how to appproach this thing. I > know that there are solutions to this problem already but I need to do > my own before I can really use anything better. Thanks for the help. I > fully intend to go with a real realational database, but not now. My > version 1 will be a console interface and dictionaries, lists and > pickling. Version 2 will be with a GUI written in tkinter, and better > and better. I just want to learn how to lay the bricks before I start > using prefab walls. You are welcome. However, I have to concur with the others that in terms of efficiency and reliability, which leads to household peace, you are better off starting with a prepackaged solution instead. You can keep developing your Python-powered database as a pet project for the time being. Your wife will be even more impressed if at one day you can tell her that you wrote completely customizable software that works the same or even better than the one she has been getting used to :) Even if not, you will have learned much about Python and related concepts along the way. Keep in mind, then, that you probably also need a graphical user interface. Please trim your quotes to the relevant minimum next time. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail. From wrw at mac.com Tue Sep 11 08:26:21 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Tue, 11 Sep 2012 08:26:21 -0400 Subject: Newbie: where's the new python gone? In-Reply-To: <26C63E01-6D76-4922-85C3-5026BA8E6617@me.com> References: <163755B1-D4FE-4660-B48B-91995D273231@mac.com> <26C63E01-6D76-4922-85C3-5026BA8E6617@me.com> Message-ID: On Sep 11, 2012, at 3:52 AM, Bob Aalsma wrote: > > Op 10 Sep 2012, om 22:53 heeft William R. Wing (Bill Wing) het volgende geschreven: > >> On Sep 10, 2012, at 11:17 AM, Bob Aalsma wrote: >> >>> Well, Bill, better late than never - thanks for stepping in. >>> You are right, my problems are not yet solved ;) >> >> As Hans pointed out, you are looking for python, not Python (the frameworks are named Python, the executable is python). Sorry about that. >> >> To eliminate the output from TimeMachine (assuming it is using an external drive or a TimeCapsule), add one more option to the find command: >> >> $ sudo find -x / -name python -print (or follow his directions for piping to a file). >> >> The -x option prevents find from descending into a volume with a different device number from the one you started on. >> >> -Bill >> > > -- > http://mail.python.org/mailman/listinfo/python-list Well, clearly, the only copies of python 2.7 on your system are from Apple (in System/Library and associated with Xcode). So, either the one you downloaded overwrote one of them, or the install failed and you didn't notice the error go zooming by in a listing. Can you run the install procedure again and capture the output? -Bill From overhaalsgang_24_bob at me.com Tue Sep 11 09:12:44 2012 From: overhaalsgang_24_bob at me.com (Bob Aalsma) Date: Tue, 11 Sep 2012 15:12:44 +0200 Subject: Newbie: where's the new python gone? In-Reply-To: References: <163755B1-D4FE-4660-B48B-91995D273231@mac.com> <26C63E01-6D76-4922-85C3-5026BA8E6617@me.com> Message-ID: <054A4F59-96D8-4494-A998-938F110438C3@me.com> Hmm, this feels embarrassing but the good news is that, on seeing the errors, I remember using a "sudo" with the make install and only later finding out that I shouldn't have. Last login: Tue Sep 11 09:46:11 on ttys000 macpro1:~ debaas$ pwd /Users/debaas macpro1:~ debaas$ ls Desktop Documents Downloads Library Movies Music Pictures Public Sites macpro1:~ debaas$ cd Desktop/ macpro1:Desktop debaas$ cd Python-2.7.3/ macpro1:Python-2.7.3 debaas$ ls /usr/local apache2 bin clamXav include lib libexec share macpro1:Python-2.7.3 debaas$ make install /usr/bin/install -c python.exe /usr/local/bin/python2.7 install: /usr/local/bin/python2.7: Permission denied make: *** [altbininstall] Error 71 So how to proceed here? -Bob Op 11 Sep 2012, om 14:26 heeft William R. Wing (Bill Wing) het volgende geschreven: > On Sep 11, 2012, at 3:52 AM, Bob Aalsma wrote: > >> >> Op 10 Sep 2012, om 22:53 heeft William R. Wing (Bill Wing) het volgende geschreven: >> >>> On Sep 10, 2012, at 11:17 AM, Bob Aalsma wrote: >>> >>>> Well, Bill, better late than never - thanks for stepping in. >>>> You are right, my problems are not yet solved ;) >>> >>> As Hans pointed out, you are looking for python, not Python (the frameworks are named Python, the executable is python). Sorry about that. >>> >>> To eliminate the output from TimeMachine (assuming it is using an external drive or a TimeCapsule), add one more option to the find command: >>> >>> $ sudo find -x / -name python -print (or follow his directions for piping to a file). >>> >>> The -x option prevents find from descending into a volume with a different device number from the one you started on. >>> >>> -Bill >>> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > > Well, clearly, the only copies of python 2.7 on your system are from Apple (in System/Library and associated with Xcode). > So, either the one you downloaded overwrote one of them, or the install failed and you didn't notice the error go zooming by in a listing. > > Can you run the install procedure again and capture the output? > > -Bill -------------- next part -------------- An HTML attachment was scrubbed... URL: From jiangwen365 at gmail.com Tue Sep 11 09:19:14 2012 From: jiangwen365 at gmail.com (=?GB2312?B?va3OxA==?=) Date: Tue, 11 Sep 2012 21:19:14 +0800 Subject: PyPyODBC 0.8.4 released with improved compatibility to pyodbc Message-ID: PyPyODBC - A Pure Python ctypes ODBC module Features - Pure Python, compatible with IronPython and PyPy (tested on Win32) - Almost totally same usage as pyodbc You can simply try pypyodbc in your existing pyodbc powered script with the following changes: #import pyodbc <-- The original pyodbc importing line import pypyodbc as pyodbc # Let pypyodbc "pretend" the pyodbc pyodbc.connect(...) # pypyodbc is now doing pyodbc's job with same APIs! History Version 0.8.4 Sep 9 2012 Improved compatibility with pyodbc; Many underlying bug fixes; Version 0.8.3 Sep 1 2012 sql_longvarchar handling fix; performance optimization; Version 0.8.2 Aug 27 2012 Differentiate sql_varchar and sql_longvarchar; Initial support for SQLAlchemy; Version 0.8.1 Aug 26 2012 Fixed the long type parameter issue; Added support for IronPython; Version 0.8 Aug 25 2012 Added getinfo method; Version 0.7 Jul 28 2012 Fixed nchar/ntext/nvarchar string truncat problem ; Version 0.6 Jul 4 2012 Added Cursor.commit() and Cursor.rollback(); Added readonly keyword to connect; Version 0.5 Jun 23 2012 Initial release; From wrw at mac.com Tue Sep 11 09:31:37 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Tue, 11 Sep 2012 09:31:37 -0400 Subject: Newbie: where's the new python gone? In-Reply-To: <054A4F59-96D8-4494-A998-938F110438C3@me.com> References: <163755B1-D4FE-4660-B48B-91995D273231@mac.com> <26C63E01-6D76-4922-85C3-5026BA8E6617@me.com> <054A4F59-96D8-4494-A998-938F110438C3@me.com> Message-ID: <06BAD859-7E6D-409C-8B9E-E646AB37273E@mac.com> On Sep 11, 2012, at 9:12 AM, Bob Aalsma wrote: > Hmm, this feels embarrassing but the good news is that, on seeing the errors, I remember using a "sudo" with the make install and only later finding out that I shouldn't have. > > Last login: Tue Sep 11 09:46:11 on ttys000 > macpro1:~ debaas$ pwd > /Users/debaas > macpro1:~ debaas$ ls > Desktop Documents Downloads Library Movies Music Pictures Public Sites > macpro1:~ debaas$ cd Desktop/ > macpro1:Desktop debaas$ cd Python-2.7.3/ > macpro1:Python-2.7.3 debaas$ ls /usr/local > apache2 bin clamXav include lib libexec share > macpro1:Python-2.7.3 debaas$ make install > /usr/bin/install -c python.exe /usr/local/bin/python2.7 > install: /usr/local/bin/python2.7: Permission denied > make: *** [altbininstall] Error 71 > > So how to proceed here? > > -Bob As others have commented, please don't top-post. The script from which you've captured a fragment of output above isn't going to work on a Mac without rewriting. (Your Mac isn't going to like python.exe for example.) As to proceeding, in all honesty, the simplest thing to do is go here: http://www.python.org/download/ Look down the page to the link for Python 2.7.3 Mac OS X 64-bit/32-bit x86-64/i386 Installer (for Mac OS X 10.6 and 10.7 [2]) and grab it. That will hand you a completely prebuilt 2.7.3 (latest) along with an installer that will put it in /Library/Frameworks where it belongs and will even edit your .profile. Good luck, Bill -------------- next part -------------- An HTML attachment was scrubbed... URL: From nawijn at gmail.com Tue Sep 11 09:42:55 2012 From: nawijn at gmail.com (Marco Nawijn) Date: Tue, 11 Sep 2012 06:42:55 -0700 (PDT) Subject: python CAD libraries? In-Reply-To: References: Message-ID: <20dc1957-5ac0-4f33-9b84-9254423b72d5@googlegroups.com> On Monday, September 10, 2012 11:10:55 PM UTC+2, Jayden wrote: > Are there any python CAD libraries that can > > > > (1) build simple 3D primitives solids such as spheres, cylinders and so on > > (2) perform bool operations on 3D solids > > (3) better if it has some transformations such has scaling, sweeping, and lofting > > > > Please recommend some good ones for me? Thanks a lot!! Hi Jayden, In my opinion, the best you can get is OpenCascade (OCC) (www.opencascade.org) in combination with the python bindings (www.pythonocc.org). OCC is a hugh C++ CAD library. It not only deals with the simple geometric stuff, but it can be used to build CAD programs similar to SolidEdge or SolidWorks. It does however come with quite a steep learning curve. When using PythonOCC, the learning curve becomes a little less steep. Also note that in my opinion, Blender cannot be considered as a CAD environment. Ofcourse it is very powerful, but I think it is more targeted towards animation and visually pleasing applications, not mechanical engineering. Regards, Marco From yoursurrogategod at gmail.com Tue Sep 11 10:11:55 2012 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Tue, 11 Sep 2012 10:11:55 -0400 Subject: Unable to compile Python 2.7.3 in Cygwin Message-ID: Hi, I'm trying to compile Python in Cygwin, with little luck. I've posted the ugliness in this link. Thoughts? http://bin.cakephp.org/view/176472400 -------------- next part -------------- An HTML attachment was scrubbed... URL: From overhaalsgang_24_bob at me.com Tue Sep 11 10:47:17 2012 From: overhaalsgang_24_bob at me.com (Bob Aalsma) Date: Tue, 11 Sep 2012 16:47:17 +0200 Subject: Newbie: where's the new python gone? In-Reply-To: <06BAD859-7E6D-409C-8B9E-E646AB37273E@mac.com> References: <163755B1-D4FE-4660-B48B-91995D273231@mac.com> <26C63E01-6D76-4922-85C3-5026BA8E6617@me.com> <054A4F59-96D8-4494-A998-938F110438C3@me.com> <06BAD859-7E6D-409C-8B9E-E646AB37273E@mac.com> Message-ID: <1F0190E2-BCB7-498D-BA41-D4CF6346F916@me.com> On 11 Sep 2012, at 15:31, William R. Wing (Bill Wing) wrote: > On Sep 11, 2012, at 9:12 AM, Bob Aalsma wrote: > >> Hmm, this feels embarrassing but the good news is that, on seeing the errors, I remember using a "sudo" with the make install and only later finding out that I shouldn't have. >> >> Last login: Tue Sep 11 09:46:11 on ttys000 >> macpro1:~ debaas$ pwd >> /Users/debaas >> macpro1:~ debaas$ ls >> Desktop Documents Downloads Library Movies Music Pictures Public Sites >> macpro1:~ debaas$ cd Desktop/ >> macpro1:Desktop debaas$ cd Python-2.7.3/ >> macpro1:Python-2.7.3 debaas$ ls /usr/local >> apache2 bin clamXav include lib libexec share >> macpro1:Python-2.7.3 debaas$ make install >> /usr/bin/install -c python.exe /usr/local/bin/python2.7 >> install: /usr/local/bin/python2.7: Permission denied >> make: *** [altbininstall] Error 71 >> >> So how to proceed here? >> >> -Bob > > As others have commented, please don't top-post. > > The script from which you've captured a fragment of output above isn't going to work on a Mac without rewriting. (Your Mac isn't going to like python.exe for example.) > > As to proceeding, in all honesty, the simplest thing to do is go here: > > http://www.python.org/download/ > > Look down the page to the link for Python 2.7.3 Mac OS X 64-bit/32-bit x86-64/i386 Installer (for Mac OS X 10.6 and 10.7 [2]) and grab it. That will hand you a completely prebuilt 2.7.3 (latest) along with an installer that will put it in /Library/Frameworks where it belongs and will even edit your .profile. > > Good luck, > Bill Sorry about top-posting. And it worked! Thank you for teaching! Regards, Bob -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Sep 11 11:55:55 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 11 Sep 2012 11:55:55 -0400 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504deedc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/11/2012 6:40 AM, Oscar Benjamin wrote: > On 11 September 2012 10:51, Duncan Booth > wrote: > > Oscar Benjamin > wrote: > > >> What interning buys you is that "s == t" is an O(1) pointer compare > >> if they are equal. But if s and t differ in the last character, > >> __eq__ will still inspect every character. There is no way to tell > >> Python "all strings are interned, if s is not t then s != t as > well". > >> > > > > I thought that if *both* strings were interned then a pointer > > comparison could decide if they were unequal without needing to check > > the characters. > > > > Have I misunderstood how intern() works? > > > > I don't think you've misunderstood how it work, but so far as I can > see the > code doesn't attempt to short circuit the "not equal but interned" case. > The comparison code doesn't look at interning at all, it only looks for > identity as a shortcut. > > > It also doesn't seem to check if the hash values have been set. I guess > the cached hash value is only used in contexts where the hash is > explicitly desired.- I believe the internal use of interning and hash comparison has varied from release to release. However, the main use of string comparison is for dict keys, especially the internal dicts for namespaces and attributes. Since the dict lookup code needs hash values anyway, to find slots with possible conflicts, I am sure it does not use the generic comparison operators but starts with hash comparisons. Terry Jan Reedy From ben+python at benfinney.id.au Tue Sep 11 12:00:06 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 12 Sep 2012 02:00:06 +1000 Subject: Parsing ISO date/time strings - where did the parser go? References: Message-ID: <87zk4wpn21.fsf@benfinney.id.au> Roy Smith writes: > In article , > Chris Angelico wrote: > > What is it that takes up forty pages [for the ISO 8601 > > specification]? RFC 2822 describes a date/time stamp in about two > > pages. In fact, the whole RFC describes the Internet Message Format > > in not much more than 40 pages. Is ISO-language just bloated? > > > > *boggle* > > You can find a copy at http://dotat.at/tmp/ISO_8601-2004_E.pdf In brief: ISO 8601 doesn't have the luxury of a single timestamp format. It also must define its terms from a rather more fundamental starting point than RFC 5822 can assume. There's some bloat (5 of the 40 pages don't even show up in the table of contents), but much of the content of the ISO 8601 standard is required, to cover the ground intended in the level of detail intended. Scope This International Standard is applicable whenever representation of dates in the Gregorian calendar, times in the 24-hour timekeeping system, time intervals and recurring time intervals or of the formats of these representations are included in information interchange. It includes * calendar dates expressed in terms of calendar year, calendar month and calendar day of the month; * ordinal dates expressed in terms of calendar year and calendar day of the year; * week dates expressed in terms of calendar year, calendar week number and calendar day of the week; * local time based upon the 24-hour timekeeping system; * Coordinated Universal Time of day; * local time and the difference from Coordinated Universal Time; * combination of date and time of day; * time intervals; * recurring time intervals. -- \ ?First things first, but not necessarily in that order.? ?The | `\ Doctor, _Doctor Who_ | _o__) | Ben Finney From ben+python at benfinney.id.au Tue Sep 11 12:03:54 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 12 Sep 2012 02:03:54 +1000 Subject: a python license problem? References: <2f6ddde4-cff2-4005-bda5-b251e9822aff@googlegroups.com> Message-ID: <87vcfkpmvp.fsf@benfinney.id.au> Jayden writes: > Python is under GPL compatible. If I develop a python code If you write new code, without deriving your work from the code of Python itself, then the license of the Python code cannot affect what you many do with what you wrote ? because the copyright on Python does not affect works not derived from it. Despite the wishes of copyright maximalists (and the PSF are not copyright maximalists, to my knowledge), there are still limits to the scope of copyright. > If python is under GPL, is the answer different? Thanks a lot!! Python is not under GPL. But unless you are deriving a work from Python and distributing the result, that doesn't alter the answer. -- \ ?I wish there was a knob on the TV to turn up the intelligence. | `\ There's a knob called ?brightness? but it doesn't work.? | _o__) ?Eugene P. Gallagher | Ben Finney From chottel at earthlink.net Tue Sep 11 12:49:14 2012 From: chottel at earthlink.net (Charles Hottel) Date: Tue, 11 Sep 2012 12:49:14 -0400 Subject: Which Version of Python? Message-ID: I have a lot of programming experience in many different languages and now I want to learn Python. Which version do you suggest I download, Python 2.x or Python 3.x ? Also why should I prefer one over the other? Right now I am thinkng Python 3.x as it has been out since 2008, but I have some concerns about backward compatibility with older packages that I might want to use. Thanks for your ideas and help. From ashernew at gmail.com Tue Sep 11 13:06:59 2012 From: ashernew at gmail.com (Asher Newcomer) Date: Tue, 11 Sep 2012 13:06:59 -0400 Subject: Which Version of Python? In-Reply-To: References: Message-ID: Having recently looked for the same answer myself, consensus seems to be that you should work with 3.x unless you know you need something that is still 2.x specific. For me, that 2.x specific item was OpenStack. On Tue, Sep 11, 2012 at 12:49 PM, Charles Hottel wrote: > I have a lot of programming experience in many different languages and now > I want to learn Python. Which version do you suggest I download, Python > 2.x > or Python 3.x ? Also why should I prefer one over the other? > > Right now I am thinkng Python 3.x as it has been out since 2008, but I have > some concerns about backward compatibility with older packages that I might > want to use. > > Thanks for your ideas and help. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Sep 11 13:14:35 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 11 Sep 2012 18:14:35 +0100 Subject: Which Version of Python? In-Reply-To: References: Message-ID: <504F717B.4060406@mrabarnett.plus.com> On 11/09/2012 17:49, Charles Hottel wrote: > I have a lot of programming experience in many different languages and now > I want to learn Python. Which version do you suggest I download, Python 2.x > or Python 3.x ? Also why should I prefer one over the other? > > Right now I am thinkng Python 3.x as it has been out since 2008, but I have > some concerns about backward compatibility with older packages that I might > want to use. > > Thanks for your ideas and help. > My own preference is for Python 3.x. Python 2.x is ending at 2.7. As you said, some older packages may still be using 2.x, but there's not that much difference between 3.x and 2.x, so you should be able to switch from one to the other one very easily. From tjreedy at udel.edu Tue Sep 11 13:46:13 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 11 Sep 2012 13:46:13 -0400 Subject: a python license problem? In-Reply-To: <87vcfkpmvp.fsf@benfinney.id.au> References: <2f6ddde4-cff2-4005-bda5-b251e9822aff@googlegroups.com> <87vcfkpmvp.fsf@benfinney.id.au> Message-ID: On 9/11/2012 12:03 PM, Ben Finney wrote: > Jayden writes: > >> Python is under GPL compatible. If I develop a python code > > If you write new code, without deriving your work from the code of > Python itself, then the license of the Python code cannot affect what > you many do with what you wrote ? because the copyright on Python does > not affect works not derived from it. > > Despite the wishes of copyright maximalists (and the PSF are not > copyright maximalists, to my knowledge), there are still limits to the > scope of copyright. If by 'copyright maximalists' you mean the authors of translation programs that claim copyright to translations, then they are really 'copyright grabbers' in that they are denying copyright to original authors of the codes translated. The usual basis for the grab is that the translated code must run with a runtime component from the translator. The runtime may or may not be physically bundled with the translated code, just as Python code can run with either a separately installed python or a bundled python, as in freeze or py2exe. The PSF explicitly says that distribution of such bundles is allowed for CPython as long as one summarized what one is doing. (See terms 2 and 3.) >> If python is under GPL, is the answer different? Thanks a lot!! > > Python is not under GPL. But unless you are deriving a work from Python > and distributing the result, that doesn't alter the answer. To be really clear, the 'Python license' is the license for the Python x.y.z software and documentation distributed by the Python Software Foundation. Other implementations have their own copyright and licenses. Code is copyrighted and licensed by the author or assignee. -- Terry Jan Reedy From woooee at gmail.com Tue Sep 11 14:13:52 2012 From: woooee at gmail.com (woooee) Date: Tue, 11 Sep 2012 11:13:52 -0700 (PDT) Subject: submit jobs on multi-core References: Message-ID: There is parallel python as well http://www.parallelpython.com/ From ian.g.kelly at gmail.com Tue Sep 11 14:41:34 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 11 Sep 2012 12:41:34 -0600 Subject: submit jobs on multi-core In-Reply-To: <504ED1EB.1080008@shopzeus.com> References: <504ED1EB.1080008@shopzeus.com> Message-ID: On Mon, Sep 10, 2012 at 11:53 PM, Laszlo Nagy wrote: > On 2012-09-11 06:16, Dhananjay wrote: >> >> Dear all, >> >> I have a python script in which I have a list of files to input one by one >> and for each file I get a number as an output. >> I used for loop to submit the file to script. >> My script uses one file at a time and returns the output. >> >> My computers has 8 cores. >> Is there any way that I could submit 8 jobs at a time and get all the >> output faster ? >> In other words, how can I modify my script so that I could submit 8 jobs >> together on 8 different processors ? >> >> I am bit new to this stuff, please suggest me some directions. > > You should first look at the multiprocessing module. It is part of the > standard library. > > http://docs.python.org/library/multiprocessing.html Or if Python 3.2 is an option, the concurrent.futures module would be very well suited for this task. From e.doxtator at gmail.com Tue Sep 11 14:45:25 2012 From: e.doxtator at gmail.com (e.doxtator at gmail.com) Date: Tue, 11 Sep 2012 11:45:25 -0700 (PDT) Subject: Single leading dash in member variable names? Message-ID: <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> All Python noob here. Trying to understand a particular syntax: class stuff: def __init__(self): self._bongo = "BongoWorld" ----------- What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it. From ian.g.kelly at gmail.com Tue Sep 11 15:06:06 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 11 Sep 2012 13:06:06 -0600 Subject: Single leading dash in member variable names? In-Reply-To: <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> References: <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> Message-ID: On Tue, Sep 11, 2012 at 12:45 PM, wrote: > All > > Python noob here. Trying to understand a particular syntax: > > class stuff: > def __init__(self): > self._bongo = "BongoWorld" > > ----------- > > What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it. Single leading underscore is a convention indicating that the name should be considered private and not used externally. It's a softer version of the double leading underscore that means basically the same thing but has syntactic significance. From john.ruckstuhl at gmail.com Tue Sep 11 15:13:45 2012 From: john.ruckstuhl at gmail.com (ruck) Date: Tue, 11 Sep 2012 12:13:45 -0700 (PDT) Subject: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py In-Reply-To: References: <504e4a8d$0$29981$c3e8da3$5496439d@news.astraweb.com> <83af64e3-bc26-4217-8afa-e4f6d45b604d@googlegroups.com> <504eb3fc$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9ef20f77-487f-4250-91af-5d7d2491da05@googlegroups.com> On Tuesday, September 11, 2012 12:21:24 AM UTC-7, Tim Golden wrote: > And so it does, but you'll notice from the MSDN docs that the \\? > syntax must be supplied as a Unicode string, which os.listdir > will do if you pass it a Python unicode object and not otherwise: I was saying os.listdir doesn't like the r'\\?\' prefix. But Tim corrects me -- so yes, Steven's earler suggestion "Why don't you just prepend a '?' to paths like they tell you to?" does work, when I supply it in unicode. Good: >>> os.listdir(u'\\\\?\\C:\\Users\\john\\Desktop\\sandbox\\goo') [u'voo...'] Bad: >>> os.listdir('\\\\?\\C:\\Users\\john\\Desktop\\sandbox\\goo') Traceback (most recent call last): File "", line 1, in os.listdir('\\\\?\\C:\\Users\\john\\Desktop\\sandbox\\goo') WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: '\\\\?\\C:\\Users\\john\\Desktop\\sandbox\\goo/*.*' Thanks to both of you for taking the time to teach. BTW, when I posted the original, I was trying to supply my own customized ntpath module, and I was really puzzled as to why it wasn't getting picked up! According to sys.path I expected my custom ntpath.py to be chosen, instead of the standard Lib/ntpath.py. Now I guess I understand why. I moved Lib/ntpath.* out of the way, and learned that during initialization, Python is importing "site" module, which is importing "os" which is importing "ntpath" -- before my dir is added to sys.path. So later when I import os, it and ntpath have already been imported, so Python doesn't attempt a fresh import. To get my custom ntpath.py honored, need to RELOAD, like: import os import ntpath reload(ntpath) print 'os.walk(\'goo\') with isdir override in custom ntpath' for root, dirs, files in os.walk('goo'): print root, dirs, files where the diff betw standard ntpath.py and my ntpath.py are: 14c14,19 < from genericpath import * --- > from genericpath import * > > def isdir(s): > return genericpath.isdir('\\\\?\\' + abspath(s + '\\')) > def isfile(s): > return genericpath.isfile('\\\\?\\' + abspath(s + '\\')) I'm not sure how I could have known that ntpath was already imported, since *I* didn't import it, but that was the key to my confusion. Thanks again for the help. John From john.ruckstuhl at gmail.com Tue Sep 11 15:13:45 2012 From: john.ruckstuhl at gmail.com (ruck) Date: Tue, 11 Sep 2012 12:13:45 -0700 (PDT) Subject: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py In-Reply-To: References: <504e4a8d$0$29981$c3e8da3$5496439d@news.astraweb.com> <83af64e3-bc26-4217-8afa-e4f6d45b604d@googlegroups.com> <504eb3fc$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9ef20f77-487f-4250-91af-5d7d2491da05@googlegroups.com> On Tuesday, September 11, 2012 12:21:24 AM UTC-7, Tim Golden wrote: > And so it does, but you'll notice from the MSDN docs that the \\? > syntax must be supplied as a Unicode string, which os.listdir > will do if you pass it a Python unicode object and not otherwise: I was saying os.listdir doesn't like the r'\\?\' prefix. But Tim corrects me -- so yes, Steven's earler suggestion "Why don't you just prepend a '?' to paths like they tell you to?" does work, when I supply it in unicode. Good: >>> os.listdir(u'\\\\?\\C:\\Users\\john\\Desktop\\sandbox\\goo') [u'voo...'] Bad: >>> os.listdir('\\\\?\\C:\\Users\\john\\Desktop\\sandbox\\goo') Traceback (most recent call last): File "", line 1, in os.listdir('\\\\?\\C:\\Users\\john\\Desktop\\sandbox\\goo') WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: '\\\\?\\C:\\Users\\john\\Desktop\\sandbox\\goo/*.*' Thanks to both of you for taking the time to teach. BTW, when I posted the original, I was trying to supply my own customized ntpath module, and I was really puzzled as to why it wasn't getting picked up! According to sys.path I expected my custom ntpath.py to be chosen, instead of the standard Lib/ntpath.py. Now I guess I understand why. I moved Lib/ntpath.* out of the way, and learned that during initialization, Python is importing "site" module, which is importing "os" which is importing "ntpath" -- before my dir is added to sys.path. So later when I import os, it and ntpath have already been imported, so Python doesn't attempt a fresh import. To get my custom ntpath.py honored, need to RELOAD, like: import os import ntpath reload(ntpath) print 'os.walk(\'goo\') with isdir override in custom ntpath' for root, dirs, files in os.walk('goo'): print root, dirs, files where the diff betw standard ntpath.py and my ntpath.py are: 14c14,19 < from genericpath import * --- > from genericpath import * > > def isdir(s): > return genericpath.isdir('\\\\?\\' + abspath(s + '\\')) > def isfile(s): > return genericpath.isfile('\\\\?\\' + abspath(s + '\\')) I'm not sure how I could have known that ntpath was already imported, since *I* didn't import it, but that was the key to my confusion. Thanks again for the help. John From e.doxtator at gmail.com Tue Sep 11 16:53:26 2012 From: e.doxtator at gmail.com (e.doxtator at gmail.com) Date: Tue, 11 Sep 2012 13:53:26 -0700 (PDT) Subject: Single leading dash in member variable names? In-Reply-To: References: <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> Message-ID: On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote: > On Tue, Sep 11, 2012 at 12:45 PM, I wrote: > > > All > > > > > > Python noob here. Trying to understand a particular syntax: > > > > > > class stuff: > > > def __init__(self): > > > self._bongo = "BongoWorld" > > > > > > ----------- > > > > > > What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it. > > > > Single leading underscore is a convention indicating that the name > > should be considered private and not used externally. It's a softer > > version of the double leading underscore that means basically the same > > thing but has syntactic significance. Thank you! PEP 8 says this is bad form. What do you think? From e.doxtator at gmail.com Tue Sep 11 16:53:26 2012 From: e.doxtator at gmail.com (e.doxtator at gmail.com) Date: Tue, 11 Sep 2012 13:53:26 -0700 (PDT) Subject: Single leading dash in member variable names? In-Reply-To: References: <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> Message-ID: On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote: > On Tue, Sep 11, 2012 at 12:45 PM, I wrote: > > > All > > > > > > Python noob here. Trying to understand a particular syntax: > > > > > > class stuff: > > > def __init__(self): > > > self._bongo = "BongoWorld" > > > > > > ----------- > > > > > > What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it. > > > > Single leading underscore is a convention indicating that the name > > should be considered private and not used externally. It's a softer > > version of the double leading underscore that means basically the same > > thing but has syntactic significance. Thank you! PEP 8 says this is bad form. What do you think? From oscar.j.benjamin at gmail.com Tue Sep 11 17:18:37 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 11 Sep 2012 21:18:37 +0000 (UTC) Subject: submit jobs on multi-core References: Message-ID: On 2012-09-11, Dhananjay wrote: > --===============0316394162== > Content-Type: multipart/alternative; boundary=20cf30776bd309ffd004c96557e2 > > --20cf30776bd309ffd004c96557e2 > Content-Type: text/plain; charset=ISO-8859-1 > > Dear all, > > I have a python script in which I have a list of files to input one by one > and for each file I get a number as an output. > I used for loop to submit the file to script. > My script uses one file at a time and returns the output. > > My computers has 8 cores. > Is there any way that I could submit 8 jobs at a time and get all the > output faster ? > In other words, how can I modify my script so that I could submit 8 jobs > together on 8 different processors ? > > I am bit new to this stuff, please suggest me some directions. > > Thank you. The simplest way I've found to do this is to use something like GNU parallel. I don't know if there's a Windows equivalent but it works well for me on linux and you can use it for any program (not just python scripts). >From the wikipedia page: http://en.wikipedia.org/wiki/GNU_parallel """ The most common usage is to replace the shell loop, for example (for x in `cat list` ; do do_something $x done) | process_output to the form of cat list | parallel do_something | process_output """ Note that there are two basic types of parallel execution depending on whether or not your parallel processes need to communicate with one another. I'm assuming that you really just want to run independent jobs simultaneously. Otherwise the other suggestions may be more relevant. Oscar From ian.g.kelly at gmail.com Tue Sep 11 17:32:29 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 11 Sep 2012 15:32:29 -0600 Subject: Single leading dash in member variable names? In-Reply-To: References: <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> Message-ID: On Tue, Sep 11, 2012 at 2:53 PM, wrote: > On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote: >> Single leading underscore is a convention indicating that the name >> should be considered private and not used externally. It's a softer >> version of the double leading underscore that means basically the same >> thing but has syntactic significance. > > Thank you! > > PEP 8 says this is bad form. What do you think? Where are you seeing that? It says: Use one leading underscore only for non-public methods and instance > variables. > > To avoid name clashes with subclasses, use two leading underscores to > invoke Python's name mangling rules. > > ... Generally, double leading underscores should be used only to avoid > name conflicts with attributes in classes designed to be subclassed. > So a single leading underscore is the preferred style for non-public methods and attributes. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Sep 11 17:34:03 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 11 Sep 2012 17:34:03 -0400 Subject: Single leading dash in member variable names? In-Reply-To: References: <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> Message-ID: On 9/11/2012 4:53 PM, e.doxtator at gmail.com wrote: >>> What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it. >> Single leading underscore is a convention indicating that the name >> should be considered private and not used externally. It's a softer >> version of the double leading underscore that means basically the same >> thing but has syntactic significance. > PEP 8 says this is bad form. What do you think? Please quote the specific statement you want commented. The stdlib routinely uses _names for internal implementation objects. __ugh is perhaps never used. -- Terry Jan Reedy From ashish.makani at gmail.com Tue Sep 11 17:51:23 2012 From: ashish.makani at gmail.com (ashish makani) Date: Tue, 11 Sep 2012 14:51:23 -0700 (PDT) Subject: How to send email programmatically from a gmail email a/c when port 587(smtp) is blocked Message-ID: <0f6686fd-7363-43d6-a5fa-0bd4f12586b5@googlegroups.com> Hi c.l.p peeps I am stuck with an issue, so am coming to the Pythonista deltaforce who rescue me everytime :) I am trying to send out email programmatically, from a gmail a/c, using smtplib, using the following chunk of code (b/w [ & ] below) [ import smtplib from email.mime.text import MIMEText #uname, pwd are username & password of gmail a/c i am trying to send from server = smtplib.SMTP('smtp.gmail.com:587') server.starttls() # get response(220, '2.0.0 Ready to start TLS') server.login(uname,pwd) # get response(235, '2.7.0 Accepted') toaddrs = ['x at gmail.com', 'y at gmail.com' ] # list of To email addresses msg = MIMEText('email body') msg['Subject'] = 'email subject' server.sendmail(fromaddr, toaddrs, msg.as_string()) ] The code above works perfectly fine on my local machine, but fails on the production server at the university where i work( all ports other than port 80 are blocked) :( So , when i try to run the 2 py statements (in bold below) on a python prompt from the production server, which has port 587 blocked, i get the following error { >>> import smtplib >>> server = smtplib.SMTP('smtp.gmail.com:587') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/smtplib.py", line 239, in __init__ (code, msg) = self.connect(host, port) File "/usr/lib/python2.6/smtplib.py", line 295, in connect self.sock = self._get_socket(host, port, self.timeout) File "/usr/lib/python2.6/smtplib.py", line 273, in _get_socket return socket.create_connection((port, host), timeout) File "/usr/lib/python2.6/socket.py", line 514, in create_connection raise error, msg socket.error: [Errno 101] Network is unreachable } 1. How can i overcome this ? A friend suggested , that i could use something called smtp relay, which would solve my problem, but would be time-consuming & a pain to set up. I did some cursory googling & searching on stackoverflow but could not find any good, well explained results. I dont know anything about SMTP. Anybody has any recommendations on a good explanation on smtp relay & how to set it up for sending email from a gmail a/c using a python script ? 2. Also, is there a more elegant/cleaner/graceful solution to my problem than using an smtp relay ? Any & all explanations/links/code snippets/thoughts/ideas/suggestions/feedback/comments/wisdom of the c.l.p community would be greatly appreciated. Thanks a ton cheers ashish email : ashish.makani domain:gmail.com p.s. some more context so people dont presume we are spammers :) These emails are automated diagnostic emails sent to a group of a few of us admins, so we get notified when a python heartbeat script, detects a failure in things like n/w connectivity, router status, etc. All of us dont use university email, we use gmail . ?The only way to do great work is to love what you do. If you haven?t found it yet, keep looking. Don?t settle. As with all matters of the heart, you?ll know when you find it.? - Steve Jobs (1955 - 2011) From max at alcyone.com Tue Sep 11 18:02:31 2012 From: max at alcyone.com (Erik Max Francis) Date: Tue, 11 Sep 2012 15:02:31 -0700 Subject: Single leading dash in member variable names? In-Reply-To: References: <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> Message-ID: On 09/11/2012 01:53 PM, e.doxtator at gmail.com wrote: > On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote: >> On Tue, Sep 11, 2012 at 12:45 PM, I wrote: >>> What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it. >> >> Single leading underscore is a convention indicating that the name >> should be considered private and not used externally. It's a softer >> version of the double leading underscore that means basically the same >> thing but has syntactic significance. > > Thank you! > > PEP 8 says this is bad form. What do you think? Where does it say that? -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Jabber erikmaxfrancis I will always remember / This moment -- Sade From joshua.landau.ws at gmail.com Tue Sep 11 18:09:40 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Tue, 11 Sep 2012 23:09:40 +0100 Subject: Double sided double underscored variable names Message-ID: Were I to make a language to compile to Python, it is highly likely I would need to use hidden variable names to work constructs that Python alone does not have. This is the situation I face. If I were to use internal double-underscored names of the form __BS_* internalname*__, would the compiled code be able to assume that no-one had overwritten these variables and never will, even through modification of, say, locals(). I ask because Python's docs seem to specify that double sided double underscored names are strictly for Python and its special names. In other words, is not using __these_names__ in Python code rule or heavy convention. __BS__ is used because the name of the language is BluntSharp. Do not expect the language to ever be useful or widespread; I am doing this mostly for fun. An alternative is modifying the AST (as I am really compiling to Python's AST) to have the variables with names such as "+BS_internalname", but that seems like it might break a lot. I also doubt that it is good convention. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Sep 11 18:22:17 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Sep 2012 08:22:17 +1000 Subject: Double sided double underscored variable names In-Reply-To: References: Message-ID: On Wed, Sep 12, 2012 at 8:09 AM, Joshua Landau wrote: > If I were to use internal double-underscored names of the form > __BS_internalname__, would the compiled code be able to assume that no-one > had overwritten these variables and never will, even through modification > of, say, locals(). I ask because Python's docs seem to specify that double > sided double underscored names are strictly for Python and its special > names. Interesting. If you're compiling your code to Python, you may be able to, if necessary, adorn a user's variable name(s). I'd be inclined to use a single underscore notation like _BS_internalname_ and then, in the event of a collision (which would be incredibly unlikely unless someone's fiddling), rename the offending variable to _BS_BS_something_ - which of course you'd never yourself use. Would that serve? ChrisA From breamoreboy at yahoo.co.uk Tue Sep 11 18:47:51 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 11 Sep 2012 23:47:51 +0100 Subject: How to send email programmatically from a gmail email a/c when port 587(smtp) is blocked In-Reply-To: <0f6686fd-7363-43d6-a5fa-0bd4f12586b5@googlegroups.com> References: <0f6686fd-7363-43d6-a5fa-0bd4f12586b5@googlegroups.com> Message-ID: On 11/09/2012 22:51, ashish makani wrote: > Hi c.l.p peeps > > I am stuck with an issue, so am coming to the Pythonista deltaforce who rescue me everytime :) > [big snip] I say old chap, it's simply not cricket to ask a question like this some 32 minutes after asking the same question on the tutor mailing list. -- Cheers. Mark Lawrence. From joshua.landau.ws at gmail.com Tue Sep 11 18:48:51 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Tue, 11 Sep 2012 23:48:51 +0100 Subject: Double sided double underscored variable names In-Reply-To: References: Message-ID: On 11 September 2012 23:22, Chris Angelico wrote: > On Wed, Sep 12, 2012 at 8:09 AM, Joshua Landau > wrote: > > If I were to use internal double-underscored names of the form > > __BS_internalname__, would the compiled code be able to assume that > no-one > > had overwritten these variables and never will, even through modification > > of, say, locals(). I ask because Python's docs seem to specify that > double > > sided double underscored names are strictly for Python and its special > > names. > > Interesting. If you're compiling your code to Python, you may be able > to, if necessary, adorn a user's variable name(s). I'd be inclined to > use a single underscore notation like _BS_internalname_ and then, in > the event of a collision (which would be incredibly unlikely unless > someone's fiddling), rename the offending variable to > _BS_BS_something_ - which of course you'd never yourself use. Would > that serve? > Well, the problem is that a lot of collisions aren't predictable. "locals()['foo'] = 2", for example. If it weren't for Python's annoying flexibility* I would definitely do something very close to what you suggest. Remember that "locals()" isn't Python's only introspection tool. How about "from foo import *"? I could just make the claim "You use non-explicitly declared names and you pay the price", but that seems... less nice. *Being "annoying" is how I'm pretty sure I can get inline function definitions working, though, so I shouldn't give it too much rap... -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Sep 11 18:50:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Sep 2012 08:50:12 +1000 Subject: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py In-Reply-To: <9ef20f77-487f-4250-91af-5d7d2491da05@googlegroups.com> References: <504e4a8d$0$29981$c3e8da3$5496439d@news.astraweb.com> <83af64e3-bc26-4217-8afa-e4f6d45b604d@googlegroups.com> <504eb3fc$0$29890$c3e8da3$5496439d@news.astraweb.com> <9ef20f77-487f-4250-91af-5d7d2491da05@googlegroups.com> Message-ID: On Wed, Sep 12, 2012 at 5:13 AM, ruck wrote: > I'm not sure how I could have known that ntpath was already imported, since *I* didn't import it, but that was the key to my confusion. One way to find out is to peek at the cache. >>> import sys >>> sys.modules There are quite a few of them in the 3.2 interactive that I just tried this in. ChrisA From rosuav at gmail.com Tue Sep 11 18:52:10 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Sep 2012 08:52:10 +1000 Subject: Double sided double underscored variable names In-Reply-To: References: Message-ID: On Wed, Sep 12, 2012 at 8:48 AM, Joshua Landau wrote: > Well, the problem is that a lot of collisions aren't predictable. > "locals()['foo'] = 2", for example. If it weren't for Python's annoying > flexibility* I would definitely do something very close to what you suggest. > Remember that "locals()" isn't Python's only introspection tool. How about > "from foo import *"? You're not supposed to mutate locals(), but I suppose globals() works the same way. Inline functions? I like this idea. I tend to want them in pretty much any language I write in. ChrisA From d at davea.name Tue Sep 11 18:57:19 2012 From: d at davea.name (Dave Angel) Date: Tue, 11 Sep 2012 18:57:19 -0400 Subject: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py In-Reply-To: <9ef20f77-487f-4250-91af-5d7d2491da05@googlegroups.com> References: <504e4a8d$0$29981$c3e8da3$5496439d@news.astraweb.com> <83af64e3-bc26-4217-8afa-e4f6d45b604d@googlegroups.com> <504eb3fc$0$29890$c3e8da3$5496439d@news.astraweb.com> <9ef20f77-487f-4250-91af-5d7d2491da05@googlegroups.com> Message-ID: <504FC1CF.70808@davea.name> On 09/11/2012 03:13 PM, ruck wrote: > > > I'm not sure how I could have known that ntpath was already imported, since *I* didn't import it, but that was the key to my confusion. > import sys print sys.modules -- DaveA From ben+python at benfinney.id.au Tue Sep 11 19:55:07 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 12 Sep 2012 09:55:07 +1000 Subject: Which Version of Python? References: Message-ID: <87r4q8p12c.fsf@benfinney.id.au> "Charles Hottel" writes: > I have a lot of programming experience in many different languages and now > I want to learn Python. Good for you, and welcome! > Which version do you suggest I download, Python 2.x or Python 3.x ? > Also why should I prefer one over the other? This question is a good one. It is common enough that the home page has a link to the community's answer/discussion at . > Right now I am thinkng Python 3.x as it has been out since 2008, but I > have some concerns about backward compatibility with older packages > that I might want to use. The fact that Python 3 has been out for a number of years is important, as is the fact that the Python developers and the community of third-party library developers have worked quite hard to make it feasible to work in Python 3. More important, from the perspective of a newcomer, is that Python 2 is essentially in maintenance-only mode, receiving only bug fixes. All larger improvements are only going into Python 3. The set of third-party libraries which are not ready for Python 3 still has some significant members, and will certainly never be zero. But that set has shrunk significantly in the many years that Python 3 has been active. At this stage, I would advise any person wanting to learn Python qua Python (i.e. without considering the wrinkles of some specific task) to focus on Python 3. If you need to learn older versions, that need will present itself and you can learn the legacy quirks then; for now, learn Python the way it is intended to be by going for Python 3. -- \ ?A lie can be told in a few words. Debunking that lie can take | `\ pages. That is why my book? is five hundred pages long.? ?Chris | _o__) Rodda, 2011-05-05 | Ben Finney From peter.milliken at gmail.com Tue Sep 11 20:17:14 2012 From: peter.milliken at gmail.com (Peter) Date: Tue, 11 Sep 2012 17:17:14 -0700 (PDT) Subject: Which Version of Python? In-Reply-To: <87r4q8p12c.fsf@benfinney.id.au> References: <87r4q8p12c.fsf@benfinney.id.au> Message-ID: <858be08d-c3bd-48e7-920d-b27901e13af7@googlegroups.com> If your desire is to "learn" Python then I would stick to 2.7 My reasoning would be that there are still a significant number of packages that have not been ported to 3.x (and may never be ported). Not having looked at the changes in 3.x (so don't flame me! :-)), it would seem that anything you "learn" in 2.7 would be easily transferred "up" when and if you feel the need to go to 3.x, but in the meantime enjoy the better support of a greater range of packages that are still only 2.x compatible! i.e. learning (and using) features of 3.x could make it difficult to go "down" when/if you decide you really need to use a library that hasn't (and may never!) be ported to 3.x. For example, Graysons book on Python GUI programming is still one of the better Python GUI books (although very old now!) and it would steer you towards using the Pmw library - which may never be ported to 3.x. If you decide to use wxPython for your GUI work then I see that has support for 2.x only also. So in this case, staying with the lower common denominator might be the better choice. From dustin at v.igoro.us Tue Sep 11 20:40:58 2012 From: dustin at v.igoro.us (Dustin J. Mitchell) Date: Tue, 11 Sep 2012 20:40:58 -0400 Subject: Standard Asynchronous Python In-Reply-To: References: <504d60ab$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: Thanks for the second round of responses. I think this gives me some focus - concentrate on the API, talk to the framework developers, and start redrafting the PEP sooner rather than later. Thanks! Dustin From steve+comp.lang.python at pearwood.info Tue Sep 11 20:51:49 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Sep 2012 00:51:49 GMT Subject: Double sided double underscored variable names References: Message-ID: <504fdca5$0$29981$c3e8da3$5496439d@news.astraweb.com> Sorry for breaking threading, but Joshua's post does not show up on my usenet provider. On Wed, 12 Sep 2012 08:22:17 +1000, Chris Angelico wrote: > On Wed, Sep 12, 2012 at 8:09 AM, Joshua Landau > wrote: >> >> If I were to use internal double-underscored names of the form >> __BS_internalname__, would the compiled code be able to assume that >> no-one had overwritten these variables and never will, Certainly not. It is virtually never possible to make that assumption in Python. Nearly everything can be shadowed at runtime. (One exception is local variables of a function, which can only be seen from inside that function. But you don't need to wrap local variable names in underscores to treat them as local.) Dunder ("Double leading and trailing UNDERscore") names are normal names subject to the same rules as anything else in Python (with one exception), which means you can modify them in all sorts of ways at runtime: py> _int = int py> class MyInt(_int): ... def __add__(self, other): ... return 42 ... py> int = MyInt py> a = int("10000") py> a + 1 42 py> type(a).__add__ = lambda self, other: 23 py> a + 1 23 The one exception how dunder names are treated specially is that Python uses a short-cut for name-lookup which means you cannot override them on a per-instance basis like normal other attribute names. >> even through modification of, say, locals(). Modifying locals() is an implementation detail which may not be supported. >> I ask because Python's docs seem to >> specify that double sided double underscored names are strictly for >> Python and its special names. Dunder names are reserved for use by Python's built-ins and syntax, that is all. > Interesting. If you're compiling your code to Python, you may be able > to, if necessary, adorn a user's variable name(s). I'd be inclined to > use a single underscore notation like _BS_internalname_ and then, in the > event of a collision (which would be incredibly unlikely unless > someone's fiddling), rename the offending variable to _BS_BS_something_ > - which of course you'd never yourself use. Would that serve? This seems to be a mere extension of the name-mangling that occurs with leading-only double-underscore attributes like self.__spam. This can be a right PITA at times, and offers so little protection that it isn't worthwhile. __names only protect against *accidental* name collisions, and not all of those. -- Steven From bahamutzero8825 at gmail.com Tue Sep 11 21:07:46 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 11 Sep 2012 20:07:46 -0500 Subject: Which Version of Python? In-Reply-To: <858be08d-c3bd-48e7-920d-b27901e13af7@googlegroups.com> References: <87r4q8p12c.fsf@benfinney.id.au> <858be08d-c3bd-48e7-920d-b27901e13af7@googlegroups.com> Message-ID: <504FE062.4000706@gmail.com> On 2012.09.11 19:17, Peter wrote: > If your desire is to "learn" Python then I would stick to 2.7 > > My reasoning would be that there are still a significant number of packages that have not been ported to 3.x (and may never be ported). This is true, but the /potential/ for the need for one of these packages is not a good reason to learn from a branch that will never get any new features. If there is indeed a compelling reason to stay with the older version, then it is a worthwhile tradeoff. Otherwise, it is just silly. > Not having looked at the changes in 3.x (so don't flame me! :-)) That would be a good reason /to/ flame you. ;) > , it would seem that anything you "learn" in 2.7 would be easily transferred "up" when and if you feel the need to go to 3.x, 3.x is not a simple superset of 2.7 - there are certain limitations and ways of doing things in 2.x that don't apply to 3.x. A new programmer should learn, for example, handling Unicode properly (which is strongly encouraged in 3.x) and then learn how to deal with less-than-ideal implementations (like 2.x) rather than learn how to do it sloppily and then be frustrated when 3.x wants them to do it correctly. Backward compatibility was not broken for trivial reasons. > i.e. learning (and using) features of 3.x could make it difficult to go "down" The official documentation does point out things that have been added/changed both overall in the "What's New" page and specifically in each module's documentation. > when/if you decide you really need to use a library that hasn't (and may never!) be ported to 3.x. I don't think it's a good idea to encourage people (especially newbies) to stick with packages that won't get updated. I'm not saying that a package that isn't planned to be 3.x compatible will necessarily be unmaintained, but being unmaintained is the reason many packages will not be made 3.x compatible. In any case, packages that aren't getting support for 3.x will likely be replaced with better alternatives, especially once people start flocking en masse to 3.x (I'm no expert, but my guess is that this will happen once Django and Twisted support 3.x). If 3.0 had come out a month ago, I would see value in learning 2.x, but it's been nearly 4 years. -- CPython 3.3.0b1 | Windows NT 6.1.7601.17803 From steve+comp.lang.python at pearwood.info Tue Sep 11 21:14:16 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Sep 2012 01:14:16 GMT Subject: Double sided double underscored variable names References: Message-ID: <504fe1e7$0$29981$c3e8da3$5496439d@news.astraweb.com> And again, Joshua's original post is not available from my provider. Joshua, I suspect that something about your post is being seen as spam and dropped by at least some providers. On Wed, 12 Sep 2012 08:52:10 +1000, Chris Angelico wrote: > On Wed, Sep 12, 2012 at 8:48 AM, Joshua Landau > wrote: >> >> Well, the problem is that a lot of collisions aren't predictable. >> "locals()['foo'] = 2", for example. If it weren't for Python's annoying >> flexibility* I can't see your footnote there, so you may have already covered this, but for the record, what you call Python's "annoying flexibility" is fundamental to Python's programming model and done so for good reasons. The ability to shadow built-ins is, at times, incredibly useful rather than annoying. The world is full of bondage and domination languages that strongly restrict what you can do. Python doesn't need to be another one of them. Python's optimizing compiler, PyPy, is able to optimize code very well without such restrictions. >> I would definitely do something very close to what you >> suggest. Remember that "locals()" isn't Python's only introspection >> tool. How about "from foo import *"? I wouldn't call "import *" an introspection tool. At least, no more so than print. > You're not supposed to mutate locals(), It's not so much you're not allowed to do it, but that the result of making changes to locals() inside a function is implementation dependent: CPython 2: writing to the dict returned by locals() will work, but the changes will not be reflected in the actual local variables, except under very restricted circumstances; CPython 3: those restricted circumstances that allowed writes to locals() to modify local variables are now SyntaxErrors; Stackless: presumably the exact same behaviour as CPython (since Stackless is a fork, not a re-implementation); Jython: the same as CPython; IronPython: writes to locals() will modify the corresponding local variable. Outside of a function, locals() returns globals() and writes will always modify the global variable (this is a language guarantee). > but I suppose globals() works the same way. > > Inline functions? I like this idea. I tend to want them in pretty much > any language I write in. What do you mean by in-line functions? If you mean what you literally say, I would answer that Python has that with lambda. But I guess you probably mean something more like macros. -- Steven From joshua.landau.ws at gmail.com Tue Sep 11 21:32:19 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Wed, 12 Sep 2012 02:32:19 +0100 Subject: Double sided double underscored variable names In-Reply-To: <504fdca5$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <504fdca5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12 September 2012 01:51, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > Sorry for breaking threading, but Joshua's post does not show up on my > usenet provider. > That may explain why I keep getting ignored -.- I thought it was something I said :P I'm just using EMail through GMail, posting to python-list at python.org. If that is the wrong way, I would love to know what I should be doing. > On Wed, 12 Sep 2012 08:22:17 +1000, Chris Angelico wrote: > > > On Wed, Sep 12, 2012 at 8:09 AM, Joshua Landau > > wrote: > >> > >> If I were to use internal double-underscored names of the form > >> __BS_internalname__, would the compiled code be able to assume that > >> no-one had overwritten these variables and never will, > > Certainly not. It is virtually never possible to make that assumption in > Python. Nearly everything can be shadowed at runtime. > > (One exception is local variables of a function, which can only be seen > from inside that function. But you don't need to wrap local variable > names in underscores to treat them as local.) > > Dunder ("Double leading and trailing UNDERscore") names are normal names > subject to the same rules as anything else in Python (with one > exception), which means you can modify them in all sorts of ways at > runtime: > > py> _int = int > py> class MyInt(_int): > ... def __add__(self, other): > ... return 42 > ... > py> int = MyInt > py> a = int("10000") > py> a + 1 > 42 > py> type(a).__add__ = lambda self, other: 23 > py> a + 1 > 23 > Fair play. > The one exception how dunder names are treated specially is that Python > uses a short-cut for name-lookup which means you cannot override them on > a per-instance basis like normal other attribute names. > > >> even through modification of, say, locals(). > > Modifying locals() is an implementation detail which may not be supported. Nice to know. > >> I ask because Python's docs seem to > >> specify that double sided double underscored names are strictly for > >> Python and its special names. > > Dunder names are reserved for use by Python's built-ins and syntax, that > is all. The idea is that if they were reserved then nobody should ever use them. They may be able to, yes, but if you are not meant to make any up, and __BS_internalname__ isn't a Python-reserved name, then maybe I could claim that it's safe territory. > > Interesting. If you're compiling your code to Python, you may be able > > to, if necessary, adorn a user's variable name(s). I'd be inclined to > > use a single underscore notation like _BS_internalname_ and then, in the > > event of a collision (which would be incredibly unlikely unless > > someone's fiddling), rename the offending variable to _BS_BS_something_ > > - which of course you'd never yourself use. Would that serve? > > This seems to be a mere extension of the name-mangling that occurs with > leading-only double-underscore attributes like self.__spam. This can be a > right PITA at times, and offers so little protection that it isn't > worthwhile. __names only protect against *accidental* name collisions, > and not all of those. I disagree. Not with your opinion on self.__spam, but on its equivalence to the the mentioned idea. I have never used (due to absence of need) double leading underscored names, but name mangling is a rigidly different concept to simply naming a variable differently to another. As I can introspect my own compiled code* (gasp!) I can check for any direct name clashes. Python does not do the same with mangling, I believe. It's not like I don't have options. I could always say that inexplicit names have to be careful not to start with "_BS_" and then deal nicely with the explicit ones as said above. But then, people aren't going to be prepending "_BS_" explicitly unless they want to 'break' the code. If /you/ wanted to use a programming language that compiled to Python, would you mind _BS_internalname_ variables littered around the place, and would you prefer if they avoided as many conflicts as they can? I could always make explicit conflicts a warning rather than avoid them. I'm not sure what the practical choice is. * When it's done, of course -------------- next part -------------- An HTML attachment was scrubbed... URL: From joshua.landau.ws at gmail.com Tue Sep 11 21:38:09 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Wed, 12 Sep 2012 02:38:09 +0100 Subject: Double sided double underscored variable names In-Reply-To: <504fe1e7$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <504fe1e7$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12 September 2012 02:14, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > And again, Joshua's original post is not available from my provider. > Joshua, I suspect that something about your post is being seen as spam > and dropped by at least some providers. > I am sorry to ask this, but in the meantime can someone who isn't spam-filtered repost my messages? I'll give them a cookie! To repeat my previous post, I'm using GMail and posting to python-list at python.org. If that is what I'm meant to be doing, I'll try another email address. > On Wed, 12 Sep 2012 08:52:10 +1000, Chris Angelico wrote: > > > On Wed, Sep 12, 2012 at 8:48 AM, Joshua Landau > > wrote: > >> > >> Well, the problem is that a lot of collisions aren't predictable. > >> "locals()['foo'] = 2", for example. If it weren't for Python's annoying > >> flexibility* > > I can't see your footnote there, so you may have already covered this, > but for the record, what you call Python's "annoying flexibility" is > fundamental to Python's programming model and done so for good reasons. > The ability to shadow built-ins is, at times, incredibly useful rather > than annoying. > > The world is full of bondage and domination languages that strongly > restrict what you can do. Python doesn't need to be another one of them. > Python's optimizing compiler, PyPy, is able to optimize code very well > without such restrictions. I agree :P. The footnote should portray that I said that in jest. > >> I would definitely do something very close to what you > >> suggest. Remember that "locals()" isn't Python's only introspection > >> tool. How about "from foo import *"? > > I wouldn't call "import *" an introspection tool. At least, no more so > than print. Yeah, I meant "things that can change the current scope without explicitly naming the changes". "print" doesn't do that, but you are correct in what you say. > but I suppose globals() works the same way. > > > > Inline functions? I like this idea. I tend to want them in pretty much > > any language I write in. > > What do you mean by in-line functions? If you mean what you literally > say, I would answer that Python has that with lambda. > > But I guess you probably mean something more like macros. No, just multi-line lambda. Macros, if my knowledge of lower-level languages is valid, would be sorta' silly in Python. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jayden.shui at gmail.com Tue Sep 11 21:44:13 2012 From: jayden.shui at gmail.com (Jayden) Date: Tue, 11 Sep 2012 18:44:13 -0700 (PDT) Subject: python CAD libraries? In-Reply-To: <20dc1957-5ac0-4f33-9b84-9254423b72d5@googlegroups.com> References: <20dc1957-5ac0-4f33-9b84-9254423b72d5@googlegroups.com> Message-ID: <3257ccf2-f640-4090-83a7-1c6431c16989@googlegroups.com> On Tuesday, September 11, 2012 9:42:56 AM UTC-4, Marco Nawijn wrote: > On Monday, September 10, 2012 11:10:55 PM UTC+2, Jayden wrote: > > > Are there any python CAD libraries that can > > > > > > > > > > > > (1) build simple 3D primitives solids such as spheres, cylinders and so on > > > > > > (2) perform bool operations on 3D solids > > > > > > (3) better if it has some transformations such has scaling, sweeping, and lofting > > > > > > > > > > > > Please recommend some good ones for me? Thanks a lot!! > > > > Hi Jayden, > > > > In my opinion, the best you can get is OpenCascade (OCC) (www.opencascade.org) in combination with the python bindings (www.pythonocc.org). OCC is a hugh C++ CAD library. It not only deals with the simple geometric stuff, but it can be used to build CAD programs similar to SolidEdge or SolidWorks. It does however come with quite a steep learning curve. When using PythonOCC, the learning curve becomes a little less steep. > > > > Also note that in my opinion, Blender cannot be considered as a CAD environment. Ofcourse it is very powerful, but I think it is more targeted towards animation and visually pleasing applications, not mechanical engineering. > > > > Regards, > > > > Marco Hi, Marco, Thank you so much! This is what I exactly want. But I am a little concerned about its steep learning curve. Is it really hard to learn pythonOCC? Averagely, how long does it take to begin to program some practical code? Do you have any good advice for me to learn it? I deeply appreciate your kind help!! Best regards, Jayden From joshua.landau.ws at gmail.com Tue Sep 11 21:45:10 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Wed, 12 Sep 2012 02:45:10 +0100 Subject: Double sided double underscored variable names In-Reply-To: References: <504fe1e7$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: This is an email address linked to my GMail account. If this works better, tell me and I'll switch. It's still sending through GMail though. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Sep 11 22:11:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Sep 2012 02:11:22 GMT Subject: Which Version of Python? References: <87r4q8p12c.fsf@benfinney.id.au> <858be08d-c3bd-48e7-920d-b27901e13af7@googlegroups.com> Message-ID: <504fef49$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 11 Sep 2012 17:17:14 -0700, Peter wrote: > If your desire is to "learn" Python then I would stick to 2.7 > > My reasoning would be that there are still a significant number of > packages that have not been ported to 3.x (and may never be ported). But if all you want is to learn Python, then those packages are irrelevant. If I want to learn to write Python code, why should I care about SomePackage, regardless of whether it supports Python 3.x or 2.x or even 1.x? As a beginner to the language, I don't even know it exists, and chances are I'm never going to use it. (I was happily using Python using only the standard library for about seven years before I installed my first third-party library.) You may not have intended it this way, but the argument "stick to Python 2, because packages!" is a typical troll response. It might have been a reasonable response six years ago, when there weren't many (or even any) major packages that supported Python 3, but now many major packages do and most of those that don't are in the process of doing so. Now the choice is, paradoxically, much harder because library support is much more split: some libraries support 2.x, some 3.x, and some both. Of course, if you *need* to use SomePackage which only supports Python 2 or 3, then that will drive your decision to learn Python 2 or 3. But consider: (1) If a package only supports Python 2 now, and *has no plans* to support Python 3, I would consider that package more or less a dead end and be reluctant to start a new project with it unless I had no other choice at all. (Seriously guys, if you're the developer of a project that only supports 2.x and you aren't at least *thinking about* supporting 3.x, your project is going to be irrelevant to the wider world soon.) (2) The syntax differences between Python 2 and 3 are very minor. By the time you are proficient in one, you will be *easily* be able to jump to the other. > Not having looked at the changes in 3.x (so don't flame me! :-)), it > would seem that anything you "learn" in 2.7 would be easily transferred > "up" when and if you feel the need to go to 3.x, It goes both ways. But frankly, whenever I drop down from 3.x code to 2.x code, I get really annoyed that there's a lot of excellent stuff I cannot use. > but in the meantime > enjoy the better support of a greater range of packages that are still > only 2.x compatible! That's true. But the range of 3.x compatible third party libraries is very impressive: it includes numpy and scipy, CherryPy, parts of zope (but not yet all of it), pyparsing, an unofficial port of nltk, py2exe, and many more. Others, like django, have committed to support 3.x as soon as they can drop support for 2.4 or 2.5. See also: http://python3wos.appspot.com/ PyPy is now in the process of supporting Python 3. Within a few years, Python 3 will be the standard. > i.e. learning (and using) features of 3.x could > make it difficult to go "down" when/if you decide you really need to use > a library that hasn't (and may never!) be ported to 3.x. Any package that is not ported to 3.x will eventually be as obsolete and irrelevant as packages that only support Python 1.5. Python 2.7 will have an extended support period, but that won't last forever. My estimate is that we're past the half-way mark: in another four years, the question of "2.x or 3.x" will be irrelevant, people will be asking "I want to use library foo, but it only supports 2.7, what should I do?", and in eight years, people won't even ask that, they'll just ignore library foo as abandoned. > So in this case, staying with the lower common denominator might be the > better choice. Everyone has to make that choice for themselves, based on what libraries they intend to use. For those who don't intend to use any libraries at all, I think the answer is simple: Learn the version of Python that comes installed on your computer, or if you have to install it yourself, learn Python 3. -- Steven From steve+comp.lang.python at pearwood.info Tue Sep 11 22:15:40 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Sep 2012 02:15:40 GMT Subject: Which Version of Python? References: <87r4q8p12c.fsf@benfinney.id.au> <858be08d-c3bd-48e7-920d-b27901e13af7@googlegroups.com> <504fef49$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <504ff04b$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Sep 2012 02:11:22 +0000, Steven D'Aprano wrote: > On Tue, 11 Sep 2012 17:17:14 -0700, Peter wrote: > >> If your desire is to "learn" Python then I would stick to 2.7 >> >> My reasoning would be that there are still a significant number of >> packages that have not been ported to 3.x (and may never be ported). > > But if all you want is to learn Python, then those packages are > irrelevant. If I want to learn to write Python code, why should I care > about SomePackage, regardless of whether it supports Python 3.x or 2.x > or even 1.x? As a beginner to the language, I don't even know it exists, > and chances are I'm never going to use it. > > (I was happily using Python using only the standard library for about > seven years before I installed my first third-party library.) > > You may not have intended it this way, but the argument "stick to Python > 2, because packages!" is a typical troll response. It might have been a > reasonable response six years ago, when there weren't many (or even any) > major packages that supported Python 3, Hardly surprising given that Python 3 came out four years ago. Sorry, brain-fart. I meant four years ago. -- Steven From j.m.dagenhart at gmail.com Tue Sep 11 22:28:10 2012 From: j.m.dagenhart at gmail.com (j.m.dagenhart at gmail.com) Date: Tue, 11 Sep 2012 19:28:10 -0700 (PDT) Subject: generators as decorators simple issue Message-ID: I'm trying to call SetName on an object to prevent me from ever having to call it explictly again on that object. Best explained by example. def setname(cls): '''this is the proposed generator to call SetName on the object''' try: cls.SetName(cls.__name__) finally: yield cls class Trial: '''class to demonstrate with''' def SetName(self, name): print 1, 1 @setname class Test(Trial): '''i want SetName to be called by using setname as a decorator''' def __init__(self): print 'Yay! or Invalid.' if __name__ == '__main__': test = Test() How can i fix this? This is my exact error: python decors2.py Traceback (most recent call last): File "decors2.py", line 23, in test = Test() TypeError: 'generator' object is not callable From maniandram01 at gmail.com Tue Sep 11 22:55:24 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 11 Sep 2012 19:55:24 -0700 (PDT) Subject: generators as decorators simple issue In-Reply-To: References: Message-ID: <9ead5a5c-2fe0-44ce-9d90-13e19b95d31e@googlegroups.com> On Wednesday, 12 September 2012 07:58:10 UTC+5:30, pyjoshsys wrote: > I'm trying to call SetName on an object to prevent me from ever having to call it explictly again on that object. Best explained by example. > [snip] In your decorator, you are using `yield cls` - it should be `return cls` 99.99% of the time. From maniandram01 at gmail.com Tue Sep 11 22:58:29 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 11 Sep 2012 19:58:29 -0700 (PDT) Subject: Which Version of Python? In-Reply-To: References: Message-ID: On Tuesday, 11 September 2012 22:19:08 UTC+5:30, Charles Hottel wrote: > I have a lot of programming experience in many different languages and now > > I want to learn Python. Which version do you suggest I download, Python 2.x > > or Python 3.x ? Also why should I prefer one over the other? > > > > Right now I am thinkng Python 3.x as it has been out since 2008, but I have > > some concerns about backward compatibility with older packages that I might > > want to use. > > > > Thanks for your ideas and help. Use Python 3 because most packages support Python 3. Python 2.7 has many features that Python 3 has so it will require minimal effort to write Python 2.x code. From maniandram01 at gmail.com Tue Sep 11 23:05:02 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 11 Sep 2012 20:05:02 -0700 (PDT) Subject: python CAD libraries? In-Reply-To: References: Message-ID: On Tuesday, 11 September 2012 02:40:55 UTC+5:30, Jayden wrote: > Are there any python CAD libraries that can > > > > (1) build simple 3D primitives solids such as spheres, cylinders and so on > > (2) perform bool operations on 3D solids > > (3) better if it has some transformations such has scaling, sweeping, and lofting > > > > Please recommend some good ones for me? Thanks a lot!! You could use Blender. It has support for Python 3 (I don't know whether it has support for Python 2) From dwightdhutto at gmail.com Tue Sep 11 23:43:14 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 11 Sep 2012 23:43:14 -0400 Subject: python CAD libraries? In-Reply-To: <3257ccf2-f640-4090-83a7-1c6431c16989@googlegroups.com> References: <20dc1957-5ac0-4f33-9b84-9254423b72d5@googlegroups.com> <3257ccf2-f640-4090-83a7-1c6431c16989@googlegroups.com> Message-ID: Hi, Marco, > > Thank you so much! This is what I exactly want. But I am a little > concerned about its steep learning curve. Is it really hard to learn > pythonOCC? Averagely, how long does it take to begin to program some > practical code? Do you have any good advice for me to learn it? I deeply > appreciate your kind help!! > > Best regards, > > Jayden > -- > http://mail.python.org/mailman/listinfo/python-list > Hey Jayden, You gotta learn to use the google searches buddy, although sometimes a good conversation can help: I found this under search term 'pythonOCC example code' http://code.google.com/p/pythonocc-examples/ and a converted pdf manual from quickview. You can download the pdf by typing in the above search term, and going straight to the main link: https://docs.google.com/viewer?a=v&q=cache:iu53RJFs1XEJ:https://pythonocc.googlecode.com/svn-history/r999/trunk/doc/tutorials/geometry_modeling_and_visualization/LATEX_src/VisualizationOfGeometryWithUtilisingpythonOCC.pdf+&hl=en&gl=us&pid=bl&srcid=ADGEESgHGUGqRqXy6Z9MKCgIIh19JfY9_BYl_xw5tQODTx1N8Hqb3CPU_oruG2LKpNhbfnrEgKEvLTyJHvfOymsHcNSMAQ7WoAa_SW-Bdg33WKVmtoD7dvEtajyqv4KMQuMLgv-NT_om&sig=AHIEtbSGCtWIUBBiFSsELS1AregIpXUVjA&pli=1 -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Tue Sep 11 23:53:21 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 11 Sep 2012 23:53:21 -0400 Subject: Which Version of Python? In-Reply-To: References: Message-ID: I try to usually use several versions to know the difference. You never know when a package might come along, and you want to try it out, and then version becomes compatibility. Alternatively, a client might come along and insist that a particular version be used. Do a little quick research on the differences, and try them out. You might want to know a few things like from __future__ import x for the 2's or print 'this' become print('this') in later ones, etc. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jayden.shui at gmail.com Tue Sep 11 23:58:57 2012 From: jayden.shui at gmail.com (Jayden) Date: Tue, 11 Sep 2012 20:58:57 -0700 (PDT) Subject: pythonOCC examples doesn't work? Message-ID: I installed (1) pythonxy2.7.2.3 (with python2.7) and (2) pythonOCC-0.5-all-in-one.win32.py26 on windows 7 64 bit computer. I try run pythonOCC examples in its example folder, such as the helloworld.py and got errors as follows: ImportantError: DLL load failed: The specified module could not be found. The error come from the line of code: from OCC.BrepPrimAPI import * From jayden.shui at gmail.com Wed Sep 12 00:02:14 2012 From: jayden.shui at gmail.com (Jayden) Date: Tue, 11 Sep 2012 21:02:14 -0700 (PDT) Subject: pythonOCC examples doesn't work? Message-ID: I installed (1) pythonxy2.7.2.3 (with python2.7) and (2) pythonOCC-0.5-all-in-one.win32.py26 on windows 7 64 bit computer. I try run pythonOCC examples in its example folder, such as the helloworld.py and got errors as follows: ImportantError: DLL load failed: The specified module could not be found. The error come from the line of code: from OCC.BrepPrimAPI import * How to fix the error? Thanks a lot!! From dwightdhutto at gmail.com Wed Sep 12 00:11:01 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 12 Sep 2012 00:11:01 -0400 Subject: pythonOCC examples doesn't work? In-Reply-To: References: Message-ID: On Tue, Sep 11, 2012 at 11:58 PM, Jayden wrote: > I installed > (1) pythonxy2.7.2.3 (with python2.7) and > (2) pythonOCC-0.5-all-in-one.win32.py26 > on windows 7 64 bit computer. > > I try run pythonOCC examples in its example folder, such as the > helloworld.py and got errors as follows: > > ImportantError: DLL load failed: The specified module could not be > found. > > The error come from the line of code: > > from OCC.BrepPrimAPI import * > > Not sure if this would fix it(had kind of a similar problem I think a > while back, I have the AMD WOW 64, but you might want to install the 2.7_64 > version of Python, and if that doesn't work, come back with the results. > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Sep 12 00:12:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Sep 2012 14:12:20 +1000 Subject: Double sided double underscored variable names In-Reply-To: References: <504fe1e7$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 12, 2012 at 11:38 AM, Joshua Landau wrote: > On 12 September 2012 02:14, Steven D'Aprano > wrote: >> >> And again, Joshua's original post is not available from my provider. >> Joshua, I suspect that something about your post is being seen as spam >> and dropped by at least some providers. > > I am sorry to ask this, but in the meantime can someone who isn't > spam-filtered repost my messages? I'll give them a cookie! > To repeat my previous post, I'm using GMail and posting to > python-list at python.org. If that is what I'm meant to be doing, I'll try > another email address. Mailing to python-list at python from Gmail is exactly what I do, and far as I know, none of my posts are getting lost. But then, I'm seeing all your posts, too, so maybe I just don't know when my posts don't go through. >> On Wed, 12 Sep 2012 08:52:10 +1000, Chris Angelico wrote: >> >> > Inline functions? I like this idea. I tend to want them in pretty much >> > any language I write in. >> >> What do you mean by in-line functions? If you mean what you literally >> say, I would answer that Python has that with lambda. >> >> But I guess you probably mean something more like macros. > > No, just multi-line lambda. Macros, if my knowledge of lower-level languages > is valid, would be sorta' silly in Python. Ah, okay. I was thinking more along the lines of what you call macros, but in the C++ sense of inline functions. In C, macros are handled at precompilation stage, and are dangerous. Classic example: #define squared(x) x*x x_squared = squared(6+7) So your macros end up littered with parentheses, and it still doesn't solve anything, as the argument still gets evaluated twice. (A problem if it has side effects - eg if it's a function call.) What I'm thinking of, though, is like C++ functions. You can put the 'inline' keyword onto any function, and the compiler will do its best to inline it (in fact, a good optimizing compiler will inline things regardless, but that's a separate point). I can write: inline int squared(int x) {return x*x;} and C++ will add no function overhead, but will still do all the proper evaluation order etc. Of course, C++ doesn't allow monkeypatching, so you'll never have semantic differences from inlining. It's just a performance question. But I use inline functions like constants - for instance, I could create a function that converts a database ID into an internal reference number, and I can change the definition of that function in one place and have it apply everywhere, just like if I wanted to change the definition of math.PI to 3.142857 for fun one day. Of course I can use a normal (out-of-line) function for this, but that has overhead in most languages. Hence, wanting inline functions. ChrisA From dwightdhutto at gmail.com Wed Sep 12 00:17:14 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 12 Sep 2012 00:17:14 -0400 Subject: pythonOCC examples doesn't work? In-Reply-To: References: Message-ID: I came up with this thread: http://techblog.ironfroggy.com/2007/01/python-on-windows-and-path.html But you might want to go to the pywin list for this one. http://mail.python.org/mailman/listinfo/python-win32 It says win32, but they should be able to help either way. > -- > Best Regards, > David Hutto > *CEO:* *http://www.hitwebdevelopment.com* > > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Wed Sep 12 00:39:52 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 11 Sep 2012 21:39:52 -0700 (PDT) Subject: generators as decorators simple issue References: Message-ID: <14d034e0-d477-4cde-8a7c-1f31f2e68ee2@v19g2000pbt.googlegroups.com> On Sep 12, 12:28?pm, j.m.dagenh... at gmail.com wrote: > def setname(cls): > ? ? '''this is the proposed generator to call SetName on the object''' > ? ? try: > ? ? ? ? cls.SetName(cls.__name__) > ? ? finally: > ? ? ? ? yield cls A generator is (basically) a callable that acts like an iterator. You'd use a generator if you wanted to loop with for or a list comprehension across the output of the generator: for foo in setname(Test) A decorator is a callable that takes another callable as an argument, either modifying it or returning a wrapped version of it: Test = setname(Test) You don't want to iterate over anything, so you should change `yield` to `return`. From nawijn at gmail.com Wed Sep 12 00:42:21 2012 From: nawijn at gmail.com (Marco Nawijn) Date: Tue, 11 Sep 2012 21:42:21 -0700 (PDT) Subject: pythonOCC examples doesn't work? In-Reply-To: References: Message-ID: On Wednesday, September 12, 2012 6:02:14 AM UTC+2, Jayden wrote: > I installed > > (1) pythonxy2.7.2.3 (with python2.7) and > > (2) pythonOCC-0.5-all-in-one.win32.py26 > > on windows 7 64 bit computer. > > > > I try run pythonOCC examples in its example folder, such as the helloworld.py and got errors as follows: > > > > ImportantError: DLL load failed: The specified module could not be found. > > > > The error come from the line of code: > > > > from OCC.BrepPrimAPI import * > > > > How to fix the error? Thanks a lot!! Hi Jayden, It has been some time ago that I used PythonOCC and I used it on Linux, so I cannot be of much help here. It sounds like you have to tell Windows where to look for the installed libraries (environment variables?). Anyhow, I recommend to post the question to the PythonOCC mailinglist. They are quite responsive. One last suggestion. OCC itself comes with a small utility called DRAWEXE. It is a tcl/tk program that can be used to play around with a lot of the functionality provided by OCC. Good luck! Marco From dwightdhutto at gmail.com Wed Sep 12 01:10:09 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 12 Sep 2012 01:10:09 -0400 Subject: Single leading dash in member variable names? In-Reply-To: References: <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> Message-ID: Not to jump in with another question(this seems somewhat relevant to the conversation, maybe not), but is this similar to a private,public, or protected class similar to the C type langs? -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed Sep 12 02:08:02 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 12 Sep 2012 08:08:02 +0200 Subject: generators as decorators simple issue In-Reply-To: References: Message-ID: Am 12.09.2012 04:28 schrieb j.m.dagenhart at gmail.com: > I'm trying to call SetName on an object to prevent me from ever having to call it explictly again on that object. Best explained by example. > > > def setname(cls): > '''this is the proposed generator to call SetName on the object''' > try: > cls.SetName(cls.__name__) > finally: > yield cls > > > class Trial: > '''class to demonstrate with''' > def SetName(self, name): > print 1, 1 > > @setname > class Test(Trial): > '''i want SetName to be called by using setname as a decorator''' > def __init__(self): > > print 'Yay! or Invalid.' > > if __name__ == '__main__': > test = Test() > > > How can i fix this? I am not sure what exactly you want to achieve, but I see 2 problems here: 1. Your setname operates on a class, but your SetName() is an instance function. 2. I don't really understand the try...finally yield stuff. As others already said, you probably just want to return. I don't see what a generator would be useful for here... def setname(cls): '''this is the proposed generator to call SetName on the object''' try: cls.SetName(cls.__name__) finally: return cls and class Trial(object): '''class to demonstrate with''' @classmethod def SetName(cls, name): print 1, 1 should solve your problems. From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed Sep 12 02:17:11 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 12 Sep 2012 08:17:11 +0200 Subject: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py In-Reply-To: <504eb3fc$0$29890$c3e8da3$5496439d@news.astraweb.com> References: <504e4a8d$0$29981$c3e8da3$5496439d@news.astraweb.com> <83af64e3-bc26-4217-8afa-e4f6d45b604d@googlegroups.com> <504eb3fc$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 11.09.2012 05:46 schrieb Steven D'Aprano: > Good for you. (Sorry, that comes across as more condescending than it is > intended as.) Monkey-patching often gets used for quick scripts and tiny > pieces of code because it works. > > Just beware that if you extend that technique to larger bodies of code, > say when using a large framework, or multiple libraries, your experience > may not be quite so good. Especially if *they* are monkey-patching too, > as some very large frameworks sometimes do. (Or so I am lead to believe.) This sonds like a good use case for a context manager, like the one in decimal.Context.get_manager(). First shot: @contextlib.contextmanager def changed_os_path(**k): old = {} try: for i in k.items(): old[i] = getattr(os.path, i) setattr(os.path, i, k[i]) yield None finally: for i in k.items(): setattr(os.path, i, old[i]) and so for your code you can use print 'os.walk(\'goo\') with modified isdir()' with changed_os_path(isdir=my_isdir): for root, dirs, files in os.walk('goo'): print root, dirs, files so the change is only effective as long as you are in the relevant code part and is reverted as soon as you leave it. Thomas From breamoreboy at yahoo.co.uk Wed Sep 12 02:30:49 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 12 Sep 2012 07:30:49 +0100 Subject: Which Version of Python? In-Reply-To: References: Message-ID: On 11/09/2012 17:49, Charles Hottel wrote: > I have a lot of programming experience in many different languages and now > I want to learn Python. Which version do you suggest I download, Python 2.x > or Python 3.x ? Also why should I prefer one over the other? > > Right now I am thinkng Python 3.x as it has been out since 2008, but I have > some concerns about backward compatibility with older packages that I might > want to use. > > Thanks for your ideas and help. > > Perhaps this will sway you http://docs.python.org/dev/whatsnew/3.3.html There is no longer an equivalent document for the Python 1.x or 2.x series of releases. -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Wed Sep 12 02:41:33 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 12 Sep 2012 07:41:33 +0100 Subject: pythonOCC examples doesn't work? In-Reply-To: References: Message-ID: On 12/09/2012 05:02, Jayden wrote: > I installed > (1) pythonxy2.7.2.3 (with python2.7) and > (2) pythonOCC-0.5-all-in-one.win32.py26 Can you safely mix these? > on windows 7 64 bit computer. > > I try run pythonOCC examples in its example folder, such as the helloworld.py and got errors as follows: > > ImportantError: DLL load failed: The specified module could not be found. > > The error come from the line of code: > > from OCC.BrepPrimAPI import * > > How to fix the error? Thanks a lot!! > See above, I hope, I don't actually know :) -- Cheers. Mark Lawrence. From dwightdhutto at gmail.com Wed Sep 12 03:19:44 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 12 Sep 2012 03:19:44 -0400 Subject: pythonOCC examples doesn't work? In-Reply-To: References: Message-ID: So used to google, forgot to check the python docs: http://docs.python.org/faq/windows.html and this should be useful as well, which is from: http://stackoverflow.com/questions/5030362/how-to-use-opencv-in-python "I suspect you have the same problem I've run into. If you have a 64-bit version of Python, it cannot load 32-bit DLLs. OpenCV currently only ships 32-bit binaries. If you want 64-bit .pyd and .dll files, you have to compile them yourself. There are some instructionson the OpenCV Wiki, but it's not for the faint of heart. Expect to have a substantial time investment. The easiest solution is to: 1. Uninstall 64-bit Python 2. Install a 32-bit distribution. The PythonXY distribution includes pyopencv -- a good set of OpenCV hooks. The only limitation is that it's 32-bit, so don't make plans to process gigapixel astronomy data with it! ;) If you *must* have the 64-bit version, follow these instructionsto get it OpenCV to compile with Visual Studio 2010. There's a discussion on stackoverflow that describes building 64-bit apps with VC Express." And again, check on the pywin mailing list -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Wed Sep 12 03:37:16 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 12 Sep 2012 08:37:16 +0100 Subject: pythonOCC examples doesn't work? In-Reply-To: References: Message-ID: On 12/09/2012 08:19, Dwight Hutto wrote: > So used to google, forgot to check the python docs: > > http://docs.python.org/faq/windows.html > > and this should be useful as well, which is from: > > http://stackoverflow.com/questions/5030362/how-to-use-opencv-in-python > > "I suspect you have the same problem I've run into. If you have a 64-bit > version of Python, it cannot load 32-bit DLLs. OpenCV currently only ships > 32-bit binaries. If you want 64-bit .pyd and .dll files, you have to > compile them yourself. There are some > instructionson the > OpenCV Wiki, but it's not for the faint of heart. Expect to have a > substantial time investment. > > The easiest solution is to: > > 1. Uninstall 64-bit Python > 2. Install a 32-bit distribution. > > The PythonXY distribution includes pyopencv -- a good set of OpenCV hooks. > The only limitation is that it's 32-bit, so don't make plans to process > gigapixel astronomy data with it! ;) > > If you *must* have the 64-bit version, follow these > instructionsto > get it OpenCV to compile with Visual Studio 2010. There's a discussion > on stackoverflow that describes building 64-bit apps with VC Express." > > > And again, check on the pywin mailing list > > All very impressive, but as Dennis Lee Bieber has pointed out and which I suspected there is a binary incompatibility between the OP's Python version and pythonOCC version. Others would be able to see this for themselves but you insist on sending email without context. Please don't do this. -- Cheers. Mark Lawrence. From dwightdhutto at gmail.com Wed Sep 12 04:12:32 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 12 Sep 2012 04:12:32 -0400 Subject: pythonOCC examples doesn't work? In-Reply-To: References: Message-ID: On Wed, Sep 12, 2012 at 3:37 AM, Mark Lawrence wrote: > On 12/09/2012 08:19, Dwight Hutto wrote: >> >> So used to google, forgot to check the python docs: >> >> http://docs.python.org/faq/windows.html >> >> and this should be useful as well, which is from: >> >> http://stackoverflow.com/questions/5030362/how-to-use-opencv-in-python >> >> "I suspect you have the same problem I've run into. If you have a >> 64-bit >> version of Python, it cannot load 32-bit DLLs. OpenCV currently only ships >> 32-bit binaries. If you want 64-bit .pyd and .dll files, you have to >> compile them yourself. There are some >> instructionson the >> >> OpenCV Wiki, but it's not for the faint of heart. Expect to have a >> substantial time investment. >> >> The easiest solution is to: >> >> 1. Uninstall 64-bit Python >> 2. Install a 32-bit distribution. >> >> >> The PythonXY distribution includes pyopencv -- a good set of OpenCV hooks. >> The only limitation is that it's 32-bit, so don't make plans to process >> gigapixel astronomy data with it! ;) >> >> If you *must* have the 64-bit version, follow these >> >> instructionsto >> >> get it OpenCV to compile with Visual Studio 2010. There's a discussion >> on stackoverflow that describes building 64-bit apps with VC Express." >> >> >> And again, check on the pywin mailing list >> >> > > All very impressive, but as Dennis Lee Bieber has pointed out and which I > suspected there is a binary incompatibility between the OP's Python version > and pythonOCC version. DIdn't see this, I was too busy helping the OP search for an answer, and educate us both at the same time. Others would be able to see this for themselves but > you insist on sending email without context. Please don't do this. How are my emails without context? I'm referring the OP to the docs, as well as posts related to their question. It goes to use google, and RTFM, and putting it politely to them. I could summarize, but they have to do the real reading. I'm not researching this, and if I was, I'd charge for the time. This is to show that things can get complex if you don't use google, or read the docs. Why does the OP keep asking here, when there are answers out there. especially on the pywin list, which Windows users are usually referred to. Please point out what's out of context. The links and references place it into context if the OP finds them useful, and I believe I searched well for them. Would the OP like to tell me I wasn't helpful? Because now they're probably on a search to figure out how to make these compatible, which means more questions, and more reading. Plus the OP said he's on 64. Read the quote from stackoverflow: "I suspect you have the same problem I've run into. If you have a 64-bit version of Python, it cannot load 32-bit DLLs. OpenCV currently only ships 32-bit binaries. If you want 64-bit .pyd and .dll files, you have to compile them yourself. " A different program, but roughly the same in analogy, I do believe. And where in here was the OP referenced to the python docs on windows: >> http://docs.python.org/faq/windows.html Was that out of context as well? Let's not argue about this, I was pointing them to what I saw as the best possible resources to overcome his current problem, and it was all in context of the conversation as far as I'm concerned. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From wuwei23 at gmail.com Wed Sep 12 04:34:56 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 12 Sep 2012 01:34:56 -0700 (PDT) Subject: Which Version of Python? References: Message-ID: <236c2754-d656-4595-8364-7503ef7c15d6@q7g2000pbj.googlegroups.com> On 12 Sep, 16:31, Mark Lawrence wrote: > Perhaps this will sway youhttp://docs.python.org/dev/whatsnew/3.3.html > There is no longer an equivalent document for the Python 1.x or 2.x > series of releases. Perhaps not for 1.x but the 2.x series is still covered: http://docs.python.org/dev/whatsnew/index.html Actually, 1.6 is included here: http://www.python.org/download/releases/1.6.1/ From maniandram01 at gmail.com Wed Sep 12 04:41:56 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 12 Sep 2012 01:41:56 -0700 (PDT) Subject: Which Version of Python? In-Reply-To: <236c2754-d656-4595-8364-7503ef7c15d6@q7g2000pbj.googlegroups.com> References: <236c2754-d656-4595-8364-7503ef7c15d6@q7g2000pbj.googlegroups.com> Message-ID: On Wednesday, 12 September 2012 14:04:56 UTC+5:30, alex23 wrote: > On 12 Sep, 16:31, Mark Lawrence wrote: > > > Perhaps this will sway youhttp://docs.python.org/dev/whatsnew/3.3.html > > > There is no longer an equivalent document for the Python 1.x or 2.x > > > series of releases. > > > > Perhaps not for 1.x but the 2.x series is still covered: > > http://docs.python.org/dev/whatsnew/index.html > > > > Actually, 1.6 is included here: > > http://www.python.org/download/releases/1.6.1/ I think he meant the length of the document. From maniandram01 at gmail.com Wed Sep 12 04:42:56 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 12 Sep 2012 01:42:56 -0700 (PDT) Subject: Which Version of Python? In-Reply-To: References: <236c2754-d656-4595-8364-7503ef7c15d6@q7g2000pbj.googlegroups.com> Message-ID: On Wednesday, 12 September 2012 14:11:56 UTC+5:30, Ramchandra Apte wrote: > On Wednesday, 12 September 2012 14:04:56 UTC+5:30, alex23 wrote: > > > On 12 Sep, 16:31, Mark Lawrence wrote: > > > > > > > Perhaps this will sway youhttp://docs.python.org/dev/whatsnew/3.3.html > > > > > > > There is no longer an equivalent document for the Python 1.x or 2.x > > > > > > > series of releases. > > > > > > > > > > > > Perhaps not for 1.x but the 2.x series is still covered: > > > > > > http://docs.python.org/dev/whatsnew/index.html > > > > > > > > > > > > Actually, 1.6 is included here: > > > > > > http://www.python.org/download/releases/1.6.1/ > > > > I think he meant the length of the document. Sorry, Mark must have meant theres no "What's New" document of the same length (its very long). From joshua.landau.ws at gmail.com Wed Sep 12 05:55:58 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Wed, 12 Sep 2012 10:55:58 +0100 Subject: Double sided double underscored variable names In-Reply-To: References: <504fe1e7$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/09/2012, Chris Angelico wrote: > On Wed, Sep 12, 2012 at 11:38 AM, Joshua Landau > wrote: >> On 12 September 2012 02:14, Steven D'Aprano >> wrote: >>> >>> On Wed, 12 Sep 2012 08:52:10 +1000, Chris Angelico wrote: >>> >>> > Inline functions? I like this idea. I tend to want them in pretty much >>> > any language I write in. >>> >>> What do you mean by in-line functions? If you mean what you literally >>> say, I would answer that Python has that with lambda. >>> >>> But I guess you probably mean something more like macros. >> >> No, just multi-line lambda. Macros, if my knowledge of lower-level >> languages >> is valid, would be sorta' silly in Python. > > Ah, okay. I was thinking more along the lines of what you call macros, > but in the C++ sense of inline functions. In C, macros are handled at > precompilation stage, and are dangerous. Classic example: > > #define squared(x) x*x > > x_squared = squared(6+7) > > So your macros end up littered with parentheses, and it still doesn't > solve anything, as the argument still gets evaluated twice. (A problem > if it has side effects - eg if it's a function call.) > > What I'm thinking of, though, is like C++ functions. You can put the > 'inline' keyword onto any function, and the compiler will do its best > to inline it (in fact, a good optimizing compiler will inline things > regardless, but that's a separate point). I can write: > > inline int squared(int x) {return x*x;} > > and C++ will add no function overhead, but will still do all the > proper evaluation order etc. > > Of course, C++ doesn't allow monkeypatching, so you'll never have > semantic differences from inlining. It's just a performance question. > But I use inline functions like constants - for instance, I could > create a function that converts a database ID into an internal > reference number, and I can change the definition of that function in > one place and have it apply everywhere, just like if I wanted to > change the definition of math.PI to 3.142857 for fun one day. Of > course I can use a normal (out-of-line) function for this, but that > has overhead in most languages. Hence, wanting inline functions. Interesting. I'd overestimated macros and underestimated inline functions. I am not sure how to make a version of that with scope-compatibility. Inlining inline_def f(y): x = y +1 would hopefully not change the outside scope*, but I'm not sure how to make that. I could make it work by banning "=", but then it's almost a macro but with internal_a = input_a internal_b = input_b ... at the start... * If I understand rightly From andrea.crotti.0 at gmail.com Wed Sep 12 06:20:02 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 12 Sep 2012 11:20:02 +0100 Subject: forked processes and testing Message-ID: I wrote a decorator that takes a function, run it in a forked process and return the PID: def on_forked_process(func): from os import fork """Decorator that forks the process, runs the function and gives back control to the main process """ def _on_forked_process(*args, **kwargs): pid = fork() if pid == 0: func(*args, **kwargs) sys.exit(0) else: return pid return _on_forked_process It seems in general to work but I'm not able to test it, for example this fails: def test_on_forked_process(self): @utils.on_forked_process def _dummy_func(): pass with self.assertRaises(SystemExit): retpid = _dummy_func() # pid of the son process should be always > 0 self.assertTrue(retpid > 0) and I'm not sure why, nose doesn't like the Exit apparently even if it's happening in an unrelated proces.. Any idea of how to make it testable or improve it? In theory probably I will not use it for production because I should use something smarter to control the various processes I need to run, but for my integration tests it's quite useful, because then I can kill the processes like except KeyboardInterrupt: from os import kill from signal import SIGTERM print("Killing sink and worker") kill(sink_pid, SIGTERM) kill(worker_pid, SIGTERM) From j.m.dagenhart at gmail.com Wed Sep 12 06:22:31 2012 From: j.m.dagenhart at gmail.com (pyjoshsys) Date: Wed, 12 Sep 2012 03:22:31 -0700 (PDT) Subject: generators as decorators simple issue In-Reply-To: References: Message-ID: <3ffa457e-7836-46d0-8246-03b6bd90a025@googlegroups.com> The output is still not what I want. Now runtime error free, however the output is not what I desire. def setname(cls): '''this is the proposed generator to call SetName on the object''' try: cls.SetName(cls.__name__) except Exception as e: print e finally: return cls class Trial(object): '''class to demonstrate with''' def __init__(self): object.__init__(self) self.name = None @classmethod def SetName(cls, name): cls.name = name @setname class Test(Trial): '''i want SetName to be called by using setname as a decorator''' def __init__(self): Trial.__init__(self) if __name__ == '__main__': test = Test() print 'instance' print '', test.name #should be Test print 'class' print '', Test.name The output is: python decors2.py instance None class Test I want: instance Test class Test Is this possible in this manner? From oscar.j.benjamin at gmail.com Wed Sep 12 06:47:02 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 12 Sep 2012 11:47:02 +0100 Subject: generators as decorators simple issue In-Reply-To: <3ffa457e-7836-46d0-8246-03b6bd90a025@googlegroups.com> References: <3ffa457e-7836-46d0-8246-03b6bd90a025@googlegroups.com> Message-ID: On Wed, 12 Sep 2012 03:22:31 -0700 (PDT), pyjoshsys wrote: > The output is still not what I want. Now runtime error free, however the output is not what I desire. > def setname(cls): > '''this is the proposed generator to call SetName on the object''' > try: > cls.SetName(cls.__name__) > except Exception as e: > print e > finally: > return cls I would write the function above in one line: cls.name = name > class Trial(object): > '''class to demonstrate with''' > def __init__(self): > object.__init__(self) > self.name = None Remove the line above. The instance attribute self.name is hiding the class attribute cls.name. Oscar From python.list at tim.thechases.com Wed Sep 12 06:49:46 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 12 Sep 2012 05:49:46 -0500 Subject: Single leading dash in member variable names? In-Reply-To: References: <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> Message-ID: <505068CA.4050301@tim.thechases.com> On 09/12/12 00:10, Dwight Hutto wrote: > Not to jump in with another question(this seems somewhat relevant > to the conversation, maybe not), but is this similar to a > private,public, or protected class similar to the C type langs? Close, but C-like languages tend to strictly enforce it, while in Python it's more of a gentleman's agreement. Python doesn't *stop* you from mucking with them, but you've been advised that, if it breaks, you get to keep both parts. -tkc From pintooo15 at gmail.com Wed Sep 12 06:58:18 2012 From: pintooo15 at gmail.com (Diabolic Preacher) Date: Wed, 12 Sep 2012 16:28:18 +0530 Subject: SAP MM Cupertino, CA In-Reply-To: References: Message-ID: I really hoped for at least one mention of Python in there. Like 'knows how to use it to calculate numbers'. anything. Does GMail learn from Google Groups' spam reporting? Thanks > >> Please explain what does this have to do with Python. -- Diabolic Preacher As Is Blog: http://abusiveviews.wordpress.com/ Bookmarks: http://diigo.com/user/dpreacher From j.m.dagenhart at gmail.com Wed Sep 12 07:15:10 2012 From: j.m.dagenhart at gmail.com (pyjoshsys) Date: Wed, 12 Sep 2012 04:15:10 -0700 (PDT) Subject: generators as decorators simple issue In-Reply-To: References: Message-ID: so decorators only pass the object and not any instance of the object as the implied argument? Is this right? The idea was to use @setname instead of instance.SetName(instance.__name__). I thought decorators would do this, but it seems not. From dwightdhutto at gmail.com Wed Sep 12 07:20:58 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 12 Sep 2012 07:20:58 -0400 Subject: SAP MM Cupertino, CA In-Reply-To: References: Message-ID: Looks to me like someone recruiting experienced programmers, and there is a demographic here who would probably like a job like that. Definitely not considered SPAM by me. They're not selling, they're trying to gainfully employ a good programmer from a list meant to interact and learn. If I had enough business, this is one of the places I'd look as well. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Wed Sep 12 07:25:16 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 12 Sep 2012 07:25:16 -0400 Subject: SAP MM Cupertino, CA In-Reply-To: References: Message-ID: On Wed, Sep 12, 2012 at 6:58 AM, Diabolic Preacher wrote: > I really hoped for at least one mention of Python in there. It does seem like a blanketed letter to several groups, but maybe they're looking for any good programmer. Once you learn a language, and in my opinion learn to algorithm, then functionality/widget set to implement, you can do any of them. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From kushal.kumaran+python at gmail.com Wed Sep 12 07:31:05 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Wed, 12 Sep 2012 17:01:05 +0530 Subject: forked processes and testing In-Reply-To: References: Message-ID: On Wed, Sep 12, 2012 at 3:50 PM, andrea crotti wrote: > I wrote a decorator that takes a function, run it in a forked process > and return the PID: > > def on_forked_process(func): > from os import fork > """Decorator that forks the process, runs the function and gives > back control to the main process > """ > def _on_forked_process(*args, **kwargs): > pid = fork() > if pid == 0: > func(*args, **kwargs) > sys.exit(0) > else: > return pid > > return _on_forked_process > > It seems in general to work but I'm not able to test it, for example this fails: > > def test_on_forked_process(self): > @utils.on_forked_process > def _dummy_func(): > pass > > with self.assertRaises(SystemExit): > retpid = _dummy_func() > # pid of the son process should be always > 0 > self.assertTrue(retpid > 0) > > > and I'm not sure why, nose doesn't like the Exit apparently even if > it's happening in an unrelated proces.. > > Any idea of how to make it testable or improve it? > Use os._exit instead of sys.exit in your child process. Remember that fork creates a new process that is running the same code as the original process. In your case, the child process also has your test harness as the caller. sys.exit raises an exception that reaches the test harness in the child process, which interferes with your test run. > In theory probably I will not use it for production because I should > use something smarter to control the various processes I need to run, > but for my integration tests it's quite useful, because then I can > kill the processes like > > except KeyboardInterrupt: > from os import kill > from signal import SIGTERM > print("Killing sink and worker") > kill(sink_pid, SIGTERM) > kill(worker_pid, SIGTERM) > -- > http://mail.python.org/mailman/listinfo/python-list -- regards, kushal From jamie at kode5.net Wed Sep 12 08:12:49 2012 From: jamie at kode5.net (Jamie Paul Griffin) Date: Wed, 12 Sep 2012 13:12:49 +0100 Subject: Which Version of Python? In-Reply-To: References: Message-ID: <20120912121249.GA29312@kontrol.kode5.net> [ Ramchandra Apte wrote on Tue 11.Sep'12 at 19:58:29 -0700 ] > On Tuesday, 11 September 2012 22:19:08 UTC+5:30, Charles Hottel wrote: > > I have a lot of programming experience in many different languages and now > > > > I want to learn Python. Which version do you suggest I download, Python 2.x > > > > or Python 3.x ? Also why should I prefer one over the other? > > > > > > > > Right now I am thinkng Python 3.x as it has been out since 2008, but I have > > > > some concerns about backward compatibility with older packages that I might > > > > want to use. > > > > > > > > Thanks for your ideas and help. > > Use Python 3 because most packages support Python 3. Python 2.7 has many features that Python 3 has so it will require minimal effort to write Python 2.x code. When I first started to learn Python - about a year ago - I got myself a book which focuses on version 3 but is does also include Version 2. The author wrote that because a number of supporting libraries have not been updated to work in Python 3, and where "it is felt that the theory still needs to be expounded upon" Python 2.x will be used in lieu of Python 3. I personally, as a beginner, have found this approach helpful. Although, when this book was published Python 3.1 was the latest release, so of course since then said libraries most probably have been updated. So, as a fellow beginner i'd go for version 3.x. Jamie. From petef4+usenet at gmail.com Wed Sep 12 08:31:14 2012 From: petef4+usenet at gmail.com (Pete Forman) Date: Wed, 12 Sep 2012 13:31:14 +0100 Subject: Parsing ISO date/time strings - where did the parser go? References: Message-ID: <86txv3fmnh.fsf@gmail.com> John Nagle writes: > I want to parse standard ISO date/time strings such as > > 2012-09-09T18:00:00-07:00 > > into Python "datetime" objects. Consider whether RFC 3339 might be a more suitable format. It is a subset of ISO 8601 extended format. Some of the restrictions are Year must be 4 digits Fraction separator is period, not comma All components including time-offset are mandatory, except for time-secfrac time-minute in time-offset is not optional, must use ?hh:mm or Z Some latitude is allowed T may be replaced by e.g. space Extra feature time-offset of -00:00 means UTC but local time is unknown -- Pete Forman From librarama at gmail.com Wed Sep 12 08:48:09 2012 From: librarama at gmail.com (Libra) Date: Wed, 12 Sep 2012 05:48:09 -0700 (PDT) Subject: Boolean function on variable-length lists Message-ID: Hello, I need to implement a function that returns 1 only if all the values in a list satisfy given constraints (at least one constraint for each element in the list), and zero otherwise. For example, I may have a list L = [1, 2, 3, 4] and the following constraints: L[0] >= 1 L[1] <= 3 L[2] == 2 L[3] >= 3 In this case, the function returns 0 because the third constraint is not satisfied. With fixed-length lists, I can sometimes use a very naive approach and hard-code the constraints combined with AND. Nonetheless, the problems are: 1) even with fixed-length lists, the hard-code approach requires a lot of effort (especially with long lists) and is prone to error; 2) the constraints may change, so with a hard-code approach the effort grows exponentially; 3) I need to work on variable-length lists (generally, lists of numbers). I can't figure out anything useful. Could you please suggest me a suitable ways? Thanks Libra From jabba.laci at gmail.com Wed Sep 12 08:56:12 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Wed, 12 Sep 2012 14:56:12 +0200 Subject: avoid the redefinition of a function Message-ID: Hi, I have an installer script that contains lots of little functions. It has an interactive menu and the corresponding function is called. Over time it grew long and when I want to add a new function, I should give a unique name to that function. However, Python allows the redefinition of functions: #!/usr/bin/env python def step_1(): print 1 def step_1(): print 2 step_1() This will call the 2nd function. Now my functions are called step_ID (like step_27(), step_28(), etc.). How to avoid the danger of redefinition? Now, when I write a new function, I search for its name to see if it's unique but there must be a better way. Thanks, Laszlo P.S.: the script is here ( https://github.com/jabbalaci/jabbatron ) if you are interested. It's made for Ubuntu. From jpiitula at ling.helsinki.fi Wed Sep 12 09:02:44 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 12 Sep 2012 16:02:44 +0300 Subject: Boolean function on variable-length lists References: Message-ID: Libra writes: > Hello, > > I need to implement a function that returns 1 only if all the values > in a list satisfy given constraints (at least one constraint for > each element in the list), and zero otherwise. > > For example, I may have a list L = [1, 2, 3, 4] and the following > constraints: > L[0] >= 1 > L[1] <= 3 > L[2] == 2 > L[3] >= 3 > > In this case, the function returns 0 because the third constraint is > not satisfied. So you would associate each constraint with an index. You could maintain a list of constraints and apply it to the values as follows: >>> cs = [ lambda x : x >= 1, lambda x : x <= 3, lambda x : x == 2, ... lambda x : x >= 3 ] >>> { f(x) for f, x in zip(cs, [1,2,3,4]) } {False, True} >>> { f(x) for f, x in zip(cs, [1,2,2,4]) } {True} >>> Then map the return value to 0 if it contains a False, else to 1. From steve+comp.lang.python at pearwood.info Wed Sep 12 09:11:41 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Sep 2012 13:11:41 GMT Subject: Boolean function on variable-length lists References: Message-ID: <50508a0d$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Sep 2012 05:48:09 -0700, Libra wrote: > Hello, > > I need to implement a function that returns 1 only if all the values in > a list satisfy given constraints (at least one constraint for each > element in the list), and zero otherwise. What are the restrictions on the constraints themselves? Could they be arbitrarily complicated? "Item 2 must be an even number divisible by 17 and 39 with at least eight digits but no greater than four million, unless today is Tuesday, in which case it must be equal to six exactly." I'm going to assume you have a list of functions which take a single argument and then return True if it meets the constraint and False if it doesn't. Using your examples later: > For example, I may have a list L = [1, 2, 3, 4] and the following > constraints: > L[0] >= 1 > L[1] <= 3 > L[2] == 2 > L[3] >= 3 constraints = [ lambda x: x >= 1, lambda x: x <= 3, lambda x: x == 2, lambda x: x >= 3, ] ought to handle any reasonable constraint. Then use the zip() function to match up constraints with values, and all() to make sure they are all met. Since this sounds like homework, I won't give you the exact solution. If you still can't solve it, come back with your attempt and we'll give you a bit more help. -- Steven From maniandram01 at gmail.com Wed Sep 12 09:15:21 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 12 Sep 2012 06:15:21 -0700 (PDT) Subject: avoid the redefinition of a function In-Reply-To: References: Message-ID: <97ae2677-ef7c-424d-9c40-eaf47a50d475@googlegroups.com> On Wednesday, 12 September 2012 18:26:36 UTC+5:30, Jabba Laci wrote: > Hi, > > > > I have an installer script that contains lots of little functions. It > > has an interactive menu and the corresponding function is called. Over > > time it grew long and when I want to add a new function, I should give > > a unique name to that function. However, Python allows the > > redefinition of functions: > > > > #!/usr/bin/env python > > > > def step_1(): > > print 1 > > > > def step_1(): > > print 2 > > > > step_1() > > > > This will call the 2nd function. Now my functions are called step_ID > > (like step_27(), step_28(), etc.). How to avoid the danger of > > redefinition? Now, when I write a new function, I search for its name > > to see if it's unique but there must be a better way. > > > > Thanks, > > > > Laszlo > > P.S.: the script is here ( https://github.com/jabbalaci/jabbatron ) if > > you are interested. It's made for Ubuntu. Use a code checker such as PyLint (http://www.logilab.org/857 or pylint package). Better idea: I *strongly* recommend to never use names such as step_12. Use descriptive names and the problem will not occur. Your project looks interesting. I can contribute. :-) --- Bragging rights:SO account suspended py2c, a Python to *pure* C/C++ translator, is my project (I am the author) http://code.google.com/p/py2c/ From maniandram01 at gmail.com Wed Sep 12 09:15:21 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 12 Sep 2012 06:15:21 -0700 (PDT) Subject: avoid the redefinition of a function In-Reply-To: References: Message-ID: <97ae2677-ef7c-424d-9c40-eaf47a50d475@googlegroups.com> On Wednesday, 12 September 2012 18:26:36 UTC+5:30, Jabba Laci wrote: > Hi, > > > > I have an installer script that contains lots of little functions. It > > has an interactive menu and the corresponding function is called. Over > > time it grew long and when I want to add a new function, I should give > > a unique name to that function. However, Python allows the > > redefinition of functions: > > > > #!/usr/bin/env python > > > > def step_1(): > > print 1 > > > > def step_1(): > > print 2 > > > > step_1() > > > > This will call the 2nd function. Now my functions are called step_ID > > (like step_27(), step_28(), etc.). How to avoid the danger of > > redefinition? Now, when I write a new function, I search for its name > > to see if it's unique but there must be a better way. > > > > Thanks, > > > > Laszlo > > P.S.: the script is here ( https://github.com/jabbalaci/jabbatron ) if > > you are interested. It's made for Ubuntu. Use a code checker such as PyLint (http://www.logilab.org/857 or pylint package). Better idea: I *strongly* recommend to never use names such as step_12. Use descriptive names and the problem will not occur. Your project looks interesting. I can contribute. :-) --- Bragging rights:SO account suspended py2c, a Python to *pure* C/C++ translator, is my project (I am the author) http://code.google.com/p/py2c/ From python.list at tim.thechases.com Wed Sep 12 09:18:59 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 12 Sep 2012 08:18:59 -0500 Subject: Boolean function on variable-length lists In-Reply-To: References: Message-ID: <50508BC3.4090302@tim.thechases.com> On 09/12/12 08:02, Jussi Piitulainen wrote: > Libra writes: >> For example, I may have a list L = [1, 2, 3, 4] and the following >> constraints: >> L[0] >= 1 >> L[1] <= 3 >> L[2] == 2 >> L[3] >= 3 > > So you would associate each constraint with an index. You could > maintain a list of constraints and apply it to the values as follows: > >>>> cs = [ lambda x : x >= 1, lambda x : x <= 3, lambda x : x == 2, > ... lambda x : x >= 3 ] This can even be decoupled a bit more for dynamic creation: >>> lst = [1,2,3,4] >>> import operator as o >>> conditions = [ ... (o.ge, 1), ... (o.le, 3), ... (o.eq, 2), ... (o.ge, 3), ... ] >>> [op(v, constraint) for ((op, constraint), v) in zip(conditions, lst)] [True, True, False, True] >>> all(compare(value, constraint) for ((compare, constraint), value) in zip(conditions, lst)) False Note that you'd also want to check len(conditions)==len(lst) for obvious reasons. :-) -tkc From librarama at gmail.com Wed Sep 12 09:19:28 2012 From: librarama at gmail.com (Libra) Date: Wed, 12 Sep 2012 06:19:28 -0700 (PDT) Subject: Boolean function on variable-length lists In-Reply-To: References: Message-ID: On Wednesday, September 12, 2012 3:02:44 PM UTC+2, Jussi Piitulainen wrote: > So you would associate each constraint with an index. You could > maintain a list of constraints and apply it to the values as follows: Yes, even though there could be more constraints for each value in the list (at least 1 constraint for each value) > > >>> cs = [ lambda x : x >= 1, lambda x : x <= 3, lambda x : x == 2, > > ... lambda x : x >= 3 ] > > >>> { f(x) for f, x in zip(cs, [1,2,3,4]) } Just to understand, with f(x) you are defining a function f with argument x, right? I didn't know it was possible to define functions in this way. Is this a case of anonymous function? > {False, True} Actually, I don't understand the output. Why it is both False and True? > >>> { f(x) for f, x in zip(cs, [1,2,2,4]) } > {True} Ok. Thank you very much From librarama at gmail.com Wed Sep 12 09:25:35 2012 From: librarama at gmail.com (Libra) Date: Wed, 12 Sep 2012 06:25:35 -0700 (PDT) Subject: Boolean function on variable-length lists In-Reply-To: <50508a0d$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <50508a0d$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9a2374c4-6e82-4c92-a976-f9346c12b5a0@googlegroups.com> On Wednesday, September 12, 2012 3:11:42 PM UTC+2, Steven D'Aprano wrote: > On Wed, 12 Sep 2012 05:48:09 -0700, Libra wrote: > > I need to implement a function that returns 1 only if all the values in > > a list satisfy given constraints (at least one constraint for each > > element in the list), and zero otherwise. > > What are the restrictions on the constraints themselves? > Could they be arbitrarily complicated? > "Item 2 must be an even number divisible by 17 and 39 with at least eight > digits but no greater than four million, unless today is Tuesday, in > which case it must be equal to six exactly." Generally the constraints are quite simple, like the one in my example. But I can also have 2 or more constraints for each value: L[0] >= 1 L[0] <= 5 To complicate a little, what about constraints like: L[0] + L[2] >= 3 Thanks > -- > > Steven From ken at seehart.com Wed Sep 12 09:32:50 2012 From: ken at seehart.com (Ken Seehart) Date: Wed, 12 Sep 2012 06:32:50 -0700 Subject: avoid the redefinition of a function In-Reply-To: References: Message-ID: <50508F02.4010202@seehart.com> Use lambda expressions to define some constraints: gt = lambda x: lambda y: x>y eq = lambda x: lambda y: x==y constraints = [gt(2), eq(1)] data = [3,1] for i,c in enumerate(constraints): print c(data[i]) On 9/12/2012 5:56 AM, Jabba Laci wrote: > Hi, > > I have an installer script that contains lots of little functions. It > has an interactive menu and the corresponding function is called. Over > time it grew long and when I want to add a new function, I should give > a unique name to that function. However, Python allows the > redefinition of functions: > > #!/usr/bin/env python > > def step_1(): > print 1 > > def step_1(): > print 2 > > step_1() > > This will call the 2nd function. Now my functions are called step_ID > (like step_27(), step_28(), etc.). How to avoid the danger of > redefinition? Now, when I write a new function, I search for its name > to see if it's unique but there must be a better way. > > Thanks, > > Laszlo > P.S.: the script is here ( https://github.com/jabbalaci/jabbatron ) if > you are interested. It's made for Ubuntu. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3736 bytes Desc: S/MIME Cryptographic Signature URL: From librarama at gmail.com Wed Sep 12 09:33:18 2012 From: librarama at gmail.com (Libra) Date: Wed, 12 Sep 2012 06:33:18 -0700 (PDT) Subject: Boolean function on variable-length lists In-Reply-To: References: Message-ID: On Wednesday, September 12, 2012 3:19:28 PM UTC+2, Libra wrote: > > {False, True} > Actually, I don't understand the output. Why it is both False and True? Ok, I have understood now, I didn't noticed it was a set and not a list. Regards From jpiitula at ling.helsinki.fi Wed Sep 12 09:37:27 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 12 Sep 2012 16:37:27 +0300 Subject: Boolean function on variable-length lists References: Message-ID: Libra writes: > On Wednesday, September 12, 2012 3:02:44 PM UTC+2, Jussi Piitulainen wrote: > > > So you would associate each constraint with an index. You could > > maintain a list of constraints and apply it to the values as > > follows: > > Yes, even though there could be more constraints for each value in > the list (at least 1 constraint for each value) Either you write more complex constraint functions, or you use more complex data structures to hold them. > > >>> cs = [ lambda x : x >= 1, lambda x : x <= 3, lambda x : x == 2, > > > > ... lambda x : x >= 3 ] > > > > >>> { f(x) for f, x in zip(cs, [1,2,3,4]) } > > Just to understand, with f(x) you are defining a function f with > argument x, right? I didn't know it was possible to define functions > in this way. Is this a case of anonymous function? The value of each lambda expression is a function. f(x) is a function call, evaluated for each pair (f, x) from the list of pairs that the zip returns. { ... for ... in ... } creates a set of the values, no duplicates. [ ... for ... in ... ] creates a list of the values. > > {False, True} > > Actually, I don't understand the output. Why it is both False and > True? It's a set containing False and True. The False comes from the f(x) where f = lambda x : x == 2, and x is 3. There is only one True because I requested a set of the values. From oscar.j.benjamin at gmail.com Wed Sep 12 09:46:48 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 12 Sep 2012 14:46:48 +0100 Subject: Boolean function on variable-length lists In-Reply-To: <9a2374c4-6e82-4c92-a976-f9346c12b5a0@googlegroups.com> References: <50508a0d$0$29981$c3e8da3$5496439d@news.astraweb.com> <9a2374c4-6e82-4c92-a976-f9346c12b5a0@googlegroups.com> Message-ID: On 12 September 2012 14:25, Libra wrote: > On Wednesday, September 12, 2012 3:11:42 PM UTC+2, Steven D'Aprano wrote: > > On Wed, 12 Sep 2012 05:48:09 -0700, Libra wrote: > > > > I need to implement a function that returns 1 only if all the values in > > > a list satisfy given constraints (at least one constraint for each > > > element in the list), and zero otherwise. > > > > What are the restrictions on the constraints themselves? > > Could they be arbitrarily complicated? > > "Item 2 must be an even number divisible by 17 and 39 with at least eight > > digits but no greater than four million, unless today is Tuesday, in > > which case it must be equal to six exactly." > > Generally the constraints are quite simple, like the one in my example. > But I can also have 2 or more constraints for each value: > L[0] >= 1 > L[0] <= 5 > You can use: lambda x: 1 <= x and x <= 5 or lambda x: 1 <= x <= 5 > To complicate a little, what about constraints like: > L[0] + L[2] >= 3 You could rewrite all your constraints as functions on the sequence of values: lambda y: 1 <= y[0] <= 5 lambda y: y[0] + y[2] >= 3 If all of your constraints are linear (like all of the ones you have shown) then you can represent each one as a set of coefficients for a linear projection of the list combined with a threshold value (if this last point doesn't make sense then just ignore it). Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Wed Sep 12 09:51:44 2012 From: darcy at druid.net (D'Arcy Cain) Date: Wed, 12 Sep 2012 09:51:44 -0400 Subject: avoid the redefinition of a function In-Reply-To: References: Message-ID: <20120912095144.7fc445847d6f31a27945729d@druid.net> On Wed, 12 Sep 2012 14:56:12 +0200 Jabba Laci wrote: > This will call the 2nd function. Now my functions are called step_ID > (like step_27(), step_28(), etc.). How to avoid the danger of > redefinition? Now, when I write a new function, I search for its name > to see if it's unique but there must be a better way. I think your real problem is how you name your functions. Give them names that describe the operation that they do such as step_get_finagle, step_update_konkle, etc. It's harder to duplicate those unless you actually duplicate a function and it will make your code much easier to read. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From ken at seehart.com Wed Sep 12 09:51:46 2012 From: ken at seehart.com (Ken Seehart) Date: Wed, 12 Sep 2012 06:51:46 -0700 Subject: Boolean function on variable-length lists In-Reply-To: References: Message-ID: <50509372.3080001@seehart.com> Putting a few of peoples ideas together... gt = lambda x: lambda y: x>y eq = lambda x: lambda y: x==y def constrain(c,d): return all({f(x) for f, x in zip(c, d)}) constraints = [gt(2), eq(1)] data0 = [1,1] data1 = [3,1] print constrain(constraints, data0) print constrain(constraints, data1) On 9/12/2012 6:37 AM, Jussi Piitulainen wrote: > Libra writes: >> On Wednesday, September 12, 2012 3:02:44 PM UTC+2, Jussi Piitulainen wrote: >> >>> So you would associate each constraint with an index. You could >>> maintain a list of constraints and apply it to the values as >>> follows: >> Yes, even though there could be more constraints for each value in >> the list (at least 1 constraint for each value) > Either you write more complex constraint functions, or you use more > complex data structures to hold them. > >>>>>> cs = [ lambda x : x >= 1, lambda x : x <= 3, lambda x : x == 2, >>> ... lambda x : x >= 3 ] >>> >>>>>> { f(x) for f, x in zip(cs, [1,2,3,4]) } >> Just to understand, with f(x) you are defining a function f with >> argument x, right? I didn't know it was possible to define functions >> in this way. Is this a case of anonymous function? > The value of each lambda expression is a function. f(x) is a function > call, evaluated for each pair (f, x) from the list of pairs that the > zip returns. > > { ... for ... in ... } creates a set of the values, no duplicates. > [ ... for ... in ... ] creates a list of the values. > >>> {False, True} >> Actually, I don't understand the output. Why it is both False and >> True? > It's a set containing False and True. The False comes from the f(x) > where f = lambda x : x == 2, and x is 3. There is only one True > because I requested a set of the values. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3736 bytes Desc: S/MIME Cryptographic Signature URL: From torriem at gmail.com Wed Sep 12 09:52:15 2012 From: torriem at gmail.com (Michael Torrie) Date: Wed, 12 Sep 2012 07:52:15 -0600 Subject: avoid the redefinition of a function In-Reply-To: References: Message-ID: <5050938F.7030105@gmail.com> On 09/12/2012 06:56 AM, Jabba Laci wrote: > I have an installer script that contains lots of little functions. It > has an interactive menu and the corresponding function is called. Over > time it grew long and when I want to add a new function, I should give > a unique name to that function. However, Python allows the > redefinition of functions: > > #!/usr/bin/env python > > def step_1(): > print 1 > > def step_1(): > print 2 > > step_1() > > This will call the 2nd function. Now my functions are called step_ID > (like step_27(), step_28(), etc.). How to avoid the danger of > redefinition? Now, when I write a new function, I search for its name > to see if it's unique but there must be a better way. I don't understand the other poster's suggestion to your problem. I have looked at your script and think I understand how you are using them. Keep in mind that functions in python are just objects. So rather than define them as step_##() and then search the globals list for them, why not just define them as descriptive functions (for example, "install_java") and then put them into a list. For example: def install_java(): pass def install_tomcat(): pass steps = [install_java, install_tomcat, etc] # or steps.append(install_java) if steps already has stuff in it, etc # then: for step in steps: step() From alister.ware at ntlworld.com Wed Sep 12 10:04:13 2012 From: alister.ware at ntlworld.com (Alister) Date: Wed, 12 Sep 2012 14:04:13 GMT Subject: avoid the redefinition of a function References: <97ae2677-ef7c-424d-9c40-eaf47a50d475@googlegroups.com> Message-ID: On Wed, 12 Sep 2012 06:15:21 -0700, Ramchandra Apte wrote: > On Wednesday, 12 September 2012 18:26:36 UTC+5:30, Jabba Laci wrote: >> Hi, >> >> >> >> I have an installer script that contains lots of little functions. It >> >> has an interactive menu and the corresponding function is called. Over >> >> time it grew long and when I want to add a new function, I should give >> >> a unique name to that function. However, Python allows the >> >> redefinition of functions: >> >> >> >> #!/usr/bin/env python >> >> >> >> def step_1(): >> >> print 1 >> >> >> >> def step_1(): >> >> print 2 >> >> >> >> step_1() >> >> >> >> This will call the 2nd function. Now my functions are called step_ID >> >> (like step_27(), step_28(), etc.). How to avoid the danger of >> >> redefinition? Now, when I write a new function, I search for its name >> >> to see if it's unique but there must be a better way. >> >> >> >> Thanks, >> >> >> >> Laszlo >> >> P.S.: the script is here ( https://github.com/jabbalaci/jabbatron ) if >> >> you are interested. It's made for Ubuntu. > > Use a code checker such as PyLint (http://www.logilab.org/857 or pylint > package). > Better idea: > I *strongly* recommend to never use names such as step_12. Use > descriptive names and the problem will not occur. > Your project looks interesting. I can contribute. :-) > --- > Bragging rights:SO account suspended py2c, a Python to *pure* C/C++ > translator, is my project (I am the author) > http://code.google.com/p/py2c/ +1 Regards the Naming of your functions it makes it harder for new users to read & understand the code (and yourself in 6 months!) -- Overload -- core meltdown sequence initiated. From bamba777 at gmail.com Wed Sep 12 10:06:07 2012 From: bamba777 at gmail.com (bamba777 at gmail.com) Date: Wed, 12 Sep 2012 10:06:07 -0400 Subject: odt2sphinx 0.2.3 released In-Reply-To: <5048A1EB.1030701@gmail.com> Message-ID: <472E538F6F0D67A41F4EB895AA01E9B68C01EA11@traore-iphone> ??????? ?? > -----Original Message----- > From: "Christophe de Vienne" > Sent: Thu, 06 Sep 2012 15:15:23 +0200 > To: python-announce at python.org > Subject: odt2sphinx 0.2.3 released > > Hello, > > odt2sphinx 0.2.3 is now available on pypi : > > http://pypi.python.org/pypi/odt2sphinx/. > > Odt2sphinx convert OpenDocument Text file(s) to one or several .rst > files suitable for Sphinx. > > Changes > ------- > > * Fix filename generation by replacing any non-alphanumeric > character (issue #3). > > * Fix handling of non-styled lists. > > > Regards, > > Christophe de Vienne > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ > Sent using Eatoni's Triage app for iPhone and iPad. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dkatorza at gmail.com Wed Sep 12 10:24:46 2012 From: dkatorza at gmail.com (dkatorza at gmail.com) Date: Wed, 12 Sep 2012 07:24:46 -0700 (PDT) Subject: using text file to get ip address from hostname Message-ID: hello , i'm new to Python and i searched the web and could not find an answer for my issue. i need to get an ip address from list of hostnames which are in a textfile. this is what i have so far -------------------------------------------------------------------------- #!/usr/bin/env python #Get the IP Address import socket hostname = 'need it to read from a text file' addr = socket.gethostbyname(hostname) print 'The address of ', hostname, 'is', addr --------------------------------------------------------------------------- any idea ? sorry for my english thanks. From breamoreboy at yahoo.co.uk Wed Sep 12 10:29:49 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 12 Sep 2012 15:29:49 +0100 Subject: Boolean function on variable-length lists In-Reply-To: <50509372.3080001@seehart.com> References: <50509372.3080001@seehart.com> Message-ID: On 12/09/2012 14:51, Ken Seehart wrote: [snip] Could you please not top post on this list, thanks. -- Cheers. Mark Lawrence. From rosuav at gmail.com Wed Sep 12 10:35:30 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Sep 2012 00:35:30 +1000 Subject: using text file to get ip address from hostname In-Reply-To: References: Message-ID: On Thu, Sep 13, 2012 at 12:24 AM, wrote: > i'm new to Python and i searched the web and could not find an answer for my issue. > > i need to get an ip address from list of hostnames which are in a textfile. This is sounding like homework, so I'll just give you a basic pointer. You have there something that successfully resolves one hostname to an IP address. Now you want to expand that to reading an entire file of them and resolving them all. Presumably you need to produce a list of IP addresses; check the question as to whether you need to create a file, or output to the screen, or something else. What you want, here, is to open a file and iterate over it. The most convenient way would be to have one hostname per line and iterate over the lines of the file. Check out these pages in the Python docs (you're using Python 2 so I'm going with Python 2.7.3 documentation): Opening a file: http://docs.python.org/library/functions.html#open Ensuring that it'll be closed when you're done: http://docs.python.org/reference/compound_stmts.html#the-with-statement Looping over an iterable: http://docs.python.org/tutorial/controlflow.html#for-statements See where that takes you; in fact, all of http://docs.python.org/tutorial/ is worth reading, if you haven't already. Have fun, enjoy Python! ChrisA From dkatorza at gmail.com Wed Sep 12 10:41:10 2012 From: dkatorza at gmail.com (dkatorza at gmail.com) Date: Wed, 12 Sep 2012 07:41:10 -0700 (PDT) Subject: using text file to get ip address from hostname In-Reply-To: References: Message-ID: ?????? ??? ?????, 12 ??????? 2012 17:24:50 UTC+3, ??? dkat... at gmail.com: > hello , > > > > i'm new to Python and i searched the web and could not find an answer for my issue. > > > > i need to get an ip address from list of hostnames which are in a textfile. > > > > this is what i have so far > > -------------------------------------------------------------------------- > > #!/usr/bin/env python > > #Get the IP Address > > > > import socket > > hostname = 'need it to read from a text file' > > addr = socket.gethostbyname(hostname) > > print 'The address of ', hostname, 'is', addr > > > > --------------------------------------------------------------------------- > > > > any idea ? > > sorry for my english > > > > thanks. thank you ChrisA it's not really homework, i found a lab exercise on the web and i;m trying to study with it. maybe not the most efficient way. i have a file with hostnames ordered line by line. i will check the sources and will get back with outcome. once again , Thanks, From ian.g.kelly at gmail.com Wed Sep 12 11:09:08 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 12 Sep 2012 09:09:08 -0600 Subject: generators as decorators simple issue In-Reply-To: <3ffa457e-7836-46d0-8246-03b6bd90a025@googlegroups.com> References: <3ffa457e-7836-46d0-8246-03b6bd90a025@googlegroups.com> Message-ID: On Wed, Sep 12, 2012 at 4:22 AM, pyjoshsys wrote: > The output is still not what I want. Now runtime error free, however the output is not what I desire. [SNIP] > class Trial(object): > '''class to demonstrate with''' > def __init__(self): > object.__init__(self) > self.name = None > > @classmethod > def SetName(cls, name): > cls.name = name [SNIP] > if __name__ == '__main__': > test = Test() > print 'instance' > print '', test.name #should be Test > print 'class' > print '', Test.name > > > The output is: python decors2.py > instance > None > class > Test > > I want: > instance > Test > class > Test > > Is this possible in this manner? The SetName class method sets the name on the *class* dictionary. The class's __init__ method also sets a name (None) on the *instance* dictionary. From an instance's perspective, the instance dictionary will shadow the class dictionary. If you remove the attribute from the instance dictionary entirely (delete the "self.name = None" line), and leave the class dictionary as is, then you will get the output you want (although from your later post I am not certain that this is the behaviour you want). On Wed, Sep 12, 2012 at 5:15 AM, pyjoshsys wrote: > so decorators only pass the object and not any instance of the object as the implied argument? Is this right? Right. > The idea was to use @setname instead of instance.SetName(instance.__name__). The appropriate place to do this so that it applies to all instances of the class rather than to the class would be inside the __init__ method. Also, instances don't have a __name__ attribute, so it's still unclear to me what you're looking for. Did you mean the effect to be that of "instance.SetName(cls.__name__)"? If so, then the decorator approach (with the line "self.name = None" removed) should be fine for your purposes -- you'll just have the name stored in the class dict instead of in each instance dict, but it will still be visible as long as you haven't shadowed it. From jelleferinga at gmail.com Wed Sep 12 11:12:55 2012 From: jelleferinga at gmail.com (jelle) Date: Wed, 12 Sep 2012 08:12:55 -0700 (PDT) Subject: pythonOCC examples doesn't work? In-Reply-To: References: Message-ID: <499af0e3-cfbd-49cd-89c7-c7cea015a5c5@googlegroups.com> You installed python 2.7 and expect a 2.6 module to work with it. That won't work. Finally, you need to install the OpenCasCade libs to be able to run PythonOCC. -jelle From dustin at v.igoro.us Wed Sep 12 11:14:34 2012 From: dustin at v.igoro.us (Dustin J. Mitchell) Date: Wed, 12 Sep 2012 11:14:34 -0400 Subject: odt2sphinx 0.2.3 released In-Reply-To: <472E538F6F0D67A41F4EB895AA01E9B68C01EA11@traore-iphone> References: <5048A1EB.1030701@gmail.com> <472E538F6F0D67A41F4EB895AA01E9B68C01EA11@traore-iphone> Message-ID: On Wed, Sep 12, 2012 at 10:06 AM, wrote: > ?????????????? ? ?? And that's why you shouldn't let your kids play with your iPad :) Dustin From e.doxtator at gmail.com Wed Sep 12 11:23:49 2012 From: e.doxtator at gmail.com (e.doxtator at gmail.com) Date: Wed, 12 Sep 2012 08:23:49 -0700 (PDT) Subject: Single leading dash in member variable names? In-Reply-To: References: <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> Message-ID: On Tuesday, September 11, 2012 5:02:31 PM UTC-5, Erik Max Francis wrote: > On 09/11/2012 01:53 PM, me wrote: > > > On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote: > > >> On Tue, Sep 11, 2012 at 12:45 PM, I wrote: > > >>> What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it. > > >> > > >> Single leading underscore is a convention indicating that the name > > >> should be considered private and not used externally. It's a softer > > >> version of the double leading underscore that means basically the same > > >> thing but has syntactic significance. > > > > > > Thank you! > > > > > > PEP 8 says this is bad form. What do you think? > > > > Where does it say that? Apologies. It's in David Goodger's "Code Like A Pythonista" in the "Naming" section. (http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#naming) From ian.g.kelly at gmail.com Wed Sep 12 11:23:58 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 12 Sep 2012 09:23:58 -0600 Subject: Single leading dash in member variable names? In-Reply-To: References: <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> Message-ID: On Tue, Sep 11, 2012 at 11:10 PM, Dwight Hutto wrote: > Not to jump in with another question(this seems somewhat relevant to the > conversation, maybe not), but is this similar to a private,public, or > protected class similar to the C type langs? More like "this is an implementation detail and in the future it could be changed or removed entirely without warning". I consider them private unless documented otherwise. From janis.judvaitis at gmail.com Wed Sep 12 11:26:34 2012 From: janis.judvaitis at gmail.com (janis.judvaitis at gmail.com) Date: Wed, 12 Sep 2012 08:26:34 -0700 (PDT) Subject: using subprocess.Popen does not suppress terminal window on Windows In-Reply-To: <9dc66012-988e-4581-aaab-169dbadbbf93@35g2000vbj.googlegroups.com> References: <9dc66012-988e-4581-aaab-169dbadbbf93@35g2000vbj.googlegroups.com> Message-ID: Hi, and I'm sorry for using this old thread, but I'm experiencing the same problem, except, that I wan't to execute any shell script or exe without blank terminal window. Is there any way in python to supress blank console screen while script is executing? Multiplatform solution would be nice. With best regards, J?nis. On Friday, June 18, 2010 7:23:19 PM UTC+3, Steven wrote: > I am calling a ruby program from a python gui and using > subprocess.Popen in Windows XP using python 2.6. Unfortunately, > whenever the ruby program is called a blank command window appears on > screen, annoying my users. Is there a way to suppress this behaviour? > > Below is a minimal program that demonstrates the problem. The problem > does not manifest if the python program is launched via the command > line. To duplicate launch from Windows Explorer by double-clicking on > the python file. > > --- call_double.pyw --- > from subprocess import * > import time > > time.sleep(3) # to show that command window is result of call to Popen > p = Popen(['ruby.exe', 'double.rb'], stdin=PIPE, stdout=PIPE, > stderr=PIPE) > results = open('results.txt', 'w') > for n in range(10): > p.stdin.write("%d\n" % n) > result = p.stdout.readline().strip() > results.write('double(%s) => %2s\n' % (n, result)) > results.close() > > --- end of call_double.pyw --- > > --- double.rb --- > while true > puts $stdin.gets().strip!.to_i * 2 > STDOUT.flush > end > --- end of double.rb --- > > thanks for any help, > Steven Rumbalski I From giacomo.alzetta at gmail.com Wed Sep 12 11:54:29 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Wed, 12 Sep 2012 08:54:29 -0700 (PDT) Subject: Add a "key" parameter to bisect* functions? Message-ID: <498c7e5a-6bf9-4413-9672-77f74649cb68@googlegroups.com> I've just noticed that the bisect module lacks of the key parameter. The documentation points to a recipe that could be used to handle a sorted collection, but I think it's an overkill if I want to bisect my sequence only once or twice with a key. Having something like `bisect(sequence, key=my_key)` would be much easier and would conform to the other operations such as max/min/sorted. Is there some reason behind this lack? From python at mrabarnett.plus.com Wed Sep 12 11:55:40 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Sep 2012 16:55:40 +0100 Subject: Boolean function on variable-length lists In-Reply-To: <50509372.3080001@seehart.com> References: <50509372.3080001@seehart.com> Message-ID: <5050B07C.60507@mrabarnett.plus.com> On 12/09/2012 14:51, Ken Seehart wrote: > Putting a few of peoples ideas together... > > > gt = lambda x: lambda y: x>y > eq = lambda x: lambda y: x==y > > def constrain(c,d): > return all({f(x) for f, x in zip(c, d)}) > If you're going to use 'all', why use a set? return all(f(x) for f, x in zip(c, d)) This will stop as soon as a constraint fails. > constraints = [gt(2), eq(1)] > data0 = [1,1] > data1 = [3,1] > > print constrain(constraints, data0) > print constrain(constraints, data1) > From miki.tebeka at gmail.com Wed Sep 12 12:01:57 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 12 Sep 2012 09:01:57 -0700 (PDT) Subject: Creating socket.connect while in epoll loop Message-ID: Greetings, I'm trying to write a reverse TCP proxy using epoll (just for learning). I've started with the code at http://scotdoyle.com/python-epoll-howto.html and got to https://gist.github.com/3707665. However, I can't create a new connection. When reaching line 34 (backend.connect), I get the following error (on line 34): socket.error: [Errno 115] Operation now in progress I tried moving the socket creation to a different thread, but same problem. Any ideas how to so fix this? (keep in mind I'm a total newbie in this area). Thanks, -- Miki From giacomo.alzetta at gmail.com Wed Sep 12 12:03:55 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Wed, 12 Sep 2012 09:03:55 -0700 (PDT) Subject: Add a "key" parameter to bisect* functions? In-Reply-To: <498c7e5a-6bf9-4413-9672-77f74649cb68@googlegroups.com> References: <498c7e5a-6bf9-4413-9672-77f74649cb68@googlegroups.com> Message-ID: <3db43e76-4534-41e4-85ad-f15cfc057d8b@googlegroups.com> Il giorno mercoled? 12 settembre 2012 17:54:31 UTC+2, Giacomo Alzetta ha scritto: > I've just noticed that the bisect module lacks of the key parameter. > > > > The documentation points to a recipe that could be used to handle a sorted collection, but I think it's an overkill if I want to bisect my sequence only once or twice with a key. Having something like `bisect(sequence, key=my_key)` would be much easier and would conform to the other operations such as max/min/sorted. > > > > Is there some reason behind this lack? Uhm, I've found this piece of documentation: http://docs.python.org/library/bisect.html#other-examples Now, what it's stated there does not make sense for me: 1) Adding a key/reversed parameter wont decrease the speed of calls to bisect that does not use those parameters. At least a good implementation should guarantee that 2) Yes, providing a key means that either bisect should do some caching in order to speed multiple look-ups, or the keys have to be recomputed every time. But, I think that using this as a reason to not provide this parameter is wrong. It's up to the user to decide what has to be done to make code fast. If he has to do multiple lookups then he should precompute them(but this is true also for sort etc.), but if he just has to use this feature once than computing "on-the-fly" is simply perfect. 3) Also, the fact that you can bisect only in asceding order sounds strange to me. It's not hard to bisect in both directions... Probably it would be correct to document possible pitfalls of using the eventually added "key" and "reversed" parameters(such as multiple key evaluation etc.), but I can't see other cons to this. Also, this change would be 100% backward compatible. From miki.tebeka at gmail.com Wed Sep 12 12:05:09 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 12 Sep 2012 09:05:09 -0700 (PDT) Subject: Add a "key" parameter to bisect* functions? In-Reply-To: <498c7e5a-6bf9-4413-9672-77f74649cb68@googlegroups.com> References: <498c7e5a-6bf9-4413-9672-77f74649cb68@googlegroups.com> Message-ID: > I've just noticed that the bisect module lacks of the key parameter. > ... > Is there some reason behind this lack? See full discussion at http://bugs.python.org/issue4356. Guido said it's going in, however there's no time frame for it. From davidgshi at yahoo.co.uk Wed Sep 12 12:15:14 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Wed, 12 Sep 2012 17:15:14 +0100 (BST) Subject: Python-list Digest, Vol 108, Issue 98 In-Reply-To: References: Message-ID: <1347466514.83894.YahooMailNeo@web133205.mail.ir2.yahoo.com> Hi, Where do I find ArcPy.py? It seems that the link disappeared. Regards. David -------------- next part -------------- An HTML attachment was scrubbed... URL: From giacomo.alzetta at gmail.com Wed Sep 12 12:22:12 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Wed, 12 Sep 2012 09:22:12 -0700 (PDT) Subject: Add a "key" parameter to bisect* functions? In-Reply-To: References: <498c7e5a-6bf9-4413-9672-77f74649cb68@googlegroups.com> Message-ID: Il giorno mercoled? 12 settembre 2012 18:05:10 UTC+2, Miki Tebeka ha scritto: > > I've just noticed that the bisect module lacks of the key parameter. > > > ... > > > Is there some reason behind this lack? > > See full discussion at http://bugs.python.org/issue4356. Guido said it's going in, however there's no time frame for it. Oh, nice. So eventually it'll be added. Correct me if I'm wrong, but the reason for this absence is that people could think that doing repeated bisects using keys would be fast, even though keys has to be recomputed? I think that could simply be fixed with a "Note:\Warning:" on the documentation. So that you can create keys with caching or use precomputed keys when you have to do a lot of bisects. From ian.g.kelly at gmail.com Wed Sep 12 12:52:21 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 12 Sep 2012 10:52:21 -0600 Subject: Single leading dash in member variable names? In-Reply-To: References: <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> Message-ID: On Wed, Sep 12, 2012 at 9:23 AM, wrote: > > On Tuesday, September 11, 2012 5:02:31 PM UTC-5, Erik Max Francis wrote: > > On 09/11/2012 01:53 PM, me wrote: > > > PEP 8 says this is bad form. What do you think? > > > > > > > > Where does it say that? > > Apologies. It's in David Goodger's "Code Like A Pythonista" in the "Naming" section. (http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#naming) That's arguing against double leading underscore, not single leading underscore. I pretty much agree with it; I rarely use the name-mangling syntax myself. From mdengler at gmail.com Wed Sep 12 12:53:07 2012 From: mdengler at gmail.com (mdengler at gmail.com) Date: Wed, 12 Sep 2012 09:53:07 -0700 (PDT) Subject: Single leading dash in member variable names? In-Reply-To: References: <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> Message-ID: <159d0e9d-6fb5-41ba-a1e9-def00f5493a7@googlegroups.com> On Wednesday, September 12, 2012 4:23:49 PM UTC+1, (unknown) wrote: > [...] David Goodger's "Code Like A Pythonista" in the "Naming" section [says single leading underscore is bad form]. (http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#naming) Looks like it says the opposite: "[rather than trying to hide attributes with double-leading-underscores, i]t's better to use the single-leading-underscore convention, _internal". From jabba.laci at gmail.com Wed Sep 12 12:56:46 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Wed, 12 Sep 2012 18:56:46 +0200 Subject: avoid the redefinition of a function In-Reply-To: <5050938F.7030105@gmail.com> References: <5050938F.7030105@gmail.com> Message-ID: > For example: > > def install_java(): > pass > > def install_tomcat(): > pass Thanks for the answers. I decided to use numbers in the name of the functions to facilitate function calls. Now if you have this menu option for instance: (5) install mc You can type just "5" as user input and step_5() is called automatically. If I use descriptive names like install_java() then selecting a menu point would be more difficult. And I don't want users to type "java", I want to stick to simple numbers. Laszlo From jayden.shui at gmail.com Wed Sep 12 13:03:31 2012 From: jayden.shui at gmail.com (Jayden) Date: Wed, 12 Sep 2012 10:03:31 -0700 (PDT) Subject: pythonOCC examples doesn't work? In-Reply-To: <499af0e3-cfbd-49cd-89c7-c7cea015a5c5@googlegroups.com> References: <499af0e3-cfbd-49cd-89c7-c7cea015a5c5@googlegroups.com> Message-ID: <3263eed9-241d-4031-8ee4-6406d999773f@googlegroups.com> On Wednesday, September 12, 2012 11:12:55 AM UTC-4, jelle wrote: > You installed python 2.7 and expect a 2.6 module to work with it. > > That won't work. Finally, you need to install the OpenCasCade libs to be able to run PythonOCC. > > > > -jelle I think that is the reason. Thanks a lot!! From miki.tebeka at gmail.com Wed Sep 12 13:24:42 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 12 Sep 2012 10:24:42 -0700 (PDT) Subject: Add a "key" parameter to bisect* functions? In-Reply-To: References: <498c7e5a-6bf9-4413-9672-77f74649cb68@googlegroups.com> Message-ID: <75dbbe23-6aeb-4c39-a454-174c8ebf78f6@googlegroups.com> > Correct me if I'm wrong, but the reason for this absence is that people could > think that doing repeated bisects using keys would be fast, even though keys > has to be recomputed? I think the main point Raymond had was: If we added key= to bisect, it would encourage bad design and steer people after from better solutions. But you need to ask him :) From python.list at tim.thechases.com Wed Sep 12 13:34:06 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 12 Sep 2012 12:34:06 -0500 Subject: avoid the redefinition of a function In-Reply-To: References: <5050938F.7030105@gmail.com> Message-ID: <5050C78E.2070706@tim.thechases.com> On 09/12/12 11:56, Jabba Laci wrote: >> For example: >> >> def install_java(): >> pass >> >> def install_tomcat(): >> pass > > Thanks for the answers. I decided to use numbers in the name of the > functions to facilitate function calls. Now if you have this menu > option for instance: > > (5) install mc > > You can type just "5" as user input and step_5() is called > automatically. If I use descriptive names like install_java() then > selecting a menu point would be more difficult. And I don't want users > to type "java", I want to stick to simple numbers. You can do something like the below that I tossed together in a couple minutes. It sniffs for globals callables (usually functions, though could be objects with a __call__ method) that are named "install_*" and then maps the user's numeric answer to the corresponding function and calls it. -tkc import sys PREFIX = "install_" def install_java(*args, **kwargs): print "Java!" def install_tomcat(*args, **kwargs): print "Tomcat!" def install_mc(*args, **kwargs): print "mc!" def install_exit(*args, **kwargs): sys.exit(0) functions = [ (name, value) for name, value in sorted(globals().items()) if name.startswith(PREFIX) and callable(value) ] dispatch = dict( (i+1, value) for i, (name, value) in enumerate(functions) ) for i, (name, value) in enumerate(functions): print("%i) %s" % (i+1, name[len(PREFIX):])) while True: choice = raw_input("Choose to install/quit: ") try: i = int(choice) except: continue if i in dispatch: dispatch[i]("some args") else: print("Please choose a valid option") From alister.ware at ntlworld.com Wed Sep 12 13:51:35 2012 From: alister.ware at ntlworld.com (Alister) Date: Wed, 12 Sep 2012 17:51:35 GMT Subject: using text file to get ip address from hostname References: Message-ID: On Wed, 12 Sep 2012 07:41:10 -0700, dkatorza wrote: > ?????? ??? ?????, 12 ??????? 2012 17:24:50 UTC+3, ??? dkat... at gmail.com: >> hello , >> >> >> >> i'm new to Python and i searched the web and could not find an answer >> for my issue. >> >> >> >> i need to get an ip address from list of hostnames which are in a >> textfile. >> >> >> >> this is what i have so far >> >> -------------------------------------------------------------------------- >> >> #!/usr/bin/env python >> >> #Get the IP Address >> >> >> >> import socket >> >> hostname = 'need it to read from a text file' >> >> addr = socket.gethostbyname(hostname) >> >> print 'The address of ', hostname, 'is', addr >> >> >> >> --------------------------------------------------------------------------- >> >> >> >> any idea ? >> >> sorry for my english >> >> >> >> thanks. > > thank you ChrisA it's not really homework, i found a lab exercise on the > web and i;m trying to study with it. maybe not the most efficient way. > > i have a file with hostnames ordered line by line. > > i will check the sources and will get back with outcome. > > once again , Thanks, so self inflicted homework :-), a good way to learn so ChrisA's pointers of where to look are probably the best thing for you. if you get stuck post back sample code & i am sure someone will be happy to hint a little deeper Good luck -- QOTD: "Wouldn't it be wonderful if real life supported control-Z?" From alister.ware at ntlworld.com Wed Sep 12 14:04:51 2012 From: alister.ware at ntlworld.com (Alister) Date: Wed, 12 Sep 2012 18:04:51 GMT Subject: avoid the redefinition of a function References: <5050938F.7030105@gmail.com> Message-ID: <7944s.27167$CU7.24982@fx02.am4> On Wed, 12 Sep 2012 18:56:46 +0200, Jabba Laci wrote: >> For example: >> >> def install_java(): >> pass >> >> def install_tomcat(): >> pass > > Thanks for the answers. I decided to use numbers in the name of the > functions to facilitate function calls. Now if you have this menu option > for instance: > > (5) install mc > > You can type just "5" as user input and step_5() is called > automatically. If I use descriptive names like install_java() then > selecting a menu point would be more difficult. And I don't want users > to type "java", I want to stick to simple numbers. > > Laszlo No No NO! you cant just pass user input to system calls without validating it first (google sql injection for examples of the damage unsanitised input can cause, it is not just as SQL problem) it is just as easy so select a reasonably named function as a bad one option=raw_input('select your option :') if option =="1": install_java() if option =="2": install_other() alternatively you cold add your functions into a dictionary an call them from that opts={'1':install java,'2':install_other} option=raw_input('select your option :') opts[option] Poorly named functions are a major example of poor programming style. one of the fundamental pillars for python is readability! -- He's a about half the size of the others. But he's got a chainsaw. From python at mrabarnett.plus.com Wed Sep 12 14:33:12 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Sep 2012 19:33:12 +0100 Subject: avoid the redefinition of a function In-Reply-To: <7944s.27167$CU7.24982@fx02.am4> References: <5050938F.7030105@gmail.com> <7944s.27167$CU7.24982@fx02.am4> Message-ID: <5050D568.9050208@mrabarnett.plus.com> On 12/09/2012 19:04, Alister wrote: > On Wed, 12 Sep 2012 18:56:46 +0200, Jabba Laci wrote: > >>> For example: >>> >>> def install_java(): >>> pass >>> >>> def install_tomcat(): >>> pass >> >> Thanks for the answers. I decided to use numbers in the name of the >> functions to facilitate function calls. Now if you have this menu option >> for instance: >> >> (5) install mc >> >> You can type just "5" as user input and step_5() is called >> automatically. If I use descriptive names like install_java() then >> selecting a menu point would be more difficult. And I don't want users >> to type "java", I want to stick to simple numbers. >> >> Laszlo > > No No NO! > you cant just pass user input to system calls without validating it first > (google sql injection for examples of the damage unsanitised input can > cause, it is not just as SQL problem) > > it is just as easy so select a reasonably named function as a bad one > > option=raw_input('select your option :') > > if option =="1": install_java() > if option =="2": install_other() > > alternatively you cold add your functions into a dictionary an call them > from that > > opts={'1':install java,'2':install_other} > > option=raw_input('select your option :') > opts[option] > > Poorly named functions are a major example of poor programming style. > > one of the fundamental pillars for python is readability! > Or you could do this: def install_java(): "Install Java" print "Installing Java" def install_tomcat(): "Install Tomcat" print "Installing Tomcat" menu = [install_java, install_tomcat] for index, func in enumerate(menu, start=1): print "{0}) {1}".format(index, func.__doc__) option = raw_input("Select your option : ") try: opt = int(option) except ValueError: print "Not a valid option" else: if 1 <= opt < len(menu): menu[opt - 1]() else: print "Not a valid option" From sanith.recruiter at gmail.com Wed Sep 12 14:51:12 2012 From: sanith.recruiter at gmail.com (Sanith Nair) Date: Wed, 12 Sep 2012 11:51:12 -0700 (PDT) Subject: Java Python Developer Required at NYC NY Message-ID: <3f47b773-3f83-4bf0-ae0d-90b8a9dc3293@googlegroups.com> Hi, I am looking for a Java Python developer at NYC NY for one of our direct client. It is a 6 Months contract position. We need a person with experience in developing trading applications and very good with Python Development. If interested, please send me your resume to my email address, ie Sanith_Nair at artechinfo.com Thanks Sanith Nair Lead Recruiter Artech Information Systems LLC 240 Cedar Knolls Road, Suite 100 | Cedar Knolls, NJ 07927 Office: 973.967.3522 | Fax: 973.998.2599 Email: Sanith_Nair at artechinfo.com | Website: www.artechinfo.com From calderone.jeanpaul at gmail.com Wed Sep 12 14:53:56 2012 From: calderone.jeanpaul at gmail.com (calderone.jeanpaul at gmail.com) Date: Wed, 12 Sep 2012 11:53:56 -0700 (PDT) Subject: Creating socket.connect while in epoll loop In-Reply-To: References: Message-ID: <5dea64eb-0033-4be4-858f-9d930955ef51@googlegroups.com> On Wednesday, September 12, 2012 12:01:58 PM UTC-4, Miki Tebeka wrote: > Greetings, > > I'm trying to write a reverse TCP proxy using epoll (just for learning). > > I've started with the code at http://scotdoyle.com/python-epoll-howto.html and got to https://gist.github.com/3707665. > > > However, I can't create a new connection. When reaching line 34 (backend.connect), I get the following error (on line 34): > > socket.error: [Errno 115] Operation now in progress > You cannot synchronously set up a new TCP connection using a non-blocking socket. Instead, you begin the connection attempt and it fails with EINPROGRESS and then you use epoll to find out when the attempt completes. I suggest reading the implementation of a Twisted reactor to see an example of how this is done. Here are a couple links to get you started: http://twistedmatrix.com/trac/browser/trunk/twisted/internet/tcp.py http://twistedmatrix.com/trac/browser/trunk/twisted/internet/epollreactor.py Jean-Paul > > > I tried moving the socket creation to a different thread, but same problem. > > Any ideas how to so fix this? (keep in mind I'm a total newbie in this area). > > > > Thanks, > > -- > > Miki From Sanith_Nair at artechinfo.com Wed Sep 12 14:58:12 2012 From: Sanith_Nair at artechinfo.com (Sanith_Nair at artechinfo.com) Date: Wed, 12 Sep 2012 14:58:12 -0400 Subject: Java Python Developer Required at NYC NY Message-ID: Hi, I am looking for a Java Python developer at NYC NY for one of our direct client. It is a 6 Months contract position. We need a person with experience in developing trading applications and very good with Python Development. If interested, please send me your resume to my email address, ie Sanith_Nair at artechinfo.com Thanks Sanith Nair Lead Recruiter Artech Information Systems LLC 240 Cedar Knolls Road, Suite 100 | Cedar Knolls, NJ 07927 Office: 973.967.3522 | Fax: 973.998.2599 Email: Sanith_Nair at artechinfo.com | Website: www.artechinfo.com Artech is the #10 Largest IT Staffing Company in the US About Artech Information Systems LLC Artech is an employer-of-choice for over 5,500 consultants across the globe. We recruit world-class talent for over 55 Fortune 500 companies coast-to-coast across the US, India, China and Mexico. We are one of the fastest-growing companies in the US, and this may be your opportunity to join us! Want to read more about Artech? Click here to visit our website or click on the following links to read what others are saying about us: Better Business Bureau, Hoovers, The Wall Street Journal, Inc., Entrepreneur, eWeek, NMSDC, dBusiness News, Diversity Careers, The Artech Circle, NJTVOnline Email secured by Check Point -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/png Size: 9050 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 2452 bytes Desc: not available URL: From tjreedy at udel.edu Wed Sep 12 16:37:11 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 12 Sep 2012 16:37:11 -0400 Subject: avoid the redefinition of a function In-Reply-To: References: Message-ID: On 9/12/2012 8:56 AM, Jabba Laci wrote: > This will call the 2nd function. Now my functions are called step_ID > (like step_27(), step_28(), etc.). How to avoid the danger of > redefinition? Now, when I write a new function, I search for its name > to see if it's unique but there must be a better way. Before starting to write the new function, write a test and see if it fails with a "NameError new_name not found". The test failure also assures one that the test is being run. (I don't always test first, but I once discovered a test not being run when I modified it in a way that should have made it fail, but it didn't.) -- Terry Jan Reedy From tjreedy at udel.edu Wed Sep 12 16:51:09 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 12 Sep 2012 16:51:09 -0400 Subject: forked processes and testing In-Reply-To: References: Message-ID: On 9/12/2012 6:20 AM, andrea crotti wrote: > I wrote a decorator that takes a function, run it in a forked process > and return the PID: This strikes me as an abuse of the decorator syntax. @wrap def f(): pass is just syntactic sugar for def f(): pass f = wrap(f) but that is not what you are doing. def run_in_fork(func) def f(): pass run_in_fork(f) would let you test run_in_fork with simple test oriented functions and separately test your real functions without the complication of the fork process. My 2 cents anyway. -- Terry Jan Reedy From miki.tebeka at gmail.com Wed Sep 12 16:52:43 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 12 Sep 2012 13:52:43 -0700 (PDT) Subject: Creating socket.connect while in epoll loop In-Reply-To: <5dea64eb-0033-4be4-858f-9d930955ef51@googlegroups.com> References: <5dea64eb-0033-4be4-858f-9d930955ef51@googlegroups.com> Message-ID: > You cannot synchronously set up a new TCP connection using a non-blocking > socket. Instead, you begin the connection attempt and it fails with EINPROGRESS and then you use epoll to find out when the attempt completes. OK. > I suggest reading the implementation of a Twisted reactor to see an example of how this is done. That was the idea, learning. > Here are a couple links to get you started: > http://twistedmatrix.com/trac/browser/trunk/twisted/internet/tcp.py > http://twistedmatrix.com/trac/browser/trunk/twisted/internet/epollreactor.py Thank you very much! From tjreedy at udel.edu Wed Sep 12 16:58:18 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 12 Sep 2012 16:58:18 -0400 Subject: pythonOCC examples doesn't work? In-Reply-To: References: Message-ID: > On 12/09/2012 08:19, Dwight Hutto wrote: >> The easiest solution is to: >> >> 1. Uninstall 64-bit Python No need to do this, at least not on windows. >> 2. Install a 32-bit distribution. in a separate directory. I have had both on my win7 machine so I could run (test) python code on both. One can put python-code-dir.pth in the site-packages directories of both. -- Terry Jan Reedy From tjreedy at udel.edu Wed Sep 12 17:04:52 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 12 Sep 2012 17:04:52 -0400 Subject: using text file to get ip address from hostname In-Reply-To: References: Message-ID: On 9/12/2012 10:41 AM, dkatorza at gmail.com wrote: > it's not really homework, i found a lab exercise on the web > and i;m trying to study with it. maybe not the most efficient way. > > i have a file with hostnames ordered line by line. Key fact for this exercise: open files are iterable. So your top level structure is... for line in open(): -- Terry Jan Reedy From darcy at druid.net Wed Sep 12 17:42:16 2012 From: darcy at druid.net (D'Arcy Cain) Date: Wed, 12 Sep 2012 17:42:16 -0400 Subject: avoid the redefinition of a function In-Reply-To: References: <5050938F.7030105@gmail.com> Message-ID: <20120912174216.ecea9245b12a014f59d9b3ea@druid.net> On Wed, 12 Sep 2012 18:56:46 +0200 Jabba Laci wrote: > (5) install mc > > You can type just "5" as user input and step_5() is called > automatically. If I use descriptive names like install_java() then > selecting a menu point would be more difficult. And I don't want users > to type "java", I want to stick to simple numbers. Your users shouldn't be working this out in any case. Consider, computer time is cheap. Programmer time is not cheap but it is short lived. User time is forever. Don't be lazy. Parse the input and prepare to present proper error messages just in case your users are not perfect. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From darcy at druid.net Wed Sep 12 17:47:13 2012 From: darcy at druid.net (D'Arcy Cain) Date: Wed, 12 Sep 2012 17:47:13 -0400 Subject: avoid the redefinition of a function In-Reply-To: References: Message-ID: <20120912174713.64537455090c4058120d9409@druid.net> On Wed, 12 Sep 2012 16:37:11 -0400 Terry Reedy wrote: > assures one that the test is being run. (I don't always test first, but > I once discovered a test not being run when I modified it in a way that > should have made it fail, but it didn't.) 1. Write the test 2. Run the test - make sure it fails 3. write code until test passes 4. Stop writing code People underestimate the importance of steps 2 and 4. Number 2 is important because a test that can't fail is worse than useless. Number 4 is important because it prevents code that doesn't have a corresponding test. If you feel the need to write more code then go back to step 1. And run all of your tests every day. You will sleep better at night. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From darcy at druid.net Wed Sep 12 17:49:24 2012 From: darcy at druid.net (D'Arcy Cain) Date: Wed, 12 Sep 2012 17:49:24 -0400 Subject: avoid the redefinition of a function In-Reply-To: <7944s.27167$CU7.24982@fx02.am4> References: <5050938F.7030105@gmail.com> <7944s.27167$CU7.24982@fx02.am4> Message-ID: <20120912174924.938e5d73757684856f1bed86@druid.net> On Wed, 12 Sep 2012 18:04:51 GMT Alister wrote: > No No NO! > you cant just pass user input to system calls without validating it first > (google sql injection for examples of the damage unsanitised input can > cause, it is not just as SQL problem) http://xkcd.com/327/ -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From python.list at tim.thechases.com Wed Sep 12 18:45:52 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 12 Sep 2012 17:45:52 -0500 Subject: avoid the redefinition of a function In-Reply-To: <20120912174713.64537455090c4058120d9409@druid.net> References: <20120912174713.64537455090c4058120d9409@druid.net> Message-ID: <505110A0.4060508@tim.thechases.com> On 09/12/12 16:47, D'Arcy Cain wrote: > On Wed, 12 Sep 2012 16:37:11 -0400 > Terry Reedy wrote: >> assures one that the test is being run. (I don't always test first, but >> I once discovered a test not being run when I modified it in a way that >> should have made it fail, but it didn't.) > > 1. Write the test > 2. Run the test - make sure it fails > 3. write code until test passes > 4. Stop writing code > > People underestimate the importance of steps 2 and 4. Number 2 is > important because a test that can't fail is worse than useless. Number > 4 is important because it prevents code that doesn't have a > corresponding test. If you feel the need to write more code then go > back to step 1. > > And run all of your tests every day. You will sleep better at night. Though I usually try to do test-driven development, I confess a fondness for Titus Brown's "Stupidity driven testing"[1] :-) -tkc [1] http://ivory.idyll.org/blog/stupidity-driven-testing.html (one of my most memorable pearls from PyCon'07) From azandi at adconion.com Wed Sep 12 19:44:20 2012 From: azandi at adconion.com (azandi) Date: Wed, 12 Sep 2012 16:44:20 -0700 (PDT) Subject: conflicting installations of python Message-ID: I installed python 2.7.3 using macports on Lion, and used port select python python27. However python version still shows 2.7.1. Any ideas why is that happenning? And how to fix it? Thanks in advance, From d at davea.name Wed Sep 12 19:49:31 2012 From: d at davea.name (Dave Angel) Date: Wed, 12 Sep 2012 19:49:31 -0400 Subject: using subprocess.Popen does not suppress terminal window on Windows In-Reply-To: References: <9dc66012-988e-4581-aaab-169dbadbbf93@35g2000vbj.googlegroups.com> Message-ID: <50511F8B.2060907@davea.name> On 09/12/2012 11:26 AM, janis.judvaitis at gmail.com wrote: > Hi, and I'm sorry for using this old thread, but I'm experiencing the same problem, except, that I wan't to execute any shell script or exe without blank terminal window. > Is there any way in python to supress blank console screen while script is executing? Multiplatform solution would be nice. > With best regards, J?nis. > it's not clear from your question: Are you launching non-Python programs from a python one, using Popen? If so, I can't help. It's the launchee that determines if a console is created, as best as I know. However, if you're trying to launch a python program without its getting a console, then read on. No need for a multiplatform solution, since the problem is a Windows one. Windows will create a console for a new process unless the parent console is still available (eg. you run it from command line) or unless the executable is marked with the "no console" flag. (I don't recall what that's actually called, I haven't used Windows in a long time). Anyway, in the Windows version, there are two executables python.exe and pythonw.exe. You want the latter one, either by explicitly naming it in your launcher (batch file, script, whatever), or by using the .pyw extension, which is normally associated with the pythonw.exe program. -- DaveA From d at davea.name Wed Sep 12 20:36:49 2012 From: d at davea.name (Dave Angel) Date: Wed, 12 Sep 2012 20:36:49 -0400 Subject: avoid the redefinition of a function In-Reply-To: References: <5050938F.7030105@gmail.com> Message-ID: <50512AA1.9090709@davea.name> On 09/12/2012 12:56 PM, Jabba Laci wrote: > Thanks for the answers. I decided to use numbers in the name of the > functions to facilitate function calls. Now if you have this menu > option for instance: > > (5) install mc > > You can type just "5" as user input and step_5() is called > automatically. If I use descriptive names like install_java() then > selecting a menu point would be more difficult. And I don't want users > to type "java", I want to stick to simple numbers. > > Laszlo Many of the other answers were interesting and useful, but I don't think anyone else pointed out the real problem with your code. If you have a bunch of functions defined in one place, and a bunch of choices for the user defined in another, you need to make one place which maps them all together. That way, when you define a new function, you also define the part of the menu that tells the user what to type. For example, you might make a list like the following: CHOICES = [("install mc", install_mc), ("install java", install_java), ....etc.... ] And your input routine will be something like: for index, item in iterate(CHOICES): print "(", index, ")", item[0] choice = int(raw_input()) function = CHOICES[choice][1] This isn't exactly the way i'd do it, and of course it's missing all kinds of error checking. But the point is that adding a new function to the menu only requires one place to "know" the number of the function. And the number is only indirectly known, as the location in the CHOICES. I hope this sparks some ideas. -- DaveA From roy at panix.com Wed Sep 12 20:58:23 2012 From: roy at panix.com (Roy Smith) Date: Wed, 12 Sep 2012 20:58:23 -0400 Subject: Some questions about atexit Message-ID: The atexit docs (http://docs.python.org/library/atexit.html) are very confusing. In one place they say, "The order in which the functions are called is not defined". In another place, "all functions registered are called in last in, first out order". Which is correct? Also, it's not clear how atexit handlers interact with threading. Do all handlers get called in the main thread? What if some other thread registers a handler? Does it get called in that thread? From jason at powerpull.net Wed Sep 12 21:59:09 2012 From: jason at powerpull.net (Jason Friedman) Date: Wed, 12 Sep 2012 19:59:09 -0600 Subject: submit jobs on multi-core In-Reply-To: References: <504ED1EB.1080008@shopzeus.com> Message-ID: >>> I have a python script in which I have a list of files to input one by one >>> and for each file I get a number as an output. >>> I used for loop to submit the file to script. >>> My script uses one file at a time and returns the output. >>> >>> My computers has 8 cores. >>> Is there any way that I could submit 8 jobs at a time and get all the >>> output faster ? >> > Or if Python 3.2 is an option, the concurrent.futures module would be > very well suited for this task. Agreed. From tjreedy at udel.edu Wed Sep 12 22:29:00 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 12 Sep 2012 22:29:00 -0400 Subject: Some questions about atexit In-Reply-To: References: Message-ID: On 9/12/2012 8:58 PM, Roy Smith wrote: > The atexit docs (http://docs.python.org/library/atexit.html) are very > confusing. In one place they say, "The order in which the functions are > called is not defined". In another place, "all functions registered are > called in last in, first out order". Which is correct? Check the tracker (bugs.python.org) for atexit issues, open and closed. I believe there was one about order and whether to make a guarantee. The doc might have been changed one place and not another. The newer statement is probably correct. In any case, the wrong place should be corrected. > Also, it's not clear how atexit handlers interact with threading. Do > all handlers get called in the main thread? What if some other thread > registers a handler? Does it get called in that thread? Don't know about this. -- Terry Jan Reedy From yueyoum at gmail.com Wed Sep 12 22:55:03 2012 From: yueyoum at gmail.com (=?UTF-8?B?5pyI5b+n6IyX?=) Date: Thu, 13 Sep 2012 10:55:03 +0800 Subject: confused in decorate and closure Message-ID: HI, I have some test code: def num(num): def deco(func): def wrap(*args, **kwargs): inputed_num = num return func(*args, **kwargs) return wrap return deco @num(5) def test(a): return a + inputed_num print test(1) when run this code, I got an error shows that 'inputed_num' is not defined My question is: In wrap function, is there not a closure that func can got 'inputed_num' ? Anyway, If not, how should I do to got my aim: Initialize some value, and use this value directly in the main function. Thinks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Wed Sep 12 23:01:01 2012 From: darcy at druid.net (D'Arcy Cain) Date: Wed, 12 Sep 2012 23:01:01 -0400 Subject: avoid the redefinition of a function In-Reply-To: <505110A0.4060508@tim.thechases.com> References: <20120912174713.64537455090c4058120d9409@druid.net> <505110A0.4060508@tim.thechases.com> Message-ID: <20120912230101.1a946134e604e12e3672b711@druid.net> On Wed, 12 Sep 2012 17:45:52 -0500 Tim Chase wrote: > On 09/12/12 16:47, D'Arcy Cain wrote: > > And run all of your tests every day. You will sleep better at night. > > Though I usually try to do test-driven development, I confess a > fondness for Titus Brown's "Stupidity driven testing"[1] :-) The two are not mutually exclusive. One of the benefits of proper unit testing is that while you might make mistakes, they should always be new ones. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From nad at acm.org Wed Sep 12 23:06:35 2012 From: nad at acm.org (Ned Deily) Date: Wed, 12 Sep 2012 20:06:35 -0700 Subject: conflicting installations of python References: Message-ID: In article , azandi wrote: > I installed python 2.7.3 using macports on Lion, and used port select python > python27. However python version still shows 2.7.1. > > Any ideas why is that happenning? And how to fix it? Macports installs its ports into a separate root. You need to ensure that the macports bin directory comes first on your shell search path; by default, it is /opt/local/bin. Try something like this: export PATH=/opt/local/bin:$PATH Otherwise, use an alias or an absolute path: /opt/local/bin/python -- Ned Deily, nad at acm.org From jason at powerpull.net Wed Sep 12 23:12:52 2012 From: jason at powerpull.net (Jason Friedman) Date: Wed, 12 Sep 2012 21:12:52 -0600 Subject: using text file to get ip address from hostname In-Reply-To: References: Message-ID: > i need to get an ip address from list of hostnames which are in a textfile. > > this is what i have so far > -------------------------------------------------------------------------- > #!/usr/bin/env python > #Get the IP Address > > import socket > hostname = 'need it to read from a text file' > addr = socket.gethostbyname(hostname) > print 'The address of ', hostname, 'is', addr $ cat hostnames google.com microsoft.com facebook.com $ python3 Python 3.2.3 (default, May 3 2012, 15:51:42) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> for line in open("hostnames"): ... hostname = line.strip() ... print("IP address for {0} is {1}.".format(hostname, socket.gethostbyname(hostname))) ... IP address for google.com is 74.125.225.33. IP address for microsoft.com is 64.4.11.37. IP address for facebook.com is 69.171.237.16. From azandi at adconion.com Thu Sep 13 00:36:19 2012 From: azandi at adconion.com (azandi at adconion.com) Date: Wed, 12 Sep 2012 21:36:19 -0700 (PDT) Subject: conflicting installations of python In-Reply-To: References: Message-ID: Hi Ned, Thanks for your response, I think the path is fine, since which python outputs the location where macports should install python i.e. /opt/local/bin/python. also port list active | fgrep python python27 @2.7.3 lang/python27 and port location python27 Port python27 2.7.3_0 is installed as an image in: /opt/local/var/macports/software/python27/python27-2.7.3_0.darwin_11.x86_64.tbz2 Another problem caused by this installation is that somehow it removes os.urandom module: >>> import os >>> os.urandom Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'urandom' On Wednesday, September 12, 2012 8:07:43 PM UTC-7, Ned Deily wrote: > In article , > > azandi wrote: > > > > > I installed python 2.7.3 using macports on Lion, and used port select python > > > python27. However python version still shows 2.7.1. > > > > > > Any ideas why is that happenning? And how to fix it? > > > > Macports installs its ports into a separate root. You need to ensure > > that the macports bin directory comes first on your shell search path; > > by default, it is /opt/local/bin. Try something like this: > > > > export PATH=/opt/local/bin:$PATH > > > > Otherwise, use an alias or an absolute path: > > > > /opt/local/bin/python > > > > -- > > Ned Deily, > > nad at acm.org From azandi at adconion.com Thu Sep 13 00:36:19 2012 From: azandi at adconion.com (azandi at adconion.com) Date: Wed, 12 Sep 2012 21:36:19 -0700 (PDT) Subject: conflicting installations of python In-Reply-To: References: Message-ID: Hi Ned, Thanks for your response, I think the path is fine, since which python outputs the location where macports should install python i.e. /opt/local/bin/python. also port list active | fgrep python python27 @2.7.3 lang/python27 and port location python27 Port python27 2.7.3_0 is installed as an image in: /opt/local/var/macports/software/python27/python27-2.7.3_0.darwin_11.x86_64.tbz2 Another problem caused by this installation is that somehow it removes os.urandom module: >>> import os >>> os.urandom Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'urandom' On Wednesday, September 12, 2012 8:07:43 PM UTC-7, Ned Deily wrote: > In article , > > azandi wrote: > > > > > I installed python 2.7.3 using macports on Lion, and used port select python > > > python27. However python version still shows 2.7.1. > > > > > > Any ideas why is that happenning? And how to fix it? > > > > Macports installs its ports into a separate root. You need to ensure > > that the macports bin directory comes first on your shell search path; > > by default, it is /opt/local/bin. Try something like this: > > > > export PATH=/opt/local/bin:$PATH > > > > Otherwise, use an alias or an absolute path: > > > > /opt/local/bin/python > > > > -- > > Ned Deily, > > nad at acm.org From nad at acm.org Thu Sep 13 01:55:51 2012 From: nad at acm.org (Ned Deily) Date: Wed, 12 Sep 2012 22:55:51 -0700 Subject: conflicting installations of python References: Message-ID: In article , azandi at adconion.com wrote: > Thanks for your response, I think the path is fine, since which python > outputs the location where macports should install python i.e. > /opt/local/bin/python. > > also > > port list active | fgrep python > python27 @2.7.3 lang/python27 > > and > > port location python27 > > Port python27 2.7.3_0 is installed as an image in: > /opt/local/var/macports/software/python27/python27-2.7.3_0.darwin_11.x86_64.tb > z2 None of the above actually shows what is being executed when you type python. What is the output from the following commands? which python ls -l $(which python) python > Another problem caused by this installation is that somehow it removes > os.urandom module: > > >>> import os > >>> os.urandom > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute 'urandom' Looks like you are using a broken Python installation. -- Ned Deily, nad at acm.org From __peter__ at web.de Thu Sep 13 02:32:38 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 13 Sep 2012 08:32:38 +0200 Subject: confused in decorate and closure References: Message-ID: ??? wrote: > HI, I have some test code: > > > def num(num): > def deco(func): > def wrap(*args, **kwargs): > inputed_num = num > return func(*args, **kwargs) > return wrap > return deco > > > @num(5) > def test(a): > return a + inputed_num > > print test(1) > > > when run this code, I got an error shows that 'inputed_num' is not > defined > > My question is: > In wrap function, is there not a closure that func can got 'inputed_num' > ? > > > > Anyway, If not, how should I do to got my aim: Initialize some value, > and use this value directly in the main function. Variable scopes are determined statically. In > def test(a): > return a + inputed_num "inputed_num" is a global variable. > @num(5) is not a macro, but a shortcut that tells Python to execute test = num(5)(test) and thus does not change the scopes. To get the desired effect you have to turn "inputed_num" into an explicit function argument, for example: >>> def num(n): ... def deco(f): ... def wrap(*args, **kw): ... return f(n, *args, **kw) ... return wrap ... return deco ... >>> @num(42) ... def test(n, a): ... return n + a ... >>> test(1) 43 From janis.judvaitis at gmail.com Thu Sep 13 03:27:10 2012 From: janis.judvaitis at gmail.com (janis.judvaitis at gmail.com) Date: Thu, 13 Sep 2012 00:27:10 -0700 (PDT) Subject: using subprocess.Popen does not suppress terminal window on Windows In-Reply-To: <9dc66012-988e-4581-aaab-169dbadbbf93@35g2000vbj.googlegroups.com> References: <9dc66012-988e-4581-aaab-169dbadbbf93@35g2000vbj.googlegroups.com> Message-ID: Thanks for answer, but that's not helping. I'm making a little embedded system programming IDE so I need to run .exe(windows only), make commands, perl & python scripts etc(multiplatform). I'm using subprocess.Popen for all of them and it works fine except that blank console window and btw it pop's out under linux too. Maybe the problem is that original python script has .pyw extension, so it hides his own console, but I don't need thatone too. P.S. If it makes a diffrence I'm using wxPython 2.9. & Python 2.7.2. From mcepl at redhat.com Thu Sep 13 03:30:05 2012 From: mcepl at redhat.com (Matej Cepl) Date: Thu, 13 Sep 2012 09:30:05 +0200 Subject: submit jobs on multi-core In-Reply-To: References: <504ED1EB.1080008@shopzeus.com> Message-ID: On 13/09/12 03:59, Jason Friedman wrote: >> Or if Python 3.2 is an option, the concurrent.futures module would be >> very well suited for this task. Also available as an external download for Python 2.* ... http://pypi.python.org/pypi/futures/ Mat?j From __peter__ at web.de Thu Sep 13 04:23:22 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 13 Sep 2012 10:23:22 +0200 Subject: avoid the redefinition of a function References: <5050938F.7030105@gmail.com> <7944s.27167$CU7.24982@fx02.am4> <5050D568.9050208@mrabarnett.plus.com> Message-ID: MRAB wrote: > On 12/09/2012 19:04, Alister wrote: >> On Wed, 12 Sep 2012 18:56:46 +0200, Jabba Laci wrote: >> >>>> For example: >>>> >>>> def install_java(): >>>> pass >>>> >>>> def install_tomcat(): >>>> pass >>> >>> Thanks for the answers. I decided to use numbers in the name of the >>> functions to facilitate function calls. Now if you have this menu option >>> for instance: >>> >>> (5) install mc >>> >>> You can type just "5" as user input and step_5() is called >>> automatically. If I use descriptive names like install_java() then >>> selecting a menu point would be more difficult. And I don't want users >>> to type "java", I want to stick to simple numbers. >>> >>> Laszlo >> >> No No NO! >> you cant just pass user input to system calls without validating it first >> (google sql injection for examples of the damage unsanitised input can >> cause, it is not just as SQL problem) >> >> it is just as easy so select a reasonably named function as a bad one >> >> option=raw_input('select your option :') >> >> if option =="1": install_java() >> if option =="2": install_other() >> >> alternatively you cold add your functions into a dictionary an call them >> from that >> >> opts={'1':install java,'2':install_other} >> >> option=raw_input('select your option :') >> opts[option] >> >> Poorly named functions are a major example of poor programming style. >> >> one of the fundamental pillars for python is readability! >> > Or you could do this: > > > def install_java(): > "Install Java" > print "Installing Java" > > def install_tomcat(): > "Install Tomcat" > print "Installing Tomcat" > > menu = [install_java, install_tomcat] > > for index, func in enumerate(menu, start=1): > print "{0}) {1}".format(index, func.__doc__) > > option = raw_input("Select your option : ") > > try: > opt = int(option) > except ValueError: > print "Not a valid option" > else: > if 1 <= opt < len(menu): > menu[opt - 1]() > else: > print "Not a valid option" I'd still argue that a function index is the wrong approach. You can use tab completion to make entering descriptive names more convenient: import cmd class Cmd(cmd.Cmd): prompt = "Enter a command (? for help): " def do_EOF(self, args): return True def do_quit(self, args): return True @classmethod def install_command(class_, f): def wrapped(self, arg): if arg: print "Discarding argument {!r}".format(arg) return f() wrapped.__doc__ = f.__doc__ wrapped.__name__ = f.__name__ class_._add_method("do_" + f.__name__, wrapped) return f @classmethod def _add_method(class_, methodname, method): if hasattr(class_, methodname): raise ValueError("Duplicate command {!r}".format(methodname)) setattr(class_, methodname, method) command = Cmd.install_command @command def install_java(): "Install Java" print "Installing Java" @command def install_tomcat(): "Install Tomcat" print "Installing Tomcat" if __name__ == "__main__": Cmd().cmdloop() From cattail2012 at gmail.com Thu Sep 13 04:47:29 2012 From: cattail2012 at gmail.com (=?UTF-8?B?6ZKf6amw5a6H?=) Date: Thu, 13 Sep 2012 01:47:29 -0700 (PDT) Subject: python2.7 lack necessary bit to build module Message-ID: I'm in ubuntu10.04 and I decide to compile python2.7 from source myself to build a GAE app.As a result,when I done with make command,it comes out with the following warning: Python build finished, but the necessary bits to build these modules were not found: _bsddb _sqlite3 _tkinter _ssl bsddb185 dbm gdbm sunaudiodev I ignore them and continue with make install.However when I run my GAE app,it comes out with no module named _ssl and _sqlite3. I figure out _ssl problem by compile ssl myself and add --with-ssl option in configure. I want to fix all this and install all of the package which annoys me. Thanks! From oscar.j.benjamin at gmail.com Thu Sep 13 05:22:45 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 13 Sep 2012 10:22:45 +0100 Subject: =?ISO-8859-15?Q?Re:_using_subprocess.Popen_does_not_?= =?ISO-8859-15?Q?suppress_terminal_window_on=0A=09Windows?= In-Reply-To: References: <9dc66012-988e-4581-aaab-169dbadbbf93@35g2000vbj.googlegroups.com> Message-ID: On Thu, 13 Sep 2012 00:27:10 -0700 (PDT), janis.judvaitis at gmail.com wrote: > I'm making a little embedded system programming IDE so I need to run .exe(windows only), make commands, perl & python scripts etc(multiplatform). I'm using subprocess.Popen for all of them and it works fine except that blank console window and btw it pop's out under linux too. > Maybe the problem is that original python script has .pyw extension, so it hides his own console, but I don't need thatone too. > P.S. If it makes a diffrence I'm using wxPython 2.9. & Python 2.7.2. Perhaps wxPython is causing the problem. Does the 'terminal' look like a normal terminal? Does it only appear if you actually print something? Oscar From oscar.j.benjamin at gmail.com Thu Sep 13 06:20:22 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 13 Sep 2012 11:20:22 +0100 Subject: using subprocess.Popen does not suppress terminal window on Windows In-Reply-To: References: <9dc66012-988e-4581-aaab-169dbadbbf93@35g2000vbj.googlegroups.com> Message-ID: On 13 September 2012 10:22, Oscar Benjamin wrote: > On Thu, 13 Sep 2012 00:27:10 -0700 (PDT), janis.judvaitis at gmail.com wrote: > >> I'm making a little embedded system programming IDE so I need to >> > run .exe(windows only), make commands, perl & python scripts > etc(multiplatform). I'm using subprocess.Popen for all of them and it > works fine except that blank console window and btw it pop's out under > linux too. > > > Maybe the problem is that original python script has .pyw >> > extension, so it hides his own console, but I don't need thatone too. > > > P.S. If it makes a diffrence I'm using wxPython 2.9. & Python 2.7.2. >> > > Perhaps wxPython is causing the problem. Does the 'terminal' look like a > normal terminal? Does it only appear if you actually print something? Are you using app = wx.App(redirect=False) to prevent wxPython from redirecting stdout/stderr into special wxPython output windows? Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Thu Sep 13 07:30:47 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 13 Sep 2012 07:30:47 -0400 Subject: equiv of perl regexp grammar? Message-ID: I noticed this and thought it looked interesting: http://search.cpan.org/~dconway/Regexp- Grammars-1.021/lib/Regexp/Grammars.pm#DESCRIPTION I'm wondering if python has something equivalent? From ulrich.eckhardt at dominolaser.com Thu Sep 13 07:43:15 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 13 Sep 2012 13:43:15 +0200 Subject: python2.7 lack necessary bit to build module In-Reply-To: References: Message-ID: Am 13.09.2012 10:47, schrieb ???: > I'm in ubuntu10.04 and I decide to compile python2.7 from source > [...] However when I run my GAE app,it comes out with no module > named _ssl and _sqlite3. There are Debian-specific ways to ease this task that should work in Ubuntu, too. First is "apt-get build-dep", which will install all libraries that are needed to build Python as it was built by the distributor. The second is "apt-get source" and more specifically the file debian/rules within the unpacked sources then, which contains the command line that is used to configure the according package. Note that using dpkg-buildpackage you could even build customized Debian packages, in case you want to replace the system Python. Uli From maniandram01 at gmail.com Thu Sep 13 07:47:27 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 13 Sep 2012 04:47:27 -0700 (PDT) Subject: python2.7 lack necessary bit to build module In-Reply-To: References: Message-ID: <7e128cb2-2941-414a-ad46-fe5851986b2f@googlegroups.com> On Thursday, 13 September 2012 14:17:29 UTC+5:30, ??? wrote: > I'm in ubuntu10.04 and I decide to compile python2.7 from source myself to build a GAE app.As a result,when I done with make command,it comes out with the following warning: > > Python build finished, but the necessary bits to build these modules were not found: > > _bsddb _sqlite3 _tkinter _ssl > > bsddb185 dbm gdbm > > sunaudiodev > > I ignore them and continue with make install.However when I run my GAE app,it comes out with no module named _ssl and _sqlite3. > > I figure out _ssl problem by compile ssl myself and add --with-ssl option in configure. > > I want to fix all this and install all of the package which annoys me. > > Thanks! You need to the install the development packages for the libraries required by the modules. They end with -dev. From janis.judvaitis at gmail.com Thu Sep 13 08:33:25 2012 From: janis.judvaitis at gmail.com (janis.judvaitis at gmail.com) Date: Thu, 13 Sep 2012 05:33:25 -0700 (PDT) Subject: using subprocess.Popen does not suppress terminal window on Windows In-Reply-To: <9dc66012-988e-4581-aaab-169dbadbbf93@35g2000vbj.googlegroups.com> References: <9dc66012-988e-4581-aaab-169dbadbbf93@35g2000vbj.googlegroups.com> Message-ID: <86dbbda6-6cac-4a01-b575-85ab24421221@googlegroups.com> It looks like normal terminal to me, could You define normal? Looks like it appears only when target script prints something, but it shouldn't cus I'm using pipes on stdout and stderr. If anyone is interested I'm using function doPopen from here: http://code.google.com/p/mansos/source/browse/trunk/tools/IDE/src/helperFunctions.py From python.list at tim.thechases.com Thu Sep 13 08:42:03 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 13 Sep 2012 07:42:03 -0500 Subject: Python2.4 on Win32 suddenly started crashing last night Message-ID: <5051D49B.1070009@tim.thechases.com> I'm not sure if this is some Win32 update that was silently applied by our netadmin, but when I simply "import socket" at the command line, it's crashing (with the "Do you want to send this information to Microsoft" debug/crash dialog). It was working as of last night, and to the best of my knowledge, nothing was changed on the system. It took a while to track it down, but it came from importing smtplib which in turn imports socket. I've tried "import socket" and it crashes, but then tried importing each of the modules that are imported in socket.py and nothing dies: C:\Program Files\Python24\Lib>python Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import _socket >>> from _socket import * >>> import _ssl >>> from _ssl import * >>> import os, sys >>> from errno import EBADF >>> sys.platform 'win32' >>> import socket [win32 crash happens here] Does anybody have any hints? I'm unfortunately somewhat bound to 2.4 due to some external binary libraries that we're tied to. Thanks, -tkc From andrea.crotti.0 at gmail.com Thu Sep 13 08:51:17 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 13 Sep 2012 13:51:17 +0100 Subject: main and dependent objects Message-ID: I am in a situation where I have a class Obj which contains many attributes, and also contains logically another object of class Dependent. This dependent_object, however, also needs to access many fields of the original class, so at the moment we did something like this: class Dependent: def __init__(self, orig): self.orig = orig def using_other_attributes(self): print("Using attr1", self.orig.attr1) class Obj: def __init__(self): self.attr1 = "attr1" self.attr2 = "attr2" self.attr3 = "attr3" self.dependent_object = Dependent(self) But I'm not so sure it's a good idea, it's a bit smelly.. Any other suggestion about how to get a similar result? I could of course passing all the arguments needed to the constructor of Dependent, but it's a bit tedious.. Thanks, Andrea From roy at panix.com Thu Sep 13 09:03:43 2012 From: roy at panix.com (Roy Smith) Date: Thu, 13 Sep 2012 09:03:43 -0400 Subject: Some questions about atexit References: Message-ID: In article , Terry Reedy wrote: > On 9/12/2012 8:58 PM, Roy Smith wrote: > > The atexit docs (http://docs.python.org/library/atexit.html) are very > > confusing. In one place they say, "The order in which the functions are > > called is not defined". In another place, "all functions registered are > > called in last in, first out order". Which is correct? > > Check the tracker (bugs.python.org) for atexit issues, open and closed. Thanks for the pointer. The operative one seems to be http://bugs.python.org/issue15233 From python.list at tim.thechases.com Thu Sep 13 09:08:10 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 13 Sep 2012 08:08:10 -0500 Subject: Python2.4 on Win32 suddenly started crashing last night In-Reply-To: <5051D49B.1070009@tim.thechases.com> References: <5051D49B.1070009@tim.thechases.com> Message-ID: <5051DABA.9030806@tim.thechases.com> On 09/13/12 07:42, Tim Chase wrote: > It was working as of last night, and to the best of my knowledge, > nothing was changed on the system. It took a while to track it > down, but it came from importing smtplib which in turn imports socket. > > I've tried "import socket" and it crashes, but then tried importing > each of the modules that are imported in socket.py and nothing dies: > > C:\Program Files\Python24\Lib>python > Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import _socket >>>> from _socket import * >>>> import _ssl >>>> from _ssl import * >>>> import os, sys >>>> from errno import EBADF >>>> sys.platform > 'win32' >>>> import socket > [win32 crash happens here] Further diagnostics (copying socket.py to suckit.py and adding a sys.exit(1) at various points and then importing sucket) seem to point to this line in socket.py: __all__.extend(os._get_exports_list(_socket)) So I can reduce the case to >>> import _socket >>> import os >>> os._get_exports_list(_socket) and it goes kablooie. If I do the same with _ssl: >>> import _ssl >>> import os >>> os._get_exports_list(_ssl) and it works fine. -tkc From python at mrabarnett.plus.com Thu Sep 13 09:12:41 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 13 Sep 2012 14:12:41 +0100 Subject: Python2.4 on Win32 suddenly started crashing last night In-Reply-To: <5051D49B.1070009@tim.thechases.com> References: <5051D49B.1070009@tim.thechases.com> Message-ID: <5051DBC9.9060009@mrabarnett.plus.com> On 13/09/2012 13:42, Tim Chase wrote: > I'm not sure if this is some Win32 update that was silently applied > by our netadmin, but when I simply "import socket" at the command > line, it's crashing (with the "Do you want to send this information > to Microsoft" debug/crash dialog). > > It was working as of last night, and to the best of my knowledge, > nothing was changed on the system. It took a while to track it > down, but it came from importing smtplib which in turn imports socket. > > I've tried "import socket" and it crashes, but then tried importing > each of the modules that are imported in socket.py and nothing dies: > > C:\Program Files\Python24\Lib>python > Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import _socket >>>> from _socket import * >>>> import _ssl >>>> from _ssl import * >>>> import os, sys >>>> from errno import EBADF >>>> sys.platform > 'win32' >>>> import socket > [win32 crash happens here] > > > Does anybody have any hints? I'm unfortunately somewhat bound to > 2.4 due to some external binary libraries that we're tied to. > I've just downloaded, installed and tested Python 2.4.4. No crash. This is with Windows XP Pro (32-bit). From jeanmichel at sequans.com Thu Sep 13 09:24:24 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 13 Sep 2012 15:24:24 +0200 (CEST) Subject: main and dependent objects In-Reply-To: Message-ID: <57804014.446922.1347542664064.JavaMail.root@sequans.com> ----- Original Message ----- > I am in a situation where I have a class Obj which contains many > attributes, and also contains logically another object of class > Dependent. > > This dependent_object, however, also needs to access many fields of > the > original class, so at the moment we did something like this: > > > class Dependent: > def __init__(self, orig): > self.orig = orig > > def using_other_attributes(self): > print("Using attr1", self.orig.attr1) > > > class Obj: > def __init__(self): > self.attr1 = "attr1" > self.attr2 = "attr2" > self.attr3 = "attr3" > > self.dependent_object = Dependent(self) > > > But I'm not so sure it's a good idea, it's a bit smelly.. > Any other suggestion about how to get a similar result? > > I could of course passing all the arguments needed to the constructor > of > Dependent, but it's a bit tedious.. > > > Thanks, > Andrea > -- > http://mail.python.org/mailman/listinfo/python-list > Nothing shocking right here imo. It looks like a classic parent-child implementation. However it seems the relation between Obj and Dependent are 1-to-1. Since Dependent need to access all Obj attributes, are you sure that Dependent and Obj are not actually the same class ? JM From python.list at tim.thechases.com Thu Sep 13 09:35:58 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 13 Sep 2012 08:35:58 -0500 Subject: Python2.4 on Win32 suddenly started crashing last night In-Reply-To: <5051DBC9.9060009@mrabarnett.plus.com> References: <5051D49B.1070009@tim.thechases.com> <5051DBC9.9060009@mrabarnett.plus.com> Message-ID: <5051E13E.6020402@tim.thechases.com> On 09/13/12 08:12, MRAB wrote: > I've just downloaded, installed and tested Python 2.4.4. No crash. > > This is with Windows XP Pro (32-bit). Could I get the MD5 of your $PYTHONDIR\DLLs\_socket.pyd to see if it matches mine? >>> data = file('_socket.pyd', 'rb').read() >>> import md5 >>> md5.md5(data).hexdigest() '7a7fc2d9e9df65690658c989bd9e95bb' It's looking like it might be a corrupt DLL or something to which it links is causing issues. Alternatively, it might be possible to find/download the 2.4.3 _socket.pyd, or possibly overwrite it with a 2.4.4 _socket.pyd (I don't know how backwards compatible the ABI is for binary modules) Thanks! -tkc From python at mrabarnett.plus.com Thu Sep 13 09:51:45 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 13 Sep 2012 14:51:45 +0100 Subject: Python2.4 on Win32 suddenly started crashing last night In-Reply-To: <5051E13E.6020402@tim.thechases.com> References: <5051D49B.1070009@tim.thechases.com> <5051DBC9.9060009@mrabarnett.plus.com> <5051E13E.6020402@tim.thechases.com> Message-ID: <5051E4F1.2080308@mrabarnett.plus.com> On 2012-09-13 14:35, Tim Chase wrote: > On 09/13/12 08:12, MRAB wrote: >> I've just downloaded, installed and tested Python 2.4.4. No crash. >> >> This is with Windows XP Pro (32-bit). > > Could I get the MD5 of your $PYTHONDIR\DLLs\_socket.pyd to see if it > matches mine? > >>>> data = file('_socket.pyd', 'rb').read() >>>> import md5 >>>> md5.md5(data).hexdigest() > '7a7fc2d9e9df65690658c989bd9e95bb' > > It's looking like it might be a corrupt DLL or something to which it > links is causing issues. Alternatively, it might be possible to > find/download the 2.4.3 _socket.pyd, or possibly overwrite it with a > 2.4.4 _socket.pyd (I don't know how backwards compatible the ABI is > for binary modules) > I get this: Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> data = file(r'C:\Python24\DLLs\_socket.pyd', 'rb').read() >>> import md5 >>> md5.md5(data).hexdigest() '166f1020fedc254d6f25ccee0994caff' From python.list at tim.thechases.com Thu Sep 13 10:45:31 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 13 Sep 2012 09:45:31 -0500 Subject: [SOLVED] Python2.4 on Win32 suddenly started crashing last night In-Reply-To: <5051E4F1.2080308@mrabarnett.plus.com> References: <5051D49B.1070009@tim.thechases.com> <5051DBC9.9060009@mrabarnett.plus.com> <5051E13E.6020402@tim.thechases.com> <5051E4F1.2080308@mrabarnett.plus.com> Message-ID: <5051F18B.7050908@tim.thechases.com> On 09/13/12 08:51, MRAB wrote: > I get this: > > Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> data = file(r'C:\Python24\DLLs\_socket.pyd', 'rb').read() > >>> import md5 > >>> md5.md5(data).hexdigest() > '166f1020fedc254d6f25ccee0994caff' Thanks for taking the time to hammer on this. I archived off my binary module from the site-packages directory, uninstalled 2.4.3, reinstalled using 2.4.4 and copied back in the item to the site-packages directory, and everything is working now. I can only attribute it to bitrot, sun-spots, or some such oddity. Thanks again. From andrea.crotti.0 at gmail.com Thu Sep 13 10:59:34 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 13 Sep 2012 15:59:34 +0100 Subject: main and dependent objects In-Reply-To: <57804014.446922.1347542664064.JavaMail.root@sequans.com> References: <57804014.446922.1347542664064.JavaMail.root@sequans.com> Message-ID: 2012/9/13 Jean-Michel Pichavant : > > Nothing shocking right here imo. It looks like a classic parent-child implementation. > However it seems the relation between Obj and Dependent are 1-to-1. Since Dependent need to access all Obj attributes, are you sure that Dependent and Obj are not actually the same class ? > > > JM Yes well the main class is already big enough, and the relation is 1-1 but the dependent class can be also considered separate to split things more nicely.. So I think it will stay like this for now and see how it goes. From ben+python at benfinney.id.au Thu Sep 13 11:02:09 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 14 Sep 2012 01:02:09 +1000 Subject: Guides for communicating with business accounting systems Message-ID: <87y5kenez2.fsf@benfinney.id.au> Howdy all, What material should a team of programmers read before designing a database model and export format for sending commerce transactions to a business accounting system? I'm especially not wanting ad hoc advice in this thread; this is surely an old, complex problem with a lot of ground already covered. Primers on pitfalls to avoid and non-obvious best practices are what I'd like to be directed toward. Constraints: * The shop is already written, and is maintained internally. Ideally we would use a widely-tested and third-party-maintained solution, but that's a struggle still ahead of us. For now, we must work with our private code base. * None of the developer team are have much experience with the field of business accounting, so if possible we need to learn from the past design mistakes of others without making them ourselves. * Our application is operating in Australia, with the sales tax tracking requirements that come with that. Australia-specific information is particularly desirable. * The business has switched to a different accounting service recently; it may well change again soon. We want to at least consider robustness of our shop's transaction tracking design in the face of a possible future switch to a different accounting system. I'm happy to asnwer questions, but I'm not about to hash out the design in this thread; that's our development team's job. What I want is pointers to a putative ?What every programmer needs to know about storing commercial transactions for business accounting? general guide. Does that information already exist where I can point our team to it? -- \ ?I went to a general store. They wouldn't let me buy anything | `\ specifically.? ?Steven Wright | _o__) | Ben Finney From garyr at fidalgo.net Thu Sep 13 11:04:56 2012 From: garyr at fidalgo.net (garyr) Date: Thu, 13 Sep 2012 08:04:56 -0700 Subject: SciPy for Python 2.6? Message-ID: Is there a version for SciPy/numpy available for Python 2.6? I could only find a version for 2.7 on the SciPy site. A search on the Scipy mailing list archive did not turn up anything. The link to the Scipy-user list signup appeared to be broken. From ulrich.eckhardt at dominolaser.com Thu Sep 13 11:05:17 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 13 Sep 2012 17:05:17 +0200 Subject: main and dependent objects In-Reply-To: References: Message-ID: Am 13.09.2012 14:51, schrieb andrea crotti: > I am in a situation where I have a class Obj which contains many > attributes, and also contains logically another object of class > Dependent. > > This dependent_object, however, also needs to access many fields of the > original class, so at the moment we did something like this: [...] > I could of course passing all the arguments needed to the constructor of > Dependent, but it's a bit tedious.. Jean-Michel already asked a good question, i.e. whether those two classes should be separate at all. I'll ask a similar question: Can't the shared data be put into a third, separate class? That way passing all the needed arguments wouldn't be tedious any more. Also, it makes clear that both outer and inner class depend on common data, but that the inner class doesn't depend on the outer beyond that. Now, just to get at least something Python-specific into this, you could override the __getitem__ of the inner class and transparently look up the item in the outer class if the inner class doesn't have it. Uli From paulstaten at gmail.com Thu Sep 13 11:17:15 2012 From: paulstaten at gmail.com (paulstaten at gmail.com) Date: Thu, 13 Sep 2012 08:17:15 -0700 (PDT) Subject: subprocess call is not waiting. Message-ID: I have a subprocess.call which tries to download a data from a remote server using HTAR. I put the call in a while loop, which tests to see if the download was successful, and if not, loops back around up to five times, just in case my internet connection has a hiccup. Subprocess.call is supposed to wait. But it doesn't work as intended. The loop quickly runs 5 times, starting a new htar command each time. After five times around, my program tells me my download failed, because the target file doesn't yet exist. But it turns out that the download is still happening---five times. When I run htar from the shell, I don't get a shell prompt again until after the download is complete. How come control is returned to python before the htar command is through? I've tried using Popen with wait and/or communicate, but no waiting ever happens. This is troublesome not only because I don't get to post process my data, but because when I run this script for multiple datasets (checking to see whether I have local copies), I quickly get a "Too many open files" error. (I began working on that by trying to use Popopen with fds_close, etc.) Should I just go back to os.system? From readmax at hushmail.com Thu Sep 13 11:19:32 2012 From: readmax at hushmail.com (Max) Date: Thu, 13 Sep 2012 15:19:32 +0000 (UTC) Subject: datetime Message-ID: How do I set the time in Python? Also, is there any *direct* way to shift it? Say, it's 09:00 now and Python makes it 11:30 *without* me having specified "11:30" but only given Python the 2h30m interval. Note that any "indirect" methods may need complicated ways to keep track of the milliseconds lost while running them. It even took around one second in some virtual machine guest systems. So I'm hoping Python happens to have the magic needed to do the job for me. From jeanmichel at sequans.com Thu Sep 13 11:22:46 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 13 Sep 2012 17:22:46 +0200 (CEST) Subject: main and dependent objects In-Reply-To: Message-ID: <891610793.527018.1347549766643.JavaMail.root@sequans.com> ----- Original Message ----- > 2012/9/13 Jean-Michel Pichavant : > > > > Nothing shocking right here imo. It looks like a classic > > parent-child implementation. > > However it seems the relation between Obj and Dependent are 1-to-1. > > Since Dependent need to access all Obj attributes, are you sure > > that Dependent and Obj are not actually the same class ? > > > > > > JM > > Yes well the main class is already big enough, and the relation is > 1-1 > but the dependent class can be also considered separate to split > things more nicely.. > > So I think it will stay like this for now and see how it goes. > Difficult to say given the meaningless names you provided. Just in case, you can still split things nicely in 2 classes and still get Dependent to be the same thing than Obj : by inheritance. It is a common way to extend one class's features. class Obj class Dependent(Obj) But do it only if Dependent **is** actually an Obj. If Dependent not an Obj but part of an Obj, then your original implementation is probably the way to go. JM From python at mrabarnett.plus.com Thu Sep 13 11:28:12 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 13 Sep 2012 16:28:12 +0100 Subject: SciPy for Python 2.6? In-Reply-To: References: Message-ID: <5051FB8C.7030005@mrabarnett.plus.com> On 2012-09-13 16:04, garyr wrote: > Is there a version for SciPy/numpy available for Python 2.6? I could only > find a version for 2.7 on the SciPy site. A search on the Scipy mailing list > archive did not turn up anything. The link to the Scipy-user list signup > appeared to be broken. > There's numpy 1.6.2 here: http://pypi.python.org/pypi/numpy From rosuav at gmail.com Thu Sep 13 11:30:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Sep 2012 01:30:14 +1000 Subject: Guides for communicating with business accounting systems In-Reply-To: <87y5kenez2.fsf@benfinney.id.au> References: <87y5kenez2.fsf@benfinney.id.au> Message-ID: On Fri, Sep 14, 2012 at 1:02 AM, Ben Finney wrote: > What I want is pointers to a putative ?What every programmer needs to > know about storing commercial transactions for business accounting? > general guide. > > Does that information already exist where I can point our team to it? Not a guide per se, but a keyword to look for: ACID compliance. You'll be maintaining multiple pieces of information that depend on each other (simple example being a ledger table showing transactions and an accounts table holding balances), and you need to guarantee that the database is consistent. Log aggressively. I'm sure nobody would ever dream of maintaining customer balances without an associated ledger showing how that balance came to be; it's less obvious but just as helpful in many other areas. If anything happens to corrupt your data, you should be able to recognize from internal evidence that something's wrong. GST isn't particularly complicated, but again, be really REALLY clear what's going on. It's better to be massively verbose in the database and then squash things down for display than to be left wondering, when you trace back through things, what money went where. Be aware of your ninths/elevenths; when there's 10% tax in a $10 item, the ex tax price is $9.090909... which will annoy everyone with 1c errors. Don't use MySQL. :) Okay, that's hardly a *rule*, but it's a strong recommendation. ChrisA From jeanmichel at sequans.com Thu Sep 13 11:34:29 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 13 Sep 2012 17:34:29 +0200 (CEST) Subject: subprocess call is not waiting. In-Reply-To: Message-ID: <746448155.528147.1347550469072.JavaMail.root@sequans.com> ----- Original Message ----- > I have a subprocess.call which tries to download a data from a remote > server using HTAR. I put the call in a while loop, which tests to > see if the download was successful, and if not, loops back around up > to five times, just in case my internet connection has a hiccup. > > Subprocess.call is supposed to wait. > > But it doesn't work as intended. The loop quickly runs 5 times, > starting a new htar command each time. After five times around, my > program tells me my download failed, because the target file doesn't > yet exist. But it turns out that the download is still > happening---five times. > > When I run htar from the shell, I don't get a shell prompt again > until after the download is complete. How come control is returned > to python before the htar command is through? > > I've tried using Popen with wait and/or communicate, but no waiting > ever happens. This is troublesome not only because I don't get to > post process my data, but because when I run this script for > multiple datasets (checking to see whether I have local copies), I > quickly get a "Too many open files" error. (I began working on that > by trying to use Popopen with fds_close, etc.) > > Should I just go back to os.system? > -- > http://mail.python.org/mailman/listinfo/python-list > A related subset of code would be useful. You can use subprocess.PIPE to redirect stdout & stderr et get them with communicate, something like: proc = subprocess.Popen(['whatever'], stdout=subprocess.PIPE, stdout=subprocess.PIPE) stdout, stderr = proc.communicate() print stdout print stderr Just by looking at stdout and stderr, you should be able to see why htar is returning so fast. JM PS : if you see nothing wrong, is it possible that htar runs asynchronously ? From python at mrabarnett.plus.com Thu Sep 13 11:35:26 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 13 Sep 2012 16:35:26 +0100 Subject: subprocess call is not waiting. In-Reply-To: References: Message-ID: <5051FD3E.8040801@mrabarnett.plus.com> On 2012-09-13 16:17, paulstaten at gmail.com wrote: > I have a subprocess.call which tries to download a data from a remote server using HTAR. I put the call in a while loop, which tests to see if the download was successful, and if not, loops back around up to five times, just in case my internet connection has a hiccup. > > Subprocess.call is supposed to wait. > > But it doesn't work as intended. The loop quickly runs 5 times, starting a new htar command each time. After five times around, my program tells me my download failed, because the target file doesn't yet exist. But it turns out that the download is still happening---five times. > > When I run htar from the shell, I don't get a shell prompt again until after the download is complete. How come control is returned to python before the htar command is through? > > I've tried using Popen with wait and/or communicate, but no waiting ever happens. This is troublesome not only because I don't get to post process my data, but because when I run this script for multiple datasets (checking to see whether I have local copies), I quickly get a "Too many open files" error. (I began working on that by trying to use Popopen with fds_close, etc.) > > Should I just go back to os.system? > Which OS? Is there some documentation somewhere? From rosuav at gmail.com Thu Sep 13 11:43:04 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Sep 2012 01:43:04 +1000 Subject: datetime In-Reply-To: References: Message-ID: On Fri, Sep 14, 2012 at 1:19 AM, Max wrote: > Say, it's 09:00 now and Python makes it 11:30 *without* me having specified > "11:30" but only given Python the 2h30m interval. Could you cheat and change the timezone offset? :D ChrisA From python at mrabarnett.plus.com Thu Sep 13 11:46:38 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 13 Sep 2012 16:46:38 +0100 Subject: subprocess call is not waiting. In-Reply-To: <746448155.528147.1347550469072.JavaMail.root@sequans.com> References: <746448155.528147.1347550469072.JavaMail.root@sequans.com> Message-ID: <5051FFDE.80500@mrabarnett.plus.com> On 2012-09-13 16:34, Jean-Michel Pichavant wrote: > ----- Original Message ----- >> I have a subprocess.call which tries to download a data from a remote >> server using HTAR. I put the call in a while loop, which tests to >> see if the download was successful, and if not, loops back around up >> to five times, just in case my internet connection has a hiccup. >> >> Subprocess.call is supposed to wait. >> >> But it doesn't work as intended. The loop quickly runs 5 times, >> starting a new htar command each time. After five times around, my >> program tells me my download failed, because the target file doesn't >> yet exist. But it turns out that the download is still >> happening---five times. >> >> When I run htar from the shell, I don't get a shell prompt again >> until after the download is complete. How come control is returned >> to python before the htar command is through? >> >> I've tried using Popen with wait and/or communicate, but no waiting >> ever happens. This is troublesome not only because I don't get to >> post process my data, but because when I run this script for >> multiple datasets (checking to see whether I have local copies), I >> quickly get a "Too many open files" error. (I began working on that >> by trying to use Popopen with fds_close, etc.) >> >> Should I just go back to os.system? >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > A related subset of code would be useful. > > You can use subprocess.PIPE to redirect stdout & stderr et get them with communicate, something like: > > proc = subprocess.Popen(['whatever'], stdout=subprocess.PIPE, stdout=subprocess.PIPE) > stdout, stderr = proc.communicate() > print stdout > print stderr > > Just by looking at stdout and stderr, you should be able to see why htar is returning so fast. > > JM > > PS : if you see nothing wrong, is it possible that htar runs asynchronously ? > The OP says that it waits when run from the shell. From andrea.crotti.0 at gmail.com Thu Sep 13 12:00:19 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 13 Sep 2012 17:00:19 +0100 Subject: Python presentations Message-ID: I have to give a couple of Python presentations in the next weeks, and I'm still thinking what is the best approach. In one presentation for example I will present decorators and context managers, and my biggest doubt is how much I should show and explain in slides and how much in an interactive way (with ipython for example). For my experience if I only see code in slides I tend not to believe that it works somehow, but also only looking at someone typing can be hard to follow and understand what is going on.. So maybe I should do first slides and then interactive demo, or the other way around, showing first how everything works and then explaining the code with slides. What do you think work best in general? From gordon at panix.com Thu Sep 13 12:06:05 2012 From: gordon at panix.com (John Gordon) Date: Thu, 13 Sep 2012 16:06:05 +0000 (UTC) Subject: Python presentations References: Message-ID: In andrea crotti writes: > For my experience if I only see code in slides I tend not to believe > that it works somehow Presumably you will have some credibility with your audience so they won't just assume you're making it up? I think slides would be fine. -- 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 wrw at mac.com Thu Sep 13 12:16:17 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Thu, 13 Sep 2012 12:16:17 -0400 Subject: Python presentations In-Reply-To: References: Message-ID: On Sep 13, 2012, at 12:00 PM, andrea crotti wrote: > I have to give a couple of Python presentations in the next weeks, and > I'm still thinking what is the best approach. > > In one presentation for example I will present decorators and context > managers, and my biggest doubt is how much I should show and explain in > slides and how much in an interactive way (with ipython for example). [byte] Speaking from experience as both a presenter and an audience member, please be sure that anything you demo interactively you include in your slide deck (even if only as an addendum). I assume your audience will have access to the deck after your talk (on-line or via hand-outs), and you want them to be able to go home and try it out for themselves. Nothing is more frustrating than trying to duplicate something you saw a speaker do, and fail because of some detail you didn't notice at the time of the talk. A good example is one that was discussed on the matplotlib-users list several weeks ago: http://www.loria.fr/~rougier/teaching/matplotlib/ -Bill From emile at fenx.com Thu Sep 13 12:16:46 2012 From: emile at fenx.com (Emile van Sebille) Date: Thu, 13 Sep 2012 09:16:46 -0700 Subject: Guides for communicating with business accounting systems In-Reply-To: <87y5kenez2.fsf@benfinney.id.au> References: <87y5kenez2.fsf@benfinney.id.au> Message-ID: On 9/13/2012 8:02 AM Ben Finney said... > Howdy all, > > What material should a team of programmers read before designing a > database model and export format for sending commerce transactions to a > business accounting system? The only standard I'm aware of is the EDI specification which I first encountered in the mid 70's and which is updated routinely. The full spec is the size of a telephone book (do they even still make those?) and both trading partners select from it the documents they intend to exchange. The back end integration is then left to both parties. If your data structure is sufficient to supply the content expected in the EDI specs for the documents you'd expect to exchange you should be OK on your database model. Unfortunately, the spec resembles the RS232 spec in that it leaves the details as an implementation issue to be settled between the two trading partners. Another problem is that the spec is privately (through an association) controlled and I've often had issues getting my hands on the proper documentation when I wasn't working with a trading partner. (I didn't want to pay the association fees to join and thereby gain access to the documentation directly.) There's a good overview at http://www.linktionary.com/e/edi.html HTH, Emile > > I'm especially not wanting ad hoc advice in this thread; this is surely > an old, complex problem with a lot of ground already covered. Primers on > pitfalls to avoid and non-obvious best practices are what I'd like to be > directed toward. > > Constraints: > > * The shop is already written, and is maintained internally. Ideally we > would use a widely-tested and third-party-maintained solution, but > that's a struggle still ahead of us. For now, we must work with our > private code base. > > * None of the developer team are have much experience with the field of > business accounting, so if possible we need to learn from the past > design mistakes of others without making them ourselves. > > * Our application is operating in Australia, with the sales tax tracking > requirements that come with that. Australia-specific information is > particularly desirable. > > * The business has switched to a different accounting service recently; > it may well change again soon. We want to at least consider robustness > of our shop's transaction tracking design in the face of a possible > future switch to a different accounting system. > > I'm happy to asnwer questions, but I'm not about to hash out the design > in this thread; that's our development team's job. > > What I want is pointers to a putative ?What every programmer needs to > know about storing commercial transactions for business accounting? > general guide. > > Does that information already exist where I can point our team to it? > From foobar at invalid.invalid Thu Sep 13 12:26:17 2012 From: foobar at invalid.invalid (mblume) Date: Thu, 13 Sep 2012 16:26:17 +0000 (UTC) Subject: Python presentations References: Message-ID: Am Thu, 13 Sep 2012 17:00:19 +0100 schrieb andrea crotti: > > I have to give a couple of Python presentations in the next weeks, and > I'm still thinking what is the best approach. > My idea for an introductory presentation of python was to prepare some code snippets (all valid python), show them in the editor, explain them, then run in a console. Beginners could then use these code snippets for their own experiments. HTH Martin From ian.g.kelly at gmail.com Thu Sep 13 13:08:23 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 13 Sep 2012 11:08:23 -0600 Subject: datetime In-Reply-To: References: Message-ID: On Thu, Sep 13, 2012 at 9:19 AM, Max wrote: > How do I set the time in Python? On what platform? I don't know of any libraries for this, so it would be a matter of making the necessary system calls (which is all that a library would do anyway). > Also, is there any *direct* way to shift it? Only by changing the timezone setting. Any method of offsetting the system clock itself is going to involve at some level reading the current value, adding or subtracting, and then setting the new value. > Note that any "indirect" methods may need complicated ways to keep > track of the milliseconds lost while running them. It even took around one > second in some virtual machine guest systems. So I'm hoping Python happens to > have the magic needed to do the job for me. If you're concerned about individual seconds, then you probably should do this in a low-level language like C. Also, the clock is going to drift naturally over time anyway. How are you going to keep it in sync if not with ntp? From andrea.crotti.0 at gmail.com Thu Sep 13 13:13:43 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 13 Sep 2012 18:13:43 +0100 Subject: Python presentations In-Reply-To: References: Message-ID: 2012/9/13 William R. Wing (Bill Wing) : > > [byte] > > Speaking from experience as both a presenter and an audience member, please be sure that anything you demo interactively you include in your slide deck (even if only as an addendum). I assume your audience will have access to the deck after your talk (on-line or via hand-outs), and you want them to be able to go home and try it out for themselves. > > Nothing is more frustrating than trying to duplicate something you saw a speaker do, and fail because of some detail you didn't notice at the time of the talk. A good example is one that was discussed on the matplotlib-users list several weeks ago: > > http://www.loria.fr/~rougier/teaching/matplotlib/ > > -Bill Yes that's a good point thanks, in general everything is already in a git repository, now only in my dropbox but later I will make it public. Even the code that I should write there should already written anyway, and to make sure everything is available I could use the save function of IPython and add it to the repository... In general I think that explaining code on a slide (if it involves some new concepts in particular) it's better, but then showing what it does it's always a plus. It's not the same if you say this will go 10x faster than the previous one, and showing that it actually does on your machine.. From woooee at gmail.com Thu Sep 13 13:24:46 2012 From: woooee at gmail.com (woooee at gmail.com) Date: Thu, 13 Sep 2012 10:24:46 -0700 (PDT) Subject: subprocess call is not waiting. In-Reply-To: References: Message-ID: It possibly requires a "shell=True", but without any code on any way to test, we can not say. From ramit.prasad at jpmorgan.com Thu Sep 13 13:48:06 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 13 Sep 2012 17:48:06 +0000 Subject: How to print something only if it exists? In-Reply-To: <9s4nh9-8dr.ln1@chris.zbmc.eu> References: <9s4nh9-8dr.ln1@chris.zbmc.eu> Message-ID: <5B80DD153D7D744689F57F4FB69AF474166788E7@SCACMX008.exchad.jpmchase.net> tinnews at isbd.co.uk wrote: > I want to print a series of list elements some of which may not exist, > e.g. I have a line:- > > print day, fld[1], balance, fld[2] > > fld[2] doesn't always exist (fld is the result of a split) so the > print fails when it isn't set. > > I know I could simply use an if but ultimately there may be more > elements of fld in the print and the print may well become more > complex (most like will be formatted for example). Thus it would be > good if there was some way to say "print this if it exists". You can use an inline if-else statement. print day, fld[1], balance, fld[2] if len(fld) >= 3 else '' Ramit -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From jeanmichel at sequans.com Thu Sep 13 13:54:44 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 13 Sep 2012 19:54:44 +0200 (CEST) Subject: Python presentations In-Reply-To: Message-ID: <1920698015.577016.1347558884232.JavaMail.root@sequans.com> ----- Original Message ----- > I have to give a couple of Python presentations in the next weeks, > and > I'm still thinking what is the best approach. > > In one presentation for example I will present decorators and context > managers, and my biggest doubt is how much I should show and explain > in > slides and how much in an interactive way (with ipython for example). > > For my experience if I only see code in slides I tend not to believe > that it works somehow, but also only looking at someone typing can be > hard to follow and understand what is going on.. > > So maybe I should do first slides and then interactive demo, or the > other way around, showing first how everything works and then > explaining > the code with slides. > > What do you think work best in general? > -- > http://mail.python.org/mailman/listinfo/python-list > I don't like decorators, I think they're not worth the mental effort. So if I were to intend to your presentation, I'd really like you to start demonstrating how decorators are life savers, or with less emphasis, how they can be worth the effort and make me regret all these years without decorators. Some features in python have this WoW! effect, try to trigger it in front of your audience, that should really help them focus on the subject and be interested in your presentation. Also try to keep the presentation interactive by asking questions to your audience (unless some of them are already participating), otherwise people will be snoring or texting after 20 minutes. I think the key for a presentation is to make people interested in the subject and make them realize they can benefit from what you're presenting. Everyone can then google 'python decorators' for the technical and boring details. I must add that I'm not en experienced presenter, so take my advices for what they're worth (hmm not sure about this grammatical construct :-/ ) JM From alister.ware at ntlworld.com Thu Sep 13 13:59:32 2012 From: alister.ware at ntlworld.com (Alister) Date: Thu, 13 Sep 2012 17:59:32 GMT Subject: avoid the redefinition of a function References: <5050938F.7030105@gmail.com> <7944s.27167$CU7.24982@fx02.am4> <5050D568.9050208@mrabarnett.plus.com> Message-ID: <8ap4s.78261$pt3.37809@fx25.am4> On Thu, 13 Sep 2012 10:23:22 +0200, Peter Otten wrote: > MRAB wrote: > >> On 12/09/2012 19:04, Alister wrote: >>> On Wed, 12 Sep 2012 18:56:46 +0200, Jabba Laci wrote: >>> >>>>> For example: >>>>> >>>>> def install_java(): >>>>> pass >>>>> >>>>> def install_tomcat(): >>>>> pass >>>> >>>> Thanks for the answers. I decided to use numbers in the name of the >>>> functions to facilitate function calls. Now if you have this menu >>>> option for instance: >>>> >>>> (5) install mc >>>> >>>> You can type just "5" as user input and step_5() is called >>>> automatically. If I use descriptive names like install_java() then >>>> selecting a menu point would be more difficult. And I don't want >>>> users to type "java", I want to stick to simple numbers. >>>> >>>> Laszlo >>> >>> No No NO! >>> you cant just pass user input to system calls without validating it >>> first (google sql injection for examples of the damage unsanitised >>> input can cause, it is not just as SQL problem) >>> >>> it is just as easy so select a reasonably named function as a bad one >>> >>> option=raw_input('select your option :') >>> >>> if option =="1": install_java() >>> if option =="2": install_other() >>> >>> alternatively you cold add your functions into a dictionary an call >>> them from that >>> >>> opts={'1':install java,'2':install_other} >>> >>> option=raw_input('select your option :') >>> opts[option] >>> >>> Poorly named functions are a major example of poor programming style. >>> >>> one of the fundamental pillars for python is readability! >>> >> Or you could do this: >> >> >> def install_java(): >> "Install Java" >> print "Installing Java" >> >> def install_tomcat(): >> "Install Tomcat" >> print "Installing Tomcat" >> >> menu = [install_java, install_tomcat] >> >> for index, func in enumerate(menu, start=1): >> print "{0}) {1}".format(index, func.__doc__) >> >> option = raw_input("Select your option : ") >> >> try: >> opt = int(option) >> except ValueError: >> print "Not a valid option" >> else: >> if 1 <= opt < len(menu): >> menu[opt - 1]() >> else: >> print "Not a valid option" > > I'd still argue that a function index is the wrong approach. You can use > tab completion to make entering descriptive names more convenient: > > import cmd > > class Cmd(cmd.Cmd): > prompt = "Enter a command (? for help): " > > def do_EOF(self, args): > return True > def do_quit(self, args): > return True > > @classmethod def install_command(class_, f): > def wrapped(self, arg): > if arg: > print "Discarding argument {!r}".format(arg) > return f() > > wrapped.__doc__ = f.__doc__ > wrapped.__name__ = f.__name__ class_._add_method("do_" + > f.__name__, wrapped) > return f > > @classmethod def _add_method(class_, methodname, method): > if hasattr(class_, methodname): > raise ValueError("Duplicate command > {!r}".format(methodname)) > setattr(class_, methodname, method) > > command = Cmd.install_command > > @command def install_java(): > "Install Java" > print "Installing Java" > > @command def install_tomcat(): > "Install Tomcat" > print "Installing Tomcat" > > if __name__ == "__main__": > Cmd().cmdloop() To be honest I prefer the "if X do Y" approach for readability but a dictionary can be undated dynamically & used to automatically create the menu so it can have its place -- I'll see you... on the dark side of the moon... -- Pink Floyd From tjreedy at udel.edu Thu Sep 13 14:07:34 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 13 Sep 2012 14:07:34 -0400 Subject: datetime In-Reply-To: References: Message-ID: On 9/13/2012 11:19 AM, Max wrote: > How do I set the time in Python? If you look up 'time' in the index of the current manual, it directs you to the time module. "time.clock_settime(clk_id, time) Set the time of the specified clock clk_id. Availability: Unix. New in version 3.3." You did not specify *which* time to set, but ... "time.CLOCK_REALTIME System-wide real-time clock. Setting this clock requires appropriate privileges. Availability: Unix. New in version 3.3." Chris already suggested an approach for changing your process's idea of time. However, setting time.timezone seems to have no effect > Also, is there any *direct* way to shift it? If you mean time.clock_shift(clk_id, shift_seconds), no. time.clock_settime(clk_id, time.clock_gettime(clk_id) + delta_seconds) > Note that any "indirect" methods may need complicated ways to keep > track of the milliseconds lost while running them. Whay would a millisecond matter? System clocks are never synchronized to official UTC time that closely without special hardware to receive time broadcasts. > It even took around one > second in some virtual machine guest systems. So I'm hoping Python happens to > have the magic needed to do the job for me. The above should be well under a second. -- Terry Jan Reedy From alister.ware at ntlworld.com Thu Sep 13 14:18:18 2012 From: alister.ware at ntlworld.com (Alister) Date: Thu, 13 Sep 2012 18:18:18 GMT Subject: Python presentations References: Message-ID: > Also try to keep the presentation interactive by asking questions to > your audience (unless some of them are already participating), otherwise > people will be snoring or texting after 20 minutes. That is a v good suggestion. the best presentation I ever attended was one on using an emergency life raft presented by a member of the local sailing club (I was a scuba diver at the time & our club was lending them some pool time) The whole presentation consisted of a sequence of questions fired at the audience to get them to think the problem trough & arrive at the correct sequence of events. Genius -- The best prophet of the future is the past. From chicken at mcnuggets.com Thu Sep 13 14:34:59 2012 From: chicken at mcnuggets.com (Chicken McNuggets) Date: Thu, 13 Sep 2012 19:34:59 +0100 Subject: Batching HTTP requests with httplib (Python 2.7) Message-ID: I'm writing a simple library that communicates with a web service and am wondering if there are any generally well regarded methods for batching HTTP requests? The problem with most web services is that they require a list of sequential commands to be executed in a certain order to complete a given task (or at least the one I am using does) so having to manually call each command is a bit of a pain. How would you go about the design of a library to interact with these services? Any help is greatly appreciated :). From paulstaten at gmail.com Thu Sep 13 14:36:40 2012 From: paulstaten at gmail.com (paulstaten at gmail.com) Date: Thu, 13 Sep 2012 11:36:40 -0700 (PDT) Subject: subprocess call is not waiting. In-Reply-To: References: <746448155.528147.1347550469072.JavaMail.root@sequans.com> Message-ID: Thanks, guys. MRAB-RedHat 6 64-bit, Python 2.6.5 JM-Here's the relevant stuff from my last try. I've also tried with subprocess.call. Just now I tried shell=True, but it made no difference. sticking a print(out) in there just prints a blank line in between each iteration. It's not until the 5 trials are finished that I am told: download failed, etc. from os.path import exists from subprocess import call from subprocess import Popen from shlex import split from time import sleep while (exists(file)==0) and (nTries < 5): a = Popen(split('htar -xvf ' + htarArgs), stdout=PIPE, stderr=PIPE) (out,err) = a.communicate() if exists(file)==0: nTries += 1 sleep(0.5) if exists(file)==0: # now that the file should be moved print('download failed: ' + file) return 1 I've also tried using shell=True with popopen. From paulstaten at gmail.com Thu Sep 13 14:36:40 2012 From: paulstaten at gmail.com (paulstaten at gmail.com) Date: Thu, 13 Sep 2012 11:36:40 -0700 (PDT) Subject: subprocess call is not waiting. In-Reply-To: References: <746448155.528147.1347550469072.JavaMail.root@sequans.com> Message-ID: Thanks, guys. MRAB-RedHat 6 64-bit, Python 2.6.5 JM-Here's the relevant stuff from my last try. I've also tried with subprocess.call. Just now I tried shell=True, but it made no difference. sticking a print(out) in there just prints a blank line in between each iteration. It's not until the 5 trials are finished that I am told: download failed, etc. from os.path import exists from subprocess import call from subprocess import Popen from shlex import split from time import sleep while (exists(file)==0) and (nTries < 5): a = Popen(split('htar -xvf ' + htarArgs), stdout=PIPE, stderr=PIPE) (out,err) = a.communicate() if exists(file)==0: nTries += 1 sleep(0.5) if exists(file)==0: # now that the file should be moved print('download failed: ' + file) return 1 I've also tried using shell=True with popopen. From ramit.prasad at jpmorgan.com Thu Sep 13 14:39:17 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 13 Sep 2012 18:39:17 +0000 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> Dwight Hutto wrote: > Why don' you just time it,eit lops through incrementing thmax input/ What? Without context I have no idea what this means. Ramit -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From dwightdhutto at gmail.com Thu Sep 13 14:43:11 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Thu, 13 Sep 2012 14:43:11 -0400 Subject: equiv of perl regexp grammar? In-Reply-To: References: Message-ID: On Thu, Sep 13, 2012 at 7:30 AM, Neal Becker wrote: > I noticed this and thought it looked interesting: > > http://search.cpan.org/~dconway/Regexp- > Grammars-1.021/lib/Regexp/Grammars.pm#DESCRIPTION > > I'm wondering if python has something equivalent? > If you mean regex, it's import re. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From ian.g.kelly at gmail.com Thu Sep 13 14:54:41 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 13 Sep 2012 12:54:41 -0600 Subject: equiv of perl regexp grammar? In-Reply-To: References: Message-ID: On Thu, Sep 13, 2012 at 5:30 AM, Neal Becker wrote: > I noticed this and thought it looked interesting: > > http://search.cpan.org/~dconway/Regexp- > Grammars-1.021/lib/Regexp/Grammars.pm#DESCRIPTION > > I'm wondering if python has something equivalent? The pyparsing module is a good option for building grammar parsers. There's nothing that I know of that tries to slot them into regular expressions like that. From dihedral88888 at googlemail.com Thu Sep 13 15:01:17 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 13 Sep 2012 12:01:17 -0700 (PDT) Subject: Python presentations In-Reply-To: References: Message-ID: <06a1a81b-246b-4e7b-ba34-4701f46889c8@googlegroups.com> mblume? 2012?9?14????UTC+8??12?26?17???? > Am Thu, 13 Sep 2012 17:00:19 +0100 schrieb andrea crotti: > > > > > > I have to give a couple of Python presentations in the next weeks, and > > > I'm still thinking what is the best approach. > > > > > My idea for an introductory presentation of python was to prepare some > > code snippets (all valid python), show them in the editor, explain them, > > then run in a console. > > > > Beginners could then use these code snippets for their own experiments. > > > > HTH > > Martin I'll contribute one point in Python. def powerlist(x, n): # n is a natural number result=[] y=1 for i in xrange(n): result.append(y) y*=x return result # any object in the local function can be returned From readmax at hushmail.com Thu Sep 13 15:06:23 2012 From: readmax at hushmail.com (readmax) Date: Thu, 13 Sep 2012 19:06:23 +0000 (UTC) Subject: datetime References: Message-ID: Terry Reedy udel.edu> writes: > You did not specify *which* time to set, but ... > > If you mean time.clock_shift(clk_id, shift_seconds), no. > > time.clock_settime(clk_id, time.clock_gettime(clk_id) + delta_seconds) > I am talking about the system-wide clock on Debian. What should I use as "clk_id"? BTW, if by "version 3.3" you mean python 3, I am only using 2.x. From dwightdhutto at gmail.com Thu Sep 13 15:37:42 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Thu, 13 Sep 2012 15:37:42 -0400 Subject: Comparing strings from the back? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> Message-ID: On Thu, Sep 13, 2012 at 2:39 PM, Prasad, Ramit wrote: > Dwight Hutto wrote: >> Why don' you just time it,eit lops through incrementing thmax input/ > > What? Without context I have no idea what this means. > > > Ramit Why don't you read the OP: Let's assume you're testing two strings for equality. You've already done the obvious quick tests (i.e they're the same length), and you're down to the O(n) part of comparing every character. I'm wondering if it might be faster to start at the ends of the strings instead of at the beginning? If the strings are indeed equal, it's the same amount of work starting from either end. But, if it turns out that for real-life situations, the ends of strings have more entropy than the beginnings, the odds are you'll discover that they're unequal quicker by starting at the end. > and this one from me: First include len(string)/2, in order to include starting at the center of the string, and threading/weaving by 2 processes out. import timeit do the the rest, and see which has the fastest time.> -- > Why don't take the time to read the OP, and ramit in your head? Remember that you're in the middle of a conversation where the OP is following as it goes along, so anyone reading the entire set of postings should get it. But for people who just want to jump in, and assume that the only thing that matters is one piece, without reading the entire content of the conversation, will always have something out of context for them. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From breamoreboy at yahoo.co.uk Thu Sep 13 15:53:55 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 13 Sep 2012 20:53:55 +0100 Subject: Comparing strings from the back? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> Message-ID: On 13/09/2012 19:39, Prasad, Ramit wrote: > Dwight Hutto wrote: >> Why don' you just time it,eit lops through incrementing thmax input/ > > What? Without context I have no idea what this means. > > > Ramit > You're wasting your time, I've been described as a jackass for having the audacity to ask for context :) -- Cheers. Mark Lawrence. From rowen at uw.edu Thu Sep 13 16:33:20 2012 From: rowen at uw.edu (Russell E. Owen) Date: Thu, 13 Sep 2012 13:33:20 -0700 Subject: Tkinter bug in Entry widgets on OS X References: Message-ID: In article , Kevin Walzer wrote: > On 8/31/12 6:18 AM, Arnaud Delobelle wrote: > > I'm very inexperienced with Tkinter (I've never used it before). All > > I'm looking for is a workaround, i.e. a way to somehow suppress that > > output. > > What are you trying to do? Navigate the focus to another widget? You > should use the tab bar for that, not the arrow key. The entry widget is > a single-line widget, and doesn't have up/down as the text widget does. Based on other replies it looks as if the OP found a way to intercept the event with suitable binding. But I can answer the "why": on Mac OS X in a one-line text box up-arrow should move the cursor to the beginning and down-arrow to the end. That's standard behavior. In any case I can't imagine ever wanting to see special chars get added when arrow keys are pressed. The default behavior of the Entry widget is unfortunate. -- Russell From joshua.landau.ws at gmail.com Thu Sep 13 16:34:43 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Thu, 13 Sep 2012 21:34:43 +0100 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> Message-ID: On 13 September 2012 20:53, Mark Lawrence wrote: > On 13/09/2012 19:39, Prasad, Ramit wrote: > >> Dwight Hutto wrote: >> >>> Why don' you just time it,eit lops through incrementing thmax input/ >>> >> >> What? Without context I have no idea what this means. >> > > You're wasting your time, I've been described as a jackass for having the > audacity to ask for context :) I'm pretty sure you are in the wrong, acting as if what he said didn't make sense! Just read it, he obviously was telling you to time it, as eit lops are inside thmax input/ which, as you should know if you *bothered to read the thread*, is incrementing. "don'" is short for "don't", by the way. -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Thu Sep 13 16:43:19 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 13 Sep 2012 21:43:19 +0100 Subject: using subprocess.Popen does not suppress terminal window on Windows In-Reply-To: <86dbbda6-6cac-4a01-b575-85ab24421221@googlegroups.com> References: <9dc66012-988e-4581-aaab-169dbadbbf93@35g2000vbj.googlegroups.com> <86dbbda6-6cac-4a01-b575-85ab24421221@googlegroups.com> Message-ID: On 13 September 2012 13:33, wrote: > It looks like normal terminal to me, could You define normal? > > Looks like it appears only when target script prints something, but it > shouldn't cus I'm using pipes on stdout and stderr. > > If anyone is interested I'm using function doPopen from here: > http://code.google.com/p/mansos/source/browse/trunk/tools/IDE/src/helperFunctions.py > -- > http://mail.python.org/mailman/listinfo/python-list > I asked about the terminal window since you mentioned that it pops up under linux which would suggest you're not having the usual Windows console/gui problem. In any case, have you tried this: http://code.activestate.com/recipes/409002-launching-a-subprocess-without-a-console-window/ Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Thu Sep 13 17:06:23 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Thu, 13 Sep 2012 17:06:23 -0400 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> Message-ID: On Thu, Sep 13, 2012 at 4:34 PM, Joshua Landau wrote: > On 13 September 2012 20:53, Mark Lawrence wrote: >> >> On 13/09/2012 19:39, Prasad, Ramit wrote: >>> >>> Dwight Hutto wrote: >>>> >>>> Why don' you just time it,eit lops through incrementing thmax input/ >>> >>> >>> What? Without context I have no idea what this means. >>> >> >> You're wasting your time, I've been described as a jackass for having the >> audacity to ask for context :) > > > I'm pretty sure you are in the wrong, acting as if what he said didn't make > sense! Just read it, he obviously was telling you to time it, as eit lops > are inside thmax input/ which, as you should know if you bothered to read > the thread, is incrementing. > > "don'" is short for "don't", by the way. > > -- > http://mail.python.org/mailman/listinfo/python-list > It's the fact that I consider the entire conversation the context. Reading the OP's being the primary, and things they responded positively to. There are other things that get mixed up as well, like not hitting the ... in gmail, and so that content doesn't show, or hitting reply, instead of reply all, and things getting jumbled for the others involved in the conversation. Then there is the problem of people saying you posted too much of the context, or not inline with the OP, just at the end, or top posting. I try to keep it along the line of what the OP has read, and they know the context in which it's meant. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From breamoreboy at yahoo.co.uk Thu Sep 13 17:17:44 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 13 Sep 2012 22:17:44 +0100 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> Message-ID: On 13/09/2012 21:34, Joshua Landau wrote: > On 13 September 2012 20:53, Mark Lawrence wrote: > >> On 13/09/2012 19:39, Prasad, Ramit wrote: >> >>> Dwight Hutto wrote: >>> >>>> Why don' you just time it,eit lops through incrementing thmax input/ >>>> >>> >>> What? Without context I have no idea what this means. >>> >> >> You're wasting your time, I've been described as a jackass for having the >> audacity to ask for context :) > > > I'm pretty sure you are in the wrong, acting as if what he said didn't make > sense! Just read it, he obviously was telling you to time it, as eit lops > are inside thmax input/ which, as you should know if you *bothered to read > the thread*, is incrementing. > > "don'" is short for "don't", by the way. > > > I do grovellingly apologize for my appalling breach of netiquette. I am of course assuming that the rules have changed and that it's now my responsibility to wade back through maybe a couple of hundred responses on a long thread to find the context. I also guess that I'm never going to achieve my ambition of being a pot smoking hippy CEO of a web development company :( -- Cheers. Mark Lawrence. From python.list at tim.thechases.com Thu Sep 13 17:26:07 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 13 Sep 2012 16:26:07 -0500 Subject: Least-lossy string.encode to us-ascii? Message-ID: <50524F6F.6070604@tim.thechases.com> I've got a bunch of text in Portuguese and to transmit them, need to have them in us-ascii (7-bit). I'd like to keep as much information as possible, just stripping accents, cedillas, tildes, etc. So "servi?o m?vil" becomes "servico movil". Is there anything stock that I've missed? I can do mystring.encode('us-ascii', 'replace') but that doesn't keep as much information as I'd hope. -tkc From dwightdhutto at gmail.com Thu Sep 13 17:35:46 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Thu, 13 Sep 2012 17:35:46 -0400 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> Message-ID: On Thu, Sep 13, 2012 at 5:17 PM, Mark Lawrence wrote: > On 13/09/2012 21:34, Joshua Landau wrote: >> >> On 13 September 2012 20:53, Mark Lawrence wrote:acci sequence >> >>> On 13/09/2012 19:39, Prasad, Ramit wrote: >>> >>>> Dwight Hutto wrote: >>>> >>>>> Why don' you just time it,eit lops through incrementing thmax input/ >>>>> >>>> >>>> What? Without context I have no idea what this means. >>>> >>> >>> You're wasting your time, I've been described as a jackass for having >>> the >>> audacity to ask for context :) >> >> >> >> I'm pretty sure you are in the wrong, acting as if what he said didn't >> make >> sense! Just read it, he obviously was telling you to time it, as eit lops >> are inside thmax input/ which, as you should know if you *bothered to read >> the thread*, is incrementing. >> >> >> "don'" is short for "don't", by the way. >> >> >> > > I do grovellingly apologize for my appalling breach of netiquette. I am of > course assuming that the rules have changed and that it's now my > responsibility to wade back through maybe a couple of hundred responses on a > long thread to find the context. I also guess that I'm never going to > achieve my ambition of being a pot smoking hippy CEO of a web development > company :( > > > -- > Cheers. Cheers usually implies you're an alcoholic pressing buttons, with the half of rest of the coders on the net. So don't give up hope, you might be able to take a medication that doesn't impair your judgement with the side effects alcohol has, And of course leaves you without the ability to read any of the responses to say you were right in certain instances, so something must be wrong with your mail reader, or your alcoholic mind. Also, without reading the other posts, you're probably just placing in a duplicate answer sometimes, which might make you seem like a copy cat. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From vlastimil.brom at gmail.com Thu Sep 13 17:44:18 2012 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 13 Sep 2012 23:44:18 +0200 Subject: Least-lossy string.encode to us-ascii? In-Reply-To: <50524F6F.6070604@tim.thechases.com> References: <50524F6F.6070604@tim.thechases.com> Message-ID: 2012/9/13 Tim Chase : > I've got a bunch of text in Portuguese and to transmit them, need to > have them in us-ascii (7-bit). I'd like to keep as much information > as possible, just stripping accents, cedillas, tildes, etc. So > "servi?o m?vil" becomes "servico movil". Is there anything stock > that I've missed? I can do mystring.encode('us-ascii', 'replace') > but that doesn't keep as much information as I'd hope. > > -tkc > Hi, would something like the following be enough for your needs? Unfortunately, I can't check it reliably with regard to Portuguese. >>> import unicodedata >>> unicodedata.normalize("NFD", u"servi?o m?vil").encode("ascii", "ignore").decode("ascii") u'servico movil' >>> There is also "Unidecode", but I haven't used it myself sofar... http://pypi.python.org/pypi/Unidecode/ hth, vbr From lists at cheimes.de Thu Sep 13 18:00:45 2012 From: lists at cheimes.de (Christian Heimes) Date: Fri, 14 Sep 2012 00:00:45 +0200 Subject: Least-lossy string.encode to us-ascii? In-Reply-To: <50524F6F.6070604@tim.thechases.com> References: <50524F6F.6070604@tim.thechases.com> Message-ID: Am 13.09.2012 23:26, schrieb Tim Chase: > I've got a bunch of text in Portuguese and to transmit them, need to > have them in us-ascii (7-bit). I'd like to keep as much information > as possible, just stripping accents, cedillas, tildes, etc. So > "servi?o m?vil" becomes "servico movil". Is there anything stock > that I've missed? I can do mystring.encode('us-ascii', 'replace') > but that doesn't keep as much information as I'd hope. The unidecode [1] package contains a large mapping of unicode chars to ASCII. It even supports cool stuff like Chinese to ASCII: >>> import unidecode >>> print u"\u5317\u4EB0" ?? >>> print unidecode.unidecode(u"\u5317\u4EB0") Bei Jing icu4c and pyicu [2] may contain more methods for conversion but they require binary extensions. By the way ICU can do a lot of cool, too: >>> import icu >>> rbf = icu.RuleBasedNumberFormat(icu.URBNFRuleSetTag.SPELLOUT, icu.Locale.getUS()) >>> rbf.format(23) u'twenty-three' >>> rbf.format(100000) u'one hundred thousand' Regards, Christian [1] http://pypi.python.org/pypi/Unidecode/0.04.9 [2] http://pypi.python.org/pypi/PyICU/1.4 From python.list at tim.thechases.com Thu Sep 13 18:06:25 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 13 Sep 2012 17:06:25 -0500 Subject: [SOLVED] Least-lossy string.encode to us-ascii? In-Reply-To: References: <50524F6F.6070604@tim.thechases.com> Message-ID: <505258E1.7020500@tim.thechases.com> On 09/13/12 16:44, Vlastimil Brom wrote: > >>> import unicodedata > >>> unicodedata.normalize("NFD", u"servi?o m?vil").encode("ascii", "ignore").decode("ascii") > u'servico movil' Works well for all the test-cases I threw at it. Thanks! -tkc From ethan at stoneleaf.us Thu Sep 13 18:29:40 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 13 Sep 2012 15:29:40 -0700 Subject: Least-lossy string.encode to us-ascii? In-Reply-To: <50524F6F.6070604@tim.thechases.com> References: <50524F6F.6070604@tim.thechases.com> Message-ID: <50525E54.2000502@stoneleaf.us> [sorry for the direct reply, Tim] Tim Chase wrote: > I've got a bunch of text in Portuguese and to transmit them, need to > have them in us-ascii (7-bit). I'd like to keep as much information > as possible, just stripping accents, cedillas, tildes, etc. So > "servi?o m?vil" becomes "servico movil". Is there anything stock > that I've missed? I can do mystring.encode('us-ascii', 'replace') > but that doesn't keep as much information as I'd hope. I haven't yet used it myself, but I've heard good things about http://pypi.python.org/pypi/Unidecode/ ~Ethan~ From news at blinne.net Thu Sep 13 18:33:43 2012 From: news at blinne.net (Alexander Blinne) Date: Fri, 14 Sep 2012 00:33:43 +0200 Subject: Python presentations In-Reply-To: <06a1a81b-246b-4e7b-ba34-4701f46889c8@googlegroups.com> References: <06a1a81b-246b-4e7b-ba34-4701f46889c8@googlegroups.com> Message-ID: <50525f48$0$6573$9b4e6d93@newsspool3.arcor-online.net> On 13.09.2012 21:01, 88888 Dihedral wrote: > def powerlist(x, n): > # n is a natural number > result=[] > y=1 > for i in xrange(n): > result.append(y) > y*=x > return result # any object in the local function can be returned def powerlist(x, n): result=[1] for i in xrange(n-1): result.append(result[-1]*x) return result def powerlist(x,n): if n==1: return [1] p = powerlist(x,n-1) return p + [p[-1]*x] From rosuav at gmail.com Thu Sep 13 18:38:43 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Sep 2012 08:38:43 +1000 Subject: Python presentations In-Reply-To: <50525f48$0$6573$9b4e6d93@newsspool3.arcor-online.net> References: <06a1a81b-246b-4e7b-ba34-4701f46889c8@googlegroups.com> <50525f48$0$6573$9b4e6d93@newsspool3.arcor-online.net> Message-ID: On Fri, Sep 14, 2012 at 8:33 AM, Alexander Blinne wrote: > On 13.09.2012 21:01, 88888 Dihedral wrote: >> def powerlist(x, n): >> # n is a natural number >> result=[] >> y=1 >> for i in xrange(n): >> result.append(y) >> y*=x >> return result # any object in the local function can be returned > > def powerlist(x, n): > result=[1] > for i in xrange(n-1): > result.append(result[-1]*x) > return result > > def powerlist(x,n): > if n==1: > return [1] > p = powerlist(x,n-1) > return p + [p[-1]*x] Eh, much simpler. def powerlist(x,n): return [x*i for i in xrange(n-1)] But you're responding to a bot there. Rather clever as bots go, though. ChrisA From miki.tebeka at gmail.com Thu Sep 13 18:58:26 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 13 Sep 2012 15:58:26 -0700 (PDT) Subject: Python presentations In-Reply-To: References: Message-ID: <3540adcc-cf2d-46a8-a822-a3183d5ea944@googlegroups.com> > What do you think work best in general? I find typing during class (other than small REPL examples) time consuming and error prone. What works well for me is to create a slidy HTML presentation with asciidoc, then I can include code snippets that can be also run from the command line. (Something like: [source,python,numbered] --------------------------------------------------- include::src/sin.py[] --------------------------------------------------- Output example: http://i.imgur.com/Aw9oQ.png ) Let me know if you're interested and I'll send you a example project. HTH, -- Miki From miki.tebeka at gmail.com Thu Sep 13 18:58:26 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 13 Sep 2012 15:58:26 -0700 (PDT) Subject: Python presentations In-Reply-To: References: Message-ID: <3540adcc-cf2d-46a8-a822-a3183d5ea944@googlegroups.com> > What do you think work best in general? I find typing during class (other than small REPL examples) time consuming and error prone. What works well for me is to create a slidy HTML presentation with asciidoc, then I can include code snippets that can be also run from the command line. (Something like: [source,python,numbered] --------------------------------------------------- include::src/sin.py[] --------------------------------------------------- Output example: http://i.imgur.com/Aw9oQ.png ) Let me know if you're interested and I'll send you a example project. HTH, -- Miki From andrea.crotti.0 at gmail.com Thu Sep 13 19:15:49 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Fri, 14 Sep 2012 00:15:49 +0100 Subject: Python presentations In-Reply-To: <3540adcc-cf2d-46a8-a822-a3183d5ea944@googlegroups.com> References: <3540adcc-cf2d-46a8-a822-a3183d5ea944@googlegroups.com> Message-ID: <50526925.50903@gmail.com> On 09/13/2012 11:58 PM, Miki Tebeka wrote: >> What do you think work best in general? > I find typing during class (other than small REPL examples) time consuming and error prone. > > What works well for me is to create a slidy HTML presentation with asciidoc, then I can include code snippets that can be also run from the command line. > (Something like: > > [source,python,numbered] > --------------------------------------------------- > include::src/sin.py[] > --------------------------------------------------- > > Output example: http://i.imgur.com/Aw9oQ.png > ) > > Let me know if you're interested and I'll send you a example project. > > HTH, > -- > Miki Yes please send me something and I'll have a look. For my slides I'm using hieroglyph: http://heiroglyph.readthedocs.org/en/latest/index.html which works with sphinx, so in theory I might be able to run the code as well.. But in general probably the best way is to copy and paste in a ipython session, to show that what I just explained actually works as expected.. From ramit.prasad at jpmorgan.com Thu Sep 13 19:26:12 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 13 Sep 2012 23:26:12 +0000 Subject: pythonOCC examples doesn't work? In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF47416678FC5@SCACMX008.exchad.jpmchase.net> Dwight Hutto wrote: [snip] > On Wed, Sep 12, 2012 at 3:37 AM, Mark Lawrence > wrote: [snip] > Others would be able to see this for themselves but > > you insist on sending email without context. Please don't do this. > > How are my emails without context? I'm referring the OP to the docs, > as well as posts related to their question. It goes to use google, and > RTFM, and putting it politely to them. > I have noticed that you do not always quote what you are talking about. Sometimes I can guess or look at another message and see what you are talking about, but not always. This list philosophy seems to be "quote what is relevant and trim what is not". Not on a "go lookup the previous message to find context". > I could summarize, but they have to do the real reading. I'm not > researching this, and if I was, I'd charge for the time. This is to > show that things can get complex if you don't use google, or read the > docs. Context is not the same as explaining absolutely everything. It means that I, the reader, can see *what* you are talking about and what you are responding *to*. I do agree with the stance not to spoon feed OP(s). > > Why does the OP keep asking here, when there are answers out there. > especially on the pywin list, which Windows users are usually referred > to. I was not aware that Windows users were "usually" referred anywhere. Most referrals are on a case-by-case basis as many problems or questions from Windows Python developers are Python questions and not specific to pywin. > > Please point out what's out of context. The links and references place > it into context if the OP finds them useful, and I believe I searched > well for them. > > Would the OP like to tell me I wasn't helpful? Because now they're > probably on a search to figure out how to make these compatible, which > means more questions, and more reading. Nobody is claiming you are not helpful. I appreciate your effort, I just do not always know what is going on in a thread especially if I see the thread jump to something I can contribute to but now have no context with which to help. Not to mention that the archive for this list is searchable. Your answer is much more useful for future searchers if you leave some context for someone reading this. [snip] > > Let's not argue about this, I was pointing them to what I saw as the > best possible resources to overcome his current problem, and it was > all in context of the conversation as far as I'm concerned. > It is in context of the "thread", but the context of the "conversation" was lost. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From tjreedy at udel.edu Thu Sep 13 19:28:35 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 13 Sep 2012 19:28:35 -0400 Subject: datetime In-Reply-To: References: Message-ID: On 9/13/2012 3:06 PM, readmax wrote: > Terry Reedy udel.edu> writes: > > >> You did not specify *which* time to set, but ... > >> >> If you mean time.clock_shift(clk_id, shift_seconds), no. >> >> time.clock_settime(clk_id, time.clock_gettime(clk_id) + delta_seconds) >> > > I am talking about the system-wide clock on Debian. > What should I use as "clk_id"? Read the doc. > BTW, if by "version 3.3" you mean python 3 x.y in the doc means pythonx.y -- Terry Jan Reedy From ramit.prasad at jpmorgan.com Thu Sep 13 19:30:31 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 13 Sep 2012 23:30:31 +0000 Subject: Which Version of Python? In-Reply-To: References: <236c2754-d656-4595-8364-7503ef7c15d6@q7g2000pbj.googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47416678FD6@SCACMX008.exchad.jpmchase.net> Ramchandra Apte wrote: > On Wednesday, 12 September 2012 14:11:56 UTC+5:30, Ramchandra Apte wrote: > > On Wednesday, 12 September 2012 14:04:56 UTC+5:30, alex23 wrote: > > > On 12 Sep, 16:31, Mark Lawrence wrote: > > > > Perhaps this will sway youhttp://docs.python.org/dev/whatsnew/3.3.html > > > > There is no longer an equivalent document for the Python 1.x or 2.x > > > > series of releases. > > > Perhaps not for 1.x but the 2.x series is still covered: > > > http://docs.python.org/dev/whatsnew/index.html > > > Actually, 1.6 is included here: > > > http://www.python.org/download/releases/1.6.1/ > > I think he meant the length of the document. > Sorry, Mark must have meant theres no "What's New" document of the same length > (its very long). Would you mind trimming your responses of blank lines? The double line spacing makes it difficult to read. I know that it may be google groups that is doubling line spaces but it would help if you could remove the extra lines that you can when replying (as I have done above). Thanks, Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From tjreedy at udel.edu Thu Sep 13 19:36:56 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 13 Sep 2012 19:36:56 -0400 Subject: Least-lossy string.encode to us-ascii? In-Reply-To: <50524F6F.6070604@tim.thechases.com> References: <50524F6F.6070604@tim.thechases.com> Message-ID: On 9/13/2012 5:26 PM, Tim Chase wrote: > I've got a bunch of text in Portuguese and to transmit them, need to > have them in us-ascii (7-bit). I'd like to keep as much information > as possible,just stripping accents, cedillas, tildes, etc. 'keep as much information as possible' would mean an effectively lossless transliteration, which you could do with a dict. {: 'o', : 'c,' (or pick something that would never occur in normal text of the sort you are transmitting), ...} -- Terry Jan Reedy From cs at zip.com.au Thu Sep 13 19:46:40 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 14 Sep 2012 09:46:40 +1000 Subject: Python presentations In-Reply-To: References: Message-ID: <20120913234640.GA1751@cskk.homeip.net> On 13Sep2012 17:00, andrea crotti wrote: | I have to give a couple of Python presentations in the next weeks, and | I'm still thinking what is the best approach. | | In one presentation for example I will present decorators and context | managers, and my biggest doubt is how much I should show and explain in | slides and how much in an interactive way (with ipython for example). | | For my experience if I only see code in slides I tend not to believe | that it works somehow, but also only looking at someone typing can be | hard to follow and understand what is going on.. | | So maybe I should do first slides and then interactive demo, or the | other way around, showing first how everything works and then explaining | the code with slides. Slides first. My own experience is that someone typing code where I've not seen at least a summary explaination ahead of time slides straight off my brain. Ideally, two projectors: the current slides and an interactive python environment for demos. That way people can cross reference. But otherwise: a few slides, then a short demo if what was just spoken about, then slides... -- Cameron Simpson Standing on the faces of midgets, I can see for yards. - David N Stivers D0D#857 From python.list at tim.thechases.com Thu Sep 13 19:54:22 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 13 Sep 2012 18:54:22 -0500 Subject: Least-lossy string.encode to us-ascii? In-Reply-To: References: <50524F6F.6070604@tim.thechases.com> Message-ID: <5052722E.7060707@tim.thechases.com> On 09/13/12 18:36, Terry Reedy wrote: > On 9/13/2012 5:26 PM, Tim Chase wrote: >> I've got a bunch of text in Portuguese and to transmit them, need to >> have them in us-ascii (7-bit). I'd like to keep as much information >> as possible,just stripping accents, cedillas, tildes, etc. > > 'keep as much information as possible' would mean an effectively > lossless transliteration, which you could do with a dict. > {: 'o', : 'c,' (or pick something that would > never occur in normal text of the sort you are transmitting), ...} Vlastimil's solution kept the characters but stripped them of their accents/tildes/cedillas/etc, doing just what I wanted, all using the stdlib. Hard to do better than that :-) -tkc From luckysmack at gmail.com Thu Sep 13 20:20:47 2012 From: luckysmack at gmail.com (Shawn McElroy) Date: Thu, 13 Sep 2012 17:20:47 -0700 (PDT) Subject: How to implement a combo Web and Desktop app in python. Message-ID: I am somewhat new to python. I am still learning it. I am starting an app that I ma not quite sure how to best implement it. In the grand scheme, there will be 4 apps total. There will be a core shared between them that allows them to easily talk to each other (ill explain) and communicate with a database, as well as redis for pubsub events. I also need things to work on both web, and desktop. So i will likely have to keep the UI and the core of each app in their own separate apps entirely. The main core on the web will be a REST interface with proper content negotiation, depending on what is requested. Normally, if the desktop is online, you may think "If you have a good rest interface, this makes the desktop version pointless". While true for some cases, the reason I need a desktop implementation, is because the end user still needs to be able to use the app while there is no internet connectivity. For example, an in store POS system. They would still need to process transactions like cash while offline, and they would also need access to their inventory. This is also good for intermittent connection problems, and for speed. So they don't have to worry about networking issues to do things. For this reason a local database is also needed. And when online, it keeps in sync with the remote database. So I need to find a way I can implement this in the best way, to help prevent code duplication, and reduce the amount of time it takes to get into production. If possible, I would like to use some kind of built in webkit for desktop as well, so users have the same experience both online and locally. So i would likely need to package a webserver as well (tornado/gunicorn?) If it was entirely online, I see how I could implement this, but when needing to have a desktop version, I feel like I would need to split things up differently. Here is so far, how I would think that I need to structure everything. Core: this is the CORE api to talk to the server, and interact with the systems. I should be able to do most things using this interface, and the individual apps may (or may not) add onto this for specific functionality. App: this is the individual apps. going along with my example, these could be the actual POS interface, a shopping cart, product catalog/inventory management, and an admin/backend that would tie into everything and be able to show things like product/customer stats and so on. Presentation: the actual user interfaces for each app. I also feel like I should put it all into one app, bundled, and only split up the ui based on web vs desktop. The different 4 apps may also be at 4 web addresses. such as: http://main.com (would probably include the admin app) http://pos.com http://products.com so what is avaiable to the end user, will also be dependant on the domain as well. If they are all on one core, with only the UI separated out, the rest interface would likely be on all of them and only allow things based on what app you are looking at. Unless you are on the master domain where everything is allowed. I understand this is a complex question about implementation, and could be philosophically different depending on the developer. But im not sure how to best go about it, so I was hoping to get some ideas and input. Should I do it an entirely different way? Currently for the apps themselves, I am looking at using either flask, bottle, web2py, or pyramid. I need to understand how I am going to implement it more before I choose a framework. Django is nice, but it doesnt seem to fit what I need to do. There are rest api plugins available for it, but if the core of my app is based on REST, it seemed to make more sense to start with something that has REST built into the core of the framework. Any input or advice is much appreciated. Thanks. - Shawn McElroy From dwightdhutto at gmail.com Thu Sep 13 21:11:58 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Thu, 13 Sep 2012 21:11:58 -0400 Subject: pythonOCC examples doesn't work? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47416678FC5@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF47416678FC5@SCACMX008.exchad.jpmchase.net> Message-ID: On Thu, Sep 13, 2012 at 7:26 PM, Prasad, Ramit wrote: > Dwight Hutto wrote: > > [snip] > >> On Wed, Sep 12, 2012 at 3:37 AM, Mark Lawrence >> wrote: > > [snip] > >> Others would be able to see this for themselves but >> > you insist on sending email without context. Please don't do this. >> >> How are my emails without context? I'm referring the OP to the docs, >> as well as posts related to their question. It goes to use google, and >> RTFM, and putting it politely to them. >> > > > I have noticed that you do not always quote what you are talking about. > Sometimes I can guess or look at another message and see what you > are talking about, but not always. This list philosophy seems to be > "quote what is relevant and trim what is not". Not on a > "go lookup the previous message to find context". > >> I could summarize, but they have to do the real reading. I'm not >> researching this, and if I was, I'd charge for the time. This is to >> show that things can get complex if you don't use google, or read the >> docs. > > > Context is not the same as explaining absolutely everything. > It means that I, the reader, can see *what* you are talking about > and what you are responding *to*. > > I do agree with the stance not to spoon feed OP(s). > >> >> Why does the OP keep asking here, when there are answers out there. >> especiThey would still need to process transactions like cash while offline, and they would also need access to their inventory.ally on the pywin list, which Windows users are usually referred >> to. > > I was not aware that Windows users were "usually" referred anywhere. > Most referrals are on a case-by-case basis as many problems or > questions from Windows Python developers are Python questions and > not specific to pywin. > >> >> Please point out what's out of context. The links and references place >> it into context if the OP finds them useful, and I believe I searched >> well for them. >> >> Would the OP like to tell me I wasn't helpful? Because now they're >> probably on a search to figure out how to make these compatible, which >> means more questions, and more reading. > > Nobody is claiming you are not helpful. I appreciate your effort, > I just do not always know what is going on in a thread especially > if I see the thread jump to something I can contribute to but now have > no context with which to help. Not to mention that the archive for > this list is searchable. Your answer is much more useful for future > searchers if you leave some context for someone reading this. > > [snip] > >> >> Let's not argue about this, I was pointing them to what I saw as the >> best possible resources to overcome his current problem, and it was >> all in context of the conversation as far as I'm concerned. >> > > It is in context of the "thread", but the context of the > "conversation" was lost. > > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. > -- > http://mail.python.org/mailman/listinfo/python-list Your point is taken. Most of the time, if it's in an in line response I would write the email line by line, with the referenced text shown above my response. However, when it seems like a conversation, I just trim the above, and respond. That's how I view an e-mail, like an ongoing conversation. >From now on, I'll leave the mailing I'm responding to above, and delete the point's I'm not talking about, which is about what I usually do. So being attacked about no context(which was an attack out of context, based on a few messages one night), when the whole conversation is in the topic reader/gmail/etc seemed a little ignorant to reading through. All he had to do was look back up to the email s just above my response, and see, or read just through mine, not read everyone. But anyway, I'll be more informative as to exactly what I was referencing, instead of treating it like an ongoing conversation where everyone was present, and paying attention to the whole of the topic. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Thu Sep 13 21:14:28 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Thu, 13 Sep 2012 21:14:28 -0400 Subject: pythonOCC examples doesn't work? In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47416678FC5@SCACMX008.exchad.jpmchase.net> Message-ID: On Thu, Sep 13, 2012 at 9:11 PM, Dwight Hutto wrote: > On Thu, Sep 13, 2012 at 7:26 PM, Prasad, Ramit > wrote: >> Dwight Hutto wrote: >> >> [snip] >> >>> On Wed, Sep 12, 2012 at 3:37 AM, Mark Lawrence >>> wrote: >> >> [snip] >> >>> Others would be able to see this for themselves but >>> > you insist on sending email without context. Please don't do this. >>> >>> How are my emails without context? I'm referring the OP to the docs, >>> as well as posts related to their question. It goes to use google, and >>> RTFM, and putting it politely to them. >>> >> >> >> I have noticed that you do not always quote what you are talking about. >> Sometimes I can guess or look at another message and see what you >> are talking about, but not always. This list philosophy seems to be >> "quote what is relevant and trim what is not". Not on a >> "go lookup the previous message to find context". >> >>> I could summarize, but they have to do the real reading. I'm not >>> researching this, and if I was, I'd charge for the time. This is to >>> show that things can get complex if you don't use google, or read the >>> docs. >> >> >> Context is not the same as explaining absolutely everything. >> It means that I, the reader, can see *what* you are talking about >> and what you are responding *to*. >> >> I do agree with the stance not to spoon feed OP(s). >> >>> >>> Why does the OP keep asking here, when there are answers out there. >>> especiThey would still need to process transactions like cash while offline, and they would also need access to their inventory.ally on the pywin list, which Windows users are usually referred >>> to. >> >> I was not aware that Windows users were "usually" referred anywhere. >> Most referrals are on a case-by-case basis as many problems or >> questions from Windows Python developers are Python questions and >> not specific to pywin. >> >>> >>> Please point out what's out of context. The links and references place >>> it into context if the OP finds them useful, and I believe I searched >>> well for them. >>> >>> Would the OP like to tell me I wasn't helpful? Because now they're >>> probably on a search to figure out how to make these compatible, which >>> means more questions, and more reading. >> >> Nobody is claiming you are not helpful. I appreciate your effort, >> I just do not always know what is going on in a thread especially >> if I see the thread jump to something I can contribute to but now have >> no context with which to help. Not to mention that the archive for >> this list is searchable. Your answer is much more useful for future >> searchers if you leave some context for someone reading this. >> >> [snip] >> >>> >>> Let's not argue about this, I was pointing them to what I saw as the >>> best possible resources to overcome his current problem, and it was >>> all in context of the conversation as far as I'm concerned. >>> >> >> It is in context of the "thread", but the context of the >> "conversation" was lost. >> >> >> This email is confidential and subject to important disclaimers and >> conditions including on offers for the purchase or sale of >> securities, accuracy and completeness of information, viruses, >> confidentiality, legal privilege, and legal entity disclaimers, >> available at http://www.jpmorgan.com/pages/disclosures/email. >> -- >> http://mail.python.org/mailman/listinfo/python-list > > Your point is taken. Most of the time, if it's in an in line response > I would write the email line by line, with the referenced text shown > above my response. > > However, when it seems like a conversation, I just trim the above, and > respond. That's how I view an e-mail, like an ongoing conversation. > > From now on, I'll leave the mailing I'm responding to above, and > delete the point's I'm not talking about, which is about what I > usually do. > > So being attacked about no context(which was an attack out of context, > based on a few messages one night), when the whole conversation is in > the topic reader/gmail/etc seemed a little ignorant to reading > through. All he had to do was look back up to the email s just above > my response, and see, or read just through mine, not read everyone. > > But anyway, I'll be more informative as to exactly what I was > referencing, instead of treating it like an ongoing conversation where > everyone was present, and paying attention to the whole of the topic. > > > -- > Best Regards, > David Hutto > CEO: http://www.hitwebdevelopment.com And if you look at the above in gmail, you can see the ...'s that when not clicked, won't show some of the responses I leave just above, and it clips my signature line as well. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From wuwei23 at gmail.com Thu Sep 13 21:58:10 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 13 Sep 2012 18:58:10 -0700 (PDT) Subject: Decorators not worth the effort References: Message-ID: On Sep 14, 3:54?am, Jean-Michel Pichavant wrote: > I don't like decorators, I think they're not worth the mental effort. Because passing a function to a function is a huge cognitive burden? From wuwei23 at gmail.com Thu Sep 13 22:05:16 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 13 Sep 2012 19:05:16 -0700 (PDT) Subject: main and dependent objects References: Message-ID: <455b699d-1439-4105-829d-fe3499110685@k13g2000pbq.googlegroups.com> On Sep 13, 10:52?pm, andrea crotti wrote: > I am in a situation where I have a class Obj which contains many > attributes, and also contains logically another object of class > Dependent. > But I'm not so sure it's a good idea, it's a bit smelly.. It's actually a well regarded technique known as composition: http://en.wikipedia.org/wiki/Object_composition While it has an ostensible focus on game development, I found this article to be very good at explaining the concept: http://gameprogrammingpatterns.com/component.html From metolone at gmail.com Thu Sep 13 22:09:38 2012 From: metolone at gmail.com (Mark Tolonen) Date: Thu, 13 Sep 2012 19:09:38 -0700 (PDT) Subject: Least-lossy string.encode to us-ascii? In-Reply-To: References: <50524F6F.6070604@tim.thechases.com> Message-ID: <8a35c480-7594-4202-afe8-f03db9418301@googlegroups.com> On Thursday, September 13, 2012 4:53:13 PM UTC-7, Tim Chase wrote: > On 09/13/12 18:36, Terry Reedy wrote: > > > On 9/13/2012 5:26 PM, Tim Chase wrote: > > >> I've got a bunch of text in Portuguese and to transmit them, need to > > >> have them in us-ascii (7-bit). I'd like to keep as much information > > >> as possible,just stripping accents, cedillas, tildes, etc. > > > > > > 'keep as much information as possible' would mean an effectively > > > lossless transliteration, which you could do with a dict. > > > {: 'o', : 'c,' (or pick something that would > > > never occur in normal text of the sort you are transmitting), ...} > > > > Vlastimil's solution kept the characters but stripped them of their > > accents/tildes/cedillas/etc, doing just what I wanted, all using the > > stdlib. Hard to do better than that :-) > > > > -tkc How about using UTF-7 for transmission and decode on the other end? This keeps the transmission all 7-bit, and no loss. >>> s=u"servi?o m?vil".encode('utf-7') >>> print s servi+AOc-o m+APM-vil >>> print s.decode('utf-7') servi?o m?vil -Mark From metolone at gmail.com Thu Sep 13 22:09:38 2012 From: metolone at gmail.com (Mark Tolonen) Date: Thu, 13 Sep 2012 19:09:38 -0700 (PDT) Subject: Least-lossy string.encode to us-ascii? In-Reply-To: References: <50524F6F.6070604@tim.thechases.com> Message-ID: <8a35c480-7594-4202-afe8-f03db9418301@googlegroups.com> On Thursday, September 13, 2012 4:53:13 PM UTC-7, Tim Chase wrote: > On 09/13/12 18:36, Terry Reedy wrote: > > > On 9/13/2012 5:26 PM, Tim Chase wrote: > > >> I've got a bunch of text in Portuguese and to transmit them, need to > > >> have them in us-ascii (7-bit). I'd like to keep as much information > > >> as possible,just stripping accents, cedillas, tildes, etc. > > > > > > 'keep as much information as possible' would mean an effectively > > > lossless transliteration, which you could do with a dict. > > > {: 'o', : 'c,' (or pick something that would > > > never occur in normal text of the sort you are transmitting), ...} > > > > Vlastimil's solution kept the characters but stripped them of their > > accents/tildes/cedillas/etc, doing just what I wanted, all using the > > stdlib. Hard to do better than that :-) > > > > -tkc How about using UTF-7 for transmission and decode on the other end? This keeps the transmission all 7-bit, and no loss. >>> s=u"servi?o m?vil".encode('utf-7') >>> print s servi+AOc-o m+APM-vil >>> print s.decode('utf-7') servi?o m?vil -Mark From cs at zip.com.au Thu Sep 13 22:12:11 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 14 Sep 2012 12:12:11 +1000 Subject: Decorators not worth the effort In-Reply-To: References: Message-ID: <20120914021211.GA15642@cskk.homeip.net> On 13Sep2012 18:58, alex23 wrote: | On Sep 14, 3:54?am, Jean-Michel Pichavant | wrote: | > I don't like decorators, I think they're not worth the mental effort. | | Because passing a function to a function is a huge cognitive burden? It is for me when I'm _writing_ the decorator:-) But if I get it right and name it well I find it dramaticly _decreases_ the cognitive burden of the code using the decorator... -- Cameron Simpson Observing the first balloon ascent in Paris, [Ben] Franklin heard a scoffer ask, "What good is it?" He spoke for a generation of scientists in his retort, "What good is a newly born infant?" - John F. Kasson From cs at zip.com.au Thu Sep 13 22:31:28 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 14 Sep 2012 12:31:28 +1000 Subject: Batching HTTP requests with httplib (Python 2.7) In-Reply-To: References: Message-ID: <20120914023128.GA15850@cskk.homeip.net> On 13Sep2012 19:34, Chicken McNuggets wrote: | I'm writing a simple library that communicates with a web service and am | wondering if there are any generally well regarded methods for batching | HTTP requests? | | The problem with most web services is that they require a list of | sequential commands to be executed in a certain order to complete a | given task (or at least the one I am using does) so having to manually | call each command is a bit of a pain. How would you go about the design | of a library to interact with these services? | | Any help is greatly appreciated :). Maybe I'm missing something. What's hard about: - wrapping the web services calls in a simple wrapper which composes the call, runs it, and returns the result parts This lets you hide all the waffle about the base URL, credentials etc in the wrapper and only supply the essentials at call time. - writing your workflow thing then as a simple function: def doit(...): web_service_call1(...) web_service_call2(...) web_service_call3(...) with whatever internal control is required? This has worked for me for simple things. What am I missing about the larger context? -- Cameron Simpson Clymer's photographs of this procedure show a very clean head. This is a lie. There is oil in here, and lots of it. - Mike Mitten, rec.moto, 29sep1993 From python.list at tim.thechases.com Thu Sep 13 22:34:52 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 13 Sep 2012 21:34:52 -0500 Subject: Least-lossy string.encode to us-ascii? In-Reply-To: <8a35c480-7594-4202-afe8-f03db9418301@googlegroups.com> References: <50524F6F.6070604@tim.thechases.com> <8a35c480-7594-4202-afe8-f03db9418301@googlegroups.com> Message-ID: <505297CC.2060001@tim.thechases.com> On 09/13/12 21:09, Mark Tolonen wrote: > On Thursday, September 13, 2012 4:53:13 PM UTC-7, Tim Chase wrote: >> Vlastimil's solution kept the characters but stripped them of their >> accents/tildes/cedillas/etc, doing just what I wanted, all using the >> stdlib. Hard to do better than that :-) > > How about using UTF-7 for transmission and decode on the other end? This keeps the transmission all 7-bit, and no loss. > > >>> s=u"servi?o m?vil".encode('utf-7') > >>> print s > servi+AOc-o m+APM-vil > >>> print s.decode('utf-7') > servi?o m?vil Nice if I control both ends of the pipe. Unfortunately, I only control what goes in, and I want it to be as un-screw-uppable as possible when it comes out the other end (may be web, CSV files, PDFs, FTP'ed file dumps, spreadsheets, word-processing documents, etc), and us-ascii is the lowest-common-denominator of unscrewuppableness while requiring nothing of the the other end. :-) -tkc From wuwei23 at gmail.com Thu Sep 13 23:25:19 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 13 Sep 2012 20:25:19 -0700 (PDT) Subject: Decorators not worth the effort References: Message-ID: <50d83c64-033e-498f-a7a4-bafb2f322807@k13g2000pbq.googlegroups.com> On Sep 14, 12:12?pm, Cameron Simpson wrote: > On 13Sep2012 18:58, alex23 wrote: > | On Sep 14, 3:54?am, Jean-Michel Pichavant | wrote: > | > I don't like decorators, I think they're not worth the mental effort. > | > | Because passing a function to a function is a huge cognitive burden? > > It is for me when I'm _writing_ the decorator:-) But if I get it right > and name it well I find it dramaticly _decreases_ the cognitive burden > of the code using the decorator... Okay, I will concede that point :) From steve+comp.lang.python at pearwood.info Thu Sep 13 23:35:29 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2012 03:35:29 GMT Subject: datetime References: Message-ID: <5052a601$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 13 Sep 2012 15:19:32 +0000, Max wrote: > How do I set the time in Python? You don't. You ask the operating system to set the time. If you don't have permission to change the time, which regular users shouldn't have because it is a security threat, it will (rightly) fail. E.g.: import os os.system('date -s %s' % date_str) In Python 3.3 there is a wrapper in the time module that allows you to set the clock without an explicit system call. Again, you need permission to set the clock, or it will fail. > Also, is there any *direct* way to shift it? > > Say, it's 09:00 now and Python makes it 11:30 *without* me having > specified "11:30" but only given Python the 2h30m interval. Certainly. Just call: time.sleep(2*60**2 + 30*60) and when it returns, the clock will have shifted forward by 2h30m, just like magic! *wink* > Note that any "indirect" methods may need complicated ways to keep track > of the milliseconds lost while running them. It even took around one > second in some virtual machine guest systems. So I'm hoping Python > happens to have the magic needed to do the job for me. No. Setting the clock is not the business of any user-space application. It is the job of the operating system, which will do it the right way. At most, the application can call the OS, directly or indirectly, but it has no control over how many milliseconds are lost when you do so. On Linux, Unix or Mac, that right way is to use NTP, which will keep your computer's clock syncronised with a trusted external source. In a virtual machine, the right way is to use NTP to syncronise the VM host's time, and then tell the host to synchronise itself with the VM. On Windows, well you'll have to ask a Windows expert. If you want to bypass NTP and manage time yourself -- say, you want to simulate "what happens when the clock strikes midnight?" without having to wait for midnight -- then you probably don't need millisecond precision. If you do need millisecond precision -- why??? -- *and* expect to do it from a user-space application, you're going to have a bad time. -- Steven From steve+comp.lang.python at pearwood.info Thu Sep 13 23:39:46 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2012 03:39:46 GMT Subject: Comparing strings from the back? References: <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> Message-ID: <5052a702$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 13 Sep 2012 17:06:23 -0400, Dwight Hutto wrote: > Then there is the problem of people saying you posted too much of the > context, or not inline with the OP, just at the end, or top posting. The solution to "you quoted too much unnecessary verbiage" is not "quote nothing". It is quote only the parts that are relevant. > I try to keep it along the line of what the OP has read, and they know > the context in which it's meant. You're assuming that people read your posts immediately after they read the post you replied to. Always imagine that your reply will be read a week after the post you replied to. Do you still expect the reader to understand what you're talking about? -- Steven From wuwei23 at gmail.com Thu Sep 13 23:48:38 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 13 Sep 2012 20:48:38 -0700 (PDT) Subject: Comparing strings from the back? References: <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> Message-ID: <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> On Sep 14, 5:37?am, Dwight Hutto wrote: > Why don't take the time to read the OP, and ramit in your head? Please, don't be a dick. From steve+comp.lang.python at pearwood.info Thu Sep 13 23:49:00 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2012 03:49:00 GMT Subject: Least-lossy string.encode to us-ascii? References: Message-ID: <5052a92b$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 13 Sep 2012 16:26:07 -0500, Tim Chase wrote: > I've got a bunch of text in Portuguese and to transmit them, need to > have them in us-ascii (7-bit). That could mean two things: 1) "The receiver is incapable of dealing with Unicode in 2012, which is frankly appalling, but what can I do about it?" 2) "The transport mechanism I use to transmit the data is only capable of dealing with 7-bit ASCII strings, which is sad but pretty much standard." In the case of 1), I suggest you look at the Unicode Hammer, a.k.a. "The Stupid American": http://code.activestate.com/recipes/251871 and especially the very many useful comments. In the case of 2), just binhex or uuencode your data for transport. -- Steven From steve+comp.lang.python at pearwood.info Fri Sep 14 00:05:32 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2012 04:05:32 GMT Subject: Least-lossy string.encode to us-ascii? References: <50524F6F.6070604@tim.thechases.com> <8a35c480-7594-4202-afe8-f03db9418301@googlegroups.com> Message-ID: <5052ad0c$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 13 Sep 2012 21:34:52 -0500, Tim Chase wrote: > On 09/13/12 21:09, Mark Tolonen wrote: >> On Thursday, September 13, 2012 4:53:13 PM UTC-7, Tim Chase wrote: >>> Vlastimil's solution kept the characters but stripped them of their >>> accents/tildes/cedillas/etc, doing just what I wanted, all using the >>> stdlib. Hard to do better than that :-) >> >> How about using UTF-7 for transmission and decode on the other end? >> This keeps the transmission all 7-bit, and no loss. >> >> >>> s=u"servi?o m?vil".encode('utf-7') >> >>> print s >> servi+AOc-o m+APM-vil >> >>> print s.decode('utf-7') >> servi?o m?vil > > Nice if I control both ends of the pipe. Unfortunately, I only control > what goes in, and I want it to be as un-screw-uppable as possible when > it comes out the other end (may be web, CSV files, PDFs, FTP'ed file > dumps, spreadsheets, word-processing documents, etc), and us-ascii is > the lowest-common-denominator of unscrewuppableness while requiring > nothing of the the other end. :-) Wrong. It requires support for US-ASCII. What if the other end is an IBM mainframe using EBCDIC? Frankly, I am appalled that you are intentionally perpetuating the ignorance of US-ASCII-only applications, not because you have no choice about inter-operating with some ancient, brain-dead application, but because you artificially choose to follow an obsolete *and incorrect* standard. It is *incorrect* because you can change the meaning of text by stripping accents and deleting characters. Consequences can include murder and suicide: http://gizmodo.com/382026/a-cellphones-missing-dot-kills-two-people-puts-three-more-in-jail At least tell me that "ASCII only" is merely an *option* for your application, not the only choice, and that it defaults to UTF-8 which is the right standard to use for text. -- Steven From rosuav at gmail.com Fri Sep 14 00:15:55 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Sep 2012 14:15:55 +1000 Subject: Comparing strings from the back? In-Reply-To: <5052a702$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <5052a702$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 14, 2012 at 1:39 PM, Steven D'Aprano wrote: > You're assuming that people read your posts immediately after they read > the post you replied to. Always imagine that your reply will be read a > week after the post you replied to. And a week is extremely generous too; these posts get archived on the web. I *frequently* find myself hitting mailing list archives when researching obscurities. This is also another good reason to post follow-ups to the list, rather than in private email. You might never be thanked, but somebody years down the track may find the question and an associated answer. ChrisA From dwightdhutto at gmail.com Fri Sep 14 00:46:04 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 00:46:04 -0400 Subject: Comparing strings from the back? In-Reply-To: <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> References: <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> Message-ID: On Thu, Sep 13, 2012 at 11:48 PM, alex23 wrote: > On Sep 14, 5:37 am, Dwight Hutto wrote: >> Why don't take the time to read the OP, and ramit in your head? > > Please, don't be a dick. > > For telling him to ramit into his head that you should read the OP? -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From wuwei23 at gmail.com Fri Sep 14 00:54:54 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 13 Sep 2012 21:54:54 -0700 (PDT) Subject: Comparing strings from the back? References: <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> Message-ID: On Sep 14, 2:46?pm, Dwight Hutto wrote: > For telling him to ramit into his head that you should read the OP? Yes. I'm not sure if it was intentionally racist, but you come across as a bit of a dwight supremacist. From tadegenban at gmail.com Fri Sep 14 01:09:47 2012 From: tadegenban at gmail.com (genban tade) Date: Fri, 14 Sep 2012 13:09:47 +0800 Subject: hi Message-ID: -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Sep 14 01:24:04 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 13 Sep 2012 22:24:04 -0700 Subject: subprocess call is not waiting. In-Reply-To: References: <746448155.528147.1347550469072.JavaMail.root@sequans.com> Message-ID: On Thu, Sep 13, 2012 at 11:36 AM, wrote: > Thanks, guys. > MRAB-RedHat 6 64-bit, Python 2.6.5 In your Unix shell, what does the command: type htar output? > JM-Here's the relevant stuff from my last try. If you could give a complete, self-contained example, it would assist us in troubleshooting your problem. > I've also tried with subprocess.call. Just now I tried shell=True, but it made no difference. It's possible that htar uses some trickery to determine whether it's being invoked from a terminal or by another program, and changes its behavior accordingly, although I could not find any evidence of that based on scanning its manpage. > sticking a print(out) in there just prints a blank line in between each iteration. It's not until the 5 trials are finished that I am told: download failed, etc. > > from os.path import exists > from subprocess import call > from subprocess import Popen > from shlex import split > from time import sleep > > while (exists(file)==0) and (nTries < 5): `file` is the name of a built-in type in Python; it should therefore not be used as a variable name. Also, one would normally write that as: while not exists(file) and nTries < 5: > a = Popen(split('htar -xvf ' + htarArgs), stdout=PIPE, stderr=PIPE) What's the value of `htarArgs`? (with any sensitive parts anonymized) Also, you really shouldn't use shlex.split() at run-time like that. Unless `htarArgs` is already quoted/escaped, you'll get bad results for many inputs. Use shlex.split() once at the interactive interpreter to figure out the general form of the tokenization, then use the static result in your program as a template. > (out,err) = a.communicate() > if exists(file)==0: > nTries += 1 > sleep(0.5) > > if exists(file)==0: # now that the file should be moved > print('download failed: ' + file) > return 1 > > I've also tried using shell=True with popopen. I presume you meant Popen. Cheers, Chris From clp2 at rebertia.com Fri Sep 14 01:27:23 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 13 Sep 2012 22:27:23 -0700 Subject: subprocess call is not waiting. In-Reply-To: References: Message-ID: On Thu, Sep 13, 2012 at 8:17 AM, wrote: > I have a subprocess.call > But it doesn't work as intended. > Should I just go back to os.system? Did the os.system() version work? As of recent Python versions, os.system() is itself implemented using the `subprocess` module, so if it does work, then it assuredly can be made to work using the `subprocess` module instead. Cheers, Chris From dwightdhutto at gmail.com Fri Sep 14 01:32:28 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 01:32:28 -0400 Subject: hi In-Reply-To: References: Message-ID: Hey, how are you? -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Fri Sep 14 01:34:30 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 01:34:30 -0400 Subject: hi In-Reply-To: References: Message-ID: Wait, that was out of context. Subject: Hi On Fri, Sep 14, 2012 at 1:09 AM, genban tade wrote: > > > -- > http://mail.python.org/mailman/listinfo/python-list > Hey, how are you? -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Fri Sep 14 01:38:52 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 01:38:52 -0400 Subject: Comparing strings from the back? In-Reply-To: References: <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> Message-ID: On Fri, Sep 14, 2012 at 12:54 AM, alex23 wrote: > On Sep 14, 2:46 pm, Dwight Hutto wrote: >> For telling him to ramit into his head that you should read the OP? > > Yes. I'm not sure if it was intentionally racist, but you come across > as a bit of a dwight supremacist. Please explain any logic whatsoever that would give you that conclusion. Seems more like propaganda, and you're not very good at it. I think you're referring to a play on words(ramit). Ain't I so punny. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Fri Sep 14 01:41:28 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 01:41:28 -0400 Subject: hi In-Reply-To: References: Message-ID: On Fri, Sep 14, 2012 at 1:09 AM, genban tade -- > http://mail.python.org/mailman/listinfo/python-list ail.com> wrote: > > > -- > http://mail.python.org/mailman/listinfo/python-list > thank you for your reply,I'm new here You'll love it here. It's always amusing. But remember to hit reply all when you respond(if you're in gmail). -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Fri Sep 14 01:44:06 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 01:44:06 -0400 Subject: hi In-Reply-To: References: Message-ID: > You'll love it here. It's always amusing. > But remember to hit reply all Unless you might want to contact someone personally. Some don't mind, and some may complain. Me I don't care either way. Great to meet you though. Hope you find the it educationally stimulating. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dihedral88888 at googlemail.com Fri Sep 14 01:57:54 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 13 Sep 2012 22:57:54 -0700 (PDT) Subject: Python presentations In-Reply-To: References: <06a1a81b-246b-4e7b-ba34-4701f46889c8@googlegroups.com> <50525f48$0$6573$9b4e6d93@newsspool3.arcor-online.net> Message-ID: Chris Angelico? 2012?9?14????UTC+8??6?39?25???? > On Fri, Sep 14, 2012 at 8:33 AM, Alexander Blinne wrote: > > > On 13.09.2012 21:01, 88888 Dihedral wrote: > > >> def powerlist(x, n): > > >> # n is a natural number > > >> result=[] > > >> y=1 > > >> for i in xrange(n): > > >> result.append(y) > > >> y*=x > > >> return result # any object in the local function can be returned > > > > > > def powerlist(x, n): > > > result=[1] > > > for i in xrange(n-1): > > > result.append(result[-1]*x) > > > return result > > > > > > def powerlist(x,n): > > > if n==1: > > > return [1] > > > p = powerlist(x,n-1) > > > return p + [p[-1]*x] > > > > Eh, much simpler. > > > > def powerlist(x,n): > > return [x*i for i in xrange(n-1)] > > > > But you're responding to a bot there. Rather clever as bots go, though. > > > > ChrisA I do not object the list comprehension in concept. But I have to convert python code to cython from time to time. Well, this imposes some coding style definitely. From dihedral88888 at googlemail.com Fri Sep 14 01:57:54 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 13 Sep 2012 22:57:54 -0700 (PDT) Subject: Python presentations In-Reply-To: References: <06a1a81b-246b-4e7b-ba34-4701f46889c8@googlegroups.com> <50525f48$0$6573$9b4e6d93@newsspool3.arcor-online.net> Message-ID: Chris Angelico? 2012?9?14????UTC+8??6?39?25???? > On Fri, Sep 14, 2012 at 8:33 AM, Alexander Blinne wrote: > > > On 13.09.2012 21:01, 88888 Dihedral wrote: > > >> def powerlist(x, n): > > >> # n is a natural number > > >> result=[] > > >> y=1 > > >> for i in xrange(n): > > >> result.append(y) > > >> y*=x > > >> return result # any object in the local function can be returned > > > > > > def powerlist(x, n): > > > result=[1] > > > for i in xrange(n-1): > > > result.append(result[-1]*x) > > > return result > > > > > > def powerlist(x,n): > > > if n==1: > > > return [1] > > > p = powerlist(x,n-1) > > > return p + [p[-1]*x] > > > > Eh, much simpler. > > > > def powerlist(x,n): > > return [x*i for i in xrange(n-1)] > > > > But you're responding to a bot there. Rather clever as bots go, though. > > > > ChrisA I do not object the list comprehension in concept. But I have to convert python code to cython from time to time. Well, this imposes some coding style definitely. From wuwei23 at gmail.com Fri Sep 14 02:06:42 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 13 Sep 2012 23:06:42 -0700 (PDT) Subject: Comparing strings from the back? References: <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> Message-ID: On Sep 14, 3:39?pm, Dwight Hutto wrote: > Please explain any logic whatsoever that would give you that conclusion. Well, this: > I think you're referring to a play on words(ramit). Using foreign names derogatively is a common tactic of the racist. > Ain't I so punny. Not really, no. From wuwei23 at gmail.com Fri Sep 14 02:09:59 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 13 Sep 2012 23:09:59 -0700 (PDT) Subject: hi References: Message-ID: <2929e48b-0131-49ab-b209-8aaf1426aa50@s9g2000pbh.googlegroups.com> On Sep 14, 3:44?pm, Dwight Hutto wrote: > CEO:http://www.hitwebdevelopment.com I don't know what gives more of a negative impression of your business, your acting like a tedious douchebag or the website itself. From ben+python at benfinney.id.au Fri Sep 14 02:28:14 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 14 Sep 2012 16:28:14 +1000 Subject: Guides for communicating with business accounting systems References: <87y5kenez2.fsf@benfinney.id.au> Message-ID: <87pq5pnmo1.fsf@benfinney.id.au> Emile van Sebille writes: > The only standard I'm aware of is the EDI specification which I first > encountered in the mid 70's and which is updated routinely. The full > spec is the size of a telephone book (do they even still make those?) Thanks, that's something to look into. And yes, in Melbourne we're still getting phone books delivered. Chris Angelico writes: > GST isn't particularly complicated, but again, be really REALLY clear > what's going on. It's better to be massively verbose in the database > and then squash things down for display than to be left wondering Good advice, if depressing in its prospects. > Don't use MySQL. :) Okay, that's hardly a *rule*, but it's a strong > recommendation. That's another struggle we have in our future, unfortunately. -- \ ?If we listen only to those who are like us, we will squander | `\ the great opportunity before us: To live together peacefully in | _o__) a world of unresolved differences.? ?David Weinberger | Ben Finney From dieter at handshake.de Fri Sep 14 02:34:33 2012 From: dieter at handshake.de (Dieter Maurer) Date: Fri, 14 Sep 2012 08:34:33 +0200 Subject: How to implement a combo Web and Desktop app in python. References: Message-ID: <878vcdjeo6.fsf@handshake.de> Shawn McElroy writes: > ... > So I need to find a way I can implement this in the best way... It is in general very difficult to say reliable things about the "best" way. Because, that depends very much on details. My former employer has created a combo destop/online application based on "Zope". "Zope" is a web application framework, platform independent, easily installable, with an integrated HTTP server. It is one of the natural choices as a basis for a Python implemented web application. To get a desktop application, application and Zope was installed on the client system and a standard browser used for the ui. The main drawback of this scheme came from the limitations of the browser implemented ui. It has been very difficult to implement "deep integration" with the desktop (e.g. "drap & drop" in and out of the application; integration with the various other applications (Outlook, Word, ...)) and to provide "gimicks" provided by the surrounding environment. Thus, after 8 years, the application started to look old style and the browser based ui was replaced by a stand alone desktop application that talked via webservices with an online system (if necessary). Thus, *if* the ui requirements are fairly low (i.e. can fairly easily be implemented via a browser) you could go a similar route. If your ui requirements are high, you can replace the browser by a self developped (thick) ui application that talks via an abstraction with its backend. Properly designed, the abstraction could either be implemented by direct calls (to a local library) or by webservice calls (to an online service). This way, you could use your client application both for the (local) desktop only case as well as for the online case. Your description (stripped) suggests that you need special support for "offline" usage. The is separate functionality, independent of the desktop/online question. For example, highly available distributed database systems must provide some synchronization mechanism for resynchronization after temporary network connectivity loss. Another example: transactional systems must not lose transactions and can for example use asnychronous message queues to ensure that messages are safely delivered even in the case of temporary communication problems or failures. Thus, look at these aspects independent from the desktop/online szenario -- these aspects affect any distributed system and solutions can be found there. Those solutions tend to be complex (and expensive). From rosuav at gmail.com Fri Sep 14 02:36:58 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Sep 2012 16:36:58 +1000 Subject: Guides for communicating with business accounting systems In-Reply-To: <87pq5pnmo1.fsf@benfinney.id.au> References: <87y5kenez2.fsf@benfinney.id.au> <87pq5pnmo1.fsf@benfinney.id.au> Message-ID: On Fri, Sep 14, 2012 at 4:28 PM, Ben Finney wrote: > Chris Angelico writes: > >> Don't use MySQL. :) Okay, that's hardly a *rule*, but it's a strong >> recommendation. > > That's another struggle we have in our future, unfortunately. We moved from MySQL to PostgreSQL a little while ago, and haven't looked back. I used to automatically think of MySQL when discussing open source databasing (I've also used DB2, but not in any OSS context), but just as there's no reason to instinctively reach for PHP when you want a dynamic web site, there's no need to naturally grab MySQL. Actually I haven't used Postgres with Python yet. Should probably do that at some point. But the MySQL bindings for Python aren't so awesome they can't be matched by any other. ChrisA From dieter at handshake.de Fri Sep 14 02:40:55 2012 From: dieter at handshake.de (Dieter Maurer) Date: Fri, 14 Sep 2012 08:40:55 +0200 Subject: Decorators not worth the effort References: Message-ID: <874nn1jedk.fsf@handshake.de> > On Sep 14, 3:54?am, Jean-Michel Pichavant > wrote: >> I don't like decorators, I think they're not worth the mental effort. Fine. I like them because they can vastly improve reusability and drastically reduce redundancies (which I hate). Improved reusability and reduced redundancies can make applications more readable, easier to maintain and faster to develop. From luckysmack at gmail.com Fri Sep 14 02:52:55 2012 From: luckysmack at gmail.com (Shawn McElroy) Date: Thu, 13 Sep 2012 23:52:55 -0700 (PDT) Subject: How to implement a combo Web and Desktop app in python. In-Reply-To: References: Message-ID: This does help. I have not determined if I will make a native UI for the desktop yet. To start I just figured I would use the web based interface, and if needed, use something like qt, or wx. As for the ability to drag items into the user interface, there are javascript libraries that can handle that now, which triggers an upload of that file. So I dont think that would be a large issue. For example, minus.com does this really well with file uploads (mostly image sharing). Although you are correct in the aspect of having 'real' OS level integration. Being able to communicate with other apps as well as contextual menus. Although, could I not still implement those features from python, into the host system from python? There are also tools like 'kivi' which allow you to get system level access to do things. Though im not too sure on how far that extends, or how useful it would be. as it stands now, I plan on having the 3 layers of my app. core, apps, and presentation. the core would go on both web and desktop and has no UI. the apps add on functionality to the core, based on what the app does. This way I can distribute a single app, without the others. And the UI, will be different based on platform. web/mobile will just be html/css, and desktop, will likely end up being something like qt/wx. Thanks. On Thursday, September 13, 2012 5:20:48 PM UTC-7, Shawn McElroy wrote: > I am somewhat new to python. I am still learning it. I am starting an app that I ma not quite sure how to best implement it. > > > > In the grand scheme, there will be 4 apps total. There will be a core shared between them that allows them to easily talk to each other (ill explain) and communicate with a database, as well as redis for pubsub events. I also need things to work on both web, and desktop. So i will likely have to keep the UI and the core of each app in their own separate apps entirely. The main core on the web will be a REST interface with proper content negotiation, depending on what is requested. > > > > Normally, if the desktop is online, you may think "If you have a good rest interface, this makes the desktop version pointless". While true for some cases, the reason I need a desktop implementation, is because the end user still needs to be able to use the app while there is no internet connectivity. For example, an in store POS system. They would still need to process transactions like cash while offline, and they would also need access to their inventory. This is also good for intermittent connection problems, and for speed. So they don't have to worry about networking issues to do things. For this reason a local database is also needed. And when online, it keeps in sync with the remote database. > > > > So I need to find a way I can implement this in the best way, to help prevent code duplication, and reduce the amount of time it takes to get into production. If possible, I would like to use some kind of built in webkit for desktop as well, so users have the same experience both online and locally. So i would likely need to package a webserver as well (tornado/gunicorn?) > > > > If it was entirely online, I see how I could implement this, but when needing to have a desktop version, I feel like I would need to split things up differently. Here is so far, how I would think that I need to structure everything. > > > > Core: this is the CORE api to talk to the server, and interact with the systems. I should be able to do most things using this interface, and the individual apps may (or may not) add onto this for specific functionality. > > > > App: this is the individual apps. going along with my example, these could be the actual POS interface, a shopping cart, product catalog/inventory management, and an admin/backend that would tie into everything and be able to show things like product/customer stats and so on. > > > > Presentation: the actual user interfaces for each app. > > > > I also feel like I should put it all into one app, bundled, and only split up the ui based on web vs desktop. The different 4 apps may also be at 4 web addresses. such as: > > > > http://main.com (would probably include the admin app) > > http://pos.com > > http://products.com > > > > so what is avaiable to the end user, will also be dependant on the domain as well. If they are all on one core, with only the UI separated out, the rest interface would likely be on all of them and only allow things based on what app you are looking at. Unless you are on the master domain where everything is allowed. > > > > I understand this is a complex question about implementation, and could be philosophically different depending on the developer. But im not sure how to best go about it, so I was hoping to get some ideas and input. Should I do it an entirely different way? > > > > Currently for the apps themselves, I am looking at using either flask, bottle, web2py, or pyramid. I need to understand how I am going to implement it more before I choose a framework. Django is nice, but it doesnt seem to fit what I need to do. There are rest api plugins available for it, but if the core of my app is based on REST, it seemed to make more sense to start with something that has REST built into the core of the framework. > > > > Any input or advice is much appreciated. Thanks. > > > > - Shawn McElroy From ian.g.kelly at gmail.com Fri Sep 14 03:08:55 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 14 Sep 2012 01:08:55 -0600 Subject: hi In-Reply-To: <2929e48b-0131-49ab-b209-8aaf1426aa50@s9g2000pbh.googlegroups.com> References: <2929e48b-0131-49ab-b209-8aaf1426aa50@s9g2000pbh.googlegroups.com> Message-ID: On Fri, Sep 14, 2012 at 12:09 AM, alex23 wrote: > On Sep 14, 3:44 pm, Dwight Hutto wrote: >> CEO:http://www.hitwebdevelopment.com > > I don't know what gives more of a negative impression of your > business, your acting like a tedious douchebag or the website itself. Holy cow, that's the website of a web development company? Hopefully the brokenness of it (e.g., the "Contact Information" link leads to a 404; how are potential clients supposed to contact you?), the total lack of content, and the overall lack of graphic design are because it's a prototype and hasn't been launched yet (so why are you advertising it in your sig?) I can't see any such excuse for the 60-MB poorly rendered animated GIF on the front page or the embedded background music (that thankfully doesn't seem to play in Firefox). I don't want to be nasty about it, but as a web development company you have to consider that a website like that is going to drive away clients. Also, Dwight, you might want to reconsider the name of your company. Googling for "hit web development" turns up nothing about you, but a lot of hits about a defunct Utah company called "HIT Web Design" that apparently was running a scam and generated a lot of bad press. If it were me, I wouldn't want potential clients googling the company, seeing all that, and thinking that it's the same company or that there might be a relationship. From dwightdhutto at gmail.com Fri Sep 14 03:22:21 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 03:22:21 -0400 Subject: hi In-Reply-To: <2929e48b-0131-49ab-b209-8aaf1426aa50@s9g2000pbh.googlegroups.com> References: <2929e48b-0131-49ab-b209-8aaf1426aa50@s9g2000pbh.googlegroups.com> Message-ID: On Fri, Sep 14, 2012 at 2:09 AM, alex23 wrote: > On Sep 14, 3:44 pm, Dwight Hutto wrote: >> CEO:http://www.hitwebdevelopment.com > > I don't know what gives more of a negative impression of your > business, your acting like a tedious douchebag or the website itself. > -- > http://mail.python.org/mailman/listinfo/python-list This is more than likely a projection of yourself onto others. And this just makes you a gossiping gabby, who likes to bring people down anytime they meet someone, instead of letting them make their own opinions. Completely OT for this discussion. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From rosuav at gmail.com Fri Sep 14 03:30:26 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Sep 2012 17:30:26 +1000 Subject: pythonOCC examples doesn't work? In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47416678FC5@SCACMX008.exchad.jpmchase.net> Message-ID: On Fri, Sep 14, 2012 at 11:14 AM, Dwight Hutto wrote: > [over a hundred quoted lines snipped] > And if you look at the above in gmail, you can see the ...'s that when > not clicked, won't show some of the responses I leave just above, and > it clips my signature line as well. That's a Gmail feature, and a sop to people who can't take a moment to trim quoted text. Taking your above post as an example, there were (according to my calculation) 111 lines of text that had already been sent, being _re_sent in your post. Not everyone uses Gmail. And not everyone runs off 100Mbit internet connections. And even if everyone were to use Gmail off 100Mbit internet connections, I would still recommend trimming the text, because Gmail gives you precisely two options: all the way collapsed, or all the way expanded. If I want to read more context, I get _all_ the context. That's still not all that useful. Right while you make a post is the best time to decide how much context is needed. Spend just a few seconds thinking about how much to trim, and you can make things easier for everyone who reads your post, whether it be on python-list, comp.lang.python, or one of several web-accessible archives. And remember, this is for posterity, so be honest. How do you feel? Interesting... ChrisA From dwightdhutto at gmail.com Fri Sep 14 03:32:40 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 03:32:40 -0400 Subject: hi In-Reply-To: References: <2929e48b-0131-49ab-b209-8aaf1426aa50@s9g2000pbh.googlegroups.com> Message-ID: On Fri, Sep 14, 2012 at 3:08 AM, Ian Kelly wrote: > On Fri, Sep 14, 2012 at 12:09 AM, alex23 wrote: >> On Sep 14, 3:44 pm, Dwight Hutto wrote: >>> CEO:http://www.hitwebdevelopment.com >> >> I don't know what gives more of a negative impression of your >> business, your acting like a tedious douchebag or the website itself. > > Holy cow, that's the website of a web development company? Hopefully > the brokenness of it (e.g., the "Contact Information" link leads to a > 404 I'm constructing now as we speak, thanks for the note about placing in special 404 error pages. I do more than just this. I spend too much time taking the time to explain things that were blown out of proportion to people like you. And I think there might be a few avatars one person might post under. ; how are potential clients supposed to contact you?), the total > lack of content, and the overall lack of graphic design are because > it's a prototype and hasn't been launched yet (so why are you > advertising it in your sig?) For constructive criticism., and I like how it's starting to come together. People have different tastes. I can't see any such excuse for the > 60-MB poorly rendered animated GIF on the front page or the embedded I'm reducing that down later. It was originally 111 done in blender, and it's still a rough draft site. I don't mind the criticism, because I'm only placing it in my sig at this point, as I'm constructing it. > background music (that thankfully doesn't seem to play in Firefox). I > don't want to be nasty about it, but as a web development company you > have to consider that a website like that is going to drive away > clients. Why, because of a few graphics, and some music, that YOU don't happen to like. Statistically speaking, you're apparently not my target demographic. > > Also, Dwight, you might want to reconsider the name of your company. > Googling for "hit web development" turns up nothing about you, but a > lot of hits about a defunct Utah company called "HIT Web Design" that > apparently was running a scam and generated a lot of bad press. If it > were me, I wouldn't want potential clients googling the company, > seeing all that, and thinking that it's the same company or that there > might be a relationship. No, none at all. I came up with this name, and overtime, it should overshadow what the other company did. I don't see how you can go wrong, when the client tells you what they want to see, or here on their site or app. > http://mail.python.org/mailman/listinfo/python-list -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From vlastimil.brom at gmail.com Fri Sep 14 03:38:33 2012 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 14 Sep 2012 09:38:33 +0200 Subject: [SOLVED] Least-lossy string.encode to us-ascii? In-Reply-To: <505258E1.7020500@tim.thechases.com> References: <50524F6F.6070604@tim.thechases.com> <505258E1.7020500@tim.thechases.com> Message-ID: 2012/9/14 Tim Chase : > On 09/13/12 16:44, Vlastimil Brom wrote: >> >>> import unicodedata >> >>> unicodedata.normalize("NFD", u"servi?o m?vil").encode("ascii", "ignore").decode("ascii") >> u'servico movil' > > Works well for all the test-cases I threw at it. Thanks! > > -tkc > > Hi, I am glad, it works, but I agree with the other comments, that it would be preferable to keep the original accented text, if at all possible in the whole processing. The above works by decomposing the accented characters into "basic" characters and the bare accents (combining diacritics) using normalize() and just striping anything outside ascii in encode("...", "ignore") This works for "combinable" accents, and most of the Portuguese characters outside of ascii appear to fall into this category, but there are others as well. E.g. according to http://tlt.its.psu.edu/suggestions/international/bylanguage/portuguese.html there are at least ?????, which would be lost completely in such conversion. ? (dec.: 170) (hex.: 0xaa) # FEMININE ORDINAL INDICATOR ? (dec.: 186) (hex.: 0xba) # MASCULINE ORDINAL INDICATOR You can preprocess such cases as appropriate before doing the conversion, e.g. just: >>> u"?????".replace(u"?", u"o").replace(u"?", u"a").replace(u"?", u'"').replace(u"?", u'"').replace(u"?", u"EUR") u'oa""EUR' >>> or using a more elegant function and the replacement lists (eventually handling other cases as well). regards, vbr From dwightdhutto at gmail.com Fri Sep 14 03:49:40 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 03:49:40 -0400 Subject: pythonOCC examples doesn't work? In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47416678FC5@SCACMX008.exchad.jpmchase.net> Message-ID: > honest. How do you feel? Interesting... > Um, I guess like an inconsiderate bandwidth hog, but from now on I'll trim more text. First it was too little, and now it's too much. I just tend to cut out some or all depending on the scope of the conversation. If I just hit reply all, and send it out, it's not intentionally to use all of the text, and utilize the extra space, it's just a response. If the conversation is kind of just a few people, then I trim pretty much everything, which apparently set a guy name mark off, who I was polite to, but I'm not going to get slammed for a few simple posting mistakes, and more than likely a few of his aliases, or the group he tends to cheer up with. It's just a mailing list, lighten up because mistakes in posting will happen, even by accident. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From tadegenban at gmail.com Fri Sep 14 03:51:59 2012 From: tadegenban at gmail.com (genban tade) Date: Fri, 14 Sep 2012 15:51:59 +0800 Subject: hi In-Reply-To: References: Message-ID: Great to meet you, thank you for your advise 2012/9/14 Dwight Hutto > > You'll love it here. It's always amusing. > > But remember to hit reply all > > Unless you might want to contact someone personally. Some don't mind, > and some may complain. Me I don't care either way. > > Great to meet you though. Hope you find the it educationally stimulating. > > > -- > Best Regards, > David Hutto > CEO: http://www.hitwebdevelopment.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Fri Sep 14 04:03:59 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 04:03:59 -0400 Subject: Comparing strings from the back? In-Reply-To: References: <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> Message-ID: >> I think you're referring to a play on words(ramit). > > Using foreign names derogatively is a common tactic of the racist. Not really. But nice spin on my pun to make me look bad. Keep trying, and maybe you'll come up with an insult/ propaganda that's less obvious to the viewer that you're a liar, and a person who couldn't end this with out throwing a blatant race card. It's similar to if I said, this is real 'queer' of you to do ya big pansy, and next you'll be calling me a homophobe. Try harder, because no one would ever believe I was a racist, and if they did, it's an uninformed decision based off of cherry picken phrases out of context. Very text book propaganda of you though. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From rosuav at gmail.com Fri Sep 14 04:15:53 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Sep 2012 18:15:53 +1000 Subject: pythonOCC examples doesn't work? In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47416678FC5@SCACMX008.exchad.jpmchase.net> Message-ID: On Fri, Sep 14, 2012 at 5:49 PM, Dwight Hutto wrote: >> honest. How do you feel? Interesting... >> > Um, I guess like an inconsiderate bandwidth hog, but from now on I'll > trim more text. What you may have missed was that that was a quote from Princess Bride. Don't take it personally :) > First it was too little, and now it's too much. > > I just tend to cut out some or all depending on the scope of the conversation. > > If I just hit reply all, and send it out, it's not intentionally to > use all of the text, and utilize the extra space, it's just a > response. It's all a question of courtesy, and there's no hard-and-fast rules. But as a simple rule of thumb, assume that your post is going to be read completely without any surrounding context; will it be comprehensible? > If the conversation is kind of just a few people, then I trim pretty > much everything, which apparently set a guy name mark off, who I was > polite to, but I'm not going to get slammed for a few simple posting > mistakes, and more than likely a few of his aliases, or the group he > tends to cheer up with. There's actually no such thing as a conversation of just a few people, on a big list like this. Sure, there may be only a few contributors, but there are thousands - maybe millions - of readers. You're not being slammed, though. What you're seeing is a community doing its best to maintain itself. If we all sit silently, wishing our hardest that everyone would quote nicely, cite nicely, post without trolling, and be helpful, will it happen? (Those familiar with the Bible may note a similarity with some comments in the epistle of James.) There are two ways to ensure that the community upholds its standards: Kicking out everyone who doesn't measure up, or explaining to people and inviting them to participate. The first is a great way to have a tiny community with no growth. The second... is what you're seeing. :) Of course, there's a third option, which is to simply ignore everything and try to get on with life. That basically amounts to kicking _yourself_ out of the community, because you'll quickly give up on a forum in which everyone posts sloppily. And I'm sure you don't want all the experts to do that, because you're then left with a "blind leading the blind" mailing list... not particularly conducive to good code! > It's just a mailing list, lighten up because mistakes in posting will > happen, even by accident. Accidents are understandable, but getting defensive doesn't help :) Generally, people don't speak up until there've been several similar instances. ChrisA From wuwei23 at gmail.com Fri Sep 14 04:16:09 2012 From: wuwei23 at gmail.com (alex23) Date: Fri, 14 Sep 2012 01:16:09 -0700 (PDT) Subject: hi References: <2929e48b-0131-49ab-b209-8aaf1426aa50@s9g2000pbh.googlegroups.com> Message-ID: On Sep 14, 5:22?pm, Dwight Hutto wrote: > Completely OT for this discussion. My apologies, I'll leave you to your thrashing around like a giant child then. From wuwei23 at gmail.com Fri Sep 14 04:20:53 2012 From: wuwei23 at gmail.com (alex23) Date: Fri, 14 Sep 2012 01:20:53 -0700 (PDT) Subject: Comparing strings from the back? References: <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> Message-ID: <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> On Sep 14, 6:04?pm, Dwight Hutto wrote: > > Using foreign names derogatively is a common tactic of the racist. > > Not really. But nice spin on my pun to make me look bad. It actually *is* common behaviour of racists. > It's similar to if I said, this is real 'queer' of you to do ya big > pansy, and next you'll be calling me a homophobe. Well, *yes*. Because your choice of that terminology as derogatory shows you view it as derogatory. > Try harder, because no one would ever believe I was a racist, and if > they did, it's an uninformed decision based off of cherry picken > phrases out of context. Oh, so *now* context is important. > Very text book propaganda of you though. I don't think that word means what you think it does. From hansmu at xs4all.nl Fri Sep 14 04:52:47 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 14 Sep 2012 10:52:47 +0200 Subject: subprocess call is not waiting. In-Reply-To: References: Message-ID: <5052f05f$0$6856$e4fe514c@news2.news.xs4all.nl> On 13/09/12 19:24:46, woooee at gmail.com wrote: > It possibly requires a "shell=True", That's almost always a bad idea, and wouldn't affect waiting anyway. > but without any code or any way to test, we can not say. That's very true. -- HansM From dwightdhutto at gmail.com Fri Sep 14 04:53:01 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 04:53:01 -0400 Subject: Comparing strings from the back? In-Reply-To: <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> References: <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> Message-ID: On Fri, Sep 14, 2012 at 4:20 AM, alex23 wrote: > On Sep 14, 6:04 pm, Dwight Hutto wrote: >> > Using foreign names derogatively is a common tactic of the racist. >> >> Not really. But nice spin on my pun to make me look bad. > > It actually *is* common behaviour of racists. > Not if there name is ramit. What if your name was john? I'd say I'll be right back, I have to go take a crap on the john. It's a joke about a name, not where it originates. >> It's similar to if I said, this is real 'queer' of you to do ya big >> pansy, and next you'll be calling me a homophobe. > > Well, *yes*. Because your choice of that terminology as derogatory > shows you view it as derogatory. No it was a loose analogy to show that he's just trying to use anything he can say to slam me, and everyone can know it wasn't meant as racist. >> Try harder, because no one would ever believe I was a racist, and if >> they did, it's an uninformed decision based off of cherry picken >> phrases out of context. > > Oh, so *now* context is important. Never said it wasn't. The whole conversation to me is the context, and the OP usually follows it, and that's who it is usually intended for. >> Very text book propaganda of you though. > > I don't think that word means what you think it does. from wiki: Propaganda is a form of communication that is aimed at influencing the attitude of a community toward some cause or position. Propaganda is usually repeated and dispersed over a wide variety of media in order to create the chosen result in audience attitudes. He wants people to think I'm a racist, and you now want to see that in me as well. It seems it has propagated, and that I know exactly what it means. And all over a silly post that had too little content, at the time, to have what I said require any other posts, especially if the OP is following the conversation. > http://mail.python.org/mailman/listinfo/python-list -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Fri Sep 14 04:59:15 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 04:59:15 -0400 Subject: hi In-Reply-To: References: <2929e48b-0131-49ab-b209-8aaf1426aa50@s9g2000pbh.googlegroups.com> Message-ID: On Fri, Sep 14, 2012 at 4:16 AM, alex23 wrote: > On Sep 14, 5:22 pm, Dwight Hutto wrote: >> Completely OT for this discussion. > > My apologies, I'll leave you to your thrashing around like a giant > child then. Please explain that one. I usually keep the thrashing for inside the house, unlike your childish nature, which you like to expose to everyone. > You can start a bash David thread, and like you have been, lose the argument that I'm a bad person, just because I trimmed a post too much in the middle of a conversation. Meanwhile, I have my roughdraft site I'd like to get back to. If you have anything constructive to say, I'll be glad to listen, if not, I'll probably listen anyway. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From jeanmichel at sequans.com Fri Sep 14 05:28:22 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 14 Sep 2012 11:28:22 +0200 (CEST) Subject: Decorators not worth the effort In-Reply-To: Message-ID: <732807993.849639.1347614902104.JavaMail.root@sequans.com> ----- Original Message ----- > On Sep 14, 3:54?am, Jean-Michel Pichavant > wrote: > > I don't like decorators, I think they're not worth the mental > > effort. > > Because passing a function to a function is a huge cognitive burden? > -- > http://mail.python.org/mailman/listinfo/python-list > I was expecting that. Decorators are very popular so I kinda already know that the fault is mine. Now to the reason why I have troubles writing them, I don't know. Every time I did use decorators, I spent way too much time writing it (and debugging it). I wrote the following one, used to decorate any function that access an equipment, it raises an exception when the timeout expires. The timeout is adapted to the platform, ASIC of FPGA so people don't need to specify everytime one timeout per platform. In the end it would replace def boot(self, timeout=15): if FPGA: self.sendCmd("bootMe", timeout=timeout*3) else: self.sendCmd("bootMe", timeout=timeout) with @timeout(15) def boot(self, timeout=None): self.sendCmd("bootMe", timeout) I wrote a nice documentation with sphinx to explain this, how to use it, how it can improve code. After spending hours on the decorator + doc, feedback from my colleagues : What the F... !! Decorators are very python specific (probably exists in any dynamic language though, I don't know), in some environment where people need to switch from C to python everyday, decorators add python magic that not everyone is familiar with. For example everyone in the team is able to understand and debug the undecorated version of the above boot method. I'm the only one capable of reading the decorated version. And don't flame my colleagues, they're amazing people (just in case they're reading this :p) who are not python developers, more of users. Hence my original "decorators are not worth the mental effort". Context specific I must admit. Cheers, JM PS : Here's the decorator, just to give you an idea about how it looks. Small piece of code, but took me more than 2 hours to write it. I removed some sensible parts so I don't expect it to run. class timeout(object): """Substitute the timeout keyword argument with the appropriate value""" FACTORS = { IcebergConfig().platform.ASIC : 1, IcebergConfig().platform.FPGA : 3, } def __init__(self, asic, fpga=None, palladium=None): self.default = asic self.fpga = fpga def _getTimeout(self): platform = config().platform factor = self.FACTORS[platform.value] timeout = { platform.ASIC : self.default*factor, platform.FPGA : self.fpga or self.default*factor, }[platform.value] return timeout def __call__(self, func): def decorated(*args, **kwargs): names, _, _, defaults = inspect.getargspec(func) defaults = defaults or [] if 'timeout' not in names: raise ValueError('A "timeout" keyword argument is required') if 'timeout' not in kwargs: # means the timeout keyword arg is not in the call index = names.index('timeout') argsLength = (len(names) - len(defaults)) if index < argsLength: raise NotImplementedError('This decorator does not support non keyword "timeout" argument') if index > len(args)-1: # means the timeout has not be passed using a pos argument timeoutDef = defaults[index-argsLength] if timeoutDef is not None: _log.warning("Decorating a function with a default timeout value <> None") kwargs['timeout'] = self._getTimeout() else: _log.warning('Timeout value specified during the call, please check "%s" @timeout decorator.' % func.__name__) ret = func(*args, **kwargs) return ret return decorated From chicken at mcnuggets.com Fri Sep 14 05:53:51 2012 From: chicken at mcnuggets.com (Chicken McNuggets) Date: Fri, 14 Sep 2012 10:53:51 +0100 Subject: Batching HTTP requests with httplib (Python 2.7) References: Message-ID: On 14/09/2012 03:31, Cameron Simpson wrote: > On 13Sep2012 19:34, Chicken McNuggets wrote: > | I'm writing a simple library that communicates with a web service and am > | wondering if there are any generally well regarded methods for batching > | HTTP requests? > | > | The problem with most web services is that they require a list of > | sequential commands to be executed in a certain order to complete a > | given task (or at least the one I am using does) so having to manually > | call each command is a bit of a pain. How would you go about the design > | of a library to interact with these services? > | > | Any help is greatly appreciated :). > > Maybe I'm missing something. What's hard about: > > - wrapping the web services calls in a simple wrapper which > composes the call, runs it, and returns the result parts > This lets you hide all the waffle about the base URL, > credentials etc in the wrapper and only supply the essentials > at call time. > > - writing your workflow thing then as a simple function: > > def doit(...): > web_service_call1(...) > web_service_call2(...) > web_service_call3(...) > > with whatever internal control is required? > > This has worked for me for simple things. > > What am I missing about the larger context? > That is what I have at the moment but it is ugly as hell. I was wondering if there was a somewhat more elegant solution that I was missing. From daodennis at gmail.com Fri Sep 14 06:14:28 2012 From: daodennis at gmail.com (Dennis) Date: Fri, 14 Sep 2012 03:14:28 -0700 Subject: Asynchronous Soappy on AppEngine Message-ID: Hi, I've noticed that my Soappy calls get converted to URLFetch calls on Google AppEngine. There seems to be documentation that UrlFetch can do Asynchronous operations [1] but I'm not really sure how to make the soap operations asynchronous. Tried looking at the Soapproxy class and see if I can put in callsbacks with urllib somewhere, but I think I am even more confused now. Thoughts suggestions, besides used twisted? Regards, Dennis [1] ( https://developers.google.com/appengine/docs/python/urlfetch/asynchronousrequests -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri Sep 14 06:16:31 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2012 10:16:31 GMT Subject: Comparing strings from the back? References: <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> Message-ID: <505303ff$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 14 Sep 2012 01:20:53 -0700, alex23 wrote: > On Sep 14, 6:04?pm, Dwight Hutto wrote: [snip] Please don't feed the trolls. -- Steven From wuwei23 at gmail.com Fri Sep 14 06:26:08 2012 From: wuwei23 at gmail.com (alex23) Date: Fri, 14 Sep 2012 03:26:08 -0700 (PDT) Subject: Comparing strings from the back? References: <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> Message-ID: <9270ce06-af4a-4483-8fd5-c23cc1978796@oz6g2000pbc.googlegroups.com> On Sep 14, 6:53?pm, Dwight Hutto wrote: > Not if there name is ramit. What if your name was john? I'd say I'll > be right back, I have to go take a crap on the john. It's a joke about > a name, not where it originates. I'd recommend reading up on white privilege but I'm pretty sure it'd be a wasted suggestion. > >> It's similar to if I said, this is real 'queer' of you to do ya big > >> pansy, and next you'll be calling me a homophobe. > > > Well, *yes*. Because your choice of that terminology as derogatory > > shows you view it as derogatory. > > No it was a loose analogy You can't use something as an example to support your case, and then dismiss it as "a loose analogy" when it undermines it. > he's just trying to use anything he can say to slam me everyone > can know it wasn't meant as racist. The "anything" I'm "using" is what *you* have said. I'm not trying to "slam" you, I don't even know who you are. I just have a very short fuse for rudeness and an even shorter one for racism, even if it *was* intended in a "hyuck hyuck, I'm so punny" way. Ignorant racism is still racism. > The whole conversation to me is the context And yet: > He wants people to think I'm a racist, and you now want to see that in > me as well. It seems it has propagated, and that I know exactly what > it means. Again, so much for context. There is no "he" and me, I'm the person who made the original accusation and then followed up on it. That's not propagation, so it's not propaganda. Now, someone who starts a new thread to have a conversation *with themselves* in some bizarre piece of performance art that seems intended to brand as petty the *requests that he actually follow list etiquette*...*that* is someone I'd consider a propagandist. From tymoteusz.jankowski at gmail.com Fri Sep 14 06:49:29 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Fri, 14 Sep 2012 03:49:29 -0700 (PDT) Subject: What's wrong with my arc tangens calculation? Message-ID: I do some math with python: import math as m m.degrees(m.atan(2)) >>> 63.43494882292201 but when i lookup tg in a paper table (last decade math book) i've got these values: tg(63'10'') = 1.9768 tg(63'20'') = 1.9912 tg(63'30'') = 2.0057 For me python should return something more like 63'2x'' than 63'4x''(becasue 63'30'' is higher than 2.0) what's wrong? From rosuav at gmail.com Fri Sep 14 06:54:15 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Sep 2012 20:54:15 +1000 Subject: What's wrong with my arc tangens calculation? In-Reply-To: References: Message-ID: On Fri, Sep 14, 2012 at 8:49 PM, xliiv wrote: > I do some math with python: > > import math as m > m.degrees(m.atan(2)) >>>> 63.43494882292201 > > but when i lookup tg in a paper table (last decade math book) i've got these values: > > tg(63'10'') = 1.9768 > tg(63'20'') = 1.9912 > tg(63'30'') = 2.0057 > > For me python should return something more like 63'2x'' than 63'4x''(becasue 63'30'' is higher than 2.0) According to Google: .43494882292201 degrees = 26.0969294 arcminutes So I would say that your table and Python are in agreement. Do you know what the notation 63'30" means? ChrisA From gandalf at shopzeus.com Fri Sep 14 06:54:54 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 14 Sep 2012 12:54:54 +0200 Subject: What's wrong with my arc tangens calculation? In-Reply-To: References: Message-ID: <50530CFE.1000200@shopzeus.com> > but when i lookup tg in a paper table (last decade math book) i've got these values: > > tg(63'10'') = 1.9768 > tg(63'20'') = 1.9912 > tg(63'30'') = 2.0057 > > For me python should return something more like 63'2x'' than 63'4x''(becasue 63'30'' is higher than 2.0) > > what's wrong? > 63? 30" is 63.5?. So nothing is wrong. (You know, 1? = 60 arc second!) From dwightdhutto at gmail.com Fri Sep 14 06:56:30 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 06:56:30 -0400 Subject: Batching HTTP requests with httplib (Python 2.7) In-Reply-To: References: Message-ID: >> | The problem with most web services is that they require a list of >> | sequential commands to be executed in a certain order to complete a >> | given task (or at least the one I am using does) so having to manually >> | call each command is a bit of a pain. How would you go about the design >> | of a library to interact with these services? >> | >> | Any help is greatly appreciated :). >> >> Maybe I'm missing something. What's hard about: >> >> - wrapping the web services calls in a simple wrapper which >> composes the call, runs it, and returns the result parts >> This lets you hide all the waffle about the base URL, >> credentials etc in the wrapper and only supply the essentials >> at call time. >> >> - writing your workflow thing then as a simple function: >> >> def doit(...): >> web_service_call1(...) >> web_service_call2(...) >> web_service_call3(...) >> >> with whatever internal control is required? >> >> This has worked for me for simple things. >> >> What am I missing about the larger context? >> > > That is what I have at the moment but it is ugly as hell. I was wondering if > there was a somewhat more elegant solution that I was missing. > -- Well if the code works it works. There probably is a better way than what I came up with: def web_service_call0(y): print "Service call = %i)" % y def web_service_call1(y): print "Service call = %i)" % y def web_service_call2(y): print "Service call = %i)" % y def web_service_call3(y): print "Service call = %i)" % y def web_service_call4(y): print "Service call = %i)" % y service_num_list = [num for num in range(0,5)] for service_num in service_num_list: eval("web_service_call%i(%i)" % (service_num,service_num)) I just define the service calls, and iterate through them with an eval that places in the service call num, but you would have to have a matching list of the params that would go with each one. I'm almost positive there will be some more well written ones on the way. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From tymoteusz.jankowski at gmail.com Fri Sep 14 07:18:33 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Fri, 14 Sep 2012 04:18:33 -0700 (PDT) Subject: What's wrong with my arc tangens calculation? In-Reply-To: References: Message-ID: <95bea1d5-ccbd-4987-9b64-6555075a3c1b@googlegroups.com> On Friday, September 14, 2012 12:55:06 PM UTC+2, Laszlo Nagy wrote: > > but when i lookup tg in a paper table (last decade math book) i've got these values: > > > > > > tg(63'10'') = 1.9768 > > > tg(63'20'') = 1.9912 > > > tg(63'30'') = 2.0057 > > > > > > For me python should return something more like 63'2x'' than 63'4x''(becasue 63'30'' is higher than 2.0) > > > > > > what's wrong? > > > > > 63??? 30" is 63.5???. So nothing is wrong. (You know, 1??? = 60 arc second!) So the wrong part is me ;) The python's 63.43494882292201 is degrees (according to function math.degrees) but book's value is in minutes. Clearified Thanks, all. From tymoteusz.jankowski at gmail.com Fri Sep 14 07:18:33 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Fri, 14 Sep 2012 04:18:33 -0700 (PDT) Subject: What's wrong with my arc tangens calculation? In-Reply-To: References: Message-ID: <95bea1d5-ccbd-4987-9b64-6555075a3c1b@googlegroups.com> On Friday, September 14, 2012 12:55:06 PM UTC+2, Laszlo Nagy wrote: > > but when i lookup tg in a paper table (last decade math book) i've got these values: > > > > > > tg(63'10'') = 1.9768 > > > tg(63'20'') = 1.9912 > > > tg(63'30'') = 2.0057 > > > > > > For me python should return something more like 63'2x'' than 63'4x''(becasue 63'30'' is higher than 2.0) > > > > > > what's wrong? > > > > > 63??? 30" is 63.5???. So nothing is wrong. (You know, 1??? = 60 arc second!) So the wrong part is me ;) The python's 63.43494882292201 is degrees (according to function math.degrees) but book's value is in minutes. Clearified Thanks, all. From duncan.booth at invalid.invalid Fri Sep 14 07:26:10 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 14 Sep 2012 11:26:10 GMT Subject: Decorators not worth the effort References: Message-ID: Jean-Michel Pichavant wrote: > I wrote the following one, used to decorate any function that access > an equipment, it raises an exception when the timeout expires. The > timeout is adapted to the platform, ASIC of FPGA so people don't need > to specify everytime one timeout per platform. > > In the end it would replace > > def boot(self, timeout=15): > if FPGA: > self.sendCmd("bootMe", timeout=timeout*3) > else: > self.sendCmd("bootMe", timeout=timeout) > > with > > @timeout(15) > def boot(self, timeout=None): > self.sendCmd("bootMe", timeout) > > I wrote a nice documentation with sphinx to explain this, how to use > it, how it can improve code. After spending hours on the decorator + > doc, feedback from my colleagues : What the F... !! > I'd agree with your colleagues. How are you going to ensure that all relevant functions are decorated and yet no decorated function ever calls another decorated one? >From the code you posted it would seem appropriate that the adjustment of the timeout parameter happen in the `sendCmd()` method itself and nowhere else. Alternatively use named values for different categories of timeouts and adjust them on startup so instead of a default of `timeout= 15` you would have a default `timeout=MEDIUM_TIMEOUT` or whatever name is appropriate. -- Duncan Booth http://kupuguy.blogspot.com From dwightdhutto at gmail.com Fri Sep 14 07:36:24 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 07:36:24 -0400 Subject: Comparing strings from the back? In-Reply-To: <9270ce06-af4a-4483-8fd5-c23cc1978796@oz6g2000pbc.googlegroups.com> References: <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <9270ce06-af4a-4483-8fd5-c23cc1978796@oz6g2000pbc.googlegroups.com> Message-ID: > I'd recommend reading up on white privilege but I'm pretty sure it'd > be a wasted suggestion. Not really, I tend to like interdisciplinary study. But I'm a little of everything if you like Darwin. > >> >> It's similar to if I said, this is real 'queer' of you to do ya big >> >> pansy, and next you'll be calling me a homophobe. >> >> > Well, *yes*. Because your choice of that terminology as derogatory >> > shows you view it as derogatory. >> >> No it was a loose analogy > > You can't use something as an example to support your case, and then > dismiss it as "a loose analogy" when it undermines it. > How did it undermine it? It's the same thing, just transferred to another well known group subject to violent bigotry. I used a play on words in a response, and because his names foreign that makes me a racist. There's no logic in that, other than to bring me down, and use the worst thing you can say...playing the race card. >> he's just trying to use anything he can say to slam me everyone >> can know it wasn't meant as racist. > > The "anything" I'm "using" is what *you* have said. I'm not trying to > "slam" you, I don't even know who you are. I just have a very short > fuse for rudeness and an even shorter one for racism, It wasn't rude in terms of these things that have been said about me. Then lengthen your fuse, because I'm not a racist, I just play with words a lot, including foreign names. even if it *was* > intended in a "hyuck hyuck, I'm so punny" way. Ignorant racism is > still racism. Still trying to propagate a thought that I'm racist based on a guy who for all I know is white, and uses the A.K.A ramit. I have no freakin clue if ramit is an ethnic name or nickname...we're on the internet tweedledick(badumchee, and hyuck,hyuck,hyuck) > >> The whole conversation to me is the context > > And yet: > >> He wants people to think I'm a racist, and you now want to see that in >> me as well. It seems it has propagated, and that I know exactly what >> it means. > > Again, so much for context. There is no "he" and me, I'm the person > who made the original accusation and then followed up on it. That's > not propagation, so it's not propaganda. You're still trying to prove the point, when we all know I'm not a racist. > > Now, someone who starts a new thread to have a conversation *with > themselves* in some bizarre piece of performance art that seems > intended to brand as petty the *requests that he actually follow list > etiquette*...*that* is someone I'd consider a propagandist. > -- You mean like you taking over this thread to call me a racist, and go on ad nauseam about it, when everyone can see what you're doing is trying to prove a point you know is wrong? Go back to debate 101, and flunk your professor if he passed you. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Fri Sep 14 07:43:46 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 07:43:46 -0400 Subject: Comparing strings from the back? In-Reply-To: <505303ff$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <505303ff$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: [snip] > Please don't feed the trolls. You're down here under the bridge with the rest of us trolls too, Steven. 24/7 -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From xavier.combelle at free.fr Fri Sep 14 07:46:38 2012 From: xavier.combelle at free.fr (Xavier Combelle) Date: Fri, 14 Sep 2012 13:46:38 +0200 Subject: Batching HTTP requests with httplib (Python 2.7) In-Reply-To: References: Message-ID: <5053191E.6070003@free.fr> instead of Le 14/09/2012 12:56, Dwight Hutto a ?crit : > service_num_list = [num for num in range(0,5)] > for service_num in service_num_list: > eval("web_service_call%i(%i)" % (service_num,service_num)) > > service_num_list = [num for num in range(0,5)] for service_num in service_num_list: locals()["web_service_call%i" % (service_num,)](service_num) would be safer eval is really bad From news at blinne.net Fri Sep 14 07:47:57 2012 From: news at blinne.net (Alexander Blinne) Date: Fri, 14 Sep 2012 13:47:57 +0200 Subject: Python presentations In-Reply-To: References: <06a1a81b-246b-4e7b-ba34-4701f46889c8@googlegroups.com> <50525f48$0$6573$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <5053196e$0$6578$9b4e6d93@newsspool3.arcor-online.net> On 14.09.2012 00:38, Chris Angelico wrote: > On Fri, Sep 14, 2012 at 8:33 AM, Alexander Blinne wrote: >> def powerlist(x,n): >> if n==1: >> return [1] >> p = powerlist(x,n-1) >> return p + [p[-1]*x] > > Eh, much simpler. > > def powerlist(x,n): > return [x*i for i in xrange(n-1)] I suppose you meant: def powerlist(x,n): return [x**i for i in xrange(n-1)] But this is less efficient, because it needs more multiplications (see Horner's method) From ulrich.eckhardt at dominolaser.com Fri Sep 14 07:49:00 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 14 Sep 2012 13:49:00 +0200 Subject: Decorators not worth the effort In-Reply-To: References: Message-ID: Am 14.09.2012 11:28, schrieb Jean-Michel Pichavant: > Decorators are very popular so I kinda already know that the > fault is mine. Now to the reason why I have troubles writing > them, I don't know. Every time I did use decorators, I spent > way too much time writing it (and debugging it). > > I wrote the following one, used to decorate any function that access > an equipment, it raises an exception when the timeout expires. The > timeout is adapted to the platform, ASIC of FPGA so people don't need > to specify everytime one timeout per platform. > > In the end it would replace > > def boot(self, timeout=15): > if FPGA: > self.sendCmd("bootMe", timeout=timeout*3) > else: > self.sendCmd("bootMe", timeout=timeout) > > with > > @timeout(15) > def boot(self, timeout=None): > self.sendCmd("bootMe", timeout) > > I wrote a nice documentation with sphinx to explain this, how to use > it, how it can improve code. After spending hours on the decorator + > doc, feedback from my colleagues : What the F... !! Quite honestly: I think like your colleagues in this case and that in this case the decorator doesn't improve the code. Instead, I would probably have added a _get_timeout() function that takes care of adjusting the argument passed to the function according to the underlying hardware target. To be less abstract, the particular problem I have with your approach is that I can't even guess what your code means, let alone what parameters it actually takes. If you had written @default_timeout(15) def boot(self, timeout=None): instead, I would have been able to guess. OTOH, then again I would have wondered why you used a decorator to create a default argument when there is builtin support for specifying default arguments for functions. Maybe you could get away with a decorator like this: @adjust_timeout def boot(self, timeout=2.5): The idea is that the decorator modifies the timeout value passed to the function (or maybe just modifies the default value?) according to the underlying hardware. > Decorators are very python specific (probably exists in any dynamic > language though, I don't know), in some environment where people need > to switch from C to python everyday, decorators add python magic that > not everyone is familiar with. The same could be said for classes, iterators, significant whitespace, docstrings, lambdas. I think that this was just a bad example but it doesn't prove that decorators are worthless. Decorators are useful tools if they do something to a function, like doing something before or after the actual code, or modifying the context in which the code is called. Just setting a default parameter is possible as you have proved, but it's IMHO not a good use case. A bit more specific to your case, adding a timeout decorator would actually make much more sense if it transparently invoked the actual function in a second thread and the calling thread stops waiting for completion and raises an error after that timeout. This has the distinct advantage that the code doing the actual communication doesn't have any timeout handling code inside. I'm currently doing something similar here though I only monitor a TCP connection that is used for some telnet-style requests. Every function making a request over TCP is decorated with @_check_connection. That decorator does two things: 1. It checks for an existing fatal connection error. 2. It runs the request and filters resulting errors for fatal connection errors. The decorator looks like this: def _check_connection(fn): @functools.wraps(fn) def wrapper(self, *args, **kwargs): # check for sticky connection errors if self._connection_error: raise self._connection_error # run actual function try: return fn(self, *args, **kwargs) catch RequestFailed: # The other side signalled a failure, but # further requests can still succeed. raise catch ConnectionError, e: # The connection is broken beyond repair. # Store sticky connection and forward. self._connection_error = e raise return wrapper I have had other programmers here write such requests and they blindly copied the decorator from existing code. This works because the code inside that converts/formats/parses the inputs and outputs is completely unaware of the connection monitoring. Otherwise, I don't think anyone could explain what this decorator does, but they don't have to understand it either. It just works. I wish you a nice weekend! Uli From steve+comp.lang.python at pearwood.info Fri Sep 14 08:01:57 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2012 12:01:57 GMT Subject: Decorators not worth the effort References: Message-ID: <50531cb5$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 14 Sep 2012 11:28:22 +0200, Jean-Michel Pichavant wrote: > PS : Here's the decorator, just to give you an idea about how it looks. > Small piece of code, but took me more than 2 hours to write it. I > removed some sensible parts so I don't expect it to run. [snip timeout class] Holy over-engineering Batman!!! No wonder you don't think much of decorators, if this example of overkill is what you consider typical of them. It does much, much more than the simple code you were replacing: def boot(self, timeout=15): if FPGA: self.sendCmd("bootMe", timeout=timeout*3) else: self.sendCmd("bootMe", timeout=timeout) # becomes: @timeout(15) def boot(self, timeout=None): self.sendCmd("bootMe", timeout) Most of my decorator functions are under a dozen lines. And that's the complicated ones! Here's my solution to the example you gave: # Untested! def timeout(t=15): # Decorator factory. Return a decorator to actually do the work. if FPGA: t *= 3 def decorator(func): @functools.wraps(func) def inner(self, timeout): self.sendCmd("bootMe", timeout=t) return inner return decorator I reckon that will pretty much do what your example showed. Of course, once you start adding more and more functionality above the simple code shown above (arbitrary platforms, argument checking of the decorated function, logging, etc.) you're going to get a much more complex decorator. On the other hand, YAGNI. http://en.wikipedia.org/wiki/You_ain%27t_gonna_need_it -- Steven From rosuav at gmail.com Fri Sep 14 08:19:22 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Sep 2012 22:19:22 +1000 Subject: Python presentations In-Reply-To: <5053196e$0$6578$9b4e6d93@newsspool3.arcor-online.net> References: <06a1a81b-246b-4e7b-ba34-4701f46889c8@googlegroups.com> <50525f48$0$6573$9b4e6d93@newsspool3.arcor-online.net> <5053196e$0$6578$9b4e6d93@newsspool3.arcor-online.net> Message-ID: On Fri, Sep 14, 2012 at 9:47 PM, Alexander Blinne wrote: > On 14.09.2012 00:38, Chris Angelico wrote: >> On Fri, Sep 14, 2012 at 8:33 AM, Alexander Blinne wrote: >>> def powerlist(x,n): >>> if n==1: >>> return [1] >>> p = powerlist(x,n-1) >>> return p + [p[-1]*x] >> >> Eh, much simpler. >> >> def powerlist(x,n): >> return [x*i for i in xrange(n-1)] > > I suppose you meant: > > def powerlist(x,n): > return [x**i for i in xrange(n-1)] > > But this is less efficient, because it needs more multiplications (see > Horner's method) Err, yes, I did mean ** there. The extra multiplications may be slower, but which is worse? Lots of list additions, or lots of integer powers? In the absence of clear and compelling evidence, I'd be inclined to go with the list comp - and what's more, to skip this function altogether and use the list comp directly where it's needed. ChrisA From paulstaten at gmail.com Fri Sep 14 08:22:44 2012 From: paulstaten at gmail.com (paulstaten at gmail.com) Date: Fri, 14 Sep 2012 05:22:44 -0700 (PDT) Subject: subprocess call is not waiting. In-Reply-To: References: Message-ID: <0b598d7f-7137-47cc-8eed-80ab450536c5@googlegroups.com> os.system worked fine, and I found something in another section of code that was causing the "Too many open errors." (I was fooled, because output from subprocess call didn't seem to be coming out until the open files error. I'll go back and play with subprocess.call more, since os.system works. That's interesting about using shlex at run time. Is that just for the sake of computational cost? From python.list at tim.thechases.com Fri Sep 14 09:06:53 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 14 Sep 2012 08:06:53 -0500 Subject: Decorators not worth the effort In-Reply-To: <50531cb5$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <50531cb5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50532BED.5070106@tim.thechases.com> On 09/14/12 07:01, Steven D'Aprano wrote: > [snip timeout class] > > Holy over-engineering Batman!!! > > No wonder you don't think much of decorators, [snip] > Most of my decorator functions are under a dozen lines. And that's the > complicated ones! As are mine, and a sizable chunk of those under-a-dozen-lines are somewhat boilerplate like using @functools.wraps inside, actual def of the function, and returning that function. :-) -tkc From breamoreboy at yahoo.co.uk Fri Sep 14 09:13:07 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 14 Sep 2012 14:13:07 +0100 Subject: What's wrong with my arc tangens calculation? In-Reply-To: References: Message-ID: On 14/09/2012 11:54, Chris Angelico wrote: > On Fri, Sep 14, 2012 at 8:49 PM, xliiv wrote: >> I do some math with python: >> >> import math as m >> m.degrees(m.atan(2)) >>>>> 63.43494882292201 >> >> but when i lookup tg in a paper table (last decade math book) i've got these values: >> >> tg(63'10'') = 1.9768 >> tg(63'20'') = 1.9912 >> tg(63'30'') = 2.0057 >> >> For me python should return something more like 63'2x'' than 63'4x''(becasue 63'30'' is higher than 2.0) > > According to Google: > .43494882292201 degrees = 26.0969294 arcminutes > > So I would say that your table and Python are in agreement. Do you > know what the notation 63'30" means? > > ChrisA > Somebody or something has a length, height or width of 63 feet 30 inches? :) -- Cheers. Mark Lawrence. From rosuav at gmail.com Fri Sep 14 09:17:43 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Sep 2012 23:17:43 +1000 Subject: What's wrong with my arc tangens calculation? In-Reply-To: References: Message-ID: On Fri, Sep 14, 2012 at 11:13 PM, Mark Lawrence wrote: > Somebody or something has a length, height or width of 63 feet 30 inches? :) Sounds like the height of a building with a barometer. The thirty inches, of course, being the height of the barometer. ChrisA (big, big barometer) From jeanmichel at sequans.com Fri Sep 14 09:22:26 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 14 Sep 2012 15:22:26 +0200 (CEST) Subject: Decorators not worth the effort In-Reply-To: Message-ID: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> ----- Original Message ----- > Jean-Michel Pichavant wrote: > > > I wrote the following one, used to decorate any function that > > access > > an equipment, it raises an exception when the timeout expires. The > > timeout is adapted to the platform, ASIC of FPGA so people don't > > need > > to specify everytime one timeout per platform. > > > > In the end it would replace > > > > def boot(self, timeout=15): > > if FPGA: > > self.sendCmd("bootMe", timeout=timeout*3) > > else: > > self.sendCmd("bootMe", timeout=timeout) > > > > with > > > > @timeout(15) > > def boot(self, timeout=None): > > self.sendCmd("bootMe", timeout) > > > > I wrote a nice documentation with sphinx to explain this, how to > > use > > it, how it can improve code. After spending hours on the decorator > > + > > doc, feedback from my colleagues : What the F... !! > > > > I'd agree with your colleagues. How are you going to ensure that all > relevant functions are decorated and yet no decorated function ever > calls another decorated one? > > From the code you posted it would seem appropriate that the > adjustment > of the timeout parameter happen in the `sendCmd()` method itself and > nowhere else. Alternatively use named values for different categories > of > timeouts and adjust them on startup so instead of a default of > `timeout= > 15` you would have a default `timeout=MEDIUM_TIMEOUT` or whatever > name > is appropriate. > > -- > Duncan Booth http://kupuguy.blogspot.com > -- > http://mail.python.org/mailman/listinfo/python-list All functions set different timeout values, I cannot use a DEFAULT_VALUE. All functions are design in the same way: def doSomeAction(self, timeout): preprocess() self.sendCmd('relatedAction', timeout) # send the command to the device CLI interface postprocess() Ultimately, the goal is to have something like @timeout(2) def doAction1 @timeout(4) def doAction2 @timeout(12) def doAction3 and so on... (1 second is important, because there's a platform I remove from my example, didn't want to advertise publicly tech used by the company, that runs 1000 times slower) Additionally, the multiple check I run within the decorator is for consistency check and argument checking. I though it was a good idea because our python engine is used by a dozen of engineers to control equipment, and any misuse of this new decorator would lead to badly configured timeouts with heavy consequences on the test sessions. Sometimes a RTFM is not enough, when you need to make this work, you slip on your Batman costume like Steven suggested, and you save the day (or so I though :) ) by raising nice exceptions about missing keyword argument. But let's forget about my poor example, I end up describing my life which is pretty pointless. Here's Steven example: # Untested! def timeout(t=15): # Decorator factory. Return a decorator to actually do the work. if FPGA: t *= 3 def decorator(func): @functools.wraps(func) def inner(self, timeout): self.sendCmd("bootMe", timeout=t) return inner return decorator I can assure you, that for some python users, it's is not easy to understand what it does, this function returning a function which returns another (wrapped) function. It requires some effort. JM From andrea.crotti.0 at gmail.com Fri Sep 14 10:12:26 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Fri, 14 Sep 2012 15:12:26 +0100 Subject: Decorators not worth the effort In-Reply-To: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> References: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> Message-ID: I think one very nice and simple example of how decorators can be used is this: def memoize(f, cache={}, *args, **kwargs): def _memoize(*args, **kwargs): key = (args, str(kwargs)) if not key in cache: cache[key] = f(*args, **kwargs) return cache[key] return _memoize def fib(n): if n <= 1: return 1 return fib(n-1) + fib(n-2) @memoize def fib_memoized(n): if n <= 1: return 1 return fib_memoized(n-1) + fib_memoized(n-2) The second fibonacci looks exactly the same but while the first is very slow and would generate a stack overflow the second doesn't.. I might use this example for the presentation, before explaining what it is.. From rosuav at gmail.com Fri Sep 14 10:41:01 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 15 Sep 2012 00:41:01 +1000 Subject: Decorators not worth the effort In-Reply-To: References: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> Message-ID: On Sat, Sep 15, 2012 at 12:12 AM, andrea crotti wrote: > def fib(n): > if n <= 1: > return 1 > return fib(n-1) + fib(n-2) > > @memoize > def fib_memoized(n): > if n <= 1: > return 1 > return fib_memoized(n-1) + fib_memoized(n-2) > > > The second fibonacci looks exactly the same but while the first is > very slow and would generate a stack overflow the second doesn't.. Trouble is, you're starting with a pretty poor algorithm. It's easy to improve on what's poor. Memoization can still help, but I would start with a better algorithm, such as: def fib(n): if n<=1: return 1 a,b=1,1 for i in range(1,n,2): a+=b b+=a return b if n%2 else a def fib(n,cache=[1,1]): if n<=1: return 1 while len(cache)<=n: cache.append(cache[-1] + cache[-2]) return cache[n] Personally, I don't mind (ab)using default arguments for caching, but you could do the same sort of thing with a decorator if you prefer. I think the non-decorated non-recursive version is clear and efficient though. ChrisA From walterhurry at lavabit.com Fri Sep 14 10:54:38 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Fri, 14 Sep 2012 14:54:38 +0000 (UTC) Subject: Guides for communicating with business accounting systems References: <87y5kenez2.fsf@benfinney.id.au> <87pq5pnmo1.fsf@benfinney.id.au> Message-ID: On Fri, 14 Sep 2012 16:36:58 +1000, Chris Angelico wrote: > Actually I haven't used Postgres with Python yet. Should probably do > that at some point. But the MySQL bindings for Python aren't so awesome > they can't be matched by any other. I have found psycopg2 excellent in every respect. From typetoken at gmail.com Fri Sep 14 11:01:11 2012 From: typetoken at gmail.com (Token Type) Date: Fri, 14 Sep 2012 08:01:11 -0700 (PDT) Subject: AttributeError: 'list' object has no attribute 'lower' In-Reply-To: References: <113e44c3-cd53-4536-a60c-0363bf83a8ec@googlegroups.com> Message-ID: <97d64651-37c4-4930-a539-b7a51f2f6fc2@googlegroups.com> Thanks. By the way, do we have a list of explanations of error message? If so, whenever we come across error message, we can refer to it and solve the problem accordingly. From typetoken at gmail.com Fri Sep 14 11:01:11 2012 From: typetoken at gmail.com (Token Type) Date: Fri, 14 Sep 2012 08:01:11 -0700 (PDT) Subject: AttributeError: 'list' object has no attribute 'lower' In-Reply-To: References: <113e44c3-cd53-4536-a60c-0363bf83a8ec@googlegroups.com> Message-ID: <97d64651-37c4-4930-a539-b7a51f2f6fc2@googlegroups.com> Thanks. By the way, do we have a list of explanations of error message? If so, whenever we come across error message, we can refer to it and solve the problem accordingly. From steve+comp.lang.python at pearwood.info Fri Sep 14 11:18:27 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2012 15:18:27 GMT Subject: AttributeError: 'list' object has no attribute 'lower' References: <113e44c3-cd53-4536-a60c-0363bf83a8ec@googlegroups.com> Message-ID: <50534ac3$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 14 Sep 2012 08:01:11 -0700, Token Type wrote: > Thanks. By the way, do we have a list of explanations of error message? > If so, whenever we come across error message, we can refer to it and > solve the problem accordingly. Forget about a "list of explanations of error message[s]". There is no such list, and there never will be, because there is no limit to the number and kind of possible error messages. Instead, you should actually read the error message you see. Python is telling you what the problem is. Pay attention to it. AttributeError: 'list' object has no attribute 'lower' This tells you that you tried to access something.lower, but "something" is a list, and lists don't have an attribute or method "lower". Normally, Python will show you the line of source code with the error, so you will even see the name of the variable. -- Steven From rosuav at gmail.com Fri Sep 14 11:19:24 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 15 Sep 2012 01:19:24 +1000 Subject: AttributeError: 'list' object has no attribute 'lower' In-Reply-To: <97d64651-37c4-4930-a539-b7a51f2f6fc2@googlegroups.com> References: <113e44c3-cd53-4536-a60c-0363bf83a8ec@googlegroups.com> <97d64651-37c4-4930-a539-b7a51f2f6fc2@googlegroups.com> Message-ID: On Sat, Sep 15, 2012 at 1:01 AM, Token Type wrote: > Thanks. By the way, do we have a list of explanations of error message? If so, whenever we come across error message, we can refer to it and solve the problem accordingly. Not really, but if you paste the message into Google or DuckDuckGo or another web search engine, you'll usually find something helpful. Possibly add a few keywords about what you're doing, if the message alone is too general. By the way, you don't need to include both comp.lang.python and python-list in your addressees; they mirror each other, so sending to one will make it arrive on the other too. Have fun! ChrisA From steve+comp.lang.python at pearwood.info Fri Sep 14 11:19:58 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2012 15:19:58 GMT Subject: Decorators not worth the effort References: Message-ID: <50534b1e$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 14 Sep 2012 15:22:26 +0200, Jean-Michel Pichavant wrote: > Here's Steven example: > > # Untested! > def timeout(t=15): > # Decorator factory. Return a decorator to actually do the work. if > FPGA: > t *= 3 > def decorator(func): > @functools.wraps(func) > def inner(self, timeout): > self.sendCmd("bootMe", timeout=t) > return inner > return decorator > > I can assure you, that for some python users, it's is not easy to > understand what it does, this function returning a function which > returns another (wrapped) function. It requires some effort. Oh I agree. So does learning to tie your shoe-laces, learning to cook, and learning to drive. Learning to be a world-class chess master takes a lot of effort. Learning about decorators does not. -- Steven From jeanmichel at sequans.com Fri Sep 14 11:35:57 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 14 Sep 2012 17:35:57 +0200 (CEST) Subject: Decorators not worth the effort In-Reply-To: <50534b1e$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <230301176.1099808.1347636957818.JavaMail.root@sequans.com> ----- Original Message ----- > On Fri, 14 Sep 2012 15:22:26 +0200, Jean-Michel Pichavant wrote: > > > Here's Steven example: > > > > # Untested! > > def timeout(t=15): > > # Decorator factory. Return a decorator to actually do the > > work. if > > FPGA: > > t *= 3 > > def decorator(func): > > @functools.wraps(func) > > def inner(self, timeout): > > self.sendCmd("bootMe", timeout=t) > > return inner > > return decorator > > > > I can assure you, that for some python users, it's is not easy to > > understand what it does, this function returning a function which > > returns another (wrapped) function. It requires some effort. > > Oh I agree. So does learning to tie your shoe-laces, learning to > cook, > and learning to drive. > > Learning to be a world-class chess master takes a lot of effort. > Learning > about decorators does not. > > > -- > Steven I said some effort, not a lot of effort. Something else that requires some effort it to make experts realize that some things they consider trivial and easy, aren't actually for a lot of people. Returning to my cave. JM From wxjmfauth at gmail.com Fri Sep 14 12:15:25 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 14 Sep 2012 09:15:25 -0700 (PDT) Subject: Least-lossy string.encode to us-ascii? In-Reply-To: References: Message-ID: <725b3dd0-bd2b-404e-a261-ffe306b38c2f@googlegroups.com> Le jeudi 13 septembre 2012 23:25:27 UTC+2, Tim Chase a ?crit?: > I've got a bunch of text in Portuguese and to transmit them, need to > > have them in us-ascii (7-bit). I'd like to keep as much information > > as possible, just stripping accents, cedillas, tildes, etc. So > > "servi?o m?vil" becomes "servico movil". Is there anything stock > > that I've missed? I can do mystring.encode('us-ascii', 'replace') > > but that doesn't keep as much information as I'd hope. > Interesting case. It's where the coding of characters meets characters usage, scripts, typography, linguistic features. I cann't discuss the Portugese case, but in French and in German one way to achieve the task is to convert the text in uppercases. It preserves a correct text. >>> s = 'L?titia c?ur ?l?phant fran?ais LU? Sto? Erkl?rung st?ren' >>> libfrancais.SpecMajuscules(s) 'LAETITIA COEUR ELEPHANT FRANCAIS LUY STOSS ERKLAERUNG STOEREN' >>> r = 'LAETITIA COEUR ELEPHANT FRANCAIS LUY STOSS ERKLAERUNG STOEREN' >>> r.encode('ascii', 'strict').decode('ascii', 'strict') == r True PS Avoid Py3.3 :-) jmf From wxjmfauth at gmail.com Fri Sep 14 12:15:25 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 14 Sep 2012 09:15:25 -0700 (PDT) Subject: Least-lossy string.encode to us-ascii? In-Reply-To: References: Message-ID: <725b3dd0-bd2b-404e-a261-ffe306b38c2f@googlegroups.com> Le jeudi 13 septembre 2012 23:25:27 UTC+2, Tim Chase a ?crit?: > I've got a bunch of text in Portuguese and to transmit them, need to > > have them in us-ascii (7-bit). I'd like to keep as much information > > as possible, just stripping accents, cedillas, tildes, etc. So > > "servi?o m?vil" becomes "servico movil". Is there anything stock > > that I've missed? I can do mystring.encode('us-ascii', 'replace') > > but that doesn't keep as much information as I'd hope. > Interesting case. It's where the coding of characters meets characters usage, scripts, typography, linguistic features. I cann't discuss the Portugese case, but in French and in German one way to achieve the task is to convert the text in uppercases. It preserves a correct text. >>> s = 'L?titia c?ur ?l?phant fran?ais LU? Sto? Erkl?rung st?ren' >>> libfrancais.SpecMajuscules(s) 'LAETITIA COEUR ELEPHANT FRANCAIS LUY STOSS ERKLAERUNG STOEREN' >>> r = 'LAETITIA COEUR ELEPHANT FRANCAIS LUY STOSS ERKLAERUNG STOEREN' >>> r.encode('ascii', 'strict').decode('ascii', 'strict') == r True PS Avoid Py3.3 :-) jmf From andrea.crotti.0 at gmail.com Fri Sep 14 12:15:35 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Fri, 14 Sep 2012 17:15:35 +0100 Subject: Decorators not worth the effort In-Reply-To: References: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> Message-ID: 2012/9/14 Chris Angelico : > > Trouble is, you're starting with a pretty poor algorithm. It's easy to > improve on what's poor. Memoization can still help, but I would start > with a better algorithm, such as: > > def fib(n): > if n<=1: return 1 > a,b=1,1 > for i in range(1,n,2): > a+=b > b+=a > return b if n%2 else a > > def fib(n,cache=[1,1]): > if n<=1: return 1 > while len(cache)<=n: > cache.append(cache[-1] + cache[-2]) > return cache[n] > > Personally, I don't mind (ab)using default arguments for caching, but > you could do the same sort of thing with a decorator if you prefer. I > think the non-decorated non-recursive version is clear and efficient > though. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list The poor algorithm is much more close to the mathematical definition than the smarter iterative one.. And in your second version you include some ugly caching logic inside it, so why not using a decorator then? I'm not saying that with the memoization is the "good" solution, just that I think it's a very nice example of how to use a decorator, and maybe a good example to start with a talk on decorators.. From theology at gmail.com Fri Sep 14 12:24:56 2012 From: theology at gmail.com (Zeth) Date: Fri, 14 Sep 2012 17:24:56 +0100 Subject: PyConUK 2012 Schedule now online Message-ID: <50535A58.2040106@gmail.com> Hello! PyConUK 2012, the UK Python Conference, is taking place in Coventry from Friday 28th September to Monday 1st October. That is only two weeks away! Everyone is welcome from complete beginners through to experienced experts. The core is on Saturday and Sunday so if you cannot get time off work, you will still get all the key parts of the conference. We now have a draft schedule online: * http://pyconuk.net/Schedule It includes talks, introductory and intermediate tutorials, sprints, discussions, socials, the annual Python dinner, and of course the famous Lightning Talks. An introduction to the conference can be found here: * http://pyconuk.org More information at our wiki at: * http://pyconuk.net To book a ticket, please visit: http://pyconuk2012.eventbrite.co.uk/ Best Wishes, The Python UK Team P.S. Please forward this message to your friends, colleagues, mailing lists, social networks, local user groups, etc. From dihedral88888 at googlemail.com Fri Sep 14 12:37:37 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 14 Sep 2012 09:37:37 -0700 (PDT) Subject: Decorators not worth the effort In-Reply-To: References: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> Message-ID: <067b0f14-0d30-49b8-a937-554a571c0ef4@googlegroups.com> Chris Angelico? 2012?9?14????UTC+8??10?41?06???? > On Sat, Sep 15, 2012 at 12:12 AM, andrea crotti > > wrote: > > > def fib(n): > > > if n <= 1: > > > return 1 > > > return fib(n-1) + fib(n-2) > > > > > > @memoize > > > def fib_memoized(n): > > > if n <= 1: > > > return 1 > > > return fib_memoized(n-1) + fib_memoized(n-2) > > > > > > > > > The second fibonacci looks exactly the same but while the first is > > > very slow and would generate a stack overflow the second doesn't.. > > > > Trouble is, you're starting with a pretty poor algorithm. It's easy to > > improve on what's poor. Memoization can still help, but I would start > > with a better algorithm, such as: > > > > def fib(n): > > if n<=1: return 1 > > a,b=1,1 > > for i in range(1,n,2): > > a+=b > > b+=a > > return b if n%2 else a > > > > def fib(n,cache=[1,1]): > > if n<=1: return 1 > > while len(cache)<=n: > > cache.append(cache[-1] + cache[-2]) > > return cache[n] > > > > Personally, I don't mind (ab)using default arguments for caching, but > > you could do the same sort of thing with a decorator if you prefer. I > > think the non-decorated non-recursive version is clear and efficient > > though. > > > > ChrisA Uhn, the decorator part is good for wrapping functions in python. For example a decorator can be used to add a layor of some message handlings of those plain functions to become iterators which could be used as call back functions in a more elegant way. From dihedral88888 at googlemail.com Fri Sep 14 12:37:37 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 14 Sep 2012 09:37:37 -0700 (PDT) Subject: Decorators not worth the effort In-Reply-To: References: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> Message-ID: <067b0f14-0d30-49b8-a937-554a571c0ef4@googlegroups.com> Chris Angelico? 2012?9?14????UTC+8??10?41?06???? > On Sat, Sep 15, 2012 at 12:12 AM, andrea crotti > > wrote: > > > def fib(n): > > > if n <= 1: > > > return 1 > > > return fib(n-1) + fib(n-2) > > > > > > @memoize > > > def fib_memoized(n): > > > if n <= 1: > > > return 1 > > > return fib_memoized(n-1) + fib_memoized(n-2) > > > > > > > > > The second fibonacci looks exactly the same but while the first is > > > very slow and would generate a stack overflow the second doesn't.. > > > > Trouble is, you're starting with a pretty poor algorithm. It's easy to > > improve on what's poor. Memoization can still help, but I would start > > with a better algorithm, such as: > > > > def fib(n): > > if n<=1: return 1 > > a,b=1,1 > > for i in range(1,n,2): > > a+=b > > b+=a > > return b if n%2 else a > > > > def fib(n,cache=[1,1]): > > if n<=1: return 1 > > while len(cache)<=n: > > cache.append(cache[-1] + cache[-2]) > > return cache[n] > > > > Personally, I don't mind (ab)using default arguments for caching, but > > you could do the same sort of thing with a decorator if you prefer. I > > think the non-decorated non-recursive version is clear and efficient > > though. > > > > ChrisA Uhn, the decorator part is good for wrapping functions in python. For example a decorator can be used to add a layor of some message handlings of those plain functions to become iterators which could be used as call back functions in a more elegant way. From rosuav at gmail.com Fri Sep 14 13:30:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 15 Sep 2012 03:30:12 +1000 Subject: Decorators not worth the effort In-Reply-To: References: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> Message-ID: On Sat, Sep 15, 2012 at 2:15 AM, andrea crotti wrote: > The poor algorithm is much more close to the mathematical definition > than the smarter iterative one.. And in your second version you > include some ugly caching logic inside it, so why not using a > decorator then? I learned Fibonacci as a sequence, not as a recursive definition. So the algorithm I coded (the non-caching one) is pretty much how I learned it in mathematics. But yes, you're right that the caching is inherent to the second version; and yes, that's where a decorator can make it a LOT cleaner. As a demo of recursion and decorators, your original function pair is definitely the best. But if you want to be able to calculate fib(n) for any n without blowing your stack, my version will scale much more safely. But then again, who actually ever needs fibonacci numbers? ChrisA From wanderer at dialup4less.com Fri Sep 14 13:38:14 2012 From: wanderer at dialup4less.com (Wanderer) Date: Fri, 14 Sep 2012 10:38:14 -0700 (PDT) Subject: subprocess call is not waiting. In-Reply-To: <0b598d7f-7137-47cc-8eed-80ab450536c5@googlegroups.com> References: <0b598d7f-7137-47cc-8eed-80ab450536c5@googlegroups.com> Message-ID: <2bd2bd6b-a473-4633-ab7d-a40c9d8eb4a3@googlegroups.com> On Friday, September 14, 2012 8:22:44 AM UTC-4, pauls... at gmail.com wrote: > os.system worked fine, and I found something in another section of code that was causing the "Too many open errors." (I was fooled, because output from subprocess call didn't seem to be coming out until the open files error. > > > > I'll go back and play with subprocess.call more, since os.system works. That's interesting about using shlex at run time. Is that just for the sake of computational cost? I never got the hang of subprocess, either. I ended up wrapping os.system in a python file and using subprocess to call that with: subprocess.Popen([sys.executable, 'Wrapper.py']) This works for me. I'm using Windows 7. From tjreedy at udel.edu Fri Sep 14 16:29:25 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 14 Sep 2012 16:29:25 -0400 Subject: Decorators not worth the effort In-Reply-To: <20120914021211.GA15642@cskk.homeip.net> References: <20120914021211.GA15642@cskk.homeip.net> Message-ID: On 9/13/2012 10:12 PM, Cameron Simpson wrote: > On 13Sep2012 18:58, alex23 wrote: > | On Sep 14, 3:54 am, Jean-Michel Pichavant > | wrote: > | > I don't like decorators, I think they're not worth the mental effort. > | > | Because passing a function to a function is a huge cognitive burden? For parameterized decorators, there is extra cognitive burden. See below. > It is for me when I'm _writing_ the decorator:-) But if I get it right > and name it well I find it dramaticly _decreases_ the cognitive burden > of the code using the decorator... For a simple, unparameterized wrapper, the difficulty is entirely in the wrapper maker. It must define the final wrapper as a nested function and return it*. It is irrelevant whether the wrapper maker is used with pre-def decorator syntax or with an explicit post-def call. *I am here ignoring the option of a class with __call__ method. For a parameterized wrapper, using decorator syntax requires passing the parameter(s) first and the function to be wrapped later. This requires currying the wrapper maker with double nesting. The nesting order may seem inside-out to some. For most people, this is extra work compared to writing a wrapper that accepts the function and parameters together and only has a single level of nesting. In other words def make_wrapper(func, param): def wrapper(*args, **kwds): for i in range(param): func(*args, **kwds) return wrapper def f(x): print(x) f = make_wrapper(f, 2) f('simple') # is simpler, at least for some people, than the following # which does essentially the same thing. def make_outer(param): def make_inner(func): def wrapper(*args, **kwds): for i in range(param): func(*args, **kwds) return wrapper return make_inner @make_outer(2) def f(x): print(x) f('complex') Is the gain of not repeating the wrapped function name twice in the post-def wrapping call, and the gain of knowing the function will be wrapped before reading the def, worth the pain of currying the wrapper maker? -- Terry Jan Reedy From tjreedy at udel.edu Fri Sep 14 16:31:49 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 14 Sep 2012 16:31:49 -0400 Subject: Decorators not worth the effort In-Reply-To: <732807993.849639.1347614902104.JavaMail.root@sequans.com> References: <732807993.849639.1347614902104.JavaMail.root@sequans.com> Message-ID: On 9/14/2012 5:28 AM, Jean-Michel Pichavant wrote: > Decorators are very popular so I kinda already know that the fault is mine. Now to the reason why I have troubles writing them, I don't know. Every time I did use decorators, I spent way too much time writing it (and debugging it). -- Terry Jan Reedy From tjreedy at udel.edu Fri Sep 14 16:33:01 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 14 Sep 2012 16:33:01 -0400 Subject: Decorators not worth the effort In-Reply-To: References: <20120914021211.GA15642@cskk.homeip.net> Message-ID: On 9/14/2012 4:29 PM, Terry Reedy wrote: > On 9/13/2012 10:12 PM, Cameron Simpson wrote: >> On 13Sep2012 18:58, alex23 wrote: >> | On Sep 14, 3:54 am, Jean-Michel Pichavant >> | wrote: >> | > I don't like decorators, I think they're not worth the mental effort. >> | >> | Because passing a function to a function is a huge cognitive burden? > > For parameterized decorators, there is extra cognitive burden. See below. > > >> It is for me when I'm _writing_ the decorator:-) But if I get it right >> and name it well I find it dramaticly _decreases_ the cognitive burden >> of the code using the decorator... > > For a simple, unparameterized wrapper, the difficulty is entirely in the > wrapper maker. It must define the final wrapper as a nested function and > return it*. It is irrelevant whether the wrapper maker is used with > pre-def decorator syntax or with an explicit post-def call. > > *I am here ignoring the option of a class with __call__ method. > > For a parameterized wrapper, using decorator syntax requires passing the > parameter(s) first and the function to be wrapped later. This requires > currying the wrapper maker with double nesting. The nesting order may > seem inside-out to some. For most people, this is extra work compared to > writing a wrapper that accepts the function and parameters together and > only has a single level of nesting. > > In other words > > def make_wrapper(func, param): > def wrapper(*args, **kwds): > for i in range(param): > func(*args, **kwds) > return wrapper > > def f(x): print(x) > f = make_wrapper(f, 2) > f('simple') > > # is simpler, at least for some people, than the following > # which does essentially the same thing. > > def make_outer(param): > def make_inner(func): > def wrapper(*args, **kwds): > for i in range(param): > func(*args, **kwds) > return wrapper > return make_inner > > @make_outer(2) > def f(x): print(x) > f('complex') > > Is the gain of not repeating the wrapped function name twice in the > post-def wrapping call, and the gain of knowing the function will be > wrapped before reading the def, worth the pain of currying the wrapper > maker? > -- Terry Jan Reedy From tjreedy at udel.edu Fri Sep 14 16:37:47 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 14 Sep 2012 16:37:47 -0400 Subject: Decorators not worth the effort In-Reply-To: <732807993.849639.1347614902104.JavaMail.root@sequans.com> References: <732807993.849639.1347614902104.JavaMail.root@sequans.com> Message-ID: 2nd try, hit send button by mistake before On 9/14/2012 5:28 AM, Jean-Michel Pichavant wrote: > Decorators are very popular so I kinda already know that the fault is > mine. Now to the reason why I have troubles writing them, I don't > know. Every time I did use decorators, I spent way too much time > writing it (and debugging it). You are writing parameterized decorators, which require inverted currying of the wrapper maker. Perhaps that is why you have trouble. As I showed in response to Cameron, it may be easier to avoid that by using a traditional post-def wrapping call instead of decorator syntax. -- Terry Jan Reedy From tjreedy at udel.edu Fri Sep 14 16:43:14 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 14 Sep 2012 16:43:14 -0400 Subject: Least-lossy string.encode to us-ascii? In-Reply-To: <725b3dd0-bd2b-404e-a261-ffe306b38c2f@googlegroups.com> References: <725b3dd0-bd2b-404e-a261-ffe306b38c2f@googlegroups.com> Message-ID: On 9/14/2012 12:15 PM, wxjmfauth at gmail.com wrote: > PS Avoid Py3.3 :-) pps Start using 3.3 as soon as possible. It has Python's first fully portable non-buggy Unicode implementation. The second release candidate is already out. -- Terry Jan Reedy From tjreedy at udel.edu Fri Sep 14 16:57:29 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 14 Sep 2012 16:57:29 -0400 Subject: Least-lossy string.encode to us-ascii? In-Reply-To: <8a35c480-7594-4202-afe8-f03db9418301@googlegroups.com> References: <50524F6F.6070604@tim.thechases.com> <8a35c480-7594-4202-afe8-f03db9418301@googlegroups.com> Message-ID: On 9/13/2012 10:09 PM, Mark Tolonen wrote: > On Thursday, September 13, 2012 4:53:13 PM UTC-7, Tim Chase wrote: >> On 09/13/12 18:36, Terry Reedy wrote: >>> 'keep as much information as possible' would mean an effectively >>> lossless transliteration, which you could do with a dict. >>> {: 'o', : 'c,' (or pick something that would >> Vlastimil's solution kept the characters but stripped them of their >> accents/tildes/cedillas/etc, doing just what I wanted, all using the >> stdlib. Hard to do better than that :-) You mean, hard to do better than what you think you want, as opposed to what you said you wanted in both the subject line and the text line I quoted. What you need depends on why you need ascii only text and what the recipient will do with the ascii only text. Print it on an ascii-only printer? Or something similar? If so, a lossy encoding may be sufficient, but why not let the recipient decide to toss info? > How about using UTF-7 for transmission and decode on the other end? > This keeps the transmission all 7-bit, and no loss. > > >>> s=u"servi?o m?vil".encode('utf-7') > >>> print s > servi+AOc-o m+APM-vil > >>> print s.decode('utf-7') > servi?o m?vil Nice. I was barely aware of and forgot that option. This and similar suggestions to use existing methods is much better than my hackish approach. -- Terry Jan Reedy From ian.g.kelly at gmail.com Fri Sep 14 17:16:47 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 14 Sep 2012 15:16:47 -0600 Subject: Decorators not worth the effort In-Reply-To: References: <20120914021211.GA15642@cskk.homeip.net> Message-ID: On Fri, Sep 14, 2012 at 2:29 PM, Terry Reedy wrote: > For a simple, unparameterized wrapper, the difficulty is entirely in the > wrapper maker. It must define the final wrapper as a nested function and > return it*. It is irrelevant whether the wrapper maker is used with pre-def > decorator syntax or with an explicit post-def call. > > *I am here ignoring the option of a class with __call__ method. > > For a parameterized wrapper, using decorator syntax requires passing the > parameter(s) first and the function to be wrapped later. This requires > currying the wrapper maker with double nesting. The nesting order may seem > inside-out to some. For most people, this is extra work compared to writing > a wrapper that accepts the function and parameters together and only has a > single level of nesting. > > In other words > > def make_wrapper(func, param): > def wrapper(*args, **kwds): > for i in range(param): > func(*args, **kwds) > return wrapper > > def f(x): print(x) > f = make_wrapper(f, 2) > f('simple') > > # is simpler, at least for some people, than the following > # which does essentially the same thing. > > def make_outer(param): > def make_inner(func): > def wrapper(*args, **kwds): > for i in range(param): > func(*args, **kwds) > return wrapper > return make_inner > > @make_outer(2) > def f(x): print(x) > f('complex') > > Is the gain of not repeating the wrapped function name twice in the post-def > wrapping call, and the gain of knowing the function will be wrapped before > reading the def, worth the pain of currying the wrapper maker? If only there were a conceptually simpler way to do this. Actually, there is. I give you: metadecorators! First, the simple, non-parameterized case: from functools import partial def make_wrapper(wrapper): return lambda wrapped: partial(wrapper, wrapped) With that simple function buried in a utility module somewhere, we can do: @make_wrapper def simple_decorator(func, *args, **kwargs): do_stuff() result = func(*args, **kwargs) do_more_stuff() return result Which I think is certainly easier to understand than the nested functions approach. Parameterized decorators are not much more difficult this way. This function: def make_parameterized_wrapper(wrapper): return lambda *params: lambda wrapped: partial(wrapper, wrapped, params) enables us to write: @make_parameterized_wrapper def complex_decorator(func, (param1, param2, param3), *args, **kwargs): do_stuff(param1, param2) result = func(*args, **kwargs) do_more_stuff(param2, param3) return result And now we have a fancy parameterized decorator that again requires no thinking about nested functions at all. Sadly, that last bit of syntax will only work in Python 2; tuple parameter unpacking was removed in Python 3. It's not a complicated upgrade path, however: @make_parameterized_wrapper def complex_decorator(func, params, *args, **kwargs): (param1, param2, param3) = params do_stuff(param1, param2) result = func(*args, **kwargs) do_more_stuff(param2, param3) return result Cheers, Ian From joshua.landau.ws at gmail.com Fri Sep 14 17:19:04 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Fri, 14 Sep 2012 22:19:04 +0100 Subject: Decorators not worth the effort In-Reply-To: References: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> Message-ID: On 14 September 2012 18:30, Chris Angelico wrote: > On Sat, Sep 15, 2012 at 2:15 AM, andrea crotti > wrote: > > The poor algorithm is much more close to the mathematical definition > > than the smarter iterative one.. And in your second version you > > include some ugly caching logic inside it, so why not using a > > decorator then? > > I learned Fibonacci as a sequence, not as a recursive definition. So > the algorithm I coded (the non-caching one) is pretty much how I > learned it in mathematics. But yes, you're right that the caching is > inherent to the second version; and yes, that's where a decorator can > make it a LOT cleaner. > > As a demo of recursion and decorators, your original function pair is > definitely the best. But if you want to be able to calculate fib(n) > for any n without blowing your stack, my version will scale much more > safely. > > But then again, who actually ever needs fibonacci numbers? > I thought the example was good, not because a recursive fib is useful but because memoizing is. There are a lot of times one would like to memoize a function: not just recursive ones. Thus, the example of the decorator was valid. [offtopic] Anyhow, the "best" method has to be this: >>> from decimal import Decimal as Dec >>> def fib(n): ... rootFive = Dec(5).sqrt() ... phi = (1 + rootFive) / 2 ... return round(phi**n / rootFive) >>> fib(100) 354224848179261915075 It's just so obvious why it works. [/offtopic] -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Fri Sep 14 17:32:26 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 14 Sep 2012 21:32:26 +0000 Subject: Comparing strings from the back? In-Reply-To: References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741667C07A@SCACMX008.exchad.jpmchase.net> Dwight Hutto wrote: > On Thu, Sep 13, 2012 at 5:17 PM, Mark Lawrence > wrote: > > On 13/09/2012 21:34, Joshua Landau wrote: > >> > >> On 13 September 2012 20:53, Mark Lawrence > wrote:acci sequence > >> > >>> On 13/09/2012 19:39, Prasad, Ramit wrote: > >>> > >>>> Dwight Hutto wrote: > >>>> > >>>>> Why don' you just time it,eit lops through incrementing thmax input/ > >>>>> > >>>> > >>>> What? Without context I have no idea what this means. > >>>> > >>> > >>> You're wasting your time, I've been described as a jackass for having > >>> the > >>> audacity to ask for context :) > >> Mark, Sometimes it is the style in which something is asked, and not what specifically is asked. ;) > >> > >> > >> I'm pretty sure you are in the wrong, acting as if what he said didn't > >> make > >> sense! Just read it, he obviously was telling you to time it, as eit lops > >> are inside thmax input/ which, as you should know if you *bothered to read > >> the thread*, is incrementing. > >> > >> > >> "don'" is short for "don't", by the way. > > > > I do grovellingly apologize for my appalling breach of netiquette. I am of > > course assuming that the rules have changed and that it's now my > > responsibility to wade back through maybe a couple of hundred responses on a > > long thread to find the context. > I also guess that I'm never going to > > achieve my ambition of being a pot smoking hippy CEO of a web development > > company :( > > -- > > Cheers. > Cheers usually implies you're an alcoholic pressing buttons, with the > half of rest of the coders on the net. Dwight/David: Not necessarily true if you happen to be from the UK (or maybe just England). It seems to be a cultural signature equivalent to "Thanks"--at least in the UK (not sure about other places). [snip] Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Fri Sep 14 18:43:36 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 14 Sep 2012 22:43:36 +0000 Subject: Comparing strings from the back? In-Reply-To: References: <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> Dwight Hutto wrote: > On Fri, Sep 14, 2012 at 4:20 AM, alex23 wrote: > > On Sep 14, 6:04 pm, Dwight Hutto wrote: > >> > Using foreign names derogatively is a common tactic of the racist. > >> > >> Not really. But nice spin on my pun to make me look bad. > > > > It actually *is* common behaviour of racists. > > > > Not if there name is ramit. What if your name was john? I'd say I'll > be right back, I have to go take a crap on the john. It's a joke about > a name, not where it originates. Okay, so maybe not racist but instead offensive juvenile humor? I suppose that is better... > > >> It's similar to if I said, this is real 'queer' of you to do ya big > >> pansy, and next you'll be calling me a homophobe. Um, yes! You are using 'queer' and 'pansy' as a derogatory comparison which falls under the definition for homophobia. "Homophobia is a range of negative attitudes and feelings toward homosexuality or people who are identified or perceived as being lesbian, gay, bisexual or transgender (LGBT). Definitions refer variably to antipathy, contempt, prejudice, aversion, irrational fear, and hatred." ~ First two sentences on Wikipedia > > > > Well, *yes*. Because your choice of that terminology as derogatory > > shows you view it as derogatory. > > No it was a loose analogy to show that he's just trying to use > anything he can say to slam me, and everyone can know it wasn't meant > as racist. Since I was unsure myself if you were trying to be offensive or racist, I would disagree with "everyone can know it wasn't meant as racist". > > >> Try harder, because no one would ever believe I was a racist, and if > >> they did, it's an uninformed decision based off of cherry picken > >> phrases out of context. > > > > Oh, so *now* context is important. > > Never said it wasn't. The whole conversation to me is the context, and > the OP usually follows it, and that's who it is usually intended for. > [ snip ] This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Fri Sep 14 18:51:01 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 14 Sep 2012 22:51:01 +0000 Subject: pythonOCC examples doesn't work? In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47416678FC5@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741667C1C7@SCACMX008.exchad.jpmchase.net> Dwight Hutto wrote: > Chris Angelico wrote: > > honest. How do you feel? Interesting... > > > Um, I guess like an inconsiderate bandwidth hog, but from now on I'll > trim more text. > > First it was too little, and now it's too much. It is a fine line to walk and nobody does it perfectly all the time. We just attempt our best. > I just tend to cut out some or all depending on the scope of the conversation. > > If I just hit reply all, and send it out, it's not intentionally to > use all of the text, and utilize the extra space, it's just a > response. > > If the conversation is kind of just a few people, then I trim pretty > much everything, which apparently set a guy name mark off, who I was > polite to, but I'm not going to get slammed for a few simple posting > mistakes, and more than likely a few of his aliases, or the group he > tends to cheer up with. Sorry, I did not mean to "slam" you by any means. I was just notifying you of the list's commonly agreed upon etiquette and requesting future posts to attempt to adhere to that. > > It's just a mailing list, lighten up because mistakes in posting will > happen, even by accident. > It's just a mailing list, lighten up because a few people trying to help improve your communication to the rest of the group may come off unintentionally as being "slammed" by the community. :) This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Fri Sep 14 19:14:00 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 14 Sep 2012 23:14:00 +0000 Subject: Decorators not worth the effort In-Reply-To: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> References: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741667C22E@SCACMX008.exchad.jpmchase.net> Jean-Michel Pichavant wrote: [snip] > Ultimately, the goal is to have something like > > @timeout(2) > def doAction1 > > @timeout(4) > def doAction2 [snip] > Here's Steven example: > > # Untested! > def timeout(t=15): > # Decorator factory. Return a decorator to actually do the work. > if FPGA: > t *= 3 > def decorator(func): > @functools.wraps(func) > def inner(self, timeout): > self.sendCmd("bootMe", timeout=t) > return inner > return decorator > > I can assure you, that for some python users, it's is not easy to understand > what it does, this function returning a function which returns another > (wrapped) function. It requires some effort. > I think it would help if it was renamed to set_timeout. And I would not expect the Python user to need to understand how it *works*, just to recognize what it *does* when it is used. I may not understand list's sort method internals (beyond the use of timsort), but I know how to use it to sort a list as I want. That is usually all I need. For example, your colleagues just need to understand that the below decorator is setting a timeout for the function. @set_timeout(min=15) def some_function(): '''blah''' One minor note, the style of decorator you are using loses the docstring (at least) of the original function. I would add the @functools.wraps(func) decorator inside your decorator. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From steve+comp.lang.python at pearwood.info Fri Sep 14 19:39:28 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2012 23:39:28 GMT Subject: Decorators not worth the effort References: <20120914021211.GA15642@cskk.homeip.net> Message-ID: <5053c030$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 14 Sep 2012 15:16:47 -0600, Ian Kelly wrote: > If only there were a conceptually simpler way to do this. Actually, > there is. I give you: metadecorators! [code snipped but shown below] > Which I think is certainly easier to understand than the nested > functions approach. Maybe for you, but to me it is a big ball of mud. I have no idea how this is supposed to work! At a quick glance, I would have sworn that it *can't* work, since simple_decorator needs to see multiple arguments but only receives one, the function to be decorated. And yet it does work: py> from functools import partial py> def make_wrapper(wrapper): ... return lambda wrapped: partial(wrapper, wrapped) ... py> @make_wrapper ... def simple_decorator(func, *args, **kwargs): ... print "Entering decorated function" ... result = func(*args, **kwargs) ... print "Exiting decorated function" ... return result ... py> @simple_decorator ... def my_function(a, b, c): ... """Doc string""" ... return a+b+c ... py> my_function(1, 2, 3) Entering decorated function Exiting decorated function 6 So to me, this is far more magical than nested functions. If I saw this in t requires me to hunt through your library for the "simple function buried in a utility module somewhere" (your words), instead of seeing everything needed in a single decorator factory function. It requires that I understand how partial works, which in my opinion is quite tricky. (I never remember how it works or which arguments get curried.) And the end result is that the decorated function is less debugging- friendly than I demand: it is an anonymous partial object instead of a named function, and the doc string is lost. And it is far from clear to me how to modify your recipe to use functools.wraps in order to keep the name and docstring, or even whether I *can* use functools.wraps. I dare say I could answer all those questions with some experimentation and research. But I don't think that your "metadecorator" using partial is *inherently* more understandable than the standard decorator approach: def simple_decorator2(func): @functools.wraps(func) def inner(*args, **kwargs): print "Entering decorated function" result = func(*args, **kwargs) print "Exiting decorated function" return result return inner This is no more complex than yours, and it keeps the function name and docstring. > Parameterized decorators are not much more > difficult this way. This function: [snip code] > And now we have a fancy parameterized decorator that again requires no > thinking about nested functions at all. Again, at the cost of throwing away the function name and docstring. I realise that a lot of this boils down to personal preference, but I just don't think that nested functions are necessarily that hard to grasp, so I prefer to see as much of the decorator logic to be in one place (a nested decorator function) rather than scattered across two separate decorators plus partial. -- Steven From showell30 at yahoo.com Fri Sep 14 20:51:07 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 14 Sep 2012 17:51:07 -0700 (PDT) Subject: Comparing strings from the back? References: <504564ba$0$29978$c3e8da3$5496439d@news.astraweb.com> <504761ef$0$29981$c3e8da3$5496439d@news.astraweb.com> <50477cbb$0$29981$c3e8da3$5496439d@news.astraweb.com> <50485fca$0$29977$c3e8da3$5496439d@news.astraweb.com> <504875EA.8000603@davea.name> Message-ID: <6da9ea89-c3ee-4c2d-9d86-c7b164113bb0@kr6g2000pbb.googlegroups.com> On Sep 6, 4:04?am, Oscar Benjamin wrote: > On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: > > For random strings (as defined below), the average compare time is > > effectively unrelated to the size of the string, once the size > passes > > some point. > > Define random string as being a selection from a set of characters, > with > > replacement. ?So if we pick some set of characters, say 10 (or 256, > it > > doesn't really matter), the number of possible strings is 10**N. > > The likelihood of not finding a mismatch within k characters is > > (1/10)**k ? The likelihood of actually reaching the end of the > random > > string is (1/10)**N. ?(which is the reciprocal of the number of > strings, > > naturally) > > If we wanted an average number of comparisons, we'd have to > calculate a > > series, where each term is a probability times a value for k. > > ? ?sum((k * 9*10**-k) for k in range(1, 10)) > > Those terms very rapidly approach 0, so it's safe to stop after a > few. > > Looking at the first 9 items, I see a value of 1.1111111 > > This may not be quite right, but the value is certainly well under > 2 for > > a population of 10 characters, chosen randomly. ?And notice that N > > doesn't really come into it. > > It's exactly right. You can obtain this result analytically from > Johannes' formula above. Just replace 256 with 10 to get that the > expected number of comparisons is > > (10/9)*(1 - 10**(-N)) The math here is simple, but of course the average running time is also driven by usage patterns. Let's say you have two independently produced strings with N number of random bits. The average amount of bit comparisons that it takes to determine that the strings are different is between 1 and 2 checks for any value of N, for the same reason that the average number of times you need to flip a coin before either coming up heads or exhausting your N tries is always less than 2, and pretty darn close to 2 for even relatively small values of N. def compute_checks_for_different_strings(n): x = 1 p = 0.5 for i in range(0, n): x += p * i p = p * 0.5 print n, x for n in [10, 100, 1000, 10000]: compute_checks_for_different_strings(n) 10 1.9892578125 100 2.0 1000 2.0 10000 2.0 Now let's say your string comparison function is used to verify 100- bit passwords, and 99% of the time the password is from a legit user who types it correctly. Except for the 1% of a time when somebody fat fingers the copy/paste of their password, every strcmp call is gonna have to compare 100 pairs of characters, or N pairs. If the usage pattern says that 99% of the time you're simply verifying that two strings are equal, then the number of bits is the main driving factor for running time. From showell30 at yahoo.com Fri Sep 14 21:13:27 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 14 Sep 2012 18:13:27 -0700 (PDT) Subject: Decorators not worth the effort References: <50531cb5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sep 14, 6:05?am, Tim Chase wrote: > On 09/14/12 07:01, Steven D'Aprano wrote:> [snip timeout class] > > > Holy over-engineering Batman!!! > > > No wonder you don't think much of decorators, > > [snip] > > > Most of my decorator functions are under a dozen lines. And that's the > > complicated ones! > > As are mine, and a sizable chunk of those under-a-dozen-lines are > somewhat boilerplate like using @functools.wraps inside, actual def > of the function, and returning that function. :-) > > -tkc For parameterized decorators, I've usually seen the pattern below. Basically, you have 6 lines of boilerplate, and 2 lines of signal. The amount of boilerplate is fairly daunting, but I like the explicitness, and the nature of decorators is that they tend to get a lot of reuse, so you can amortize the pain of all the boilerplate. import functools def hello_world(name): # non-boilerplate signature def decorator(f): @functools.wraps(f) def wrapped(*args, **kw): print 'hello', name # non-boilerplate value-add f(*args, **kw) return wrapped return decorator @hello_world('earth') def add(x, y): print x + y add(2, 2) From castironpi at gmail.com Fri Sep 14 22:59:29 2012 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 14 Sep 2012 19:59:29 -0700 (PDT) Subject: unit test strategy Message-ID: Hello, I've developing a test script. There's a lot of repetition. I want to introduce a strategy for approaching it, but I don't want the program to be discredited because of the test script. Therefore, I'd like to know what people's reactions to and thoughts about it are. The first strategy I used created an iterator and advanced it between each step: self.op_chain(range(5), ('add', 5)) self.op_chain(range(5), ('add', -2), ('add', -1)) self.op_chain(range(5), ('discard', -1), ('add', 5)) self.op_chain_ok(range(5), ('update', [0, 1])) Etc. I'm considering something more complicated. 'iN' creates iterator N, 'nN' advances iterator N, an exception calls 'assertRaises', and the rest are function calls. dsi= dict.__setitem__ ddi= dict.__delitem__ dsd= dict.setdefault KE= KeyError IE= IterationError self.chain(range(10), 'i0', (dsi, 0, 1), 'n0', (dsi, 10, 1), (IE, 'n0')) self.chain(range(10), 'i0', 'n0', (dsd, 0, 0), 'n0', (dsd, 10, 1), (IE, 'n0')) self.chain(range(10), 'i0', (KE, ddi, 10), 'n0', (ddi, 9), (IE, 'n0')) Do you think the 2nd version is legible? Could it interfere with the accuracy of the test? From dwightdhutto at gmail.com Fri Sep 14 23:10:41 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 23:10:41 -0400 Subject: Comparing strings from the back? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> References: <504972d1$0$29981$c3e8da3$5496439d@news.astraweb.com> <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> Message-ID: On Fri, Sep 14, 2012 at 6:43 PM, Prasad, Ramit wrote: > Dwight Hutto wrote: >> On Fri, Sep 14, 2012 at 4:20 AM, alex2find-work-home/3 wrote: >> > On Sep 14, 6:04 pm, Dwight Hutto wrote: >> >> > Using foreign names derogatively is a common tactic of the racist. >> >> >> >> Not really. But nice spin on my pun to make me look bad. >> > >> > It actually *is* common behaviour of racists. >> > >> >> Not if there name is ramit. What if your name was john? I'd say I'll >> be right back, I have to go take a crap on the john. It's a joke about >> a name, not where it originates. > > Okay, so maybe not racist but instead offensive juvenile humor? > I suppose that is better... No, just shop talk. You hit me and hit I logarithmically hit back ..."butterfly effect". > >> >> >> It's similar to if I said, this is real 'queer' of you to do ya big >> >> pansy, and next you'll be calling me a homophobe. > > Um, yes! You are using 'queer' and 'pansy' as a derogatory comparison > which falls under the definition for homophobia. > > "Homophobia is a range of negative attitudes and feelings toward homosexuality or people who are identified or perceived as being lesbian, gay, bisexual or transgender (LGBT). Definitions refer variably to antipathy, contempt, prejudice, aversion, irrational fear, and hatred." > ~ First two sentences on Wikipedia No, analogy, and a continued attack on a subject we know is propaganda. > >> > >> > Well, *yes*. Because your choice of that terminology as derogatory >> > shows you view it as derogatory. > >> >> No it was a loose analogy to show that he's just trying to use >> anything he can say to slam me, and everyone can know it wasn't meant >> as racist. > > Since I was unsure myself if you were trying to be offensive or racist, > I would disagree with "everyone can know it wasn't meant as racist". > If you're unsure if it was racist, you should err on the side of caution. There are many nicknames on the net. That could be an ethnic name, or an A.K.A.. Non-logical, pure speculation, that is biased that your minority needs more anit-you. Don't engage in conversations you're sure to lose. >> >> >> Try harder, because no one would ever believe I was a racist, and if >> >> they did, it's an uninformed decision based off of cherry picken >> >> phrases out of context. >> > >> > Oh, so *now* context is important. >> >> Never said it wasn't. The whole conversation to me is the context, and >> the OP usually follows it, and that's who it is usually intended for. >> -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Fri Sep 14 23:26:04 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 23:26:04 -0400 Subject: unit test strategy In-Reply-To: References: Message-ID: On Fri, Sep 14, 2012 at 10:59 PM, Aaron Brady wrote: > Hello, > > I've developing a test script. There's a lot of repetition. I want to introduce a strategy for approaching it, but I don't want the program to be discredited because of the test script. Therefore, I'd like to know what people's reactions to and thoughts about it are. > > The first strategy I used created an iterator and advanced it between each step: That isn't a refined iterator below: > self.op_chain(range(5), ('add', 5)) > self.op_chain(range(5), ('add', -2), ('add', -1)) > self.op_chain(range(5), ('discard', -1), ('add', 5)) > self.op_chain_ok(range(5), ('update', [0, 1])) > Etc. > > I'm considering something more complicated. 'iN' creates iterator N, 'nN' advances iterator N, an exception calls 'assertRaises', and the rest are function calls. > dsi= dict.__setitem__ > ddi= dict.__delitem__ > dsd= dict.setdefault > KE= KeyError > IE= IterationError > self.chain(range(10), 'i0', (dsi, 0, 1), 'n0', (dsi, 10, 1), (IE, 'n0')) > self.chain(range(10), 'i0', 'n0', (dsd, 0, 0), 'n0', (dsd, 10, 1), (IE, 'n0')) > self.chain(range(10), 'i0', (KE, ddi, 10), 'n0', (ddi, 9), (IE, 'n0')) > > Do you think the 2nd version is legible? Could it interfere with the accuracy of the test? Show the test, which should show instances of wehat you want called. I could rewrite the above, but it seems you're moe in need of refining your iterations, and the values given within them. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Fri Sep 14 23:32:44 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 23:32:44 -0400 Subject: unit test strategy In-Reply-To: References: Message-ID: On Fri, Sep 14, 2012 at 11:26 PM, Dwight Hutto wrote: > On Fri, Sep 14, 2012 at 10:59 PM, Aaron Brady wrote: >> Hello, >> >> I've developing a test script. There's a lot of repetition. I want to introduce a strategy for approaching it, but I don't want the program to be discredited because of the test script. Therefore, I'd like to know what people's reactions to and thoughts about it are. >> >> The first strategy I used created an iterator and advanced it between each step: > > That isn't a refined iterator below: What I mean is look at the similarities, and the differences, then replace the differences with interpolation, in eval even. > >> self.op_chain(range(5), ('add', 5)) >> self.op_chain(range(5), ('add', -2), ('add', -1)) >> self.op_chain(range(5), ('discard', -1), ('add', 5)) >> self.op_chain_ok(range(5), ('update', [0, 1])) >> Etc. >> >> I'm considering something more complicated. 'iN' creates iterator N, 'nN' advances iterator N, an exception calls 'assertRaises', and the rest are function calls. iN = [N for N in range(0,5)] >> dsi= dict.__setitem__ >> ddi= dict.__delitem__ >> dsd= dict.setdefault >> KE= KeyError >> IE= IterationError >> self.chain(range(10), 'i0', (dsi, 0, 1), 'n0', (dsi, 10, 1), (IE, 'n0')) >> self.chain(range(10), 'i0', 'n0', (dsd, 0, 0), 'n0', (dsd, 10, 1), (IE, 'n0')) >> self.chain(range(10), 'i0', (KE, ddi, 10), 'n0', (ddi, 9), (IE, 'n0')) >> >> Do you think the 2nd version is legible? Could it interfere with the accuracy of the test? Define the 2nd version > > Show the test, which should show instances of what you want called. > > I could rewrite the above, but it seems you're more in need of refining > your iterations, and the values given within them. > -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Fri Sep 14 23:42:18 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 23:42:18 -0400 Subject: Decorators not worth the effort In-Reply-To: <874nn1jedk.fsf@handshake.de> References: <874nn1jedk.fsf@handshake.de> Message-ID: On Fri, Sep 14, 2012 at 2:40 AM, Dieter Maurer wrote: >> On Sep 14, 3:54 am, Jean-Michel Pichavant >> wrote: >>> I don't like decorators, I think they're not worth the mental effort. > > Fine. > > I like them because they can vastly improve reusability and drastically > reduce redundancies (which I hate). Improved reusability and > reduced redundancies can make applications more readable, easier > to maintain and faster to develop. Reduce redundancy, is argumentative. To me, a decorator, is no more than a logging function. Correct me if I'm wrong. It throws things at a functyion designed to watch other functions. The necessity for more than one decorator with if /else statements seems redundant, but I haven't had to use them that much recently. > > -- > http://mail.python.org/mailman/listinfo/python-list -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Fri Sep 14 23:47:11 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 14 Sep 2012 23:47:11 -0400 Subject: pythonOCC examples doesn't work? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4741667C1C7@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF47416678FC5@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4741667C1C7@SCACMX008.exchad.jpmchase.net> Message-ID: On Fri, Sep 14, 2012 at 6:51 PM, Prasad, Ramit wrote: > Dwight Hutto wrote: >> Chris Angelico wrote: >> > honest. How do you feel? Interesting... >> > >> Um, I guess like an inconsiderate bandwidth hog, but from now on I'll >> trim more text. >> >> First it was too little, and now it's too much. > > It is a fine line to walk and nobody does it perfectly all the time. > We just attempt our best. >python docs interpolation >> I just tend to cut out some or all depending on the scope of the conversation. >> >> If I just hit reply all, and send it out, it's not intentionally topython docs interpolation >> use all of the text, and utilize the extra space, it's just a >> response. >> >> If the conversation is kind of just a few people, then I trim pretty >> much everything, which apppython docs interpolationarently set a guy name mark off, who I was >> polite to, but I'm not going to get slammed for a few simple posting >> mistakes, and more than likely a few of his aliases, or the group he >> tends to cheer up with. > > Sorry, I did not mean to "slam" you by any means. I was just > notifying you of the list's commonly agreed upon etiquette and > requesting future posts to attempt to adhere to that. > >> >> It's just a mailing list, lighten up because mistakes in posting will >> happen, even by accident. >> > > It's just a mailing list, lighten up because a few people trying > to help improve your communication to the rest of the group > may come off unintentionally as being "slammed" by the community. :) > That's no problem, But some suported ad some opposed, it's a democracy, but a dictatorship by the moderators. How much did I err in their opinion of stating my opinion, in relation to the statistical whole? -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From rosuav at gmail.com Fri Sep 14 23:53:37 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 15 Sep 2012 13:53:37 +1000 Subject: pythonOCC examples doesn't work? In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47416678FC5@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4741667C1C7@SCACMX008.exchad.jpmchase.net> Message-ID: On Sat, Sep 15, 2012 at 1:47 PM, Dwight Hutto wrote: > That's no problem, But some suported ad some opposed, it's a > democracy, but a dictatorship by the moderators. How much did I err in > their opinion of stating my opinion, in relation to the statistical > whole? Actually, I've not seen any moderatorial action on this list. Savoynet is as you describe, a monarchy whose head but seldom exercises power; python-list/c.l.p is an anarchy - or, if you like, a true democracy. Not a representative democracy where we all get to vote, but we all individually have the power to kick someone out - it's called a killfile. The more people you annoy, the more people won't hear you any more. ChrisA From clp2 at rebertia.com Sat Sep 15 00:02:22 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 14 Sep 2012 21:02:22 -0700 Subject: subprocess call is not waiting. In-Reply-To: <0b598d7f-7137-47cc-8eed-80ab450536c5@googlegroups.com> References: <0b598d7f-7137-47cc-8eed-80ab450536c5@googlegroups.com> Message-ID: On Fri, Sep 14, 2012 at 5:22 AM, wrote: > os.system worked fine, and I found something in another section of code that was causing the "Too many open errors." (I was fooled, because output from subprocess call didn't seem to be coming out until the open files error. > > I'll go back and play with subprocess.call more, since os.system works. That's interesting about using shlex at run time. Is that just for the sake of computational cost? No, like I said, you'll also get incorrect results. shlex isn't magic. If the exact command line it's given wouldn't work in the shell, then it won't magically fix things. Many (most?) dynamic invocations of shlex.split() are naive and flawed: >>> import shlex >>> filename = "my summer vacation.txt" >>> # the following error is less obvious when the command is more complex >>> # (and when the filename isn't hardcoded) >>> cmd = "cat " + filename >>> shlex.split(cmd) ['cat', 'my', 'summer', 'vacation.txt'] >>> # that's wrong; the entire filename should be a single list element Equivalent bash error: chris at mbp ~ $ cat my summer vacation.txt cat: my: No such file or directory cat: summer: No such file or directory cat: vacation.txt: No such file or directory The right way, in bash: chris at mbp ~ $ cat my\ summer\ vacation.txt Last summer, I interned at a tech company and... chris at mbp ~ $ cat 'my summer vacation.txt' Last summer, I interned at a tech company and? And indeed, shlex will get that right too: >>> shlex.split("cat my\ summer\ vacation.txt") ['cat', 'my summer vacation.txt'] >>> shlex.split("cat 'my summer vacation.txt'") ['cat', 'my summer vacation.txt'] BUT that presumes that your filenames are already pre-quoted or have had backslashes added, which very seldom is the case in reality. So, you can either find an escaping function and hope you never forget to invoke it (cf. SQL injection), or you can figure out the general tokenization and let `subprocess` handle the rest (cf. prepared statements): >>> split('cat examplesimplefilename') ['cat', 'examplesimplefilename'] >>> # Therefore? >>> def do_cat(filename): ... cmd = ['cat', filename] # less trivial cases would be more interesting ... call(cmd) ... >>> filename = "my summer vacation.txt" >>> # remember that those quotes are Python literal syntax and aren't in the string itself >>> print filename my summer vacation.txt >>> do_cat(filename) Last summer, I interned at a tech company and? >>> Generally, use (a) deliberately simple test filename(s) with shlex, then take the resulting list and replace the filename(s) with (a) variable(s). Or, just figure out the tokenization without recourse to shlex; it's not difficult in most cases! The Note in the Popen docs covers some common tokenization mistakes people make: http://docs.python.org/library/subprocess.html#subprocess.Popen Cheers, Chris From jyoung79 at kc.rr.com Sat Sep 15 00:36:00 2012 From: jyoung79 at kc.rr.com (jyoung79 at kc.rr.com) Date: Sat, 15 Sep 2012 4:36:00 +0000 Subject: Moving folders with content Message-ID: <20120915043600.VOQ3T.118012.root@cdptpa-web22-z01> Hello, I am working in both OS X Snow Leopard and Lion (10.6.8 and 10.7.4). I'm simply wanting to move folders (with their content) from various servers to the hard drive and then back to different directories on the servers. I want to be careful not to remove any metadata or resource forks from the files in the directories. I did a bit of researching on shutil, and looks like it is similar to using "cp -p" and copystat(), which I believe will keep the resource fork, etc. Here's the code I came up with. I'm curious if anyone finds fault with this, or if there's a better way to do this? Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> >>> import os >>> import shutil >>> >>> p1 = os.path.expanduser('~/Desktop/IN/Test/') >>> p2 = os.path.expanduser('~/Desktop/OUT/Test/') >>> >>> if os.path.exists(p2): shutil.rmtree(p2) ... >>> shutil.copytree(p1, p2) >>> shutil.rmtree(p1) >>> Thanks! Jay From dwightdhutto at gmail.com Sat Sep 15 00:40:41 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sat, 15 Sep 2012 00:40:41 -0400 Subject: pythonOCC examples doesn't work? In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47416678FC5@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4741667C1C7@SCACMX008.exchad.jpmchase.net> Message-ID: On Fri, Sep 14, 2012 at 11:53 PM, Chris Angelico wrote: > On Sat, Sep 15, 2012 at 1:47 PM, Dwight Hutto wrote: >> That's no problem, But some suported ad some opposed, it's a >> democracy, but a dictatorship by the moderators. How much did I err in >> their opinion of stating my opinion, in relation to the statistical >> whole? > > Actually, I've not seen any moderatorial action on this list. Savoynet Alan Gauld quotes, "Putting on my moderator's hat", sometimes. > is as you describe, a monarchy whose head but seldom exercises power; I think it's Rossenbom(or whoever the creator of the interpreter written in C is), "who says benevolent dictator for life" > python-list/c.l.p is an anarchy - or, if you like, a true democracy. Both, depending on whether you're a freestylist, or a pythonista who follows versions. > Not a representative democracy where we all get to vote, but we all > individually have the power to kick someone out - it's called a > killfile. No, only the individual can killfile, then they miss the point of someone they should be listening to, because they kill filed for propaganda, and not an actual cause(to join a group). The more people you annoy, the more people won't hear you > any more. Annoy, how, with truth and honesty, then go away, and kill file me with the few who are ignorant of the fact I speak the truth. > -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dieter at handshake.de Sat Sep 15 02:31:30 2012 From: dieter at handshake.de (Dieter Maurer) Date: Sat, 15 Sep 2012 08:31:30 +0200 Subject: Decorators not worth the effort In-Reply-To: References: <874nn1jedk.fsf@handshake.de> Message-ID: <20564.8386.485106.958468@localhost.localdomain> Dwight Hutto wrote at 2012-9-14 23:42 -0400: > ... >Reduce redundancy, is argumentative. > >To me, a decorator, is no more than a logging function. Correct me if >I'm wrong. Well, it depends on how you are using decorators and how complex your decorators are. If what you are using as decorating function it really trivial, as trivial as "@", then you do not gain much. But your decorator functions need not be trivial. An example: in a recent project, I have implemented a SOAP webservice where most services depend on a valid session and must return specified fields even when (as in the case of an error) there is no senseful value. Instead of putting into each of those function implementations the check "do I have a valid session?" and at the end "add required fields not specified", I opted for the following decorator: def valid_session(*fields): ! fields = ("errorcode",) + fields @decorator def valid_session(f, self, sessionkey, *args, **kw): ! s = get_session(sessionkey) ! if not s.get("authenticated", False): ! rd = {"errorcode": u"1000"} ! else: ! rd = f(self, sessionkey, *args, **kw) ! return tuple(rd.get(field, DEFAULTS.get(field, '')) for field in fields) return valid_session The lines starting with "!" represent the logic encapsulated by the decorator -- the logic, I would have to copy into each function implementation without it. I then use it this way: @valid_session() def logout(self, sessionkey): s = get_session(sessionkey) s["authenticated"] = False return {} @valid_session("amountavail") def getStock(self, sessionkey, customer, item, amount): info = self._get_article(item) return {u"amountavail":info["deliverability"] and u"0" or u"1"} @valid_session("item", "shortdescription", "pe", "me", "min", "price", "vpe", "stock", "linkpicture", "linkdetail", "linklist", "description", "tax") def fetchDetail(self, sessionkey, customer, item): return self._get_article(item) ... I hope you can see that at least in this example, the use of the decorator reduces redundancy and highly improves readability -- because boilerplate code (check valid session, add default values for unspecified fields) is not copied over and over again but isolated in a single place. The example uses a second decorator ("@decorator") -- in the decorator definition itself. This decorator comes from the "decorator" module, a module facilitating the definition of signature preserving decorators (important in my context): such a decorator ensures that the decoration result has the same parameters as the decorated function. To achieve this, complex Python implementation details and Python's introspection must be used. And I am very happy that I do not have to reproduce this logic in my decorator definitions but just say "@decorator" :-) Example 3: In another project, I had to implement a webservice where most of the functions should return "json" serialized data structures. As I like decorators, I chose a "@json" decorator. Its definition looks like this: @decorator def json(f, self, *args, **kw): r = f(self, *args, **kw) self.request.response.setHeader( 'content-type', # "application/json" made problems with the firewall, # try "text/json" instead #'application/json; charset=utf-8' 'text/json; charset=utf-8' ) return udumps(r) It calls the decorated function, then adds the correct "content-type" header and finally returns the "json" serialized return value. The webservice function definitions then look like: @json def f1(self, ....): .... @json def f2(self, ...): .... The function implementions can concentrate on their primary task. The "json" decorator" tells that the result is (by magic specified elsewhere) turned into a "json" serialized value. This example demontrates the improved maintainability (caused by the redundancy reduction): the "json rpc" specification stipulates the use of the "application/json" content type. Correspondingly, I used this content-type header initially. However, many enterprise firewalls try to protect against viruses by banning "application/*" responses -- and in those environments, my initial webservice implementation did not work. Thus, I changed the content type to "text/json". Thanks to the decorator encapsulation of the "json result logic", I could make my change at a single place -- not littered all over the webservice implementation. And a final example: Sometimes you are interested to cache (expensive) function results. Caching involves non-trivial logic (determine the cache, determine the key, check whether the cache contains a value for the key; if not, call the function, cache the result). The package "plone.memoize" defines a set of decorators (for different caching policies) which which caching can be as easy as: @memoize def f(....): .... The complete caching logic is encapsulated in the tiny "@memoize" prefix. It tells: calls to this function are cached. The function implementation can concentrate on its primary task and there is no need to obscure the implementation by the orthogonal aspect of caching. I hope I could convince you that while you may not have a serious need for decorators, there are cases where they can be really useful. Should I have not yet succeeded, I suggest you read some overview on aspect oriented programming. I am sure, you will find there losts of further examples why it is a good idea to separate general purpose aspects (logging, monitoring, persistency, resource management, caching, serialization, ...) from the primary task of a function. Decorators provide syntactic sugur to facilitate this separation in Python. -- Dieter From gandalf at shopzeus.com Sat Sep 15 02:36:10 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sat, 15 Sep 2012 08:36:10 +0200 Subject: Moving folders with content In-Reply-To: <20120915043600.VOQ3T.118012.root@cdptpa-web22-z01> References: <20120915043600.VOQ3T.118012.root@cdptpa-web22-z01> Message-ID: <505421DA.3030906@shopzeus.com> On 2012-09-15 06:36, jyoung79 at kc.rr.com wrote: > Hello, > > I am working in both OS X Snow Leopard and Lion (10.6.8 and 10.7.4). > I'm simply wanting to move folders (with their content) from various > servers to the hard drive and then back to different directories on the > servers. > > I want to be careful not to remove any metadata or resource forks from > the files in the directories. I did a bit of researching on shutil, and > looks like it is similar to using "cp -p" and copystat(), which I believe > will keep the resource fork, etc. > > Here's the code I came up with. I'm curious if anyone finds fault with > this, or if there's a better way to do this? Not in this particular case, because you know that these directories are on different computers. But instead of rmtree+copytree, I would rather use shutil.move() because it will use os.rename() when the source and the destination are on the same filesystem. Much much faster. From dieter at handshake.de Sat Sep 15 02:49:34 2012 From: dieter at handshake.de (Dieter Maurer) Date: Sat, 15 Sep 2012 08:49:34 +0200 Subject: How to implement a combo Web and Desktop app in python. References: Message-ID: <87zk4r7pc1.fsf@handshake.de> Shawn McElroy writes: > ... > Although you are correct in the aspect of having 'real' OS level integration. Being able to communicate with other apps as well as contextual menus. Although, could I not still implement those features from python, into the host system from python? There are also tools like 'kivi' which allow you to get system level access to do things. Though im not too sure on how far that extends, or how useful it would be. In my szenario you have a standard browser as (thin) client and Python only on the server side. In my szenario, the server could run on the clients desktop -- however, it ran there as a "service", i.e. not in "user space". My knowledge about Windows is limited. I do not really know whether a Windows "service" can fully interact with applications running in the "user space" and what limitations may apply. From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sat Sep 15 03:13:16 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sat, 15 Sep 2012 09:13:16 +0200 Subject: Decorators not worth the effort In-Reply-To: References: <20120914021211.GA15642@cskk.homeip.net> Message-ID: [Sorry, my Firefox destroyed the indent... Am 14.09.2012 22:29 schrieb Terry Reedy: > In other words > > def make_wrapper(func, param): > def wrapper(*args, **kwds): > for i in range(param): > func(*args, **kwds) > return wrapper > > def f(x): print(x) > f = make_wrapper(f, 2) > f('simple') > > # is simpler, at least for some people, than the following > # which does essentially the same thing. > > def make_outer(param): > def make_inner(func): > def wrapper(*args, **kwds): > for i in range(param): > func(*args, **kwds) > return wrapper > return make_inner > > @make_outer(2) > def f(x): print(x) > f('complex') For this case, my mydeco.py which I use quite often contains a def indirdeco(ind): # Update both the outer as well as the inner wrapper. # If we knew the inner one was to be updated with something # from *a, **k, we could do it. But not this way... @functools.wraps(ind) def outer(*a, **k): @functools.wraps(ind) def inner(f): return ind(f, *a, **k) return inner return outer so I can do @indirdeco def make_wrapper(func, param): @functools.wraps(func) def wrapper(*args, **kwds): for i in range(param): func(*args, **kwds) return wrapper and then nevertheless @make_wrapper(2) def f(x): print(x) BTW, I also have a "meta-decorator" for the other direction: def wrapfunction(mighty): """Wrap a function taking (f, *a, **k) and replace it with a function taking (f) and returning a function taking (*a, **k) which calls our decorated function. Other direction than indirdeco.""" @functools.wraps(mighty) def wrapped_outer(inner): @functools.wraps(inner) def wrapped_inner(*a, **k): return mighty(inner, *a, **k) wrapped_inner.func = inner # keep the wrapped function wrapped_inner.wrapper = mighty # and the replacement return wrapped_inner wrapped_outer.func = mighty # keep this as well return wrapped_outer With this, a @wrapfunction def twice(func, *a, **k): return func(*a, **k), func(*a, **k) can be used with @twice def f(x): print (x); return x very nicely. Thomas From nobody at nowhere.com Sat Sep 15 04:00:16 2012 From: nobody at nowhere.com (Nobody) Date: Sat, 15 Sep 2012 09:00:16 +0100 Subject: Moving folders with content References: Message-ID: On Sat, 15 Sep 2012 04:36:00 +0000, jyoung79 wrote: > I am working in both OS X Snow Leopard and Lion (10.6.8 and 10.7.4). > I'm simply wanting to move folders (with their content) from various > servers to the hard drive and then back to different directories on the > servers. > > I want to be careful not to remove any metadata or resource forks from > the files in the directories. I did a bit of researching on shutil, and > looks like it is similar to using "cp -p" and copystat(), which I believe > will keep the resource fork, etc. I don't think so. The shutil documentation says: Warning Even the higher-level file copying functions (copy(), copy2()) can?t copy all file metadata. On POSIX platforms, this means that file owner and group are lost as well as ACLs. On Mac OS, the resource fork and other metadata are not used. This means that resources will be lost and file type and creator codes will not be correct. On Windows, file owners, ACLs and alternate data streams are not copied. The macostools module has functions which can copy the resource fork, but they aren't available in 64-bit builds and have been removed in Python 3.0. From wxjmfauth at gmail.com Sat Sep 15 04:58:12 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 15 Sep 2012 01:58:12 -0700 (PDT) Subject: Least-lossy string.encode to us-ascii? In-Reply-To: References: <725b3dd0-bd2b-404e-a261-ffe306b38c2f@googlegroups.com> Message-ID: <2c3348d4-2f7e-4978-a275-26d5a900a962@googlegroups.com> Le vendredi 14 septembre 2012 22:45:05 UTC+2, Terry Reedy a ?crit?: > On 9/14/2012 12:15 PM, wxjmfauth at gmail.com wrote: > > > > > PS Avoid Py3.3 :-) > > > > pps Start using 3.3 as soon as possible. It has Python's first fully > > portable non-buggy Unicode implementation. The second release candidate > > is already out. > > > > -- > > Terry Jan Reedy - I will drop Python. - No complaints. - (OT, luckily one of the two Unicode TeX engines is called LuaTeX.) jmf From wxjmfauth at gmail.com Sat Sep 15 04:58:12 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 15 Sep 2012 01:58:12 -0700 (PDT) Subject: Least-lossy string.encode to us-ascii? In-Reply-To: References: <725b3dd0-bd2b-404e-a261-ffe306b38c2f@googlegroups.com> Message-ID: <2c3348d4-2f7e-4978-a275-26d5a900a962@googlegroups.com> Le vendredi 14 septembre 2012 22:45:05 UTC+2, Terry Reedy a ?crit?: > On 9/14/2012 12:15 PM, wxjmfauth at gmail.com wrote: > > > > > PS Avoid Py3.3 :-) > > > > pps Start using 3.3 as soon as possible. It has Python's first fully > > portable non-buggy Unicode implementation. The second release candidate > > is already out. > > > > -- > > Terry Jan Reedy - I will drop Python. - No complaints. - (OT, luckily one of the two Unicode TeX engines is called LuaTeX.) jmf From cs at zip.com.au Sat Sep 15 05:30:07 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 15 Sep 2012 19:30:07 +1000 Subject: Batching HTTP requests with httplib (Python 2.7) In-Reply-To: References: Message-ID: <20120915093007.GA13456@cskk.homeip.net> On 14Sep2012 10:53, Chicken McNuggets wrote: | On 14/09/2012 03:31, Cameron Simpson wrote: | > On 13Sep2012 19:34, Chicken McNuggets wrote: | > | I'm writing a simple library that communicates with a web service and am | > | wondering if there are any generally well regarded methods for batching | > | HTTP requests? | > | | > | The problem with most web services is that they require a list of | > | sequential commands to be executed in a certain order to complete a | > | given task (or at least the one I am using does) so having to manually | > | call each command is a bit of a pain. How would you go about the design | > | of a library to interact with these services? | > | > Maybe I'm missing something. What's hard about: | > | > - wrapping the web services calls in a simple wrapper which | > composes the call, runs it, and returns the result parts | > This lets you hide all the waffle about the base URL, | > credentials etc in the wrapper and only supply the essentials | > at call time. | > | > - writing your workflow thing then as a simple function: | > | > def doit(...): | > web_service_call1(...) | > web_service_call2(...) | > web_service_call3(...) | > | > with whatever internal control is required? | > | > This has worked for me for simple things. | > What am I missing about the larger context? | | That is what I have at the moment but it is ugly as hell. I was | wondering if there was a somewhat more elegant solution that I was missing. Leading disclaimer: I'm no web service expert. Well, I presume you're using a web service library like ZSI or suds? I'm using suds; started with ZSI but it had apparent maintenance stagnancy and also some other issues. I moved to suds and it's been fine. I make a class wrapping a suds Client object and some convenience functions. A suds Client object is made from the WSDL file or URL and fills out all the services with callable methods accepting the web service parameters. So the class has a setup method like this: def set_client(self, wsdlfile, baseurl): ''' Common code to set the .client attribute to a suds SOAP Client. ''' from suds.client import Client self.client = Client('file://'+wsdlfile) self.client.set_options(location = baseurl) self.client.set_options(proxy = {'https': 'proxy:3128'}) wsdlfile points at a local WSDL file, removing dependence on some server to provide the WSDL. Makes testing easier too. Then there's a general call wrapper. The wscall() method below is a slightly scoured version of something I made for work. You hand it the service name and any parameters needed for that service call and it looks it up in the Client, calls it, sanity checks the result in a generic sense. If things are good it returns the suds reply object. But if anything goes wrong it logs it and returns None. "Goes wrong" includes a successful call whose internal result contains an error response - obviously that's application dependent. The upshot is that the wrapper for a specific web service call then becomes: def thing1(self, blah, blah, ...): reply = self.wscall('thing1', blah, blah, ...) if reply is None: # badness happened; it has been logged, just return in whatever # fashion you desire - return None, raise exception, etc ... # otherwise we pick apart the reply object to get the bits that # matter and return them return stuff from the reply object and your larger logic looks like: def doit(self, ...): self.thing1(1,2,3) self.thing2(...) and so forth. The general web service wrapper wscall() below has some stuff ripped out, but I've left in some application specific stuff for illustration: - optional _client and _cred keyword parameters to override the default Client and credentials from the main class instance - the Pfx context manager stuff arranges to prefix log messages and exception strings with context, which I find very handy in debugging and logging - likewise the LogTime context manager logs things that exceed a time threshold - the wsQueue.submit(...) stuff punts the actual web service call through a capacity queue (a bit like the futures module) because this is a capacity limited multithreaded app. For your purposes you could write: websvc = getattr(_client.service, servicename) with LogTime(servicename, threshold=3): try: reply = websvc(userId=_cred.username, password=_cred.password, *args, **kwargs) except: exc_info = sys.exc_info reply = None else: exc_info = None which is much easier to follow. - the 'callStatus' thing is application specific, left as an example of a post-call sanity check you would add for calls that complete but return with an error indication Anyway, all that said, the general wrapper looks like this: def doWScall(self, servicename, _client=None, _cred=None, *args, **kwargs): ''' General wrapper for a web service call. Returns the native SUDS reply object if OK, otherwise None. `_client` can be used to override use of self.client. `_cred` can be used to override use of self.cred. ''' if _client is None: _client = self.client if _cred is None: _cred = self.cred with self.pfx: with Pfx("doWScall.%s(...)", servicename): websvc = getattr(_client.service, servicename) with LogTime(servicename, threshold=3): reply, exc_info = self.wsQueue.submit( partial(websvc, userId=_cred.username, password=_cred.password, *args, **kwargs), name=servicename).wait() if exc_info: error("FAIL, exception in web service call", exc_info=exc_info) return None if reply is None: arglist = listargs(args, kwargs) error("web service called but got None anyway: arglist=(%s)", ", ".join(arglist)) return None if hasattr(reply, 'callStatus'): if reply.callStatus == "OK": info("OK") return reply ... log an error message including relevant stuff from the reply ... return None Anyway, I hope that shows a way to get the main logic clear and the overhead for wrapping specific calls quite lightweight. Cheers, -- Cameron Simpson Well, it's one louder, isn't it? It's not ten. You see, most blokes are gonna be playing at ten, you're on ten here, all the way up, all the way up, all the way up, you're on ten on your guitar, where can you go from there? Where? Nowhere, exactly. What we do is, if we need that extra push over the cliff, you know what we do? Eleven. Exactly. One louder. - Nigel Tufnel, _This Is Spinal Tap_ From dihedral88888 at googlemail.com Sat Sep 15 05:45:42 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 15 Sep 2012 02:45:42 -0700 (PDT) Subject: Decorators not worth the effort In-Reply-To: <5053c030$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <20120914021211.GA15642@cskk.homeip.net> <5053c030$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano? 2012?9?15????UTC+8??7?39?28???? > On Fri, 14 Sep 2012 15:16:47 -0600, Ian Kelly wrote: > > > > > If only there were a conceptually simpler way to do this. Actually, > > > there is. I give you: metadecorators! > > [code snipped but shown below] > > > Which I think is certainly easier to understand than the nested > > > functions approach. > > > > Maybe for you, but to me it is a big ball of mud. I have no idea how this > > is supposed to work! At a quick glance, I would have sworn that it > > *can't* work, since simple_decorator needs to see multiple arguments but > > only receives one, the function to be decorated. And yet it does work: > > > > py> from functools import partial > > py> def make_wrapper(wrapper): > > ... return lambda wrapped: partial(wrapper, wrapped) > > ... > > py> @make_wrapper > > ... def simple_decorator(func, *args, **kwargs): > > ... print "Entering decorated function" > > ... result = func(*args, **kwargs) > > ... print "Exiting decorated function" > > ... return result > > ... > > py> @simple_decorator > > ... def my_function(a, b, c): > > ... """Doc string""" > > ... return a+b+c > > ... > > py> my_function(1, 2, 3) > > Entering decorated function > > Exiting decorated function > > 6 > > > > So to me, this is far more magical than nested functions. If I saw this > > in t requires me to hunt through your library for the "simple function > > buried in a utility module somewhere" (your words), instead of seeing > > everything needed in a single decorator factory function. It requires > > that I understand how partial works, which in my opinion is quite tricky. > > (I never remember how it works or which arguments get curried.) > > > > And the end result is that the decorated function is less debugging- > > friendly than I demand: it is an anonymous partial object instead of a > > named function, and the doc string is lost. And it is far from clear to > > me how to modify your recipe to use functools.wraps in order to keep the > > name and docstring, or even whether I *can* use functools.wraps. > > > > I dare say I could answer all those questions with some experimentation > > and research. But I don't think that your "metadecorator" using partial > > is *inherently* more understandable than the standard decorator approach: > > > > def simple_decorator2(func): > > @functools.wraps(func) > > def inner(*args, **kwargs): > > print "Entering decorated function" > > result = func(*args, **kwargs) > > print "Exiting decorated function" > > return result > > return inner > > > > This is no more complex than yours, and it keeps the function name and > > docstring. > > > > > > > Parameterized decorators are not much more > > > difficult this way. This function: > > [snip code] > > > And now we have a fancy parameterized decorator that again requires no > > > thinking about nested functions at all. > > > > Again, at the cost of throwing away the function name and docstring. > > > > I realise that a lot of this boils down to personal preference, but I > > just don't think that nested functions are necessarily that hard to > > grasp, so I prefer to see as much of the decorator logic to be in one > > place (a nested decorator function) rather than scattered across two > > separate decorators plus partial. > > > > > > > > > > -- > > Steven I think the problem is not in the replaced f.__doc__. def MIGHT_FAIL(f, MSG, *k, **h): # use MSG to determine whether to invoke f or not # and do an error catch here .... def innner(f): ..... ...... # get the right info of f here for any trapped error #return inner, result return inner From dwightdhutto at gmail.com Sat Sep 15 06:04:25 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sat, 15 Sep 2012 06:04:25 -0400 Subject: Decorators not worth the effort In-Reply-To: References: <20120914021211.GA15642@cskk.homeip.net> <5053c030$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 15, 2012 at 5:45 AM, 88888 Dihedral wrote: > Steven D'Aprano? 2012?9?15????UTC+8??7?39?28???? >> On Fri, 14 Sep 2012 15:16:47 -0600, Ian Kelly wrote: >> >> >> >> > If only there were a conceptually simpler way to do this. Actually, >> >> > there is. I give you: muman than humanetadecorators! >> >> [code snipped but shown below] >> >> > Which I think is certainly easier to understand than the nested >> >> > functions approach. >> >> >> >> Maybe for you, but to me it is a big ball of mud. I have no idea how this >> >> is supposed to work! At a quick glance, I would have sworn that it >> >> *can't* work, since simple_decorator needs to see multiple arguments but >> >> only receives one, the function to be decorated. And yet it does work: >> >> >> >> py> from functools import partial >> >> py> def make_wrapper(wrapper): >> >> ... return lambda wrapped: partial(wrapper, wrapped) >> >> ... >> >> py> @make_wrapper >> >> ... def simple_decorator(func, *args, **kwargs): >> >> ... print "Entering decorated function" >> >> ... result = func(*args, **kwargs) >> >> ... print "Exiting decorated function" >> >> ... return result >> >> ... >> >> py> @simple_decorator >> >> ... def my_function(a, b, c): >> >> ... """Doc string""" >> >> ... return a+b+c >> >> ... >> >> py> my_function(1, 2, 3) >> >> Entering decorated function >> >> Exiting decorated function >> >> 6 >> >> >> >> So to me, this is far more magical than nested functions. If I saw this >> >> in t requires me to hunt through your library for the "simple function >> >> buried in a utility module somewhere" (your words), instead of seeing >> >> everything needed in a single decorator factory function. It requires >> >> that I understand how partial works, which in my opinion is quite tricky. >> >> (I never remember how it works or which arguments get curried.) >> >> >> >> And the end result is that the decorated function is less debugging- >> >> friendly than I demand: it is an anonymous partial object instead of a >> >> named function, and the doc string is lost. And it is far from clear to >> >> me how to modify your recipe to use functools.wraps in order to keep the >> >> name and docstring, or even whether I *can* use functools.wraps. >> >> >> >> I dare say I could answer all those questions with some experimentation >> >> and research. But I don't think that your "metadecorator" using partial >> >> is *inherently* more understandable than the standard decorator approach: >> >> >> >> def simple_decorator2(func): >> >> @functools.wraps(func) >> >> def inner(*args, **kwargs): >> >> print "Entering decorated function" >> >> result = func(*args, **kwargs) >> >> print "Exiting decorated function" >> >> return result >> >> return inner >> >> >> >> This is no more complex than yours, and it keeps the function name and >> >> docstring. >> >> >> >> >> >> > Parameterized decorators are not much more >> >> > difficult this way. This function: >> >> [snip code] >> >> > And now we have a fancy parameterized decorator that again requires no >> >> > thinking about nested functions at all. >> >> >> >> Again, at the cost of throwing away the function name and docstring. >> >> >> >> I realise that a lot of this boils down to personal preference, but I >> >> just don't think that nested functions are necessarily that hard to >> >> grasp, so I prefer to see as much of the decorator logic to be in one >> >> place (a nested decorator function) rather than scattered across two >> >> separate decorators plus partial. Like chi fu, allow decorators to evolve upon themselves. Like simple moves flow through water and allow memorization of activity through evidence of existence. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From hansmu at xs4all.nl Sat Sep 15 06:52:17 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 15 Sep 2012 12:52:17 +0200 Subject: Moving folders with content In-Reply-To: References: Message-ID: <50545de1$0$6853$e4fe514c@news2.news.xs4all.nl> On 15/09/12 10:00:16, Nobody wrote: > On Sat, 15 Sep 2012 04:36:00 +0000, jyoung79 wrote: > >> I am working in both OS X Snow Leopard and Lion (10.6.8 and 10.7.4). >> I'm simply wanting to move folders (with their content) from various >> servers to the hard drive and then back to different directories on the >> servers. >> >> I want to be careful not to remove any metadata or resource forks from >> the files in the directories. I did a bit of researching on shutil, and >> looks like it is similar to using "cp -p" and copystat(), which I believe >> will keep the resource fork, etc. > > I don't think so. The shutil documentation says: > > Warning > > Even the higher-level file copying functions (copy(), copy2()) can?t > copy all file metadata. > > On POSIX platforms, this means that file owner and group are lost as well > as ACLs. On Mac OS, the resource fork and other metadata are not used. > This means that resources will be lost and file type and creator codes > will not be correct. On Windows, file owners, ACLs and alternate data > streams are not copied. > > The macostools module has functions which can copy the resource fork, but > they aren't available in 64-bit builds and have been removed in Python 3.0. You may want to use the subprocess module to run 'ditto'. If the destination folder does not exist, then ditto will copy MacOS specific aspects such as resource forks, ACLs and HFS meta-data. If the destination already exists, then ditto will copy file contents, but not modify mode, ownership or ACLs of existing folders inside the destination folder. See the manual page for details. Hope this helps, -- HansM From arijitparua123 at gmail.com Sat Sep 15 07:55:02 2012 From: arijitparua123 at gmail.com (arijitparua123 at gmail.com) Date: Sat, 15 Sep 2012 04:55:02 -0700 (PDT) Subject: See Hot Sexy Star ANUSHKA Nude Bathing Videos In All Angles. In-Reply-To: References: Message-ID: <869e732e-842a-45ac-832a-b0b3de5259c3@googlegroups.com> From arijitparua123 at gmail.com Sat Sep 15 07:56:14 2012 From: arijitparua123 at gmail.com (arijitparua123 at gmail.com) Date: Sat, 15 Sep 2012 04:56:14 -0700 (PDT) Subject: See Hot Sexy Star ANUSHKA Nude Bathing Videos In All Angles. In-Reply-To: References: Message-ID: <11610e75-3aab-4357-a2dd-de0ab188ba7b@googlegroups.com> I want to fucking with her From nikos.gr33k at gmail.com Sat Sep 15 08:22:51 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 05:22:51 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects Message-ID: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> Hello, I recently changed webhost and in the new one iam getting this error you can see if you visit http://superhost.gr when program execution reaches the line: f = open( '../' + page ) In the previous host i wasn't getting this error. page's contents is: page = form.getvalue('page') From nikos.gr33k at gmail.com Sat Sep 15 08:26:18 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 05:26:18 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> Message-ID: <0e4c9353-f744-4ef1-9ff4-6a04a86a832b@googlegroups.com> Sorry the problem appears when you try to input data botton down the page in the text area boxes and click submit. this is the error apperaing: A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. /home/nikos/public_html/cgi-bin/counter.py in () 56 # I would suggest using some kind of verification function to check that the value of 'page' is OK, before opening the file. 57 58 f = open( '../' + page ) 59 60 # read first line of the file f undefined, builtin open = , page = ['index.html', 'index.html'] : cannot concatenate 'str' and 'list' objects args = ("cannot concatenate 'str' and 'list' objects",) message = "cannot concatenate 'str' and 'list' objects" From rosuav at gmail.com Sat Sep 15 08:33:52 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 15 Sep 2012 22:33:52 +1000 Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> Message-ID: On Sat, Sep 15, 2012 at 10:22 PM, ???????? ?????? wrote: > Hello, > > I recently changed webhost and in the new one iam getting this error you can see if you visit http://superhost.gr when program execution reaches the line: > > f = open( '../' + page ) > > In the previous host i wasn't getting this error. > > page's contents is: > > page = form.getvalue('page') Well, clearly '../' is a string (str), and page must be a list. But without knowing your web framework it's hard to be sure what's going on. My guess is that form.getvalue() is returning a list of form elements with that name, so you have a list with one element in it. But check your documentation to be sure. Since this changed when you changed hosts, it may mean you now have a completely different framework. Possibly you can configure this. Alternatively, it may simply be a different version of the same system. It's hard to know just based on this, though. ChrisA From paulstaten at gmail.com Sat Sep 15 08:59:52 2012 From: paulstaten at gmail.com (paulstaten at gmail.com) Date: Sat, 15 Sep 2012 05:59:52 -0700 (PDT) Subject: subprocess call is not waiting. In-Reply-To: References: <0b598d7f-7137-47cc-8eed-80ab450536c5@googlegroups.com> Message-ID: <0405db16-6a4c-4189-a32c-2311d45eead3@googlegroups.com> That's a habit I'll make sure to avoid, then. Thanks, Chris! From nikos.gr33k at gmail.com Sat Sep 15 09:28:10 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 06:28:10 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> Message-ID: <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> ?? ???????, 15 ??????????? 2012 3:34:34 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Sat, Sep 15, 2012 at 10:22 PM, ???????? ?????? wrote: > > > Hello, > > > > > > I recently changed webhost and in the new one iam getting this error you can see if you visit http://superhost.gr when program execution reaches the line: > > > > > > f = open( '../' + page ) > > > > > > In the previous host i wasn't getting this error. > > > > > > page's contents is: > > > > > > page = form.getvalue('page') > > > > Well, clearly '../' is a string (str), and page must be a list. But > > without knowing your web framework it's hard to be sure what's going > > on. > > > > My guess is that form.getvalue() is returning a list of form elements > > with that name, so you have a list with one element in it. But check > > your documentation to be sure. > > > > Since this changed when you changed hosts, it may mean you now have a > > completely different framework. Possibly you can configure this. > > Alternatively, it may simply be a different version of the same > > system. It's hard to know just based on this, though. > > > > ChrisA Iam not using frameworks just plain python code written in Notepad++ Can you please tell me how to switch this line in order for this line to work? From nikos.gr33k at gmail.com Sat Sep 15 09:28:10 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 06:28:10 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> Message-ID: <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> ?? ???????, 15 ??????????? 2012 3:34:34 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Sat, Sep 15, 2012 at 10:22 PM, ???????? ?????? wrote: > > > Hello, > > > > > > I recently changed webhost and in the new one iam getting this error you can see if you visit http://superhost.gr when program execution reaches the line: > > > > > > f = open( '../' + page ) > > > > > > In the previous host i wasn't getting this error. > > > > > > page's contents is: > > > > > > page = form.getvalue('page') > > > > Well, clearly '../' is a string (str), and page must be a list. But > > without knowing your web framework it's hard to be sure what's going > > on. > > > > My guess is that form.getvalue() is returning a list of form elements > > with that name, so you have a list with one element in it. But check > > your documentation to be sure. > > > > Since this changed when you changed hosts, it may mean you now have a > > completely different framework. Possibly you can configure this. > > Alternatively, it may simply be a different version of the same > > system. It's hard to know just based on this, though. > > > > ChrisA Iam not using frameworks just plain python code written in Notepad++ Can you please tell me how to switch this line in order for this line to work? From sahnov.m at gmail.com Sat Sep 15 09:33:51 2012 From: sahnov.m at gmail.com (=?KOI8-R?B?88HIzs/XIO3JyMHJzA==?=) Date: Sat, 15 Sep 2012 17:33:51 +0400 Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> Message-ID: f = open( '../' + page.pop() ) 15.09.2012 17:32 ???????????? "???????? ??????" ???????: > ?? ???????, 15 ??????????? 2012 3:34:34 ?.?. UTC+3, ? ??????? Chris > Angelico ??????: > > On Sat, Sep 15, 2012 at 10:22 PM, ???????? ?????? > wrote: > > > > > Hello, > > > > > > > > > > I recently changed webhost and in the new one iam getting this error > you can see if you visit http://superhost.gr when program execution > reaches the line: > > > > > > > > > > f = open( '../' + page ) > > > > > > > > > > In the previous host i wasn't getting this error. > > > > > > > > > > page's contents is: > > > > > > > > > > page = form.getvalue('page') > > > > > > > > Well, clearly '../' is a string (str), and page must be a list. But > > > > without knowing your web framework it's hard to be sure what's going > > > > on. > > > > > > > > My guess is that form.getvalue() is returning a list of form elements > > > > with that name, so you have a list with one element in it. But check > > > > your documentation to be sure. > > > > > > > > Since this changed when you changed hosts, it may mean you now have a > > > > completely different framework. Possibly you can configure this. > > > > Alternatively, it may simply be a different version of the same > > > > system. It's hard to know just based on this, though. > > > > > > > > ChrisA > > Iam not using frameworks just plain python code written in Notepad++ > > Can you please tell me how to switch this line in order for this line to > work? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Sep 15 09:38:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 15 Sep 2012 23:38:09 +1000 Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> Message-ID: On Sat, Sep 15, 2012 at 11:28 PM, ???????? ?????? wrote: > Iam not using frameworks just plain python code written in Notepad++ > > Can you please tell me how to switch this line in order for this line to work? f = open( '../' + page[0]) will possibly work. But do try to understand what's happening, rather than simply solve the problem. You may find that something else has changed too. ChrisA From nikos.gr33k at gmail.com Sat Sep 15 09:53:37 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 06:53:37 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> Message-ID: ?? ???????, 15 ??????????? 2012 4:38:51 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Sat, Sep 15, 2012 at 11:28 PM, ???????? ?????? wrote: > > > Iam not using frameworks just plain python code written in Notepad++ > > > > > > Can you please tell me how to switch this line in order for this line to work? > > > > f = open( '../' + page[0]) > > > > will possibly work. But do try to understand what's happening, rather > > than simply solve the problem. You may find that something else has > > changed too. > > > > ChrisA i see you try to extract only the 1st element of the list, i tried that too but it gives me now this weird message: if you visit my website http://superhost.gr From nikos.gr33k at gmail.com Sat Sep 15 09:53:37 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 06:53:37 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> Message-ID: ?? ???????, 15 ??????????? 2012 4:38:51 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Sat, Sep 15, 2012 at 11:28 PM, ???????? ?????? wrote: > > > Iam not using frameworks just plain python code written in Notepad++ > > > > > > Can you please tell me how to switch this line in order for this line to work? > > > > f = open( '../' + page[0]) > > > > will possibly work. But do try to understand what's happening, rather > > than simply solve the problem. You may find that something else has > > changed too. > > > > ChrisA i see you try to extract only the 1st element of the list, i tried that too but it gives me now this weird message: if you visit my website http://superhost.gr From dihedral88888 at googlemail.com Sat Sep 15 10:18:18 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 15 Sep 2012 07:18:18 -0700 (PDT) Subject: Decorators not worth the effort In-Reply-To: References: <20120914021211.GA15642@cskk.homeip.net> <5053c030$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <331d26cd-8bb9-4994-9adf-fa2462bcfd6e@googlegroups.com> David Hutto? 2012?9?15????UTC+8??6?04?28???? > On Sat, Sep 15, 2012 at 5:45 AM, 88888 Dihedral > > wrote: > > > Steven D'Aprano? 2012?9?15????UTC+8??7?39?28???? > > >> On Fri, 14 Sep 2012 15:16:47 -0600, Ian Kelly wrote: > > >> > > >> > > >> > > >> > If only there were a conceptually simpler way to do this. Actually, > > >> > > >> > there is. I give you: muman than humanetadecorators! > > >> > > >> [code snipped but shown below] > > >> > > >> > Which I think is certainly easier to understand than the nested > > >> > > >> > functions approach. > > >> > > >> > > >> > > >> Maybe for you, but to me it is a big ball of mud. I have no idea how this > > >> > > >> is supposed to work! At a quick glance, I would have sworn that it > > >> > > >> *can't* work, since simple_decorator needs to see multiple arguments but > > >> > > >> only receives one, the function to be decorated. And yet it does work: > > >> > > >> > > >> > > >> py> from functools import partial > > >> > > >> py> def make_wrapper(wrapper): > > >> > > >> ... return lambda wrapped: partial(wrapper, wrapped) > > >> > > >> ... > > >> > > >> py> @make_wrapper > > >> > > >> ... def simple_decorator(func, *args, **kwargs): > > >> > > >> ... print "Entering decorated function" > > >> > > >> ... result = func(*args, **kwargs) > > >> > > >> ... print "Exiting decorated function" > > >> > > >> ... return result > > >> > > >> ... > > >> > > >> py> @simple_decorator > > >> > > >> ... def my_function(a, b, c): > > >> > > >> ... """Doc string""" > > >> > > >> ... return a+b+c > > >> > > >> ... > > >> > > >> py> my_function(1, 2, 3) > > >> > > >> Entering decorated function > > >> > > >> Exiting decorated function > > >> > > >> 6 > > >> > > >> > > >> > > >> So to me, this is far more magical than nested functions. If I saw this > > >> > > >> in t requires me to hunt through your library for the "simple function > > >> > > >> buried in a utility module somewhere" (your words), instead of seeing > > >> > > >> everything needed in a single decorator factory function. It requires > > >> > > >> that I understand how partial works, which in my opinion is quite tricky. > > >> > > >> (I never remember how it works or which arguments get curried.) > > >> > > >> > > >> > > >> And the end result is that the decorated function is less debugging- > > >> > > >> friendly than I demand: it is an anonymous partial object instead of a > > >> > > >> named function, and the doc string is lost. And it is far from clear to > > >> > > >> me how to modify your recipe to use functools.wraps in order to keep the > > >> > > >> name and docstring, or even whether I *can* use functools.wraps. > > >> > > >> > > >> > > >> I dare say I could answer all those questions with some experimentation > > >> > > >> and research. But I don't think that your "metadecorator" using partial > > >> > > >> is *inherently* more understandable than the standard decorator approach: > > >> > > >> > > >> > > >> def simple_decorator2(func): > > >> > > >> @functools.wraps(func) > > >> > > >> def inner(*args, **kwargs): > > >> > > >> print "Entering decorated function" > > >> > > >> result = func(*args, **kwargs) > > >> > > >> print "Exiting decorated function" > > >> > > >> return result > > >> > > >> return inner > > >> > > >> > > >> > > >> This is no more complex than yours, and it keeps the function name and > > >> > > >> docstring. > > >> > > >> > > >> > > >> > > >> > > >> > Parameterized decorators are not much more > > >> > > >> > difficult this way. This function: > > >> > > >> [snip code] > > >> > > >> > And now we have a fancy parameterized decorator that again requires no > > >> > > >> > thinking about nested functions at all. > > >> > > >> > > >> > > >> Again, at the cost of throwing away the function name and docstring. > > >> > > >> > > >> > > >> I realise that a lot of this boils down to personal preference, but I > > >> > > >> just don't think that nested functions are necessarily that hard to > > >> > > >> grasp, so I prefer to see as much of the decorator logic to be in one > > >> > > >> place (a nested decorator function) rather than scattered across two > > >> > > >> separate decorators plus partial. > > > > Like chi fu, allow decorators to evolve upon themselves. Like simple > > moves flow through water and allow memorization of activity through > > evidence of existence. > > > > > > -- > > Best Regards, The concept of decorators is just a mapping from a function to another function with the same name in python. It should be easy to be grapsed for those studied real analysis and functional analysis. From dihedral88888 at googlemail.com Sat Sep 15 10:18:18 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 15 Sep 2012 07:18:18 -0700 (PDT) Subject: Decorators not worth the effort In-Reply-To: References: <20120914021211.GA15642@cskk.homeip.net> <5053c030$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <331d26cd-8bb9-4994-9adf-fa2462bcfd6e@googlegroups.com> David Hutto? 2012?9?15????UTC+8??6?04?28???? > On Sat, Sep 15, 2012 at 5:45 AM, 88888 Dihedral > > wrote: > > > Steven D'Aprano? 2012?9?15????UTC+8??7?39?28???? > > >> On Fri, 14 Sep 2012 15:16:47 -0600, Ian Kelly wrote: > > >> > > >> > > >> > > >> > If only there were a conceptually simpler way to do this. Actually, > > >> > > >> > there is. I give you: muman than humanetadecorators! > > >> > > >> [code snipped but shown below] > > >> > > >> > Which I think is certainly easier to understand than the nested > > >> > > >> > functions approach. > > >> > > >> > > >> > > >> Maybe for you, but to me it is a big ball of mud. I have no idea how this > > >> > > >> is supposed to work! At a quick glance, I would have sworn that it > > >> > > >> *can't* work, since simple_decorator needs to see multiple arguments but > > >> > > >> only receives one, the function to be decorated. And yet it does work: > > >> > > >> > > >> > > >> py> from functools import partial > > >> > > >> py> def make_wrapper(wrapper): > > >> > > >> ... return lambda wrapped: partial(wrapper, wrapped) > > >> > > >> ... > > >> > > >> py> @make_wrapper > > >> > > >> ... def simple_decorator(func, *args, **kwargs): > > >> > > >> ... print "Entering decorated function" > > >> > > >> ... result = func(*args, **kwargs) > > >> > > >> ... print "Exiting decorated function" > > >> > > >> ... return result > > >> > > >> ... > > >> > > >> py> @simple_decorator > > >> > > >> ... def my_function(a, b, c): > > >> > > >> ... """Doc string""" > > >> > > >> ... return a+b+c > > >> > > >> ... > > >> > > >> py> my_function(1, 2, 3) > > >> > > >> Entering decorated function > > >> > > >> Exiting decorated function > > >> > > >> 6 > > >> > > >> > > >> > > >> So to me, this is far more magical than nested functions. If I saw this > > >> > > >> in t requires me to hunt through your library for the "simple function > > >> > > >> buried in a utility module somewhere" (your words), instead of seeing > > >> > > >> everything needed in a single decorator factory function. It requires > > >> > > >> that I understand how partial works, which in my opinion is quite tricky. > > >> > > >> (I never remember how it works or which arguments get curried.) > > >> > > >> > > >> > > >> And the end result is that the decorated function is less debugging- > > >> > > >> friendly than I demand: it is an anonymous partial object instead of a > > >> > > >> named function, and the doc string is lost. And it is far from clear to > > >> > > >> me how to modify your recipe to use functools.wraps in order to keep the > > >> > > >> name and docstring, or even whether I *can* use functools.wraps. > > >> > > >> > > >> > > >> I dare say I could answer all those questions with some experimentation > > >> > > >> and research. But I don't think that your "metadecorator" using partial > > >> > > >> is *inherently* more understandable than the standard decorator approach: > > >> > > >> > > >> > > >> def simple_decorator2(func): > > >> > > >> @functools.wraps(func) > > >> > > >> def inner(*args, **kwargs): > > >> > > >> print "Entering decorated function" > > >> > > >> result = func(*args, **kwargs) > > >> > > >> print "Exiting decorated function" > > >> > > >> return result > > >> > > >> return inner > > >> > > >> > > >> > > >> This is no more complex than yours, and it keeps the function name and > > >> > > >> docstring. > > >> > > >> > > >> > > >> > > >> > > >> > Parameterized decorators are not much more > > >> > > >> > difficult this way. This function: > > >> > > >> [snip code] > > >> > > >> > And now we have a fancy parameterized decorator that again requires no > > >> > > >> > thinking about nested functions at all. > > >> > > >> > > >> > > >> Again, at the cost of throwing away the function name and docstring. > > >> > > >> > > >> > > >> I realise that a lot of this boils down to personal preference, but I > > >> > > >> just don't think that nested functions are necessarily that hard to > > >> > > >> grasp, so I prefer to see as much of the decorator logic to be in one > > >> > > >> place (a nested decorator function) rather than scattered across two > > >> > > >> separate decorators plus partial. > > > > Like chi fu, allow decorators to evolve upon themselves. Like simple > > moves flow through water and allow memorization of activity through > > evidence of existence. > > > > > > -- > > Best Regards, The concept of decorators is just a mapping from a function to another function with the same name in python. It should be easy to be grapsed for those studied real analysis and functional analysis. From roy at panix.com Sat Sep 15 10:21:21 2012 From: roy at panix.com (Roy Smith) Date: Sat, 15 Sep 2012 10:21:21 -0400 Subject: cannot concatenate 'str' and 'list' objects References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> Message-ID: In article , > i see you try to extract only the 1st element of the list, i tried that too > but it gives me now this weird message: > > if you visit my website http://superhost.gr Do you realize that the hosting service you're using (HostGator) is so mis-configured that it is exposing your source code and credentials to the entire world? When I go to that URL, I get a page which includes the name of the CGI script you are running (/home/nikos/public_html/cgi-bin/counter.py). I can then do a GET on http://superhost.gr/~nikos/cgi-bin/counter.py, and can see your script source code, including the credentials to attach to your database: conn = MySQLdb.connect( db = 'nikos_tech', host = 'localhost', user = 'nikos_nikos', passwd = ) How to properly configure a web server is way beyond the scope of this mailing list, but you really need to do some research there to safeguard your own data. From __peter__ at web.de Sat Sep 15 10:29:29 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 15 Sep 2012 16:29:29 +0200 Subject: cannot concatenate 'str' and 'list' objects References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> Message-ID: ???????? ?????? wrote: > ?? ???????, 15 ??????????? 2012 4:38:51 ?.?. UTC+3, ? ??????? Chris > Angelico ??????: >> On Sat, Sep 15, 2012 at 11:28 PM, ???????? ?????? >> wrote: >> >> > Iam not using frameworks just plain python code written in Notepad++ >> >> > >> >> > Can you please tell me how to switch this line in order for this line >> > to work? >> >> >> >> f = open( '../' + page[0]) >> >> >> >> will possibly work. But do try to understand what's happening, rather >> >> than simply solve the problem. You may find that something else has >> >> changed too. >> >> >> >> ChrisA > > i see you try to extract only the 1st element of the list, i tried that > too but it gives me now this weird message: > > if you visit my website http://superhost.gr You seem to have encoding problems: >>> print '\xc4\xe5\xed \xf5\xf0\xdc\xf1\xf7\xe5\xe9 \xf4\xdd\xf4\xef\xe9\xef \xe1\xf1\xf7\xe5\xdf\xef \xde \xea\xe1\xf4\xdc\xeb\xef\xe3\xef\xf2'.decode("iso-8859-7") ??? ??????? ?????? ?????? ? ????????? That doesn't look weird (I'd guess) for someone who knows Greek... Proceeding to http://superhost.gr/cgi-bin/counter.py?page=foo.html versus http://superhost.gr/cgi-bin/counter.py?page=foo.html&page=bar.html it turns out that you get a list as the page variable only in the latter case. So you might have provoked your initial problem by following a buggy url with a duplicate page argument. From nikos.gr33k at gmail.com Sat Sep 15 10:44:35 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 07:44:35 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> Message-ID: ?? ???????, 15 ??????????? 2012 5:21:22 ?.?. UTC+3, ? ??????? Roy Smith ??????: > In article , > > > > > i see you try to extract only the 1st element of the list, i tried that too > > > but it gives me now this weird message: > > > > > > if you visit my website http://superhost.gr > > > > Do you realize that the hosting service you're using (HostGator) is so > > mis-configured that it is exposing your source code and credentials to > > the entire world? > > > > When I go to that URL, I get a page which includes the name of the CGI > > script you are running (/home/nikos/public_html/cgi-bin/counter.py). I > > can then do a GET on http://superhost.gr/~nikos/cgi-bin/counter.py, and > > can see your script source code, including the credentials to attach to > > your database: > > > > conn = MySQLdb.connect( db = 'nikos_tech', host = 'localhost', user = > > 'nikos_nikos', passwd = ) > > > > How to properly configure a web server is way beyond the scope of this > > mailing list, but you really need to do some research there to safeguard > > your own data. I cant beleive that my source code can be seen form ANYONE this easily!!!! I moved to HostGaot because i heard there were the best in the hosting business..... From rosuav at gmail.com Sat Sep 15 10:49:24 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Sep 2012 00:49:24 +1000 Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> Message-ID: On Sun, Sep 16, 2012 at 12:44 AM, ???????? ?????? wrote: > ?? ???????, 15 ??????????? 2012 5:21:22 ?.?. UTC+3, ? ??????? Roy Smith ??????: >> Do you realize that the hosting service you're using (HostGator) is so >> mis-configured that it is exposing your source code and credentials to >> the entire world? > > I cant beleive that my source code can be seen form ANYONE this easily!!!! > > I moved to HostGaot because i heard there were the best in the hosting business..... It's probably a simple misconfiguration that can be easily fixed. If you don't yourself understand it, talk to HostGator support; presumably you're paying them money for hosting, so they should be both able and willing to help you sort that out. I would recommend that you change your database password as soon as that's done, lest someone "seize the day" and take control of your database. ChrisA From nikos.gr33k at gmail.com Sat Sep 15 10:51:21 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 07:51:21 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> Message-ID: <2c37aa2e-10fb-4e34-ad40-8f16b612e369@googlegroups.com> in my case an .htaccess file gives redirects all html requests to /cgi-bin/counter.py by also provide as an argument to the counter.py script the initical html file request RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?page=$1 [L,PT,QSA] so the latter you mentioned its not the case for me. But iam wondering why this doesnt work on this server while on my previous host did..... From nikos.gr33k at gmail.com Sat Sep 15 10:51:21 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 07:51:21 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> Message-ID: <2c37aa2e-10fb-4e34-ad40-8f16b612e369@googlegroups.com> in my case an .htaccess file gives redirects all html requests to /cgi-bin/counter.py by also provide as an argument to the counter.py script the initical html file request RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?page=$1 [L,PT,QSA] so the latter you mentioned its not the case for me. But iam wondering why this doesnt work on this server while on my previous host did..... From rosuav at gmail.com Sat Sep 15 10:55:56 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Sep 2012 00:55:56 +1000 Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <2c37aa2e-10fb-4e34-ad40-8f16b612e369@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> <2c37aa2e-10fb-4e34-ad40-8f16b612e369@googlegroups.com> Message-ID: On Sun, Sep 16, 2012 at 12:51 AM, ???????? ?????? wrote: > in my case an .htaccess file gives redirects all html requests to /cgi-bin/counter.py by also provide as an argument to the counter.py script the initical html file request > > RewriteEngine On > RewriteCond %{REQUEST_FILENAME} -f > RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?page=$1 [L,PT,QSA] > > so the latter you mentioned its not the case for me. > But iam wondering why this doesnt work on this server while on my previous host did..... Okay, now we're getting to a possible difference. Check if this is properly working; perhaps HostGator don't let you use the rewrite engine in .htaccess. Make sure your .htaccess is in the right directory, too. I just tried a quick check and was greeted with a 404 page, so the rule you describe isn't active. ChrisA From nikos.gr33k at gmail.com Sat Sep 15 10:56:45 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 07:56:45 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> Message-ID: <1ddffea4-576f-45c6-beaa-04966f024ae3@googlegroups.com> Thank i will do that, ill inform the support right away! From nikos.gr33k at gmail.com Sat Sep 15 11:01:12 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 08:01:12 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> Message-ID: The .htaccess file works with HostGator because the page was working all day rediecting all html requests fine to the counter.py script. Only when i tried to post data to the text area boxes this problem made its appearance. From roy at panix.com Sat Sep 15 11:01:32 2012 From: roy at panix.com (Roy Smith) Date: Sat, 15 Sep 2012 11:01:32 -0400 Subject: cannot concatenate 'str' and 'list' objects References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> Message-ID: In article , ???????? ?????? wrote: > I cant beleive that my source code can be seen form ANYONE this easily!!!! Which is why I pointed it out. I mean no disrespect, but you appear to be in over your head. That's fine (we're all in over our heads at some point, that's how we learn new things), but once you're running a server on the Internet, the consequences of your actions become much more severe. > I moved to HostGaot because i heard there were the best in the hosting > business..... The hosting business means different things to different people. At one end, there's places like WordPress and Tumblr which hide all the details and let you pour content into a blog with some control over styling. At the other end, there's places like AWS, Rackspace, etc, which give you a raw (virtual) machine, and you're free to do anything you want on it. In between, there's paces like HostGator, which give you a slice of a shared host, and you're free to install cgi scripts under the control of Apache. How much you get to play with the Apache configuration probably varies wildly from provider to provider. It looks like HostGator either has things mis-configured to allow your /cgi-bin directory to be visible, or allows you the ability to configure those things yourself, and you mis-configured it. From nikos.gr33k at gmail.com Sat Sep 15 11:06:10 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 08:06:10 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> Message-ID: <181f1ff8-0f25-48d3-9265-1c2afef7f95b@googlegroups.com> Previous webhost has the same flaw as well, look: http://www.errorweb.gr/~nikos/cgi-bin/ giving away all my scripts. Webhost misconfiguration in both hosts! From rosuav at gmail.com Sat Sep 15 11:23:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Sep 2012 01:23:09 +1000 Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <181f1ff8-0f25-48d3-9265-1c2afef7f95b@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <181f1ff8-0f25-48d3-9265-1c2afef7f95b@googlegroups.com> Message-ID: On Sun, Sep 16, 2012 at 1:06 AM, ???????? ?????? wrote: > Previous webhost has the same flaw as well, look: > > http://www.errorweb.gr/~nikos/cgi-bin/ > > giving away all my scripts. > > Webhost misconfiguration in both hosts! And when I look at the scripts, I see things that do not fill me with confidence. You appear to be reinventing the wheel, and making it hexagonal in the process. That's not to say you shouldn't tinker with wheel design now and then, but as Roy said, the consequences get quite severe once you're hosting a web site to the world. I've been guilty of the same sorts of issues myself. I was poking at some old code today (code that dates back a few years to when I was new to PHP and didn't know of any other way to make a dynamic web site other than CGI) and found some pretty ridiculous coding bloopers. Stuff that didn't stop the site's primary functionality from working, but it sure isn't what I'd call good code. Some day I'll rewrite it all... some day I'll have time available... anyway. Your counter.py appears to be doing what most people do after the fact with log-file analysis. It's usually a lot better to simply parse Apache's log files to find out how many people view your pages, rather than maintaining the statistics. This has a race condition in it: # update existing visitor record if same pin and same host found try: cursor.execute( '''UPDATE visitors SET hits = hits + 1, agent = %s, date = %s WHERE pin = %s AND host = %s''', (agent, date, pin, host)) except MySQLdb.Error, e: print ( "Error %d: %s" % (e.args[0], e.args[1]) ) # insert new visitor record if above update did not affect a row if cursor.rowcount == 0: cursor.execute( '''INSERT INTO visitors(pin, host, hits, agent, date) VALUES(%s, %s, %s, %s, %s)''', (pin, host, 1, agent, date) ) If two page loads simultaneously execute this code, they'll both fail to update, and then both attempt to insert. Also, it's extremely insecure to simply print your database errors. Emit them to a separate log file that only you have access to, and monitor that log while you're developing. Once you're done developing, switch to an alert system if you can, because SQL errors should never occur (obviously don't alert if there are specific errors that you intend to cause and catch). See if you can replace the whole mess of CGI scripts with flat HTML files and AWStats. You'll have much more flexibility in hosting company choice, less risk of security breaches, and much MUCH easier management. ChrisA From nikos.gr33k at gmail.com Sat Sep 15 11:23:32 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 08:23:32 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> Message-ID: <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> I swicthed back my code to: f = open( '../' + page ) and http://superhost.gr works which means that line gets parsed correctly. Only when i post data to the text area boxes iam getting the error: cannot concatenate 'str' and 'list' objects how is this possible to work before and NOT work when i enter data to the page for storing to the database? From nikos.gr33k at gmail.com Sat Sep 15 11:33:15 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 08:33:15 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> Message-ID: <29a8587f-9d7d-4965-b709-b6d5c70ac3a2@googlegroups.com> You are right but iam a new python learner and i created this logging system script as a poject to better learn the lalguage itself. I can always use google analytics for serious visitor logging. Apart from that i enjoy reading my logs by typing: http://superhost.gr/?show=log :-) From rosuav at gmail.com Sat Sep 15 11:44:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Sep 2012 01:44:14 +1000 Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> Message-ID: On Sun, Sep 16, 2012 at 1:23 AM, ???????? ?????? wrote: > I swicthed back my code to: f = open( '../' + page ) > > and http://superhost.gr works which means that line gets parsed correctly. > > Only when i post data to the text area boxes iam getting the error: > > cannot concatenate 'str' and 'list' objects > > how is this possible to work before and NOT work when i enter data to the page for storing to the database? Okay. Putting everything together, I think I can see what's going on. You have a rewrite rule that's changing http://superhost.gr/ into a request that, if my hand-parsing of Apache directives is working, looks like this: http://superhost.gr/cgi-bin/counter.py?page=index.html That page doesn't quite work, as the browser goes looking for images and CSS in cgi-bin instead of the root, but that's pretty much what's going on. (I had to guess that it was index.html, as that part is implicit in the original URL.) You then have a request with a GET variable named 'page', and also a POST variable named 'page', courtesy of the hidden form variable. This would be why you're getting a list instead of a string. Is the hidden form field completely redundant? If so, just remove it. If you need that information for some other reason (eg you want to record which page the user came from), then rename one or other of them. I would recommend a naming convention whereby you keep "internal stuff" away from your main site. For instance, change your rewrite rule to create a form field called _page and have counter.py look for that. Or better still, don't use the query string for that at all, if you can (I can't remember off-hand what a rewrite rule can set, but I think you can carry extra information around in other ways). Currently, your site can be broken by adding a query string to the URL: http://superhost.gr/?page=hahahaha As a general rule, a web site should not get confused by the presence of an unexpected form field. It's not good for someone to be able to break your page like this! It appears that part of the problem is that your getvalue() function has three possibilities, similar to the issue I had a while ago with a similar PHP function. Readers of CS Lewis may recognize what I'm saying... Either she is lying, and there is no array at all; or she is mad - a single item as a scalar instead of an array; or she is telling the truth, and we have an array just like we need. ChrisA From rosuav at gmail.com Sat Sep 15 11:46:33 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Sep 2012 01:46:33 +1000 Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <29a8587f-9d7d-4965-b709-b6d5c70ac3a2@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <29a8587f-9d7d-4965-b709-b6d5c70ac3a2@googlegroups.com> Message-ID: On Sun, Sep 16, 2012 at 1:33 AM, ???????? ?????? wrote: > You are right but iam a new python learner and i created this logging system script as a poject to better learn the lalguage itself. > > I can always use google analytics for serious visitor logging. > > Apart from that i enjoy reading my logs by typing: > > http://superhost.gr/?show=log Yes, and I'm sure random visitors will enjoy reading them too, with no authentication required. You really shouldn't make all your visitors' IP addresses and usage stats public. Also, you may want to consider recording IP addresses for the "reverse dns lookup failed" entries, as there'll be a lot of them :) ChrisA From nikos.gr33k at gmail.com Sat Sep 15 12:04:26 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 09:04:26 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> Message-ID: <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> I'am not sure what to do and i didnt quite understand what the problem is. Can you please tell me what parts need fixe so for the users to be able to leave remakrs in he text area boxes? From nikos.gr33k at gmail.com Sat Sep 15 12:04:26 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 09:04:26 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> Message-ID: <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> I'am not sure what to do and i didnt quite understand what the problem is. Can you please tell me what parts need fixe so for the users to be able to leave remakrs in he text area boxes? From chris at gonnerman.org Sat Sep 15 12:09:58 2012 From: chris at gonnerman.org (Chris Gonnerman) Date: Sat, 15 Sep 2012 11:09:58 -0500 Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <2138d293-c411-404d-bbf1-1afbae3fc597@googlegroups.com> Message-ID: <5054A856.40400@gonnerman.org> > I moved to HostGaot because i heard there were the best in the hosting > business..... They are pretty good. However, you have to understand the site layout to do CGI safely. So long as your script are .cgi, putting them in ~/public_html is fine. If you need to deploy .py files, you need to put them in a different folder outside ~/public_html, for example ~/lib or ~/python, then in your CGI scripts you need to add that to the path. For example: #!/usr/bin/python import sys sys.path.append("../python") import MyModule, MyPackage.OtherModule This is more or less how all my CGI scripts on HostGator are done. -- Chris. From chris at gonnerman.org Sat Sep 15 12:13:55 2012 From: chris at gonnerman.org (Chris Gonnerman) Date: Sat, 15 Sep 2012 11:13:55 -0500 Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> Message-ID: <5054A943.5060609@gonnerman.org> On 09/15/2012 10:23 AM, ???????? ?????? wrote: > I swicthed back my code to: f = open( '../' + page ) > > and http://superhost.gr works which means that line gets parsed correctly. > > Only when i post data to the text area boxes iam getting the error: > > cannot concatenate 'str' and 'list' objects > > how is this possible to work before and NOT work when i enter data to the page for storing to the database? You really need to add some print-type diagnostics to your script temporarily, just to see what you are actually getting for parameters. For example, put this: print "Content-type: text/plain\n" near the top so you can get a source printout, then add print `page` just before you attempt your open() call so you can see what the exact Python representation of page is. Do similarly for other problems in your code. Don't leave such an "instrumented" copy of your CGI script on your site for very long and you should be safe. Also, consider using the built-in cgi traceback feature in your scripts, at least while you are debugging them (though you probably want to remove the traceback after you are "in production"). -- Chris. From dkatorza at gmail.com Sat Sep 15 12:20:42 2012 From: dkatorza at gmail.com (Dan Katorza) Date: Sat, 15 Sep 2012 09:20:42 -0700 (PDT) Subject: using text file to get ip address from hostname In-Reply-To: References: Message-ID: <0c93c99d-c837-4b20-b78f-8c367ad3cdae@googlegroups.com> ?????? ??? ?????, 12 ??????? 2012 17:24:50 UTC+3, ??? Dan Katorza: > hello , > > > > i'm new to Python and i searched the web and could not find an answer for my issue. > > > > i need to get an ip address from list of hostnames which are in a textfile. > > > > this is what i have so far > > -------------------------------------------------------------------------- > > #!/usr/bin/env python > > #Get the IP Address > > > > import socket > > hostname = 'need it to read from a text file' > > addr = socket.gethostbyname(hostname) > > print 'The address of ', hostname, 'is', addr > > > > --------------------------------------------------------------------------- > > > > any idea ? > > sorry for my english > > > > thanks. hello again friends, thanks for everyone help on this. i guess i figured it out in two ways. the second one i prefer the most. i will appreciate if someone can give me some tips. thanks again so... ------------------------------------------------------------- First ------------------------------------------------------------- #!/usr/bin/env python #Get the IP Address print("hello, please enter file name here >"), import socket for line in open(raw_input()): hostname = line.strip() print("IP address for {0} is {1}.".format(hostname,socket.gethostbyname(hostname))) ------------------------------------------------------------ second ------------------------------------------------------------ #!/usr/bin/env python #Get the IP Address import os print("Hello, please enter file name here >"), FILENAME = raw_input() if os.path.isfile(FILENAME): print("\nFile Exist!") print("\nGetting ip from host name") print("\n") import socket for line in open (FILENAME): hostname = line.strip() print("IP address for {0} is {1}.".format(hostname,socket.gethostbyname(hostname))) else: print ("\nFinished the operation") else: print ("\nFIle is missing or is not reasable"), ~ From rosuav at gmail.com Sat Sep 15 12:25:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Sep 2012 02:25:12 +1000 Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> Message-ID: On Sun, Sep 16, 2012 at 2:04 AM, ???????? ?????? wrote: > I'am not sure what to do and i didnt quite understand what the problem is. > > Can you please tell me what parts need fixe so for the users to be able to leave remakrs in he text area boxes? Your question demonstrates a more fundamental issue here, which I'll look at before answering what you actually asked. You're looking to fix your immediate problem and keep moving, without seeking to understand what's actually going on. This means you will, in all probability, bounce from crisis to crisis without ever fixing anything deep underneath; maybe your next issue will be an SQL injection problem, so you'll fiddle with all your database queries, but never connect that to this. The stated purpose of this project is to learn. Learn as much as you possibly can, then, and get a deep understanding of the underlying structure. Use Firebug or the Chrome F12 debug information or something of the sort to watch the requests going back and forth. Leaf through the Apache logs. Print a whole lot of information to the page or to an offline log. And remember, anything you can do, someone else can do just as easily, so with any private information, make sure it's at least protected by a username and password. Now, to answer your question. Actually, I already answered it in my previous post. First, decide whether or not you need the 'page' form field. Either it's redundant or it's necessary. 1) If it's redundant: Easy. Delete it. Your page will begin working again. 2) If it's necessary: Either rename it, or rename the form field you use in your rewrite rule. But spare a thought for the way your script can so easily be broken by simply appending "?page=" to any URL. That's not good, especially given how much internal information gets dumped to the page. ChrisA From nikos.gr33k at gmail.com Sat Sep 15 12:53:21 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 09:53:21 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> Message-ID: ?? ???????, 15 ??????????? 2012 7:25:15 ?.?. UTC+3, ? ??????? Chris Angelico ??????: First, decide whether or not you need the 'page' form > > field. Either it's redundant or it's necessary. > > > > 1) If it's redundant: Easy. Delete it. Your page will begin working again. > > 2) If it's necessary: Either rename it, or rename the form field you > > use in your rewrite rule. The 'page' form field is of couse neccessary because how else the python counter.py script would know which html file triggered it so to present it and do its log thing?(i intend to create a few html files) I still do not see why you say that it might be redundant. > But spare a thought for the way your script can so easily be broken by > > simply appending "?page=" to any URL. That's not good, especially > > given how much internal information gets dumped to the page. I tried it, it doesnt load any webistes that way. i.e. http://superhost.gr?page='www.google.gr' fails to load. From nikos.gr33k at gmail.com Sat Sep 15 12:53:21 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 09:53:21 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> Message-ID: ?? ???????, 15 ??????????? 2012 7:25:15 ?.?. UTC+3, ? ??????? Chris Angelico ??????: First, decide whether or not you need the 'page' form > > field. Either it's redundant or it's necessary. > > > > 1) If it's redundant: Easy. Delete it. Your page will begin working again. > > 2) If it's necessary: Either rename it, or rename the form field you > > use in your rewrite rule. The 'page' form field is of couse neccessary because how else the python counter.py script would know which html file triggered it so to present it and do its log thing?(i intend to create a few html files) I still do not see why you say that it might be redundant. > But spare a thought for the way your script can so easily be broken by > > simply appending "?page=" to any URL. That's not good, especially > > given how much internal information gets dumped to the page. I tried it, it doesnt load any webistes that way. i.e. http://superhost.gr?page='www.google.gr' fails to load. From rosuav at gmail.com Sat Sep 15 12:56:27 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Sep 2012 02:56:27 +1000 Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> Message-ID: On Sun, Sep 16, 2012 at 2:53 AM, ???????? ?????? wrote: > The 'page' form field is of couse neccessary because how else the python counter.py script would know which html file triggered it so to present it and do its log thing?(i intend to create a few html files) > > I still do not see why you say that it might be redundant. You create one 'page' value in the form, and another one in the RewriteRule. ChrisA From subhabangalore at gmail.com Sat Sep 15 13:18:14 2012 From: subhabangalore at gmail.com (Subhabrata) Date: Sat, 15 Sep 2012 10:18:14 -0700 (PDT) Subject: Some Silly Questions Message-ID: <1985f3e4-11fb-41ff-9b1d-a9b7fc5cba15@googlegroups.com> Dear Group, I am going to ask two very silly questions, if any one can kindly tell me why this structure is taken? classifier.pseudocode(depth=4) from nltk.corpus import brown Sorry to ask you these. Actually everytime I get confused with the answers. Regards, Subhabrata From nikos.gr33k at gmail.com Sat Sep 15 13:22:39 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 10:22:39 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> Message-ID: <38625eb0-3072-44f8-98db-cf112c1f1159@googlegroups.com> ?? ???????, 15 ??????????? 2012 7:56:31 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Sun, Sep 16, 2012 at 2:53 AM, ???????? ?????? wrote: > > > The 'page' form field is of couse neccessary because how else the python counter.py script would know which html file triggered it so to present it and do its log thing?(i intend to create a few html files) > > > > > > I still do not see why you say that it might be redundant. > > > > You create one 'page' value in the form, and another one in the RewriteRule. i changes the .htaccess to RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=$1 [L,PT,QSA] but now my webpage presents the error right away. I dont understand. From nikos.gr33k at gmail.com Sat Sep 15 13:22:39 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 10:22:39 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> Message-ID: <38625eb0-3072-44f8-98db-cf112c1f1159@googlegroups.com> ?? ???????, 15 ??????????? 2012 7:56:31 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Sun, Sep 16, 2012 at 2:53 AM, ???????? ?????? wrote: > > > The 'page' form field is of couse neccessary because how else the python counter.py script would know which html file triggered it so to present it and do its log thing?(i intend to create a few html files) > > > > > > I still do not see why you say that it might be redundant. > > > > You create one 'page' value in the form, and another one in the RewriteRule. i changes the .htaccess to RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=$1 [L,PT,QSA] but now my webpage presents the error right away. I dont understand. From nikos.gr33k at gmail.com Sat Sep 15 13:26:14 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 10:26:14 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <38625eb0-3072-44f8-98db-cf112c1f1159@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> <38625eb0-3072-44f8-98db-cf112c1f1159@googlegroups.com> Message-ID: <6d5a37e2-c7f4-440c-bff7-53298a367453@googlegroups.com> ?? ???????, 15 ??????????? 2012 8:22:39 ?.?. UTC+3, ? ??????? ???????? ?????? ??????: > ?? ???????, 15 ??????????? 2012 7:56:31 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > > > On Sun, Sep 16, 2012 at 2:53 AM, ???????? ?????? wrote: > > > > > > > The 'page' form field is of couse neccessary because how else the python counter.py script would know which html file triggered it so to present it and do its log thing?(i intend to create a few html files) > > > > > > > > > > > > > > I still do not see why you say that it might be redundant. > > > > > > > > > > > > You create one 'page' value in the form, and another one in the RewriteRule. > > > > i changes the .htaccess to > > > > RewriteEngine On > > RewriteCond %{REQUEST_FILENAME} -f > > RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=$1 [L,PT,QSA] > > > > but now my webpage presents the error right away. > > I dont understand. aahhh! alo it needed change to page = form.getvalue('htmlpage') now its working! at last! but can you please tell me what was wrong? Tha names of the variables was the same both in counter.py and the .htaccess But why was that confusing? From nikos.gr33k at gmail.com Sat Sep 15 13:26:14 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 10:26:14 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <38625eb0-3072-44f8-98db-cf112c1f1159@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> <38625eb0-3072-44f8-98db-cf112c1f1159@googlegroups.com> Message-ID: <6d5a37e2-c7f4-440c-bff7-53298a367453@googlegroups.com> ?? ???????, 15 ??????????? 2012 8:22:39 ?.?. UTC+3, ? ??????? ???????? ?????? ??????: > ?? ???????, 15 ??????????? 2012 7:56:31 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > > > On Sun, Sep 16, 2012 at 2:53 AM, ???????? ?????? wrote: > > > > > > > The 'page' form field is of couse neccessary because how else the python counter.py script would know which html file triggered it so to present it and do its log thing?(i intend to create a few html files) > > > > > > > > > > > > > > I still do not see why you say that it might be redundant. > > > > > > > > > > > > You create one 'page' value in the form, and another one in the RewriteRule. > > > > i changes the .htaccess to > > > > RewriteEngine On > > RewriteCond %{REQUEST_FILENAME} -f > > RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=$1 [L,PT,QSA] > > > > but now my webpage presents the error right away. > > I dont understand. aahhh! alo it needed change to page = form.getvalue('htmlpage') now its working! at last! but can you please tell me what was wrong? Tha names of the variables was the same both in counter.py and the .htaccess But why was that confusing? From rosuav at gmail.com Sat Sep 15 13:26:25 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Sep 2012 03:26:25 +1000 Subject: Some Silly Questions In-Reply-To: <1985f3e4-11fb-41ff-9b1d-a9b7fc5cba15@googlegroups.com> References: <1985f3e4-11fb-41ff-9b1d-a9b7fc5cba15@googlegroups.com> Message-ID: On Sun, Sep 16, 2012 at 3:18 AM, Subhabrata wrote: > Dear Group, > > I am going to ask two very silly questions, if any one can kindly tell me why this structure is taken? > > classifier.pseudocode(depth=4) > > from nltk.corpus import brown Not sure what your question means. The first one is a keyword argument: http://docs.python.org/tutorial/controlflow.html#keyword-arguments The second is an import statement: http://docs.python.org/tutorial/modules.html That should get you started! ChrisA From python at mrabarnett.plus.com Sat Sep 15 13:26:27 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 15 Sep 2012 18:26:27 +0100 Subject: pythonOCC examples doesn't work? In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47416678FC5@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4741667C1C7@SCACMX008.exchad.jpmchase.net> Message-ID: <5054BA43.60102@mrabarnett.plus.com> On 2012-09-15 05:40, Dwight Hutto wrote: > On Fri, Sep 14, 2012 at 11:53 PM, Chris Angelico wrote: >> On Sat, Sep 15, 2012 at 1:47 PM, Dwight Hutto wrote: >>> That's no problem, But some suported ad some opposed, it's a >>> democracy, but a dictatorship by the moderators. How much did I err in >>> their opinion of stating my opinion, in relation to the statistical >>> whole? >> >> Actually, I've not seen any moderatorial action on this list. Savoynet > > Alan Gauld quotes, "Putting on my moderator's hat", sometimes. > >> is as you describe, a monarchy whose head but seldom exercises power; > > I think it's Rossenbom(or whoever the creator of the interpreter > written in C is), "who says benevolent dictator for life" > [snip] You don't know the name of the BDFL? I'm appalled! :-) From nikos.gr33k at gmail.com Sat Sep 15 13:33:15 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 10:33:15 -0700 (PDT) Subject: datetime issue Message-ID: Hello again, one small matter too. # get some enviromental values locale.setlocale(locale.LC_ALL, 'el_GR') .......... .......... date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S' ) although iam setting greek as locale the time is 8 hours before, like in texas, us How can i change this to save the correct Greek time in variable $date ? Thank you. From rosuav at gmail.com Sat Sep 15 13:42:53 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Sep 2012 03:42:53 +1000 Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <6d5a37e2-c7f4-440c-bff7-53298a367453@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> <38625eb0-3072-44f8-98db-cf112c1f1159@googlegroups.com> <6d5a37e2-c7f4-440c-bff7-53298a367453@googlegroups.com> Message-ID: On Sun, Sep 16, 2012 at 3:26 AM, ???????? ?????? wrote: > aahhh! alo it needed change to > > page = form.getvalue('htmlpage') > > now its working! at last! > > but can you please tell me what was wrong? > > Tha names of the variables was the same both in counter.py and the .htaccess > > But why was that confusing? This is what I'm trying to explain. You need to get to know what's really happening; what is the rewrite rule doing? I could walk you through it, there's nothing magical about it, but you really need to study it for yourself so that you actually understand what's going on. You've now solved your immediate issue, so you'll probably be tempted to ignore everything else and move on. And if you're on time pressure, that's perhaps the right decision. (Five hours and you have a fully working solution. Not bad for free assistance!) But you still have the page-breaking issue: http://superhost.gr/?htmlpage=broken And there's still the question of whether or not the hidden form field is needed. I suspect it probably isn't. But these are questions for you to work out the answers to yourself. I get an impression from your posts that you're working shallowly, and probably in some haste. Your posts are somewhat sloppy in spelling and capitalization; I understand that English probably isn't your first language, but careful writing is not difficult, and you'll spare yourself the reputation of sloppy work and sloppy thinking. It takes time to truly master anything. Whether it's riding a bicycle, solving Rubik's Cube, or building a web site, you'll need to put in some hours before you can truly expect to comprehend your work. Trying to short-cut that usually results in problems down the road. Put in the time, gain the skill, and you'll reap the rewards! ChrisA From nikos.gr33k at gmail.com Sat Sep 15 13:59:14 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 10:59:14 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> <38625eb0-3072-44f8-98db-cf112c1f1159@googlegroups.com> <6d5a37e2-c7f4-440c-bff7-53298a367453@googlegroups.com> Message-ID: <2992b15f-2ca8-4a67-ad84-c22c06e8bd16@googlegroups.com> What hidden form value? you mean page variable does not needed? please clarify. Also i dont know what to do if someone enters a false entry as content for htmlpage. From nikos.gr33k at gmail.com Sat Sep 15 13:59:14 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 10:59:14 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> <38625eb0-3072-44f8-98db-cf112c1f1159@googlegroups.com> <6d5a37e2-c7f4-440c-bff7-53298a367453@googlegroups.com> Message-ID: <2992b15f-2ca8-4a67-ad84-c22c06e8bd16@googlegroups.com> What hidden form value? you mean page variable does not needed? please clarify. Also i dont know what to do if someone enters a false entry as content for htmlpage. From rosuav at gmail.com Sat Sep 15 14:02:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Sep 2012 04:02:41 +1000 Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <2992b15f-2ca8-4a67-ad84-c22c06e8bd16@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> <38625eb0-3072-44f8-98db-cf112c1f1159@googlegroups.com> <6d5a37e2-c7f4-440c-bff7-53298a367453@googlegroups.com> <2992b15f-2ca8-4a67-ad84-c22c06e8bd16@googlegroups.com> Message-ID: On Sun, Sep 16, 2012 at 3:59 AM, ???????? ?????? wrote: > What hidden form value? > > you mean page variable does not needed? please clarify. > > Also i dont know what to do if someone enters a false entry as content for htmlpage. You have this: What is that for? Is it needed? ChrisA From nikos.gr33k at gmail.com Sat Sep 15 14:10:27 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 11:10:27 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> <38625eb0-3072-44f8-98db-cf112c1f1159@googlegroups.com> <6d5a37e2-c7f4-440c-bff7-53298a367453@googlegroups.com> <2992b15f-2ca8-4a67-ad84-c22c06e8bd16@googlegroups.com> Message-ID: <8f4cfbe4-862d-4567-969d-b581ab415ea6@googlegroups.com> ?? ???????, 15 ??????????? 2012 9:03:00 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Sun, Sep 16, 2012 at 3:59 AM, ???????? ?????? wrote: > > > What hidden form value? > > > > > > you mean page variable does not needed? please clarify. > > > > > > Also i dont know what to do if someone enters a false entry as content for htmlpage. > > > > You have this: > > > > > > What is that for? Is it needed? > > > > ChrisA ah yes in the index.html page yes...yes i totally forgot about that, that bwas before creating the python counter logging when i was thinking other ways of solving this matter. What about the htmlpage=broken issue? Thanks for helping me with thi for free, i appreciate it a lot. From nikos.gr33k at gmail.com Sat Sep 15 14:10:27 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 11:10:27 -0700 (PDT) Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> <38625eb0-3072-44f8-98db-cf112c1f1159@googlegroups.com> <6d5a37e2-c7f4-440c-bff7-53298a367453@googlegroups.com> <2992b15f-2ca8-4a67-ad84-c22c06e8bd16@googlegroups.com> Message-ID: <8f4cfbe4-862d-4567-969d-b581ab415ea6@googlegroups.com> ?? ???????, 15 ??????????? 2012 9:03:00 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Sun, Sep 16, 2012 at 3:59 AM, ???????? ?????? wrote: > > > What hidden form value? > > > > > > you mean page variable does not needed? please clarify. > > > > > > Also i dont know what to do if someone enters a false entry as content for htmlpage. > > > > You have this: > > > > > > What is that for? Is it needed? > > > > ChrisA ah yes in the index.html page yes...yes i totally forgot about that, that bwas before creating the python counter logging when i was thinking other ways of solving this matter. What about the htmlpage=broken issue? Thanks for helping me with thi for free, i appreciate it a lot. From hansmu at xs4all.nl Sat Sep 15 14:52:39 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 15 Sep 2012 20:52:39 +0200 Subject: using text file to get ip address from hostname In-Reply-To: <0c93c99d-c837-4b20-b78f-8c367ad3cdae@googlegroups.com> References: <0c93c99d-c837-4b20-b78f-8c367ad3cdae@googlegroups.com> Message-ID: <5054ce77$0$6987$e4fe514c@news2.news.xs4all.nl> On 15/09/12 18:20:42, Dan Katorza wrote: > ?????? ??? ?????, 12 ??????? 2012 17:24:50 UTC+3, ??? Dan Katorza: >> hello , >> >> >> >> i'm new to Python and i searched the web and could not find an answer for my issue. >> >> >> >> i need to get an ip address from list of hostnames which are in a textfile. >> >> >> >> this is what i have so far >> >> -------------------------------------------------------------------------- >> >> #!/usr/bin/env python >> >> #Get the IP Address >> >> >> >> import socket >> >> hostname = 'need it to read from a text file' >> >> addr = socket.gethostbyname(hostname) >> >> print 'The address of ', hostname, 'is', addr >> >> >> >> --------------------------------------------------------------------------- >> >> >> >> any idea ? >> >> sorry for my english >> >> >> >> thanks. > > hello again friends, > thanks for everyone help on this. > i guess i figured it out in two ways. > the second one i prefer the most. > > i will appreciate if someone can give me some tips. > thanks again > > so... > ------------------------------------------------------------- > First > ------------------------------------------------------------- > #!/usr/bin/env python > #Get the IP Address > > > print("hello, please enter file name here >"), Instead of printing this string, you can pass it as the argument to raw_input: for line in open(raw_input("hello, please enter file name here> ")): Cosmetically, I'd prefer a space after the '>'. > import socket PEP 8 recommends putting all imports at the top of the file, like you do in your second script. > for line in open(raw_input()): > hostname = line.strip() > print("IP address for {0} is {1}.".format(hostname,socket.gethostbyname(hostname))) To my mind, this line does two things: it finds the IP address and prints it. I think it would be more readable to do these on separate lines: ip_address = socket.gethostbyname(hostname) print("IP address for {0} is {1}.".format(hostname, ip_address) This forces you to find a good name for the value returned by gethostbyname, which I consider a Good Thing (tm). PEP 8 recommends that lines should not be longer than 80 characters. Your line is longer than that; splitting it in two conceptual steps nicely solves that issue as well. > ------------------------------------------------------------ > second > ------------------------------------------------------------ > #!/usr/bin/env python > #Get the IP Address > > import os > > print("Hello, please enter file name here >"), > FILENAME = raw_input() PEP 8 recommends all upper case for constants, for example socket.IPPROTO_IPV6. The filename here is not a hard-wired constant, so it should be in lower case. > if os.path.isfile(FILENAME): Your first script allowed me to enter "/dev/tty" at the prompt, and then type a bunch of hostnames and an end-of-file character. This script reports "FIle is missing or not reasable", because /dev/tty is not a regular file. I think the message should be "File is missing or not readable or not a regular file". I'm always annoyed when I get an error message with several "or"s in it. I prefer programs that figure out which of the three potential issues is the case, and mention only one cause. > print("\nFile Exist!") > print("\nGetting ip from host name") > print("\n") > import socket > for line in open (FILENAME): > hostname = line.strip() > print("IP address for {0} is {1}.".format(hostname,socket.gethostbyname(hostname))) > else: > print ("\nFinished the operation") > else: > print ("\nFIle is missing or is not reasable"), You don't want a comma at the end of this line: it messes up the next shell prompt. Also, this line a rather far away from the test that triggers it. How about: filename = raw_input("Hello, please enter file name here> ") if not os.path.isfile(filename): if not os.exist(filename): print("\nFile {} does not exist") else: print("\nFile {} is not a regular file") sys.exit(1) print("\nFile {} exists", filename) # etc. Or you could skip the whole 'os' thing and use a try/except construct instead: #!/usr/bin/env python #Get the IP Address import sys, socket filename = raw_input("Hello, please enter file name here> ") try: infile = open(filename) except EnvironmentError as e: print(e) sys.exit(1) print("\nFile {} exists!".format(filename)) print("\nGetting IP addresses for hosts") print("\n") for line in infile: hostname = line.strip() try: ip_address = socket.gethostbyname(hostname) except EnvironmentError as e: print("Couldn't find IP address for {}: {}".format(hostname, e)) continue print("IP address for {0} is {1}.".format(hostname, ip_address)) else: print ("\nFinished the operation") Using try/except has the advantage that it will correctly report issues you didn't think about (for example, if file exists, but you don't have permission to read it). Hope this helps -- HansM From jason at powerpull.net Sat Sep 15 14:58:13 2012 From: jason at powerpull.net (Jason Friedman) Date: Sat, 15 Sep 2012 12:58:13 -0600 Subject: datetime issue In-Reply-To: References: Message-ID: > # get some enviromental values > locale.setlocale(locale.LC_ALL, 'el_GR') > date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S' ) > > although iam setting greek as locale the time is 8 hours before, like in texas, us > How can i change this to save the correct Greek time in variable $date ? http://docs.python.org/py3k/library/datetime.html#tzinfo-objects http://stackoverflow.com/questions/117514/how-do-i-use-timezones-with-a-datetime-object-in-python http://pytz.sourceforge.net/ Reading these links suggests that datetime.now() will return the system time regardless of your locale setting. Use a timezone to generate a timestamp for someplace other than where your server sits. From clp2 at rebertia.com Sat Sep 15 15:05:23 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 15 Sep 2012 12:05:23 -0700 Subject: datetime issue In-Reply-To: References: Message-ID: On Sat, Sep 15, 2012 at 10:33 AM, ???????? ?????? wrote: > Hello again, > > one small matter too. > > # get some enviromental values > locale.setlocale(locale.LC_ALL, 'el_GR') > date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S' ) > > although iam setting greek as locale Locales don't affect timezones. Otherwise, how would expatriate communities, or countries wide enough to span several timezones, properly configure their software? > the time is 8 hours before, like in texas, us Which is where HostGator operates out of. > How can i change this to save the correct Greek time in variable $date ? Use the `pytz` package that Jason pointed out. Cheers, Chris From nikos.gr33k at gmail.com Sat Sep 15 15:26:53 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 12:26:53 -0700 (PDT) Subject: datetime issue In-Reply-To: References: Message-ID: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> ?? ???????, 15 ??????????? 2012 10:05:49 ?.?. UTC+3, ? ??????? Chris Rebert ??????: > On Sat, Sep 15, 2012 at 10:33 AM, ???????? ?????? wrote: > > > Hello again, > > > > > > one small matter too. > > > > > # get some enviromental values > > > locale.setlocale(locale.LC_ALL, 'el_GR') > > > > > date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S' ) > > > > > > although iam setting greek as locale > > > > Locales don't affect timezones. Otherwise, how would expatriate > > communities, or countries wide enough to span several timezones, > > properly configure their software? > > > > > the time is 8 hours before, like in texas, us > > > > Which is where HostGator operates out of. > > > > > How can i change this to save the correct Greek time in variable $date ? > > > > Use the `pytz` package that Jason pointed out. > > > > Cheers, > > Chris I did read but wasnt able to set it to greek time. Please tell me how should i write this. date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S',gmt+2 ) didnt work out for me. From nikos.gr33k at gmail.com Sat Sep 15 15:26:53 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 12:26:53 -0700 (PDT) Subject: datetime issue In-Reply-To: References: Message-ID: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> ?? ???????, 15 ??????????? 2012 10:05:49 ?.?. UTC+3, ? ??????? Chris Rebert ??????: > On Sat, Sep 15, 2012 at 10:33 AM, ???????? ?????? wrote: > > > Hello again, > > > > > > one small matter too. > > > > > # get some enviromental values > > > locale.setlocale(locale.LC_ALL, 'el_GR') > > > > > date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S' ) > > > > > > although iam setting greek as locale > > > > Locales don't affect timezones. Otherwise, how would expatriate > > communities, or countries wide enough to span several timezones, > > properly configure their software? > > > > > the time is 8 hours before, like in texas, us > > > > Which is where HostGator operates out of. > > > > > How can i change this to save the correct Greek time in variable $date ? > > > > Use the `pytz` package that Jason pointed out. > > > > Cheers, > > Chris I did read but wasnt able to set it to greek time. Please tell me how should i write this. date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S',gmt+2 ) didnt work out for me. From python at mrabarnett.plus.com Sat Sep 15 16:28:27 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 15 Sep 2012 21:28:27 +0100 Subject: datetime issue In-Reply-To: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> Message-ID: <5054E4EB.3050605@mrabarnett.plus.com> On 2012-09-15 20:26, ???????? ?????? wrote: > ?? ???????, 15 ??????????? 2012 10:05:49 ?.?. UTC+3, ? ??????? Chris Rebert ??????: >> On Sat, Sep 15, 2012 at 10:33 AM, ???????? ?????? wrote: >> > Hello again, >> > >> > one small matter too. >> >> > # get some enviromental values >> > locale.setlocale(locale.LC_ALL, 'el_GR') >> >> > date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S' ) >> > >> > although iam setting greek as locale >> >> Locales don't affect timezones. Otherwise, how would expatriate >> communities, or countries wide enough to span several timezones, >> properly configure their software? >> >> > the time is 8 hours before, like in texas, us >> >> Which is where HostGator operates out of. >> >> > How can i change this to save the correct Greek time in variable $date ? >> >> Use the `pytz` package that Jason pointed out. >> > I did read but wasnt able to set it to greek time. > Please tell me how should i write this. > > date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S',gmt+2 ) > > didnt work out for me. > Does this help? import datetime # The time as UTC (GMT). now_utc = datetime.datetime.utcnow() print(now_utc.strftime('%Y-%m-%d %H:%M:%S')) # The time as UTC+2. now_local = now_utc + datetime.timedelta(hours=2) print(now_local.strftime('%Y-%m-%d %H:%M:%S')) From dkatorza at gmail.com Sat Sep 15 18:43:30 2012 From: dkatorza at gmail.com (Dan Katorza) Date: Sat, 15 Sep 2012 15:43:30 -0700 (PDT) Subject: using text file to get ip address from hostname In-Reply-To: References: Message-ID: <3359a0e7-f7bb-4b1f-b586-e83f337566b7@googlegroups.com> ?????? ??? ?????, 12 ??????? 2012 17:24:50 UTC+3, ??? Dan Katorza: > hello , > > > > i'm new to Python and i searched the web and could not find an answer for my issue. > > > > i need to get an ip address from list of hostnames which are in a textfile. > > > > this is what i have so far > > -------------------------------------------------------------------------- > > #!/usr/bin/env python > > #Get the IP Address > > > > import socket > > hostname = 'need it to read from a text file' > > addr = socket.gethostbyname(hostname) > > print 'The address of ', hostname, 'is', addr > > > > --------------------------------------------------------------------------- > > > > any idea ? > > sorry for my english > > > > thanks. Hi Hans, thank you very much for the tips. as i mentioned before I'm new to python and I'm trying to learn it step by step. thank you for showing me other ways, i will explore them. From rosuav at gmail.com Sat Sep 15 19:11:03 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Sep 2012 09:11:03 +1000 Subject: cannot concatenate 'str' and 'list' objects In-Reply-To: <8f4cfbe4-862d-4567-969d-b581ab415ea6@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <9c166e95-e70f-4294-833b-1071a24c6d6d@googlegroups.com> <65a098bd-4fc7-4df6-9436-3d084b810f22@googlegroups.com> <38625eb0-3072-44f8-98db-cf112c1f1159@googlegroups.com> <6d5a37e2-c7f4-440c-bff7-53298a367453@googlegroups.com> <2992b15f-2ca8-4a67-ad84-c22c06e8bd16@googlegroups.com> <8f4cfbe4-862d-4567-969d-b581ab415ea6@googlegroups.com> Message-ID: On Sun, Sep 16, 2012 at 4:10 AM, ???????? ?????? wrote: > ah yes in the index.html page yes...yes i totally forgot about that, that bwas before creating the python counter logging when i was thinking other ways of solving this matter. So it's like I was saying, redundant. :) > What about the htmlpage=broken issue? The best fix would be to stop using the querystring to pass information across the rewriterule. Research the Apache directive and learn what you can do with it, and/or research CGI for ways of learning the original URL. ChrisA From castironpi at gmail.com Sat Sep 15 23:24:52 2012 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 15 Sep 2012 20:24:52 -0700 (PDT) Subject: unit test strategy In-Reply-To: References: Message-ID: <795807da-8f2c-40f4-9975-283c48d820fc@googlegroups.com> On Friday, September 14, 2012 10:32:47 PM UTC-5, David Hutto wrote: > On Fri, Sep 14, 2012 at 11:26 PM, Dwight Hutto wrote: > > > On Fri, Sep 14, 2012 at 10:59 PM, Aaron Brady wrote: > > >> Hello, > > >> > > >> I've developing a test script. There's a lot of repetition. I want to introduce a strategy for approaching it, but I don't want the program to be discredited because of the test script. Therefore, I'd like to know what people's reactions to and thoughts about it are. > > >> > > >> The first strategy I used created an iterator and advanced it between each step: > > > > > > That isn't a refined iterator below: > > What I mean is look at the similarities, and the differences, then > > replace the differences with interpolation, in eval even. > > > > > > > > > >> self.op_chain(range(5), ('add', 5)) > > >> self.op_chain(range(5), ('add', -2), ('add', -1)) > > >> self.op_chain(range(5), ('discard', -1), ('add', 5)) > > >> self.op_chain_ok(range(5), ('update', [0, 1])) > > >> Etc. > > >> > > >> I'm considering something more complicated. 'iN' creates iterator N, 'nN' advances iterator N, an exception calls 'assertRaises', and the rest are function calls. > > > > iN = [N for N in range(0,5)] > > > > > > >> dsi= dict.__setitem__ > > >> ddi= dict.__delitem__ > > >> dsd= dict.setdefault > > >> KE= KeyError > > >> IE= IterationError > > >> self.chain(range(10), 'i0', (dsi, 0, 1), 'n0', (dsi, 10, 1), (IE, 'n0')) > > >> self.chain(range(10), 'i0', 'n0', (dsd, 0, 0), 'n0', (dsd, 10, 1), (IE, 'n0')) > > >> self.chain(range(10), 'i0', (KE, ddi, 10), 'n0', (ddi, 9), (IE, 'n0')) > > >> > > >> Do you think the 2nd version is legible? Could it interfere with the accuracy of the test? > > > > Define the 2nd version > > > > > > > > > > Show the test, which should show instances of what you want called. > > > > > > I could rewrite the above, but it seems you're more in need of refining > > > your iterations, and the values given within them. > > > > > > > -- > > Best Regards, > > David Hutto > > CEO: http://www.hitwebdevelopment.com Hi David, I'm interested in your comments, but I had difficulty interpreting them. What I want to know is, do people think that the 2nd version I presented would be a more effective test script? Do you think it would be more useful to run the tests in the function call directly? Or would it be more useful to output a program script and then run that? Is there some risk that the direct test would interfere with the results? And, is the 2nd version legible? That is, is it easy for other programmers to tell what the purpose and actual effects of a given test are? From castironpi at gmail.com Sat Sep 15 23:24:52 2012 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 15 Sep 2012 20:24:52 -0700 (PDT) Subject: unit test strategy In-Reply-To: References: Message-ID: <795807da-8f2c-40f4-9975-283c48d820fc@googlegroups.com> On Friday, September 14, 2012 10:32:47 PM UTC-5, David Hutto wrote: > On Fri, Sep 14, 2012 at 11:26 PM, Dwight Hutto wrote: > > > On Fri, Sep 14, 2012 at 10:59 PM, Aaron Brady wrote: > > >> Hello, > > >> > > >> I've developing a test script. There's a lot of repetition. I want to introduce a strategy for approaching it, but I don't want the program to be discredited because of the test script. Therefore, I'd like to know what people's reactions to and thoughts about it are. > > >> > > >> The first strategy I used created an iterator and advanced it between each step: > > > > > > That isn't a refined iterator below: > > What I mean is look at the similarities, and the differences, then > > replace the differences with interpolation, in eval even. > > > > > > > > > >> self.op_chain(range(5), ('add', 5)) > > >> self.op_chain(range(5), ('add', -2), ('add', -1)) > > >> self.op_chain(range(5), ('discard', -1), ('add', 5)) > > >> self.op_chain_ok(range(5), ('update', [0, 1])) > > >> Etc. > > >> > > >> I'm considering something more complicated. 'iN' creates iterator N, 'nN' advances iterator N, an exception calls 'assertRaises', and the rest are function calls. > > > > iN = [N for N in range(0,5)] > > > > > > >> dsi= dict.__setitem__ > > >> ddi= dict.__delitem__ > > >> dsd= dict.setdefault > > >> KE= KeyError > > >> IE= IterationError > > >> self.chain(range(10), 'i0', (dsi, 0, 1), 'n0', (dsi, 10, 1), (IE, 'n0')) > > >> self.chain(range(10), 'i0', 'n0', (dsd, 0, 0), 'n0', (dsd, 10, 1), (IE, 'n0')) > > >> self.chain(range(10), 'i0', (KE, ddi, 10), 'n0', (ddi, 9), (IE, 'n0')) > > >> > > >> Do you think the 2nd version is legible? Could it interfere with the accuracy of the test? > > > > Define the 2nd version > > > > > > > > > > Show the test, which should show instances of what you want called. > > > > > > I could rewrite the above, but it seems you're more in need of refining > > > your iterations, and the values given within them. > > > > > > > -- > > Best Regards, > > David Hutto > > CEO: http://www.hitwebdevelopment.com Hi David, I'm interested in your comments, but I had difficulty interpreting them. What I want to know is, do people think that the 2nd version I presented would be a more effective test script? Do you think it would be more useful to run the tests in the function call directly? Or would it be more useful to output a program script and then run that? Is there some risk that the direct test would interfere with the results? And, is the 2nd version legible? That is, is it easy for other programmers to tell what the purpose and actual effects of a given test are? From nikos.gr33k at gmail.com Sun Sep 16 01:15:38 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 22:15:38 -0700 (PDT) Subject: datetime issue In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> Message-ID: <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> ?? ???????, 15 ??????????? 2012 11:28:47 ?.?. UTC+3, ? ??????? MRAB ??????: > On 2012-09-15 20:26, ???????????????????????? ?????????????????? wrote: > > > ?????? ?????????????????????, 15 ????????????????????????????????? 2012 10:05:49 ???.???. UTC+3, ??? ????????????????????? Chris Rebert ??????????????????: > > >> On Sat, Sep 15, 2012 at 10:33 AM, ???????????????????????? ?????????????????? wrote: > > >> > Hello again, > > >> > > > >> > one small matter too. > > >> > > >> > # get some enviromental values > > >> > locale.setlocale(locale.LC_ALL, 'el_GR') > > >> > > >> > date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S' ) > > >> > > > >> > although iam setting greek as locale > > >> > > >> Locales don't affect timezones. Otherwise, how would expatriate > > >> communities, or countries wide enough to span several timezones, > > >> properly configure their software? > > >> > > >> > the time is 8 hours before, like in texas, us > > >> > > >> Which is where HostGator operates out of. > > >> > > >> > How can i change this to save the correct Greek time in variable > > $date ? > > >> > > >> Use the `pytz` package that Jason pointed out. > > >> > > > I did read but wasnt able to set it to greek time. > > > Please tell me how should i write this. > > > > > > date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S',gmt+2 ) > > > > > > didnt work out for me. > > > > > Does this help? > > > > import datetime > > > > # The time as UTC (GMT). > > now_utc = datetime.datetime.utcnow() > > print(now_utc.strftime('%Y-%m-%d %H:%M:%S')) > > > > # The time as UTC+2. > > now_local = now_utc + datetime.timedelta(hours=2) > > print(now_local.strftime('%Y-%m-%d %H:%M:%S')) If i wanted to alter the following line, how would i write it? date = datetime.datetime.now()+datetime.timedelta(hours=2).strftime( '%y-%m-%d %H:%M:%S') But that doesnt work, From nikos.gr33k at gmail.com Sun Sep 16 01:15:38 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sat, 15 Sep 2012 22:15:38 -0700 (PDT) Subject: datetime issue In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> Message-ID: <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> ?? ???????, 15 ??????????? 2012 11:28:47 ?.?. UTC+3, ? ??????? MRAB ??????: > On 2012-09-15 20:26, ???????????????????????? ?????????????????? wrote: > > > ?????? ?????????????????????, 15 ????????????????????????????????? 2012 10:05:49 ???.???. UTC+3, ??? ????????????????????? Chris Rebert ??????????????????: > > >> On Sat, Sep 15, 2012 at 10:33 AM, ???????????????????????? ?????????????????? wrote: > > >> > Hello again, > > >> > > > >> > one small matter too. > > >> > > >> > # get some enviromental values > > >> > locale.setlocale(locale.LC_ALL, 'el_GR') > > >> > > >> > date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S' ) > > >> > > > >> > although iam setting greek as locale > > >> > > >> Locales don't affect timezones. Otherwise, how would expatriate > > >> communities, or countries wide enough to span several timezones, > > >> properly configure their software? > > >> > > >> > the time is 8 hours before, like in texas, us > > >> > > >> Which is where HostGator operates out of. > > >> > > >> > How can i change this to save the correct Greek time in variable > > $date ? > > >> > > >> Use the `pytz` package that Jason pointed out. > > >> > > > I did read but wasnt able to set it to greek time. > > > Please tell me how should i write this. > > > > > > date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S',gmt+2 ) > > > > > > didnt work out for me. > > > > > Does this help? > > > > import datetime > > > > # The time as UTC (GMT). > > now_utc = datetime.datetime.utcnow() > > print(now_utc.strftime('%Y-%m-%d %H:%M:%S')) > > > > # The time as UTC+2. > > now_local = now_utc + datetime.timedelta(hours=2) > > print(now_local.strftime('%Y-%m-%d %H:%M:%S')) If i wanted to alter the following line, how would i write it? date = datetime.datetime.now()+datetime.timedelta(hours=2).strftime( '%y-%m-%d %H:%M:%S') But that doesnt work, From bryanjugglercryptographer at yahoo.com Sun Sep 16 02:45:33 2012 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Sat, 15 Sep 2012 23:45:33 -0700 (PDT) Subject: Standard Asynchronous Python References: <504d60ab$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: Dustin J. Mitchell wrote: > Thanks for the second round of responses. ?I think this gives me some > focus - concentrate on the API, talk to the framework developers, and > start redrafting the PEP sooner rather than later. That's mostly what you came in with, but talking to the framework developers is unarguably a good idea. So what frameworks? There is one great framework for asynchronous Python and that's Twisted. I'm not a Twisted guy... well not in the sense at issue here. I can tell you why Twisted is "massive": no workable alternative. An event-driven framework cannot simply call methods in a mainstream Python library because they often block for I/O. The good and gifted developers of Twisted have risen to the challenge by re-writing important libraries around their deferreds which they regard as beautiful. Our fellow scripting language programmers in the young node.js community work in a system that is event-driven from the ground up. They had the advantage of no important blocking sequential libraries to re-write. As a programming language JavaScript is grossly inferior to Python, yet the node.js guys have put out some useful code and impressive benchmarks with their bad-ass rock-star tech. https://www.youtube.com/watch?v=bzkRVzciAZg The obvious exemplars among Python frameworks are web frameworks. Developers of the most popular Python web framework, Django, famously stated their goal of making making web programming "stupidly easy". That registered with me. Django did spectacularly well, then Web2py did even better on that particular criterion. There are several-to- many other excellent Python web frameworks, and there's a clear consensus among the major players on how to handle simultaneous requests: threads. Dustin, I hope you carry on with your plan. I request, please, report back here what you find. As law professor James Duane said in pre- introduction of police officer George Bruch, "I'm sure [you'll] have a lot to teach all of us, including myself." -Bryan From sntshkmr60 at gmail.com Sun Sep 16 02:50:08 2012 From: sntshkmr60 at gmail.com (Santosh Kumar) Date: Sun, 16 Sep 2012 12:20:08 +0530 Subject: want to show list of available options and arguments in my command line utility Message-ID: I have a script that takes an which basically takes a command line argument and prints after processing. If I don't give the argument to the script, it gives me a ValueError: ValueError: need more than 1 value to unpack I was trying to utilizing this space, if there is no argument I want it to show: usages: myscriptpy [option] [argument] options: --help print this help message and exit Nothing more than that. I was looking on the argparse module, it can do the stuffs I want, but I don't to rewrite and mess up my current script. What should I do? From __peter__ at web.de Sun Sep 16 03:23:46 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 16 Sep 2012 09:23:46 +0200 Subject: want to show list of available options and arguments in my command line utility References: Message-ID: Santosh Kumar wrote: > I have a script that takes an which basically takes a command line > argument and prints after processing. If I don't give the argument to > the script, it gives me a ValueError: > > ValueError: need more than 1 value to unpack > > I was trying to utilizing this space, if there is no argument I want it > to show: > usages: myscriptpy [option] [argument] > > options: > --help print this help message and exit > > Nothing more than that. I was looking on the argparse module, it can > do the stuffs I want, but > I don't to rewrite and mess up my current script. What should I do? Learning to use the argparse module is a worthwhile endeavour. You should rewrite and not mess up your script. This is easier if you write unit tests to accompany the code doing the "real work". Don't forget to use version control (see http://hginit.com/ for example) to help you back out if something goes awry. Also note that learning to throw away suboptimal code is important, too. From steve+comp.lang.python at pearwood.info Sun Sep 16 03:29:40 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Sep 2012 07:29:40 GMT Subject: want to show list of available options and arguments in my command line utility References: Message-ID: <50557fe4$0$29890$c3e8da3$5496439d@news.astraweb.com> On Sun, 16 Sep 2012 12:20:08 +0530, Santosh Kumar wrote: > I have a script that takes an which basically takes a command line > argument and prints after processing. If I don't give the argument to > the script, it gives me a ValueError: > > ValueError: need more than 1 value to unpack > > I was trying to utilizing this space, if there is no argument I want it > to show: > usages: myscriptpy [option] [argument] > > options: > --help print this help message and exit > > Nothing more than that. I was looking on the argparse module, it can do > the stuffs I want, but > I don't to rewrite and mess up my current script. What should I do? Then don't mess it up. What you are basically asking for sounds like "I want to add this cool feature to my project, but I don't want to actually do the work of adding the feature. How can I snap my fingers and make it work just like magic?" The answer is, you can't. Either: 1) Do without the feature; or 2) Program the feature. For number 2), you can either modify your script to use argparse to deal with the argument handling (which is probably simplest), or you can try to duplicate argparse's functionality yourself. Make a backup copy first -- never, ever, ever work on the only copy of a working script. Or better still, use a proper VCS (version control system) to manage the software. But for small changes and simple needs, a good enough solution is "always edit a copy". In this case, it *may* be simple enough to duplicate the functionality. There's no way to tell, because you don't show any code, but my *guess* is that you have a line like: a, b = sys.argv and if you don't provide any command-line arguments, that fails with ValueError: need more than 1 value to unpack (Lots and lots and lots of other things will also fail with the same error.) Is this case, the fix is simple: args = sys.argv[1:] # ignore the first entry, which is unimportant if len(args) == 1: arg = args[0] process(arg, default_option) elif len(args) == 2: option, arg == args process(arg, option) elif len(args) > 2: do_error('too many arguments') else: do_error('not enough arguments') But as the argument checking code gets more extensive, it is time to just use argparse or one of the other libraries for argument checking instead. -- Steven From steve+comp.lang.python at pearwood.info Sun Sep 16 03:29:40 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Sep 2012 07:29:40 GMT Subject: want to show list of available options and arguments in my command line utility References: Message-ID: <50557fe4$0$11113$c3e8da3@news.astraweb.com> On Sun, 16 Sep 2012 12:20:08 +0530, Santosh Kumar wrote: > I have a script that takes an which basically takes a command line > argument and prints after processing. If I don't give the argument to > the script, it gives me a ValueError: > > ValueError: need more than 1 value to unpack > > I was trying to utilizing this space, if there is no argument I want it > to show: > usages: myscriptpy [option] [argument] > > options: > --help print this help message and exit > > Nothing more than that. I was looking on the argparse module, it can do > the stuffs I want, but > I don't to rewrite and mess up my current script. What should I do? Then don't mess it up. What you are basically asking for sounds like "I want to add this cool feature to my project, but I don't want to actually do the work of adding the feature. How can I snap my fingers and make it work just like magic?" The answer is, you can't. Either: 1) Do without the feature; or 2) Program the feature. For number 2), you can either modify your script to use argparse to deal with the argument handling (which is probably simplest), or you can try to duplicate argparse's functionality yourself. Make a backup copy first -- never, ever, ever work on the only copy of a working script. Or better still, use a proper VCS (version control system) to manage the software. But for small changes and simple needs, a good enough solution is "always edit a copy". In this case, it *may* be simple enough to duplicate the functionality. There's no way to tell, because you don't show any code, but my *guess* is that you have a line like: a, b = sys.argv and if you don't provide any command-line arguments, that fails with ValueError: need more than 1 value to unpack (Lots and lots and lots of other things will also fail with the same error.) Is this case, the fix is simple: args = sys.argv[1:] # ignore the first entry, which is unimportant if len(args) == 1: arg = args[0] process(arg, default_option) elif len(args) == 2: option, arg == args process(arg, option) elif len(args) > 2: do_error('too many arguments') else: do_error('not enough arguments') But as the argument checking code gets more extensive, it is time to just use argparse or one of the other libraries for argument checking instead. -- Steven From steve+comp.lang.python at pearwood.info Sun Sep 16 03:42:09 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Sep 2012 07:42:09 GMT Subject: unit test strategy References: Message-ID: <505582d1$0$29890$c3e8da3$5496439d@news.astraweb.com> On Fri, 14 Sep 2012 19:59:29 -0700, Aaron Brady wrote: > Hello, > > I've developing a test script. There's a lot of repetition. I want to > introduce a strategy for approaching it, but I don't want the program to > be discredited because of the test script. Test scripts should be simple enough that they don't require test scripts of their own. Or at least, not too many "test-the-test" tests. It is possible to avoid repetition without making convoluted, hard to understand code. Based on the tiny code fragments you give below, I suspect that your test script will need more testing than the code it tests! > Therefore, I'd like to know > what people's reactions to and thoughts about it are. I'd love to make some suggestions, but I have *no idea* what you are talking about. See further comments below: > The first strategy I used created an iterator and advanced it between > each step: What are you using an iterator for? What does this have to do with unit testing? So far, your explanation is rather lacking. It's a bit like: "I want to create an alarm system for my home, so I put in a screw and tightened it after each step." Doesn't really help us understand what you are doing. > self.op_chain(range(5), ('add', 5)) > self.op_chain(range(5), ('add', -2), ('add', -1)) > self.op_chain(range(5), ('discard', -1), ('add', 5)) > self.op_chain_ok(range(5), ('update', [0, 1])) > Etc. Where is the iterator you created? Where are you advancing it? What's op_chain do? > I'm considering something more complicated. 'iN' creates iterator N, > 'nN' advances iterator N, an exception calls 'assertRaises', and the > rest are function calls. [...] You've proven that even in Python people can write obfuscated code. > Do you think the 2nd version is legible? Neither version is even close to legible. > Could it interfere with the accuracy of the test? Who knows? I have no clue what your code is doing, it could be doing *anything*. -- Steven From nikos.gr33k at gmail.com Sun Sep 16 03:51:18 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sun, 16 Sep 2012 00:51:18 -0700 (PDT) Subject: datetime issue In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> Message-ID: <1774b70d-d3ad-414d-8460-bfa750b8f23f@googlegroups.com> dn = datetime.datetime.now() dd = datetime.timedelta(hours=2) date = dn + dd date = date.strftime( '%y-%m-%d %H:%M:%S' ) still giving me texas,us time for some reason From nikos.gr33k at gmail.com Sun Sep 16 03:51:18 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sun, 16 Sep 2012 00:51:18 -0700 (PDT) Subject: datetime issue In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> Message-ID: <1774b70d-d3ad-414d-8460-bfa750b8f23f@googlegroups.com> dn = datetime.datetime.now() dd = datetime.timedelta(hours=2) date = dn + dd date = date.strftime( '%y-%m-%d %H:%M:%S' ) still giving me texas,us time for some reason From jyoung79 at kc.rr.com Sun Sep 16 04:02:09 2012 From: jyoung79 at kc.rr.com (jyoung79 at kc.rr.com) Date: Sun, 16 Sep 2012 8:02:09 +0000 Subject: Moving folders with content Message-ID: <20120916080209.DO2RN.176969.root@cdptpa-web13-z01> Thank you "Nobody" and Hans! > You may want to use the subprocess module to run 'ditto'. If > the destination folder does not exist, then ditto will copy MacOS > specific aspects such as resource forks, ACLs and HFS meta-data. This looks like a good direction to go. Maybe something like: >>> import os >>> import subprocess >>> >>> p1 = os.path.expanduser('~/Desktop/IN/Test/') >>> p2 = os.path.expanduser('~/Desktop/OUT/Test/') >>> >>> cmd = 'ditto -vV "' + p1 + '" "' + p2 + '"' >>> >>> v = subprocess.check_output(cmd, shell=True) >>> Copying /Users/jay/Desktop/IN/Test/ copying file ./.DS_Store ... 6148 bytes for ./.DS_Store copying file ./dude.txt ... 4 bytes for ./dude.txt copying file ./new.png ... 114469 bytes for ./new.png Jay From vinay_sajip at yahoo.co.uk Sun Sep 16 04:07:31 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 16 Sep 2012 01:07:31 -0700 (PDT) Subject: Python Logging: Specifying converter attribute of a log formatter in config file In-Reply-To: <97b8c5f2-eaa9-456a-b766-146ac65b879e@googlegroups.com> References: <97b8c5f2-eaa9-456a-b766-146ac65b879e@googlegroups.com> Message-ID: On Thursday, August 30, 2012 11:38:27 AM UTC+1, Radha Krishna Srimanthula wrote: > > Now, how do I specify the converter attribute (time.gmtime) in the above section? Sadly, there is no way of doing this using the configuration file, other than having e.g. a class UTCFormatter(logging.Formatter): converter = time.gmtime and then using a UTCFormatter in the configuration. From nikos.gr33k at gmail.com Sun Sep 16 04:18:11 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sun, 16 Sep 2012 01:18:11 -0700 (PDT) Subject: datetime issue In-Reply-To: <1774b70d-d3ad-414d-8460-bfa750b8f23f@googlegroups.com> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <1774b70d-d3ad-414d-8460-bfa750b8f23f@googlegroups.com> Message-ID: <30245c49-6166-4860-934b-b9999cb69755@googlegroups.com> ?? ???????, 16 ??????????? 2012 10:51:18 ?.?. UTC+3, ? ??????? ???????? ?????? ??????: > dn = datetime.datetime.now() > > dd = datetime.timedelta(hours=2) > > date = dn + dd > > date = date.strftime( '%y-%m-%d %H:%M:%S' ) > > > > still giving me texas,us time for some reason which is same as this: date = ( datetime.datetime.now() + datetime.timedelta(hours=2) ).strftime( '%y-%m-%d %H:%M:%S') this also doesnt work either: date = ( datetime.datetime.now(hours=2).strftime( '%y-%m-%d %H:%M:%S') if only it would! From nikos.gr33k at gmail.com Sun Sep 16 04:18:11 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sun, 16 Sep 2012 01:18:11 -0700 (PDT) Subject: datetime issue In-Reply-To: <1774b70d-d3ad-414d-8460-bfa750b8f23f@googlegroups.com> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <1774b70d-d3ad-414d-8460-bfa750b8f23f@googlegroups.com> Message-ID: <30245c49-6166-4860-934b-b9999cb69755@googlegroups.com> ?? ???????, 16 ??????????? 2012 10:51:18 ?.?. UTC+3, ? ??????? ???????? ?????? ??????: > dn = datetime.datetime.now() > > dd = datetime.timedelta(hours=2) > > date = dn + dd > > date = date.strftime( '%y-%m-%d %H:%M:%S' ) > > > > still giving me texas,us time for some reason which is same as this: date = ( datetime.datetime.now() + datetime.timedelta(hours=2) ).strftime( '%y-%m-%d %H:%M:%S') this also doesnt work either: date = ( datetime.datetime.now(hours=2).strftime( '%y-%m-%d %H:%M:%S') if only it would! From nikos.gr33k at gmail.com Sun Sep 16 04:25:30 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sun, 16 Sep 2012 01:25:30 -0700 (PDT) Subject: datetime issue In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> Message-ID: ?? ???????, 16 ??????????? 2012 8:53:57 ?.?. UTC+3, ? ??????? Dennis Lee Bieber ??????: > On Sat, 15 Sep 2012 22:15:38 -0700 (PDT), ???????? ?????? > > declaimed the following in > > gmane.comp.python.general: > > > > > > > > > > If i wanted to alter the following line, how would i write it? > > > > > > date = datetime.datetime.now()+datetime.timedelta(hours=2).strftime( '%y-%m-%d %H:%M:%S') > > > > > > But that doesnt work, > > > > What did you expect? Object methods bind tighter than operators so > > what you have is the equivalent of > > > > dn = datetime.datetime.now() > > dd = datetime.timedelta(hours=2).strftime(...) > > date = dn + dd > > > > Try > > > > >>> import datetime > > >>> date = datetime.datetime.now()+datetime.timedelta(hours=2).strftime( '%y-%m-%d %H:%M:%S') > > Traceback (most recent call last): > > File "", line 1, in > > AttributeError: 'datetime.timedelta' object has no attribute 'strftime' > > >>> date = (datetime.datetime.now()+datetime.timedelta(hours=2) ).strftime( '%y-%m-%d %H:%M:%S') > > >>> date > > '12-09-16 03:50:44' > > >>> > > > > Note the ( ) wrapping the the + clause, with strftime() applied to > > the result of that... > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ date = ( datetime.datetime.now() + datetime.timedelta(hours=8) ).strftime( '%y-%m-%d %H:%M:%S') but iam giving +8 hours which is the time difference between texas, us where the server sits and Greece's time. cant we somehow tell it to use GMT+2 ? also it would be nice if datetime.datetime.now(GMT+2) can be used. From nikos.gr33k at gmail.com Sun Sep 16 04:25:30 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sun, 16 Sep 2012 01:25:30 -0700 (PDT) Subject: datetime issue In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> Message-ID: ?? ???????, 16 ??????????? 2012 8:53:57 ?.?. UTC+3, ? ??????? Dennis Lee Bieber ??????: > On Sat, 15 Sep 2012 22:15:38 -0700 (PDT), ???????? ?????? > > declaimed the following in > > gmane.comp.python.general: > > > > > > > > > > If i wanted to alter the following line, how would i write it? > > > > > > date = datetime.datetime.now()+datetime.timedelta(hours=2).strftime( '%y-%m-%d %H:%M:%S') > > > > > > But that doesnt work, > > > > What did you expect? Object methods bind tighter than operators so > > what you have is the equivalent of > > > > dn = datetime.datetime.now() > > dd = datetime.timedelta(hours=2).strftime(...) > > date = dn + dd > > > > Try > > > > >>> import datetime > > >>> date = datetime.datetime.now()+datetime.timedelta(hours=2).strftime( '%y-%m-%d %H:%M:%S') > > Traceback (most recent call last): > > File "", line 1, in > > AttributeError: 'datetime.timedelta' object has no attribute 'strftime' > > >>> date = (datetime.datetime.now()+datetime.timedelta(hours=2) ).strftime( '%y-%m-%d %H:%M:%S') > > >>> date > > '12-09-16 03:50:44' > > >>> > > > > Note the ( ) wrapping the the + clause, with strftime() applied to > > the result of that... > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ date = ( datetime.datetime.now() + datetime.timedelta(hours=8) ).strftime( '%y-%m-%d %H:%M:%S') but iam giving +8 hours which is the time difference between texas, us where the server sits and Greece's time. cant we somehow tell it to use GMT+2 ? also it would be nice if datetime.datetime.now(GMT+2) can be used. From steve+comp.lang.python at pearwood.info Sun Sep 16 05:53:42 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Sep 2012 09:53:42 GMT Subject: datetime issue References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> Message-ID: <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sun, 16 Sep 2012 01:25:30 -0700, ???????? ?????? wrote: [...] You seem to be emailing python-list AND posting to comp.lang.python (or the gmane mirror). Please pick one, or the other, and not both, because the mailing list and the newsgroup are mirrors of each other. Anything you send to the mailing list will be mirrored on the newsgroup automatically, there is no need to manually duplicate the post. Thank you. -- Steven From nikos.gr33k at gmail.com Sun Sep 16 06:15:11 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sun, 16 Sep 2012 03:15:11 -0700 (PDT) Subject: datetime issue In-Reply-To: <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> ?? ???????, 16 ??????????? 2012 12:53:42 ?.?. UTC+3, ? ??????? Steven D'Aprano ??????: > On Sun, 16 Sep 2012 01:25:30 -0700, ???????? ?????? wrote: > > [...] > > > > You seem to be emailing python-list AND posting to comp.lang.python (or > > the gmane mirror). Please pick one, or the other, and not both, because > > the mailing list and the newsgroup are mirrors of each other. Anything > > you send to the mailing list will be mirrored on the newsgroup > > automatically, there is no need to manually duplicate the post. > > > > > > Thank you. > > > > > > -- > > Steven Iam sorry i didnt do that on purpose and i dont know how this is done. Iam positng via google groups using chrome, thats all i know. Whats a mailing list? Can i get responses to my mail instead of constantly check the google groups site? From hansmu at xs4all.nl Sun Sep 16 06:40:18 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sun, 16 Sep 2012 12:40:18 +0200 Subject: Moving folders with content In-Reply-To: References: Message-ID: <5055ac92$0$6940$e4fe514c@news2.news.xs4all.nl> On 16/09/12 10:02:09, jyoung79 at kc.rr.com wrote: > Thank you "Nobody" and Hans! You're welcome! >> You may want to use the subprocess module to run 'ditto'. If >> the destination folder does not exist, then ditto will copy MacOS >> specific aspects such as resource forks, ACLs and HFS meta-data. > > This looks like a good direction to go. Maybe something like: > >>>> import os >>>> import subprocess >>>> >>>> p1 = os.path.expanduser('~/Desktop/IN/Test/') >>>> p2 = os.path.expanduser('~/Desktop/OUT/Test/') >>>> >>>> cmd = 'ditto -vV "' + p1 + '" "' + p2 + '"' >>>> >>>> v = subprocess.check_output(cmd, shell=True) This looks iffy: it would break if there would be any double quotes in p1 or p2. You might think that os.path.expanduser would never expand '~' to something containing a double quote, but you'd be wrong: >>> import os >>> os.environ['HOME'] = 'gotcha!"; rm -rf ' >>> print(os.path.expanduser('~/Desktop/IN/Test/')) gotcha!"; rm -rf /Desktop/IN/Test/ It's easy and safer to avoid using 'shell=True' option: cmd = ['ditto', '-vV', p1, p2] v = subprocess.check_output(cmd, shell=False) In this case, the safer version also happens to be shorter and more readable. But you should get into the habit of using shell=False whenever possible, because it is much easier to get it right. Hope this helps, -- HansM From steve+comp.lang.python at pearwood.info Sun Sep 16 06:49:38 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Sep 2012 10:49:38 GMT Subject: datetime issue References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> Message-ID: <5055aec2$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sun, 16 Sep 2012 03:15:11 -0700, ???????? ?????? wrote: > Whats a mailing list? > Can i get responses to my mail instead of constantly check the google > groups site? http://mail.python.org/mailman/listinfo/python-list -- Steven From nikos.gr33k at gmail.com Sun Sep 16 06:54:45 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sun, 16 Sep 2012 03:54:45 -0700 (PDT) Subject: datetime issue In-Reply-To: <5055aec2$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <5055aec2$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <46626459-facd-4f5f-8907-033b1759b8b4@googlegroups.com> ?? ???????, 16 ??????????? 2012 1:49:38 ?.?. UTC+3, ? ??????? Steven D'Aprano ??????: > On Sun, 16 Sep 2012 03:15:11 -0700, ???????? ?????? wrote: > > > > > Whats a mailing list? > > > Can i get responses to my mail instead of constantly check the google > > > groups site? > > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > > Steven Thank you, i prefer to be notifies only to thread iam initiating or answering to not all of te threads. Is this possible? From steve+comp.lang.python at pearwood.info Sun Sep 16 07:34:34 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Sep 2012 11:34:34 GMT Subject: datetime issue References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <5055aec2$0$29981$c3e8da3$5496439d@news.astraweb.com> <46626459-facd-4f5f-8907-033b1759b8b4@googlegroups.com> Message-ID: <5055b94a$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sun, 16 Sep 2012 03:54:45 -0700, ???????? ?????? wrote: > ?? ???????, 16 ??????????? 2012 1:49:38 ?.?. UTC+3, ? ??????? Steven > D'Aprano ??????: >> On Sun, 16 Sep 2012 03:15:11 -0700, ???????? ?????? wrote: >> >> >> >> > Whats a mailing list? >> >> > Can i get responses to my mail instead of constantly check the google >> >> > groups site? >> >> >> >> http://mail.python.org/mailman/listinfo/python-list > Thank you, i prefer to be notifies only to thread iam initiating or > answering to not all of te threads. Is this possible? No. That's not how mailing lists work. Every email gets posted to all members, unless they go onto "No Mail", in which case they get no emails at all. You are not paying anything for the help you are receiving, except to give your own time in return to help others. We are all volunteers here, and nobody is going to force you to volunteer in return, but if everyone only received threads that they initiated, nobody would see new threads and nobody would get any answers at all. -- Steven From mayuresh at kathe.in Sun Sep 16 07:52:07 2012 From: mayuresh at kathe.in (Mayuresh Kathe) Date: Sun, 16 Sep 2012 17:22:07 +0530 Subject: newbie question : gedit as an ide Message-ID: new to the group, a quick hello to all. :-) does anyone use gedit as an 'ide' for python development? if yes, may i know the caveats against using 'idle', 'bpython', etc? thank you. From nikos.gr33k at gmail.com Sun Sep 16 07:56:34 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Sun, 16 Sep 2012 04:56:34 -0700 (PDT) Subject: datetime issue In-Reply-To: <5055b94a$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <5055aec2$0$29981$c3e8da3$5496439d@news.astraweb.com> <46626459-facd-4f5f-8907-033b1759b8b4@googlegroups.com> <5055b94a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: ?? ???????, 16 ??????????? 2012 2:34:34 ?.?. UTC+3, ? ??????? Steven D'Aprano ??????: > On Sun, 16 Sep 2012 03:54:45 -0700, ???????? ?????? wrote: > > > > > ?? ???????, 16 ??????????? 2012 1:49:38 ?.?. UTC+3, ? ??????? Steven > > > D'Aprano ??????: > > >> On Sun, 16 Sep 2012 03:15:11 -0700, ???????? ?????? wrote: > > >> > > >> > > >> > > >> > Whats a mailing list? > > >> > > >> > Can i get responses to my mail instead of constantly check the google > > >> > > >> > groups site? > > >> > > >> > > >> > > >> http://mail.python.org/mailman/listinfo/python-list > > > > > Thank you, i prefer to be notifies only to thread iam initiating or > > > answering to not all of te threads. Is this possible? > > > > No. That's not how mailing lists work. Every email gets posted to all > > members, unless they go onto "No Mail", in which case they get no emails > > at all. > > > > You are not paying anything for the help you are receiving, except to > > give your own time in return to help others. We are all volunteers here, > > and nobody is going to force you to volunteer in return, but if everyone > > only received threads that they initiated, nobody would see new threads > > and nobody would get any answers at all. > > > > > > > > -- > > Steven You are right, i will set to receive them all. But i dont know what to do about the thing you say that i double post. I use google groups i dont intentionally post to python-list too. How can i avoid that and just only post to python google group? From breamoreboy at yahoo.co.uk Sun Sep 16 08:28:17 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 16 Sep 2012 13:28:17 +0100 Subject: unit test strategy In-Reply-To: References: Message-ID: On 15/09/2012 03:59, Aaron Brady wrote: > Hello, > > I've developing a test script. There's a lot of repetition. I want to introduce a strategy for approaching it, but I don't want the program to be discredited because of the test script. Therefore, I'd like to know what people's reactions to and thoughts about it are. > > The first strategy I used created an iterator and advanced it between each step: > self.op_chain(range(5), ('add', 5)) > self.op_chain(range(5), ('add', -2), ('add', -1)) > self.op_chain(range(5), ('discard', -1), ('add', 5)) > self.op_chain_ok(range(5), ('update', [0, 1])) > Etc. > > I'm considering something more complicated. 'iN' creates iterator N, 'nN' advances iterator N, an exception calls 'assertRaises', and the rest are function calls. > dsi= dict.__setitem__ > ddi= dict.__delitem__ > dsd= dict.setdefault > KE= KeyError > IE= IterationError > self.chain(range(10), 'i0', (dsi, 0, 1), 'n0', (dsi, 10, 1), (IE, 'n0')) > self.chain(range(10), 'i0', 'n0', (dsd, 0, 0), 'n0', (dsd, 10, 1), (IE, 'n0')) > self.chain(range(10), 'i0', (KE, ddi, 10), 'n0', (ddi, 9), (IE, 'n0')) > > Do you think the 2nd version is legible? Could it interfere with the accuracy of the test? > http://docs.python.org/library/unittest.html#organizing-test-code seems to be a good starting point for avoiding repetition and introducing a strategy. -- Cheers. Mark Lawrence. From ben+python at benfinney.id.au Sun Sep 16 09:18:29 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 16 Sep 2012 23:18:29 +1000 Subject: Obnoxious postings from Google Groups (was: datetime issue) References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> Message-ID: <87wqzum7h6.fsf_-_@benfinney.id.au> ???????? ?????? writes: > Iam sorry i didnt do that on purpose and i dont know how this is done. > > Iam positng via google groups using chrome, thats all i know. It is becoming quite clear that some change has happened recently to Google Groups that makes posts coming from there rather more obnoxious than before. And there doesn't seem to be much its users can do except use something else. Using Google Groups for posting to Usenet has been a bad idea for a long time, but now it just seems to be a sure recipe for annoying the rest of us. Again, not something you have much control over, except to stop using Google Groups. -- \ ?Actually I made up the term ?object-oriented?, and I can tell | `\ you I did not have C++ in mind.? ?Alan Kay, creator of | _o__) Smalltalk, at OOPSLA 1997 | Ben Finney From gd.usenet at spamfence.net Sun Sep 16 09:22:11 2012 From: gd.usenet at spamfence.net (G=?UTF-8?B?w7xudGhlciBEaWV0cmljaA==?=) Date: Sun, 16 Sep 2012 15:22:11 +0200 Subject: datetime issue References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> Message-ID: In article , ???????? ?????? wrote: [...] >also it would be nice if datetime.datetime.now(GMT+2) can be used. In , one of the first answers to your question you were pointed to pytz. This module does exactly what you ask for: >>> import datetime >>> import pytz >>> greek_date = datetime.datetime.now(pytz.timezone('Europe/Athens')) >>> greek_date >>> print(greek_date) If you do a help(pytz), obviously after having imported pytz, you will get some information about the module. At the end of this help, there are some attributes listed. One of them is all_timezones. Guess what it contains? Best regards, G?nther PS: I didn't know pytz yet. But it took me just five minutes of reading the datetime documentation and trying pytz.timezone(), to get a working example. So I don't understand, why you didn't follow the proposal of trying pytz, but claimed, it wouldn't work. Can you explain, why ist doesn't work for you rsp. what is the error when it doesn't work? From roy at panix.com Sun Sep 16 09:22:16 2012 From: roy at panix.com (Roy Smith) Date: Sun, 16 Sep 2012 09:22:16 -0400 Subject: datetime issue References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> Message-ID: In article <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee at googlegroups.com>, ???????? ?????? wrote: > Iam sorry i didnt do that on purpose and i dont know how this is done. > > Iam positng via google groups using chrome, thats all i know. > > Whats a mailing list? Is it September already? From rosuav at gmail.com Sun Sep 16 09:32:56 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Sep 2012 23:32:56 +1000 Subject: datetime issue In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> Message-ID: On Sun, Sep 16, 2012 at 11:22 PM, Roy Smith wrote: > In article <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee at googlegroups.com>, > ???????? ?????? wrote: >> Iam sorry i didnt do that on purpose and i dont know how this is done. >> >> Iam positng via google groups using chrome, thats all i know. >> >> Whats a mailing list? > > Is it September already? Yes, it is; what does that mean in response to this question? Is there something about September that causes the question, or is it a once per month[1] question? ChrisA [1] http://tvtropes.org/pmwiki/pmwiki.php/Main/OncePerEpisode From rosuav at gmail.com Sun Sep 16 10:10:19 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 17 Sep 2012 00:10:19 +1000 Subject: datetime issue In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> Message-ID: On Mon, Sep 17, 2012 at 12:06 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> > Is it September already? >> >> Yes, it is; what does that mean in response to this question? Is there >> something about September that causes the question, or is it a once >> per month[1] question? > > http://en.wikipedia.org/wiki/Eternal_September Ohh, yes. I do remember reading about that. Yes, it is definitely September. Back in 1993, I wasn't yet started on networking. My dad ran things, because I was only nine years old, and he definitely (and quite rightly) didn't let me onto the internet. So I'm a tad young to know about these things beyond what I've read in the history books... ChrisA From rosuav at gmail.com Sun Sep 16 10:14:05 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 17 Sep 2012 00:14:05 +1000 Subject: newbie question : gedit as an ide In-Reply-To: References: Message-ID: On Sun, Sep 16, 2012 at 9:52 PM, Mayuresh Kathe wrote: > new to the group, a quick hello to all. :-) > does anyone use gedit as an 'ide' for python development? > if yes, may i know the caveats against using 'idle', 'bpython', etc? > > thank you. I never really liked gedit; when I first switched my primary development platform to Linux (from working on OS/2 and Windows), it was an Ubuntu, and I felt that gedit was less than satisfactory. The second GUI editor I tried was SciTE, which IMHO is distinctly superior. Mainly, though, I don't use any sort of IDE per se; the only "IDE-like" feature in my setup is SciTE's F7 key binding to run 'make', and then a properly-configured makefile in every directory that I work in. Between that and a terminal window for git commands, there's not really much more to look for in a development environment. ChrisA From jeanpierreda at gmail.com Sun Sep 16 10:28:16 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 16 Sep 2012 10:28:16 -0400 Subject: newbie question : gedit as an ide In-Reply-To: References: Message-ID: On Sun, Sep 16, 2012 at 7:52 AM, Mayuresh Kathe wrote: > new to the group, a quick hello to all. :-) > does anyone use gedit as an 'ide' for python development? > if yes, may i know the caveats against using 'idle', 'bpython', etc? bpython isn't an IDE, it's a good interactive interpreter. As for gedit as an editor... it's actually really bad, but fixable if you install plugins. e.g., it doesn't have builtin support for case sensitive / regexp search and so on, but these can be added so that gedit becomes tolerable. In fact, one of gedit's main advantages over many of its similar competitors (in particular I'm thinking of Kate) is that the plugin support is very strong, so if it doesn't do what you want, you can make it do what you want anyway. So, install / enable plugins. Lots of them. Or use an editor designed for programmers first, such as Kate or vim or emacs. -- Devin From nobody at nowhere.com Sun Sep 16 10:31:07 2012 From: nobody at nowhere.com (Nobody) Date: Sun, 16 Sep 2012 15:31:07 +0100 Subject: Moving folders with content References: <5055ac92$0$6940$e4fe514c@news2.news.xs4all.nl> Message-ID: On Sun, 16 Sep 2012 12:40:18 +0200, Hans Mulder wrote: > But you should get into the habit of using shell=False whenever > possible, because it is much easier to get it right. More accurately, you should get into the habit of passing a list as the first argument, rather than a string. On Unix-like systems (including Mac OS X), this effectively requires shell=False. Passing a list with shell=True has behaviour which is well-defined, but rarely useful (the first element of the list will be executed as a shell command, the remaining elements will be available via the shell variables $1, $2, etc within that command). On Windows, the list is converted to a command string using the same quoting rules regardless of the value of the shell= parameter. The difference is that shell=False requires the "executable" to actually be a binary executable, while shell=True allows it to be some other type of file (e.g. a batch file, Python script, etc). From moonhkt at gmail.com Sun Sep 16 11:09:01 2012 From: moonhkt at gmail.com (moonhkt) Date: Sun, 16 Sep 2012 08:09:01 -0700 (PDT) Subject: newbie question About O'Reilly "Python for Unix and Linux System Administration" ftp Mirror question Message-ID: <013b5f8b-d599-429b-9c07-3ff7306f4d5f@wz4g2000pbc.googlegroups.com> Hi All O'Reilly Book ISBN 978-986-6840-36-4. python --version Python 2.6.2 on AIX 5.3 Using this python to get files in ftp server. I got below error. What is the error meaning and how to fix ? ftp_mirror.py Traceback (most recent call last): File "/xx../shell/ftpmirror.py", line 80, in f = FTPSync(options.host, options.username, options.password, options.remote_dir, options.local_dir, opti ons.delete) File "xx../shell/ftpmirror.py", line 17, in __init__ self.conn.cwd(ftp_base_dir) File "/opt/freeware/lib/python2.6/ftplib.py", line 536, in cwd cmd = 'CWD ' + dirname TypeError: cannot concatenate 'str' and 'NoneType' objects Source : #!/usr/bin/env python import ftplib import os class FTPSync(object): def __init__(self, host, username, password, ftp_base_dir, local_base_dir, delete=False): self.host = host self.username = username self.password = password self.ftp_base_dir = ftp_base_dir self.local_base_dir = local_base_dir self.delete = delete self.conn = ftplib.FTP(host, username, password) self.conn.cwd(ftp_base_dir) try: os.makedirs(local_base_dir) except OSError: pass os.chdir(local_base_dir) def get_dirs_files(self): dir_res = [] self.conn.dir('.', dir_res.append) files = [f.split(None, 8)[-1] for f in dir_res if f.startswith('-')] dirs = [f.split(None, 8)[-1] for f in dir_res if f.startswith('d')] return (files, dirs) def walk(self, next_dir): print "Walking to", next_dir self.conn.cwd(next_dir) try: os.mkdir(next_dir) except OSError: pass os.chdir(next_dir) ftp_curr_dir = self.conn.pwd() local_curr_dir = os.getcwd() files, dirs = self.get_dirs_files() print "FILES:", files print "DIRS:", dirs for f in files: print next_dir, ':', f outf = open(f, 'wb') try: self.conn.retrbinary('RETR %s' % f, outf.write) finally: outf.close() if self.delete: print "Deleting", f self.conn.delete(f) for d in dirs: os.chdir(local_curr_dir) self.conn.cwd(ftp_curr_dir) self.walk(d) def run(self): self.walk('.') if __name__ == '__main__': from optparse import OptionParser parser = OptionParser() parser.add_option("-o", "--host", dest="host", action='store', help="FTP host") parser.add_option("-u", "--username", dest="username", action='store', help="FTP username") parser.add_option("-p", "--password", dest="password", action='store', help="FTP password") parser.add_option("-r", "--remote_dir", dest="remote_dir", action='store', help="FTP remote starting directory") parser.add_option("-l", "--local_dir", dest="local_dir", action='store', help="Local starting directory") parser.add_option("-d", "--delete", dest="delete", default=False, action='store_true', help="use regex parser") (options, args) = parser.parse_args() f = FTPSync(options.host, options.username, options.password, options.remote_dir, options.local_dir, options.delete) f.run() From python at mrabarnett.plus.com Sun Sep 16 11:27:16 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 16 Sep 2012 16:27:16 +0100 Subject: datetime issue In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> Message-ID: <5055EFD4.2000006@mrabarnett.plus.com> On 2012-09-16 09:25, ???????? ?????? wrote: [snip] > > date = ( datetime.datetime.now() + datetime.timedelta(hours=8) ).strftime( '%y-%m-%d %H:%M:%S') > > but iam giving +8 hours which is the time difference between texas, us where the server sits and Greece's time. > > cant we somehow tell it to use GMT+2 ? > > also it would be nice if datetime.datetime.now(GMT+2) can be used. > In programming, you need attention to details. My reply didn't use datetime.datetime.now(), it used datetime.datetime.utcnow(). datetime.datetime.now() gives the local time (local to the system on which it is running). datetime.datetime.utcnow() gives the UTC (GMT) time, which is the same everywhere. The line should be this: date = (datetime.datetime.utcnow() + datetime.timedelta(hours=8) ).strftime('%Y-%m-%d %H:%M:%S') I've also used '%Y' instead of '%y' because I prefer 4 digits for the year. From joel.goldstick at gmail.com Sun Sep 16 11:33:19 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 16 Sep 2012 11:33:19 -0400 Subject: newbie question About O'Reilly "Python for Unix and Linux System Administration" ftp Mirror question In-Reply-To: <013b5f8b-d599-429b-9c07-3ff7306f4d5f@wz4g2000pbc.googlegroups.com> References: <013b5f8b-d599-429b-9c07-3ff7306f4d5f@wz4g2000pbc.googlegroups.com> Message-ID: On Sun, Sep 16, 2012 at 11:09 AM, moonhkt wrote: > Hi All > > > O'Reilly Book ISBN 978-986-6840-36-4. > > python --version > Python 2.6.2 on AIX 5.3 > > Using this python to get files in ftp server. > > I got below error. What is the error meaning and how to fix ? > > ftp_mirror.py > Traceback (most recent call last): > File "/xx../shell/ftpmirror.py", line 80, in > f = FTPSync(options.host, options.username, options.password, > options.remote_dir, options.local_dir, opti > ons.delete) > File "xx../shell/ftpmirror.py", line 17, in __init__ > self.conn.cwd(ftp_base_dir) > File "/opt/freeware/lib/python2.6/ftplib.py", line 536, in cwd > cmd = 'CWD ' + dirname > TypeError: cannot concatenate 'str' and 'NoneType' objects > > Source : > > #!/usr/bin/env python > > import ftplib > import os > > class FTPSync(object): > def __init__(self, host, username, password, ftp_base_dir, > local_base_dir, delete=False): > self.host = host > self.username = username > self.password = password > self.ftp_base_dir = ftp_base_dir > self.local_base_dir = local_base_dir > self.delete = delete > > self.conn = ftplib.FTP(host, username, password) > self.conn.cwd(ftp_base_dir) > try: > os.makedirs(local_base_dir) > except OSError: > pass > os.chdir(local_base_dir) > def get_dirs_files(self): > dir_res = [] > self.conn.dir('.', dir_res.append) > files = [f.split(None, 8)[-1] for f in dir_res if > f.startswith('-')] > dirs = [f.split(None, 8)[-1] for f in dir_res if > f.startswith('d')] > return (files, dirs) > def walk(self, next_dir): > print "Walking to", next_dir > self.conn.cwd(next_dir) > try: > os.mkdir(next_dir) > except OSError: > pass > os.chdir(next_dir) > > ftp_curr_dir = self.conn.pwd() > local_curr_dir = os.getcwd() > > files, dirs = self.get_dirs_files() > print "FILES:", files > print "DIRS:", dirs > for f in files: > print next_dir, ':', f > outf = open(f, 'wb') > try: > self.conn.retrbinary('RETR %s' % f, outf.write) > finally: > outf.close() > if self.delete: > print "Deleting", f > self.conn.delete(f) > for d in dirs: > os.chdir(local_curr_dir) > self.conn.cwd(ftp_curr_dir) > self.walk(d) > > def run(self): > self.walk('.') > > > if __name__ == '__main__': > from optparse import OptionParser > parser = OptionParser() > parser.add_option("-o", "--host", dest="host", > action='store', help="FTP host") > parser.add_option("-u", "--username", dest="username", > action='store', help="FTP username") > parser.add_option("-p", "--password", dest="password", > action='store', help="FTP password") > parser.add_option("-r", "--remote_dir", dest="remote_dir", > action='store', help="FTP remote starting directory") > parser.add_option("-l", "--local_dir", dest="local_dir", > action='store', help="Local starting directory") > parser.add_option("-d", "--delete", dest="delete", default=False, > action='store_true', help="use regex parser") > > (options, args) = parser.parse_args() comment the next line , then print the parameters and see what they are. That should get you started. > #f = FTPSync(options.host, options.username, options.password, > # options.remote_dir, options.local_dir, options.delete) f = print(options.host, options.username, options.password, options.remote_dir, options.local_dir, options.delete) > f.run() > > -- > http://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick From pandora.koura at gmail.com Sun Sep 16 11:40:42 2012 From: pandora.koura at gmail.com (pandora.koura at gmail.com) Date: Sun, 16 Sep 2012 08:40:42 -0700 (PDT) Subject: datetime issue In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> Message-ID: <5680604e-98e5-48c1-b5ac-9b837bc16770@googlegroups.com> ?? ???????, 16 ??????????? 2012 6:30:15 ?.?. UTC+3, ? ??????? MRAB ??????: > On 2012-09-16 09:25, ???????? ?????? wrote: > > [snip] > > > > > > date = ( datetime.datetime.now() + datetime.timedelta(hours=8) ).strftime( '%y-%m-%d %H:%M:%S') > > > > > > but iam giving +8 hours which is the time difference between texas, us where the server sits and Greece's time. > > > > > > cant we somehow tell it to use GMT+2 ? > > > > > > also it would be nice if datetime.datetime.now(GMT+2) can be used. > > > > > In programming, you need attention to details. > > > > My reply didn't use datetime.datetime.now(), it used > > datetime.datetime.utcnow(). > > > > datetime.datetime.now() gives the local time (local to the system on > > which it is running). > > > > datetime.datetime.utcnow() gives the UTC (GMT) time, which is the same > > everywhere. > > > > The line should be this: > > > > date = (datetime.datetime.utcnow() + datetime.timedelta(hours=8) > > ).strftime('%Y-%m-%d %H:%M:%S') > > > > I've also used '%Y' instead of '%y' because I prefer 4 digits for the year. Cant it be written more easily as: date = (datetime.datetime.utcnow(+2) i know this is not thhe correct syntax but it just needs a way to add GMT+2 hours since utc=gmt From pandora.koura at gmail.com Sun Sep 16 11:40:42 2012 From: pandora.koura at gmail.com (pandora.koura at gmail.com) Date: Sun, 16 Sep 2012 08:40:42 -0700 (PDT) Subject: datetime issue In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> Message-ID: <5680604e-98e5-48c1-b5ac-9b837bc16770@googlegroups.com> ?? ???????, 16 ??????????? 2012 6:30:15 ?.?. UTC+3, ? ??????? MRAB ??????: > On 2012-09-16 09:25, ???????? ?????? wrote: > > [snip] > > > > > > date = ( datetime.datetime.now() + datetime.timedelta(hours=8) ).strftime( '%y-%m-%d %H:%M:%S') > > > > > > but iam giving +8 hours which is the time difference between texas, us where the server sits and Greece's time. > > > > > > cant we somehow tell it to use GMT+2 ? > > > > > > also it would be nice if datetime.datetime.now(GMT+2) can be used. > > > > > In programming, you need attention to details. > > > > My reply didn't use datetime.datetime.now(), it used > > datetime.datetime.utcnow(). > > > > datetime.datetime.now() gives the local time (local to the system on > > which it is running). > > > > datetime.datetime.utcnow() gives the UTC (GMT) time, which is the same > > everywhere. > > > > The line should be this: > > > > date = (datetime.datetime.utcnow() + datetime.timedelta(hours=8) > > ).strftime('%Y-%m-%d %H:%M:%S') > > > > I've also used '%Y' instead of '%y' because I prefer 4 digits for the year. Cant it be written more easily as: date = (datetime.datetime.utcnow(+2) i know this is not thhe correct syntax but it just needs a way to add GMT+2 hours since utc=gmt From pandora.koura at gmail.com Sun Sep 16 11:41:44 2012 From: pandora.koura at gmail.com (pandora.koura at gmail.com) Date: Sun, 16 Sep 2012 08:41:44 -0700 (PDT) Subject: Obnoxious postings from Google Groups (was: datetime issue) In-Reply-To: <87wqzum7h6.fsf_-_@benfinney.id.au> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> Message-ID: <70e4dc2e-4030-4ac3-b78d-a51630816f7c@googlegroups.com> ?? ???????, 16 ??????????? 2012 4:18:50 ?.?. UTC+3, ? ??????? Ben Finney ??????: > ???????? ?????? writes: > > > > > Iam sorry i didnt do that on purpose and i dont know how this is done. > > > > > > Iam positng via google groups using chrome, thats all i know. > > > > It is becoming quite clear that some change has happened recently to > > Google Groups that makes posts coming from there rather more obnoxious > > than before. And there doesn't seem to be much its users can do except > > use something else. > > > > Using Google Groups for posting to Usenet has been a bad idea for a long > > time, but now it just seems to be a sure recipe for annoying the rest of > > us. Again, not something you have much control over, except to stop > > using Google Groups. > > > > -- > > \ ?Actually I made up the term ?object-oriented?, and I can tell | > > `\ you I did not have C++ in mind.? ?Alan Kay, creator of | > > _o__) Smalltalk, at OOPSLA 1997 | > > Ben Finney If i ditch google groups what application can i use in Windows 8 to post to this newsgroup and what newsserver too? From rosuav at gmail.com Sun Sep 16 11:41:52 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 17 Sep 2012 01:41:52 +1000 Subject: newbie question About O'Reilly "Python for Unix and Linux System Administration" ftp Mirror question In-Reply-To: <013b5f8b-d599-429b-9c07-3ff7306f4d5f@wz4g2000pbc.googlegroups.com> References: <013b5f8b-d599-429b-9c07-3ff7306f4d5f@wz4g2000pbc.googlegroups.com> Message-ID: On Mon, Sep 17, 2012 at 1:09 AM, moonhkt wrote: > Hi All > > O'Reilly Book ISBN 978-986-6840-36-4. > > python --version > Python 2.6.2 on AIX 5.3 Hi! Thanks for this, good information to open with. > Using this python to get files in ftp server. > > I got below error. What is the error meaning and how to fix ? > > ftp_mirror.py > Traceback (most recent call last): > File "/xx../shell/ftpmirror.py", line 80, in > f = FTPSync(options.host, options.username, options.password, > options.remote_dir, options.local_dir, opti > ons.delete) > File "xx../shell/ftpmirror.py", line 17, in __init__ > self.conn.cwd(ftp_base_dir) > File "/opt/freeware/lib/python2.6/ftplib.py", line 536, in cwd > cmd = 'CWD ' + dirname > TypeError: cannot concatenate 'str' and 'NoneType' objects NoneType is the type of the singleton object None. Why are you getting None where you ought to be providing a directory name? Heavily trimmed code follows: > def __init__(self, host, username, password, ftp_base_dir, > local_base_dir, delete=False): > self.conn.cwd(ftp_base_dir) > parser.add_option("-r", "--remote_dir", dest="remote_dir", > action='store', help="FTP remote starting directory") > f = FTPSync(options.host, options.username, options.password, > options.remote_dir, options.local_dir, options.delete) If you don't pass -r/--remote_dir to your script, then (presumably - I haven't actually used optparse so this is glarked from context) options.remote_dir is being set to, or left at, None. A quick look at the docs suggests that one solution is to add a default value to the options: http://docs.python.org/library/optparse.html#default-values Alternatively, treat the options as mandatory, and provide them on the command line. Side point: When you go to the docs page there, you may notice that optparse is deprecated in favour of argparse. May as well continue the tutorial with what they recommend, but it's probably worth having a look at argparse eventually. Hope that helps! Chris Angelico From pandora.koura at gmail.com Sun Sep 16 11:43:14 2012 From: pandora.koura at gmail.com (pandora.koura at gmail.com) Date: Sun, 16 Sep 2012 08:43:14 -0700 (PDT) Subject: datetime issue In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> Message-ID: ?? ???????, 16 ??????????? 2012 4:23:02 ?.?. UTC+3, ? ??????? G?nther Dietrich ??????: > In article , > > ???????? ?????? wrote: > > > > [...] > > > > >also it would be nice if datetime.datetime.now(GMT+2) can be used. > > > > In , one of > > the first answers to your question you were pointed to pytz. This module > > does exactly what you ask for: > > > > >>> import datetime > > >>> import pytz > > >>> greek_date = datetime.datetime.now(pytz.timezone('Europe/Athens')) > > >>> greek_date > > >>> print(greek_date) > > > > If you do a help(pytz), obviously after having imported pytz, you will > > get some information about the module. At the end of this help, there > > are some attributes listed. One of them is all_timezones. Guess what it > > contains? > > > > > > > > Best regards, > > > > G?nther > > > > > > > > > > PS: I didn't know pytz yet. But it took me just five minutes of reading > > the datetime documentation and trying pytz.timezone(), to get a working > > example. > > So I don't understand, why you didn't follow the proposal of trying > > pytz, but claimed, it wouldn't work. > > Can you explain, why ist doesn't work for you rsp. what is the error > > when it doesn't work? import pytz fails in my webhost unfortunately :( This module is not supported by hostgator. From pandora.koura at gmail.com Sun Sep 16 11:44:36 2012 From: pandora.koura at gmail.com (pandora.koura at gmail.com) Date: Sun, 16 Sep 2012 08:44:36 -0700 (PDT) Subject: Obnoxious postings from Google Groups (was: datetime issue) In-Reply-To: <87wqzum7h6.fsf_-_@benfinney.id.au> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> Message-ID: <0f33d5ff-216e-4de3-8ae5-aad7fefe8bc9@googlegroups.com> Whaen i tried to post just now by hitting sumbit, google groups told me that the following addresssed has benn found in this thread! i guess is used them all to notify everything! cdf072b2-7359-4417-b1e4-d984e4317091 at googlegroups.com mailman.774.1347735926.27098.python-list at python.org nikos.gr33k at gmail.com From rosuav at gmail.com Sun Sep 16 11:54:08 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 17 Sep 2012 01:54:08 +1000 Subject: datetime issue In-Reply-To: <5680604e-98e5-48c1-b5ac-9b837bc16770@googlegroups.com> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5680604e-98e5-48c1-b5ac-9b837bc16770@googlegroups.com> Message-ID: On Mon, Sep 17, 2012 at 1:40 AM, wrote: > Cant it be written more easily as: > date = (datetime.datetime.utcnow(+2) > > i know this is not thhe correct syntax but it just needs a way to add GMT+2 hours since utc=gmt I've dithered about whether to open this can of worms or let sleeping dogs lie, and I finally decided to make some metaphor potpourri. Simple UTC offsets are not the same thing as local time. There are a variety of other considerations, but the main one is Daylight Robbery Time, where every government wants to put its own stamp on things by fiddling with the DST rules a bit. Most places will move their clocks an hour forward for summer and then back for winter. But! * Some places are sensible and don't have DST at all (eg Australia/Queensland, America/Arizona) * Northern hemisphere summer corresponds to southern hemisphere winter, and vice versa * Everyone has a different way of defining the boundaries of summer and winter * And just to confuse us all, Irish Standard Time is used in summer, and they *subtract* an hour for winter time! The only way to handle timezones correctly and keep yourself even marginally sane is to hand the job on to somebody else. I dodged the whole issue by letting our Postgres database handle everything for us (date/time formats, timezones, the lot), and having our internal systems all just work in UTC. You'll likely find it easiest to do the same thing with a Python library. Just don't try to pretend to yourself that Greece uses GMT+2, because it's not that simple. For one thing, it's currently summer there... ChrisA From rosuav at gmail.com Sun Sep 16 11:57:22 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 17 Sep 2012 01:57:22 +1000 Subject: Obnoxious postings from Google Groups (was: datetime issue) In-Reply-To: <0f33d5ff-216e-4de3-8ae5-aad7fefe8bc9@googlegroups.com> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> <0f33d5ff-216e-4de3-8ae5-aad7fefe8bc9@googlegroups.com> Message-ID: On Mon, Sep 17, 2012 at 1:44 AM, wrote: > Whaen i tried to post just now by hitting sumbit, google groups told me that the following addresssed has benn found in this thread! i guess is used them all to notify everything! > > cdf072b2-7359-4417-b1e4-d984e4317091 at googlegroups.com > mailman.774.1347735926.27098.python-list at python.org > nikos.gr33k at gmail.com Ah. Did you then send to all three? Just a wild guess, but I'm thinking that might be the cause of post duplication... ChrisA From joel.goldstick at gmail.com Sun Sep 16 11:57:56 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 16 Sep 2012 11:57:56 -0400 Subject: Obnoxious postings from Google Groups (was: datetime issue) In-Reply-To: <70e4dc2e-4030-4ac3-b78d-a51630816f7c@googlegroups.com> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> <70e4dc2e-4030-4ac3-b78d-a51630816f7c@googlegroups.com> Message-ID: On Sun, Sep 16, 2012 at 11:41 AM, wrote: > ?? ???????, 16 ??????????? 2012 4:18:50 ?.?. UTC+3, ? ??????? Ben Finney ??????: >> ???????? ?????? writes: >> >> >> >> > Iam sorry i didnt do that on purpose and i dont know how this is done. >> >> > >> >> > Iam positng via google groups using chrome, thats all i know. >> >> > > >> >> It is becoming quite clear that some change has happened recently to >> >> Google Groups that makes posts coming from there rather more obnoxious >> >> than before. And there doesn't seem to be much its users can do except >> >> use something else. >> >> >> >> Using Google Groups for posting to Usenet has been a bad idea for a long >> >> time, but now it just seems to be a sure recipe for annoying the rest of >> >> us. Again, not something you have much control over, except to stop >> >> using Google Groups. >> >> >> >> -- >> >> \ ?Actually I made up the term ?object-oriented?, and I can tell | >> >> `\ you I did not have C++ in mind.? ?Alan Kay, creator of | >> >> _o__) Smalltalk, at OOPSLA 1997 | >> >> Ben Finney > > > If i ditch google groups what application can i use in Windows 8 to post to this newsgroup and what newsserver too? > -- > http://mail.python.org/mailman/listinfo/python-list email client to python-list at python.org -- Joel Goldstick From pandora.koura at gmail.com Sun Sep 16 12:02:42 2012 From: pandora.koura at gmail.com (pandora.koura at gmail.com) Date: Sun, 16 Sep 2012 09:02:42 -0700 (PDT) Subject: Obnoxious postings from Google Groups (was: datetime issue) In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> <0f33d5ff-216e-4de3-8ae5-aad7fefe8bc9@googlegroups.com> Message-ID: <6e2cc5f4-06fd-4814-b8dc-7ffa7f448af4@googlegroups.com> > > Ah. Did you then send to all three? Just a wild guess, but I'm > > thinking that might be the cause of post duplication... > > > > ChrisA I had no choise, it doesnt let me pick one, it just notifies me that it will posted to these 3. From pandora.koura at gmail.com Sun Sep 16 12:02:42 2012 From: pandora.koura at gmail.com (pandora.koura at gmail.com) Date: Sun, 16 Sep 2012 09:02:42 -0700 (PDT) Subject: Obnoxious postings from Google Groups (was: datetime issue) In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> <0f33d5ff-216e-4de3-8ae5-aad7fefe8bc9@googlegroups.com> Message-ID: <6e2cc5f4-06fd-4814-b8dc-7ffa7f448af4@googlegroups.com> > > Ah. Did you then send to all three? Just a wild guess, but I'm > > thinking that might be the cause of post duplication... > > > > ChrisA I had no choise, it doesnt let me pick one, it just notifies me that it will posted to these 3. From pandora.koura at gmail.com Sun Sep 16 12:06:30 2012 From: pandora.koura at gmail.com (pandora.koura at gmail.com) Date: Sun, 16 Sep 2012 09:06:30 -0700 (PDT) Subject: Obnoxious postings from Google Groups (was: datetime issue) In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> <70e4dc2e-4030-4ac3-b78d-a51630816f7c@googlegroups.com> Message-ID: <2d82c30b-406f-434f-b61a-ca634dbed1ce@googlegroups.com> > > > http://mail.python.org/mailman/listinfo/python-list > > > > email client to python-list at python.org > wait a minute! i must use my ISP's news server and then post o comp.lang.python no? What is python-list at python.org how can i post there? From pandora.koura at gmail.com Sun Sep 16 12:06:30 2012 From: pandora.koura at gmail.com (pandora.koura at gmail.com) Date: Sun, 16 Sep 2012 09:06:30 -0700 (PDT) Subject: Obnoxious postings from Google Groups (was: datetime issue) In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> <70e4dc2e-4030-4ac3-b78d-a51630816f7c@googlegroups.com> Message-ID: <2d82c30b-406f-434f-b61a-ca634dbed1ce@googlegroups.com> > > > http://mail.python.org/mailman/listinfo/python-list > > > > email client to python-list at python.org > wait a minute! i must use my ISP's news server and then post o comp.lang.python no? What is python-list at python.org how can i post there? From nikos.gr33k at gmail.com Sun Sep 16 12:11:39 2012 From: nikos.gr33k at gmail.com (Nick the Gr33k) Date: Sun, 16 Sep 2012 19:11:39 +0300 Subject: testing.... Message-ID: <5055FA3B.3080505@gmail.com> Test to see if it works. From news at blinne.net Sun Sep 16 12:13:36 2012 From: news at blinne.net (Alexander Blinne) Date: Sun, 16 Sep 2012 18:13:36 +0200 Subject: Python presentations In-Reply-To: References: <06a1a81b-246b-4e7b-ba34-4701f46889c8@googlegroups.com> <50525f48$0$6573$9b4e6d93@newsspool3.arcor-online.net> <5053196e$0$6578$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <5055fab1$0$6579$9b4e6d93@newsspool3.arcor-online.net> On 14.09.2012 14:19, Chris Angelico wrote: > Err, yes, I did mean ** there. The extra multiplications may be > slower, but which is worse? Lots of list additions, or lots of integer > powers? In the absence of clear and compelling evidence, I'd be > inclined to go with the list comp - and what's more, to skip this > function altogether and use the list comp directly where it's needed. I did some timing with the following versions of the function: def powerlist1(x, n): result=[1] for i in xrange(n-1): result.append(result[-1]*x) return result def powerlist2(x,n): if n==1: return [1] p = powerlist3(x,n-1) p.append(p[-1]*x) return p def powerlist3(x,n): return [x**i for i in xrange(n)] with Python 2.7 you are quite right, i used x=4. Below n=26 powerlist3 is the fastest version, for n>26 powerlist1 is faster, powerlist2 is always slower than both. With Pypy there is a completely different picture, with n<30 powerlist2 is way faster then the other two, but then powerlist1 is again faster for greater n, somehow because now C long int cannot be used any longer. for really big n powerlist3 always takes very much time :) Alex From rosuav at gmail.com Sun Sep 16 12:19:58 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 17 Sep 2012 02:19:58 +1000 Subject: Python presentations In-Reply-To: <5055fab1$0$6579$9b4e6d93@newsspool3.arcor-online.net> References: <06a1a81b-246b-4e7b-ba34-4701f46889c8@googlegroups.com> <50525f48$0$6573$9b4e6d93@newsspool3.arcor-online.net> <5053196e$0$6578$9b4e6d93@newsspool3.arcor-online.net> <5055fab1$0$6579$9b4e6d93@newsspool3.arcor-online.net> Message-ID: On Mon, Sep 17, 2012 at 2:13 AM, Alexander Blinne wrote: > def powerlist3(x,n): > return [x**i for i in xrange(n)] > > for really big n powerlist3 always takes very much time :) I would reiterate that a really big n is a really unusual use case for a function like this, except that... I frankly can't think of *any* use case for it!! But for many many applications, the simplicity and readability of a list comp instead of a function is usually going to outweigh the performance differences. However, it doesn't surprise me that individually raising a number to successive powers is slower than iterative multiplication, assuming you can't massively optimize eg with powers of 2 and bit shifts. ChrisA From joel.goldstick at gmail.com Sun Sep 16 12:23:19 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 16 Sep 2012 12:23:19 -0400 Subject: Obnoxious postings from Google Groups (was: datetime issue) In-Reply-To: <2d82c30b-406f-434f-b61a-ca634dbed1ce@googlegroups.com> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> <70e4dc2e-4030-4ac3-b78d-a51630816f7c@googlegroups.com> <2d82c30b-406f-434f-b61a-ca634dbed1ce@googlegroups.com> Message-ID: On Sun, Sep 16, 2012 at 12:06 PM, wrote: > >> >> > http://mail.python.org/mailman/listinfo/python-list >> >> >> >> email client to python-list at python.org >> > > wait a minute! i must use my ISP's news server and then post o comp.lang.python no? > > What is python-list at python.org how can i post there? > -- > http://mail.python.org/mailman/listinfo/python-list go to the url http://mail.python.org/mailman/listinfo/python-list sign up and use your email client instead. -- Joel Goldstick From gheskett at wdtv.com Sun Sep 16 12:28:01 2012 From: gheskett at wdtv.com (Gene Heskett) Date: Sun, 16 Sep 2012 12:28:01 -0400 Subject: Obnoxious postings from Google Groups (was: datetime issue) In-Reply-To: <0f33d5ff-216e-4de3-8ae5-aad7fefe8bc9@googlegroups.com> References: <87wqzum7h6.fsf_-_@benfinney.id.au> <0f33d5ff-216e-4de3-8ae5-aad7fefe8bc9@googlegroups.com> Message-ID: <201209161228.01847.gheskett@wdtv.com> On Sunday 16 September 2012 12:08:47 pandora.koura at gmail.com did opine: > Whaen i tried to post just now by hitting sumbit, google groups told me > that the following addresssed has benn found in this thread! i guess is > used them all to notify everything! > > cdf072b2-7359-4417-b1e4-d984e4317091 at googlegroups.com > mailman.774.1347735926.27098.python-list at python.org > nikos.gr33k at gmail.com Look, this googlegroups thing acting as a spam gateway has long since gotten old. Whatever agent/program you are using must be a busted windows application because it is not showing you the last line of every post that comes through the list server which is: There is, immediately above that line a '-- ' (note the space after, and its always after a linefeed or carriage return so its the first character of a line, and its code to all sane email agents that anything below it is a signature and not to be copied into a reply. Windows email tends to clip it off and a windows user will never see it! So that is why many of us lament, in long strings of expletives, the brokenness of windows email agents. Subscribing to the mailing list is a 2 step process. First you click on the above link and fill out the form and "submit" it. That will, in a minute or so, cause an email to be sent to the address you used in the form. You MUST reply to that message to confirm the subscription. Whatever email agent you use from there is up to you, but I'd suggest Thunderbird. I personally am partial to kmail, but then I'm running linux on everything here, no M$ stuff allowed on the premises. Its not open for discussion and has not been in 28 years since I discovered the trs-80 color computer and an operating system for it called OS9. Sorry folks, my rant for the day because of that gateway. 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) My web page: is up! Succumb to natural tendencies. Be hateful and boring. From tjreedy at udel.edu Sun Sep 16 12:30:36 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 16 Sep 2012 12:30:36 -0400 Subject: Obnoxious postings from Google Groups In-Reply-To: <70e4dc2e-4030-4ac3-b78d-a51630816f7c@googlegroups.com> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> <70e4dc2e-4030-4ac3-b78d-a51630816f7c@googlegroups.com> Message-ID: On 9/16/2012 11:41 AM, pandora.koura at gmail.com wrote: > If i ditch google groups PLEASE DO > what application can i use in Windows 8 to post to this newsgroup > and what newsserver too? news.gmane.org is a free newsserver that mirrors 1000s of technical email lists. python-list is gmane.comp.python.general. There are 100s of other gmane.comp.python.* groups. I use Thunderbird on Win7 because it does both mail and news. I previously used Outlook Express for same. There are others. -- Terry Jan Reedy From gheskett at wdtv.com Sun Sep 16 12:32:15 2012 From: gheskett at wdtv.com (Gene Heskett) Date: Sun, 16 Sep 2012 12:32:15 -0400 Subject: Obnoxious postings from Google Groups (was: datetime issue) In-Reply-To: <2d82c30b-406f-434f-b61a-ca634dbed1ce@googlegroups.com> References: <2d82c30b-406f-434f-b61a-ca634dbed1ce@googlegroups.com> Message-ID: <201209161232.15697.gheskett@wdtv.com> On Sunday 16 September 2012 12:29:39 pandora.koura at gmail.com did opine: > > > http://mail.python.org/mailman/listinfo/python-list > > > > email client to python-list at python.org > > wait a minute! i must use my ISP's news server and then post o > comp.lang.python no? No. > What is python-list at python.org how can i post there? Install thunderbird. Its a real email agent, even on a windows box. But first you must subscribe as I discussed in a previous msg. 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) My web page: is up! Q: How was Thomas J. Watson buried? A: 9 edge down. From steve+comp.lang.python at pearwood.info Sun Sep 16 12:52:57 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Sep 2012 16:52:57 GMT Subject: Obnoxious postings from Google Groups (was: datetime issue) References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> <70e4dc2e-4030-4ac3-b78d-a51630816f7c@googlegroups.com> Message-ID: <505603e9$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sun, 16 Sep 2012 08:41:44 -0700, pandora.koura wrote: > If i ditch google groups what application can i use in Windows 8 to post > to this newsgroup and what newsserver too? Google is your friend. Do try to find the answer to your questions before asking here. Search for "usenet news reader application". Or use Thunderbird. For the news server, you use your ISP's newserver, if they offer one, or Gmane, or any of dozens of commercial news providers who will give you access to one for a small fee. -- Steven From steve+comp.lang.python at pearwood.info Sun Sep 16 12:54:54 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Sep 2012 16:54:54 GMT Subject: Obnoxious postings from Google Groups (was: datetime issue) References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> <70e4dc2e-4030-4ac3-b78d-a51630816f7c@googlegroups.com> <2d82c30b-406f-434f-b61a-ca634dbed1ce@googlegroups.com> Message-ID: <5056045e$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sun, 16 Sep 2012 09:06:30 -0700, pandora.koura wrote: >> > http://mail.python.org/mailman/listinfo/python-list > What is python-list at python.org how can i post there? It's the same thing it was when I posted the above URL a few hours ago. Didn't you follow the link before? It has instructions there. -- Steven From charles.salvia316 at gmail.com Sun Sep 16 13:08:58 2012 From: charles.salvia316 at gmail.com (css322) Date: Sun, 16 Sep 2012 10:08:58 -0700 (PDT) Subject: Using Py_AddPendingCall Message-ID: I have an embedded Python program which runs in a thread in C. When the Python interpreter switches thread context (yielding control to another thread), I'd like to be notified so I can perform certain necessary operations. It seems that Py_AddPendingCall is exactly what I'm looking for. However, the API docs are pretty brief on this function, and I'm confused as to how Py_AddPendingCall is supposed to be used. From reading the docs, my understanding is that: (1) A worker thread calls Py_AddPendingCall and assigns a handler function. (2) When the Python interpreter runs, it calls the handler function whenever it yields control to another thread (3) The handler itself is executed in the main interpreter thread, with the GIL acquired I've googled around for example code showing how to use Py_AddPendingCall, but I can't find anything. My own attempt to use it simply doesn't work. The handler is just never called. My worker thread code: const char* PYTHON_CODE = "while True:\n" " for i in range(0,10): print(i)\n" "\n"; int handler(void* arg) { printf("Pending Call invoked!\n"); abort(); } void worker_thread() { PyGILState_STATE state = PyGILState_Ensure(); Py_AddPendingCall(&handler, NULL); PyRun_SimpleString(PYTHON_CODE); PyGILState_Release(state); } In this example, worker_thread is invoked in C as a pthread worker thread. This loops infinitely, but the pending call handler is never invoked. So,obviously I'm not understanding the docs correctly. How is Py_AddPendingCall is supposed to be used? From steve+comp.lang.python at pearwood.info Sun Sep 16 13:35:47 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Sep 2012 17:35:47 GMT Subject: Python presentations References: <06a1a81b-246b-4e7b-ba34-4701f46889c8@googlegroups.com> <50525f48$0$6573$9b4e6d93@newsspool3.arcor-online.net> <5053196e$0$6578$9b4e6d93@newsspool3.arcor-online.net> <5055fab1$0$6579$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <50560df2$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sun, 16 Sep 2012 18:13:36 +0200, Alexander Blinne wrote: > I did some timing with the following versions of the function: > > def powerlist1(x, n): > result=[1] > for i in xrange(n-1): > result.append(result[-1]*x) > return result > > def powerlist2(x,n): > if n==1: > return [1] > p = powerlist3(x,n-1) > p.append(p[-1]*x) > return p Is that a typo? I think you mean to make a recursive call to powerlist2, not a non-recursive call to powerlist3. > def powerlist3(x,n): > return [x**i for i in xrange(n)] > > with Python 2.7 you are quite right, i used x=4. Below n=26 powerlist3 > is the fastest version, for n>26 powerlist1 is faster, powerlist2 is > always slower than both. Making powerlist2 recursive, the results I get with Python 2.7 are: py> from timeit import Timer as T py> x = 2.357 py> n = 8 py> t1 = T('powerlist1(x, n)', ... setup='from __main__ import powerlist1, x, n') py> t2 = T('powerlist2(x, n)', ... setup='from __main__ import powerlist2, x, n') py> t3 = T('powerlist3(x, n)', ... setup='from __main__ import powerlist3, x, n') py> min(t1.repeat(number=100000, repeat=5)) 0.38042593002319336 py> min(t2.repeat(number=100000, repeat=5)) 0.5992050170898438 py> min(t3.repeat(number=100000, repeat=5)) 0.334306001663208 So powerlist2 is half as fast as the other two, which are very close. For large n, #1 and #3 are still neck-and-neck: py> n = 100 py> min(t1.repeat(number=100000, repeat=5)) 3.6276791095733643 py> min(t3.repeat(number=100000, repeat=5)) 3.58870792388916 which is what I would expect: the overhead of calling Python code will be greater than the speed up from avoiding float multiplications. But long integer unlimited-precision multiplications are slow. To really see the advantage of avoiding multiplications using Horner's Method (powerlist1), we need to use large integers and not floats. py> x = 12345678*10000 py> n = 3 py> min(t1.repeat(number=100000, repeat=5)) 0.2199108600616455 py> min(t3.repeat(number=100000, repeat=5)) 0.551645040512085 As n becomes bigger, the advantage also increases: py> n = 10 py> min(t1.repeat(number=100000, repeat=5)) 0.736515998840332 py> min(t3.repeat(number=100000, repeat=5)) 2.4837491512298584 In this case with n = 10, powerlist1 does 9 multiplications. But powerlist3 makes ten calls to the ** operator. The number of multiplications will depend on how cleverly exponentiation is implemented: at worst, using a naive algorithm, there will be 36 multiplications. If the algorithm is a bit smarter, there will be 19 multiplications. Either way, when the calculation is dominated by the cost of multiplication, powerlist3 is between two and four times as expensive as powerlist1. -- Steven From jyoung79 at kc.rr.com Sun Sep 16 13:46:50 2012 From: jyoung79 at kc.rr.com (jyoung79 at kc.rr.com) Date: Sun, 16 Sep 2012 17:46:50 +0000 Subject: Moving folders with content Message-ID: <20120916174650.E91BV.183633.root@cdptpa-web13-z01> Hi "Nobody" and Hans, I really appreciate you all sharing this insight with me. > You might think that os.path.expanduser > would never expand '~' to something containing a double quote, > but you'd be wrong: > >>> import os > >>> os.environ['HOME'] = 'gotcha!"; rm -rf ' > >>> print(os.path.expanduser('~/Desktop/IN/Test/')) > gotcha!"; rm -rf /Desktop/IN/Test/ > > It's easy and safer to avoid using 'shell=True' option: > > cmd = ['ditto', '-vV', p1, p2] > v = subprocess.check_output(cmd, shell=False) I would have never thought about this, and this could definitely give me problems. Thank you for this advice! Again, thank you both for the examples and deeper understanding of how subprocess works. I will definitely start passing a list as the first argument as well as updating my older code to do the same. Jay From castironpi at gmail.com Sun Sep 16 14:38:15 2012 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 16 Sep 2012 11:38:15 -0700 (PDT) Subject: unit test strategy In-Reply-To: <505582d1$0$29890$c3e8da3$5496439d@news.astraweb.com> References: <505582d1$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sunday, September 16, 2012 2:42:09 AM UTC-5, Steven D'Aprano wrote: > On Fri, 14 Sep 2012 19:59:29 -0700, Aaron Brady wrote: > > > > > Hello, > > > > > > I've developing a test script. There's a lot of repetition. I want to > > > introduce a strategy for approaching it, but I don't want the program to > > > be discredited because of the test script. > > > > Test scripts should be simple enough that they don't require test scripts > > of their own. Or at least, not too many "test-the-test" tests. It is > > possible to avoid repetition without making convoluted, hard to > > understand code. Based on the tiny code fragments you give below, I > > suspect that your test script will need more testing than the code it > > tests! > > > > > > > Therefore, I'd like to know > > > what people's reactions to and thoughts about it are. > > > > I'd love to make some suggestions, but I have *no idea* what you are > > talking about. See further comments below: > > > > > > > The first strategy I used created an iterator and advanced it between > > > each step: > > > > What are you using an iterator for? What does this have to do with unit > > testing? > > > > So far, your explanation is rather lacking. It's a bit like: > > > > "I want to create an alarm system for my home, so I put in a screw and > > tightened it after each step." > > > > Doesn't really help us understand what you are doing. > > > > > > > self.op_chain(range(5), ('add', 5)) > > > self.op_chain(range(5), ('add', -2), ('add', -1)) > > > self.op_chain(range(5), ('discard', -1), ('add', 5)) > > > self.op_chain_ok(range(5), ('update', [0, 1])) > > > Etc. > > > > Where is the iterator you created? Where are you advancing it? What's > > op_chain do? > > > > > > > I'm considering something more complicated. 'iN' creates iterator N, > > > 'nN' advances iterator N, an exception calls 'assertRaises', and the > > > rest are function calls. > > [...] > > > > You've proven that even in Python people can write obfuscated code. > > > > > > > Do you think the 2nd version is legible? > > > > Neither version is even close to legible. > > > > > > > Could it interfere with the accuracy of the test? > > > > Who knows? I have no clue what your code is doing, it could be doing > > *anything*. > > > > > > > > -- > > Steven You are forcing me to explain my test code. Here is an example of some repetitive code. for view_meth in [ dict.items, dict.keys, dict.values ]: dict0= dict( ( k, None ) for k in range( 10 ) ) iter0= iter( view_meth( dict0 ) ) dict.__setitem__( dict0, 0, 1 ) next( iter0 ) dict.__setitem__( dict0, 10, 1 ) self.assertRaises( IterationError, next, iter0 ) dict0= dict( ( k, None ) for k in range( 10 ) ) iter0= iter( view_meth( dict0 ) ) next( iter0 ) dict.__setitem__( dict0, 0, 1 ) next( iter0 ) dict.__setitem__( dict0, 10, 1 ) self.assertRaises( IterationError, next, iter0 ) dict0= dict( ( k, None ) for k in range( 10 ) ) iter0= iter( view_meth( dict0 ) ) self.assertRaises( KeyError, dict0.__delitem__, 10 ) next( iter0 ) dict.__delitem__( dict0, 9 ) self.assertRaises( IterationError, next, iter0 ) dict0= dict( ( k, None ) for k in range( 10 ) ) iter0= iter( view_meth( dict0 ) ) next( iter0 ) self.assertRaises( KeyError, dict0.__delitem__, 10 ) next( iter0 ) dict.__delitem__( dict0, 9 ) self.assertRaises( IterationError, next, iter0 ) It makes sense to condense it. However, it can be condensed rather far, as follows: dsi= dict.__setitem__ ddi= dict.__delitem__ KE= KeyError IE= IterationError chain(range(10), 'i0', (dsi, 0, 1), 'n0', (dsi, 10, 1), (IE, 'n0')) chain(range(10), 'i0', 'n0', (dsi, 0, 1), 'n0', (dsi, 10, 1), (IE, 'n0')) chain(range(10), 'i0', (KE, ddi, 10), 'n0', (ddi, 9), (IE, 'n0')) chain(range(10), 'i0', 'n0', (KE, ddi, 10), 'n0', (ddi, 9), (IE, 'n0')) The parameters to 'chain' correspond 1-to-1 with the statements earlier. The view methods are looped over in the 'chain' method instead. 'op_chain' was an earlier version; some midway point in condensing the code could be preferable. Specifically my questions are, is the code condensed beyond legibility? Should 'chain' execute the test directly, or act as a metaprogram and output the test code into a 2nd file, or both? Should 'chain' create the iterators in a dictionary, or in the function local variables directly with 'exec'? From breamoreboy at yahoo.co.uk Sun Sep 16 15:23:28 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 16 Sep 2012 20:23:28 +0100 Subject: datetime issue In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5680604e-98e5-48c1-b5ac-9b837bc16770@googlegroups.com> Message-ID: On 16/09/2012 16:54, Chris Angelico wrote: > On Mon, Sep 17, 2012 at 1:40 AM, wrote: >> Cant it be written more easily as: >> date = (datetime.datetime.utcnow(+2) >> >> i know this is not thhe correct syntax but it just needs a way to add GMT+2 hours since utc=gmt > > I've dithered about whether to open this can of worms or let sleeping > dogs lie, and I finally decided to make some metaphor potpourri. > > Simple UTC offsets are not the same thing as local time. There are a > variety of other considerations, but the main one is Daylight Robbery > Time, where every government wants to put its own stamp on things by > fiddling with the DST rules a bit. Most places will move their clocks > an hour forward for summer and then back for winter. But! > > * Some places are sensible and don't have DST at all (eg > Australia/Queensland, America/Arizona) > * Northern hemisphere summer corresponds to southern hemisphere > winter, and vice versa > * Everyone has a different way of defining the boundaries of summer and winter > * And just to confuse us all, Irish Standard Time is used in summer, > and they *subtract* an hour for winter time! > > The only way to handle timezones correctly and keep yourself even > marginally sane is to hand the job on to somebody else. I dodged the > whole issue by letting our Postgres database handle everything for us > (date/time formats, timezones, the lot), and having our internal > systems all just work in UTC. You'll likely find it easiest to do the > same thing with a Python library. > > Just don't try to pretend to yourself that Greece uses GMT+2, because > it's not that simple. For one thing, it's currently summer there... > > ChrisA > I guess that Double British Summer Time made things twice as difficult? -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Sun Sep 16 15:26:16 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 16 Sep 2012 20:26:16 +0100 Subject: Obnoxious postings from Google Groups In-Reply-To: <2d82c30b-406f-434f-b61a-ca634dbed1ce@googlegroups.com> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> <70e4dc2e-4030-4ac3-b78d-a51630816f7c@googlegroups.com> <2d82c30b-406f-434f-b61a-ca634dbed1ce@googlegroups.com> Message-ID: On 16/09/2012 17:06, pandora.koura at gmail.com wrote: > >> >>> http://mail.python.org/mailman/listinfo/python-list >> >> >> >> email client to python-list at python.org >> > > wait a minute! i must use my ISP's news server and then post o comp.lang.python no? > > What is python-list at python.org how can i post there? > I'm on Windows Vista and read many Python mailing lists with Thunderbird via gmane. -- Cheers. Mark Lawrence. From d at davea.name Sun Sep 16 15:31:19 2012 From: d at davea.name (Dave Angel) Date: Sun, 16 Sep 2012 15:31:19 -0400 Subject: datetime issue In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <5055aec2$0$29981$c3e8da3$5496439d@news.astraweb.com> <46626459-facd-4f5f-8907-033b1759b8b4@googlegroups.com> <5055b94a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50562907.6020201@davea.name> On 09/16/2012 07:56 AM, ???????? ?????? wrote: > ?? ???????, 16 ??????????? 2012 2:34:34 ?.?. UTC+3, ? ??????? Steven D'Aprano ??????: >> >> >> No. That's not how mailing lists work. Every email gets posted to all >> members, unless they go onto "No Mail", in which case they get no emails >> at all. >> >> You are not paying anything for the help you are receiving, except to >> give your own time in return to help others. We are all volunteers here, >> and nobody is going to force you to volunteer in return, but if everyone >> only received threads that they initiated, nobody would see new threads >> and nobody would get any answers at all. >> >> >> You are right, i will set to receive them all. >> >> But i dont know what to do about the thing you say that i double post. >> I use google groups i dont intentionally post to python-list too. >> How can i avoid that and just only post to python google group? Once you get the emails from the official mailing list, posting a reply is straightforward. Do a reply-all for most messages, perhaps deleting some of the to or cc addresses depending on a specific message. Then trim the parts you're not responding to, and put your new remarks after the context you are responding to. It won't double-post. For new messages, simply address a new message to python-list at python.org Depending on your mail reader, you can see the messages in threads, except for all the people who bust up the threads. When you get to that point, post a new thread specifying your email program and OS, and somebody will probably volunteer to help you get it customized (though perhaps the actual discussion for that would be offline). For anybody else listening, the way I avoid seeing the google-groups double-post is to automatically delete any message that's got a cc to google-groups. That way I only get the OTHER copy of the message. -- DaveA From mayuresh at kathe.in Sun Sep 16 15:39:26 2012 From: mayuresh at kathe.in (Mayuresh Kathe) Date: Mon, 17 Sep 2012 01:09:26 +0530 Subject: Obnoxious postings from Google Groups In-Reply-To: <70e4dc2e-4030-4ac3-b78d-a51630816f7c@googlegroups.com> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> <70e4dc2e-4030-4ac3-b78d-a51630816f7c@googlegroups.com> Message-ID: On Sunday 16 September 2012 09:11 PM, pandora.koura at gmail.com wrote: > ?? ???????, 16 ??????????? 2012 4:18:50 ?.?. UTC+3, ? ??????? Ben Finney ??????: >> ???????? ?????? writes: >> >> >> >>> Iam sorry i didnt do that on purpose and i dont know how this is done. >> >>> >> >>> Iam positng via google groups using chrome, thats all i know. >> >> > > >> >> It is becoming quite clear that some change has happened recently to >> >> Google Groups that makes posts coming from there rather more obnoxious >> >> than before. And there doesn't seem to be much its users can do except >> >> use something else. >> >> >> >> Using Google Groups for posting to Usenet has been a bad idea for a long >> >> time, but now it just seems to be a sure recipe for annoying the rest of >> >> us. Again, not something you have much control over, except to stop >> >> using Google Groups. >> > > If i ditch google groups what application can i use in Windows 8 to post to > this newsgroup and what newsserver too? > Thunderbird 15 as the newsgroup client and Unison Access as the news server (it's a paid service). From steve+comp.lang.python at pearwood.info Sun Sep 16 16:01:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Sep 2012 20:01:11 GMT Subject: unit test strategy References: <505582d1$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50563006$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sun, 16 Sep 2012 11:38:15 -0700, Aaron Brady wrote: > Here is an example of some repetitive code. > > for view_meth in [ dict.items, dict.keys, dict.values ]: > dict0= dict( ( k, None ) for k in range( 10 ) ) > iter0= iter( view_meth( dict0 ) ) > dict.__setitem__( dict0, 0, 1 ) > next( iter0 ) > dict.__setitem__( dict0, 10, 1 ) > self.assertRaises( IterationError, next, iter0 ) [...] First off, if you have any wish for this to be accepted into the standard library, I suggest you stick to PEP 8. Spaces on *both* sides of equals signs, not just one(!!!), and *no* spaces around the parenthesised arguments. Secondly, this is test code. A bit of repetition is not to be concerned about, clarity is far more important than "Don't Repeat Yourself". The aim isn't to write the fastest, or most compact code, but to have good test coverage with tests which are *obviously* correct (rather than test code which has no obvious bugs, which is very different). If a test fails, you should be able to identify quickly what failed without running a debugger to identify what part of the code failed. Thirdly, why are you writing dict.__setitem__( dict0, 0, 1 ) instead of dict0[0] = 1 ? [...] > Specifically my questions are, is the code condensed beyond legibility? Yes. > Should 'chain' execute the test directly, or act as a metaprogram and > output the test code into a 2nd file, or both? None of the above. > Should 'chain' create > the iterators in a dictionary, or in the function local variables > directly with 'exec'? Heavens to Murgatroyd, you can't be serious. Here's my attempt at this. Note the features: - meaningful names (if a bit long, but that's a hazard of tests) - distinct methods for each distinct test case - comments explaining what the test code does - use of subclassing # Untested class TestDictIteratorModificationDetection(unittest.TestCase): """Test that iterators to dicts will correctly detect when the dict has been modified, and raise an exception. """ def create_dict(self): return dict.fromkeys(range(10)) def testIteratorAllowed(self): # Iterators are allowed to run if all modifications occur # after the iterator is created but before it starts running. d = self.create_dict() for view in (dict.items, dict.keys, dict.values): # Create an iterator before modifying the dict, but do not # start iterating over it. it = iter(view(d)) # Be careful of the order of modifications here. del d[2] d.pop(4) d.popitem() d.clear() # Make sure we have something to iterate over. d[1] = 1 d.update({5: 1}) d.setdefault(8, 1) assert d # d is non-empty. next(it); next(it); next(it) self.assertRaises(StopIteration, next, it) def iterator_fails_after_modification(self, method, *args): """Iterators should not be able to continue running after the dict is modified. This helper method factors out the common code of creating a dict, an iterator to that dict, modifying the dict, and testing that further iteration fails. Pass an unbound dict method which modifies the dict in place, and and arguments to that method required. """ d = self.create_dict() for view in (dict.items, dict.keys, dict.values): it = iter(view(d)) next(it) # no exception expected here method(d, *args) self.assertRaises(IterationError, next, it) def testIteratorFailsAfterSet(self): self.iterator_fails_after_modification(dict.__setitem__, 1, 1) def testIteratorFailsAfterDel(self): self.iterator_fails_after_modification(dict.__delitem__, 1) def testIteratorFailsAfterUpdate(self): self.iterator_fails_after_modification(dict.update, {5: 1}) def testIteratorFailsAfterPop(self): self.iterator_fails_after_modification(dict.pop, 4) def testStartedIteratorFailsAfterPopItem(self): self.iterator_fails_after_modification(dict.popitem) def testStartedIteratorFailsAfterClear(self): self.iterator_fails_after_modification(dict.clear) def testStartedIteratorFailsAfterSetDefault(self): self.iterator_fails_after_modification(dict.setdefault, 99, 1) class TestDictSubclassIteratorModificationDetection( TestDictIteratorModificationDetection): def create_dict(self): class MyDict(dict): pass return MyDict.fromkeys(range(10)) I think I've got all the methods which can mutate a dictionary. If I missed any, it's easy enough to add a new test method to the class. You are free to use the above code for your own purposes, with any modifications you like, with two requests: - I would appreciate a comment in the test file acknowledging my contribution; - I would like to be notified if you submit this to the bug tracker. Thanks again for tackling this project. -- Steven From wuwei23 at gmail.com Sun Sep 16 20:38:21 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 16 Sep 2012 17:38:21 -0700 (PDT) Subject: Decorators not worth the effort References: <20120914021211.GA15642@cskk.homeip.net> Message-ID: On Sep 15, 6:30?am, Terry Reedy wrote: > > On 13Sep2012 18:58, alex23 wrote: > > | On Sep 14, 3:54 am, Jean-Michel Pichavant > > | wrote: > > | > I don't like decorators, I think they're not worth the mental effort. > > | > > | Because passing a function to a function is a huge cognitive burden? > > For parameterized decorators, there is extra cognitive burden. See below. I do regret my initial criticism, for exactly this reason. From wuwei23 at gmail.com Sun Sep 16 20:47:13 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 16 Sep 2012 17:47:13 -0700 (PDT) Subject: Obnoxious postings from Google Groups (was: datetime issue) References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> Message-ID: <6c732de0-b10f-4d40-853c-f62682970117@rg9g2000pbc.googlegroups.com> On Sep 16, 11:18?pm, Ben Finney wrote: > Using Google Groups for posting to Usenet has been a bad idea for a long > time, but now it just seems to be a sure recipe for annoying the rest of > us. Again, not something you have much control over, except to stop > using Google Groups. Agreed. While it was painful but usable in its previous form, the "new Groups" is an incomprehensible mess of pointlessness and shittery. It's still possible to use the old theme for the time being, which does avoid the double-up posts, but it's pretty clear Google aren't listening to any feedback about Groups whatsoever. I've really NFI why they bought DejaNews only to turn it into such a broken service. From roy at panix.com Sun Sep 16 20:55:52 2012 From: roy at panix.com (Roy Smith) Date: Sun, 16 Sep 2012 20:55:52 -0400 Subject: Obnoxious postings from Google Groups (was: datetime issue) References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> <6c732de0-b10f-4d40-853c-f62682970117@rg9g2000pbc.googlegroups.com> Message-ID: In article <6c732de0-b10f-4d40-853c-f62682970117 at rg9g2000pbc.googlegroups.com>, alex23 wrote: > On Sep 16, 11:18?pm, Ben Finney wrote: > > Using Google Groups for posting to Usenet has been a bad idea for a long > > time, but now it just seems to be a sure recipe for annoying the rest of > > us. Again, not something you have much control over, except to stop > > using Google Groups. > > Agreed. While it was painful but usable in its previous form, the "new > Groups" is an incomprehensible mess of pointlessness and shittery. > It's still possible to use the old theme for the time being, which > does avoid the double-up posts, but it's pretty clear Google aren't > listening to any feedback about Groups whatsoever. > > I've really NFI why they bought DejaNews only to turn it into such a > broken service. They didn't buy the service. They bought the data. Well, they really bought both, but the data is all they wanted. From alok.jadhav at credit-suisse.com Sun Sep 16 21:07:21 2012 From: alok.jadhav at credit-suisse.com (Jadhav, Alok) Date: Mon, 17 Sep 2012 09:07:21 +0800 Subject: Python garbage collector/memory manager behaving strangely Message-ID: Hi Everyone, I have a simple program which reads a large file containing few million rows, parses each row (`numpy array`) and converts into an array of doubles (`python array`) and later writes into an `hdf5 file`. I repeat this loop for multiple days. After reading each file, i delete all the objects and call garbage collector. When I run the program, First day is parsed without any error but on the second day i get `MemoryError`. I monitored the memory usage of my program, during first day of parsing, memory usage is around **1.5 GB**. When the first day parsing is finished, memory usage goes down to **50 MB**. Now when 2nd day starts and i try to read the lines from the file I get `MemoryError`. Following is the output of the program. source file extracted at C:\rfadump\au\2012.08.07.txt parsing started current time: 2012-09-16 22:40:16.829000 500000 lines parsed 1000000 lines parsed 1500000 lines parsed 2000000 lines parsed 2500000 lines parsed 3000000 lines parsed 3500000 lines parsed 4000000 lines parsed 4500000 lines parsed 5000000 lines parsed parsing done. end time is 2012-09-16 23:34:19.931000 total time elapsed 0:54:03.102000 repacking file done > s:\users\aaj\projects\pythonhf\rfadumptohdf.py(132)generateFiles() -> while single_date <= self.end_date: (Pdb) c *** 2012-08-08 *** source file extracted at C:\rfadump\au\2012.08.08.txt cought an exception while generating file for day 2012-08-08. Traceback (most recent call last): File "rfaDumpToHDF.py", line 175, in generateFile lines = self.rawfile.read().split('|\n') MemoryError I am very sure that windows system task manager shows the memory usage as **50 MB** for this process. It looks like the garbage collector or memory manager for Python is not calculating the free memory correctly. There should be lot of free memory but it thinks there is not enough. Any idea? Thanks. Alok Jadhav CREDIT SUISSE AG GAT IT Hong Kong, KVAG 67 International Commerce Centre | Hong Kong | Hong Kong Phone +852 2101 6274 | Mobile +852 9169 7172 alok.jadhav at credit-suisse.com | www.credit-suisse.com =============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html =============================================================================== -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Sun Sep 16 21:11:49 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 16 Sep 2012 18:11:49 -0700 (PDT) Subject: Comparing strings from the back? References: <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> Message-ID: On Sep 15, 1:10?pm, Dwight Hutto wrote: > On Fri, Sep 14, 2012 at 6:43 PM, Prasad, Ramit > > Since I was unsure myself if you were trying to be offensive or racist, > > I would disagree with "everyone can know it wasn't meant as racist". > > If you're unsure if it was racist, you should err on the side of > caution. If your comments are mistakable as racism, maybe *you* should be more cautious and *not make them*. From wuwei23 at gmail.com Sun Sep 16 21:14:56 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 16 Sep 2012 18:14:56 -0700 (PDT) Subject: Obnoxious postings from Google Groups (was: datetime issue) References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> <6c732de0-b10f-4d40-853c-f62682970117@rg9g2000pbc.googlegroups.com> Message-ID: On Sep 17, 10:55?am, Roy Smith wrote: > They didn't buy the service. ?They bought the data. ?Well, they really > bought both, but the data is all they wanted. I thought they'd taken most of the historical data offline now too? Either way, it was the sort of purchase-and-whither approach you usually see Yahoo take. From d at davea.name Sun Sep 16 22:12:46 2012 From: d at davea.name (Dave Angel) Date: Sun, 16 Sep 2012 22:12:46 -0400 Subject: Python garbage collector/memory manager behaving strangely In-Reply-To: References: Message-ID: <5056871E.7050206@davea.name> On 09/16/2012 09:07 PM, Jadhav, Alok wrote: > Hi Everyone, > > > > I have a simple program which reads a large file containing few million > rows, parses each row (`numpy array`) and converts into an array of > doubles (`python array`) and later writes into an `hdf5 file`. I repeat > this loop for multiple days. After reading each file, i delete all the > objects and call garbage collector. When I run the program, First day > is parsed without any error but on the second day i get `MemoryError`. I > monitored the memory usage of my program, during first day of parsing, > memory usage is around **1.5 GB**. When the first day parsing is > finished, memory usage goes down to **50 MB**. Now when 2nd day starts > and i try to read the lines from the file I get `MemoryError`. Following > is the output of the program. > > > > > > source file extracted at C:\rfadump\au\2012.08.07.txt > > parsing started > > current time: 2012-09-16 22:40:16.829000 > > 500000 lines parsed > > 1000000 lines parsed > > 1500000 lines parsed > > 2000000 lines parsed > > 2500000 lines parsed > > 3000000 lines parsed > > 3500000 lines parsed > > 4000000 lines parsed > > 4500000 lines parsed > > 5000000 lines parsed > > parsing done. > > end time is 2012-09-16 23:34:19.931000 > > total time elapsed 0:54:03.102000 > > repacking file > > done > > > s:\users\aaj\projects\pythonhf\rfadumptohdf.py(132)generateFiles() > > -> while single_date <= self.end_date: > > (Pdb) c > > *** 2012-08-08 *** > > source file extracted at C:\rfadump\au\2012.08.08.txt > > cought an exception while generating file for day 2012-08-08. > > Traceback (most recent call last): > > File "rfaDumpToHDF.py", line 175, in generateFile > > lines = self.rawfile.read().split('|\n') > > MemoryError > > > > I am very sure that windows system task manager shows the memory usage > as **50 MB** for this process. It looks like the garbage collector or > memory manager for Python is not calculating the free memory correctly. > There should be lot of free memory but it thinks there is not enough. > > > > Any idea? > > > > Thanks. > > > > > > Alok Jadhav > > CREDIT SUISSE AG > > GAT IT Hong Kong, KVAG 67 > > International Commerce Centre | Hong Kong | Hong Kong > > Phone +852 2101 6274 | Mobile +852 9169 7172 > > alok.jadhav at credit-suisse.com | www.credit-suisse.com > > > > Don't blame CPython. You're trying to do a read() of a large file, which will result in a single large string. Then you split it into lines. Why not just read it in as lines, in which case the large string isn't necessary. Take a look at the readlines() function. Chances are that even that is unnecessary, but i can't tell without seeing more of the code. lines = self.rawfile.read().split('|\n') lines = self.rawfile.readlines() When a single large item is being allocated, it's not enough to have sufficient free space, the space also has to be contiguous. After a program runs for a while, its space naturally gets fragmented more and more. it's the nature of the C runtime, and CPython is stuck with it. -- DaveA From alok.jadhav at credit-suisse.com Sun Sep 16 22:28:34 2012 From: alok.jadhav at credit-suisse.com (Jadhav, Alok) Date: Mon, 17 Sep 2012 10:28:34 +0800 Subject: Python garbage collector/memory manager behaving strangely In-Reply-To: <5056871E.7050206@davea.name> References: <5056871E.7050206@davea.name> Message-ID: Thanks Dave for clean explanation. I clearly understand what is going on now. I still need some suggestions from you on this. There are 2 reasons why I was using self.rawfile.read().split('|\n') instead of self.rawfile.readlines() - As you have seen, the line separator is not '\n' but its '|\n'. Sometimes the data itself has '\n' characters in the middle of the line and only way to find true end of the line is that previous character should be a bar '|'. I was not able specify end of line using readlines() function, but I could do it using split() function. (One hack would be to readlines and combine them until I find '|\n'. is there a cleaner way to do this?) - Reading whole file at once and processing line by line was must faster. Though speed is not of very important issue here but I think the tie it took to parse complete file was reduced to one third of original time. Regards, Alok -----Original Message----- From: Dave Angel [mailto:d at davea.name] Sent: Monday, September 17, 2012 10:13 AM To: Jadhav, Alok Cc: python-list at python.org Subject: Re: Python garbage collector/memory manager behaving strangely On 09/16/2012 09:07 PM, Jadhav, Alok wrote: > Hi Everyone, > > > > I have a simple program which reads a large file containing few million > rows, parses each row (`numpy array`) and converts into an array of > doubles (`python array`) and later writes into an `hdf5 file`. I repeat > this loop for multiple days. After reading each file, i delete all the > objects and call garbage collector. When I run the program, First day > is parsed without any error but on the second day i get `MemoryError`. I > monitored the memory usage of my program, during first day of parsing, > memory usage is around **1.5 GB**. When the first day parsing is > finished, memory usage goes down to **50 MB**. Now when 2nd day starts > and i try to read the lines from the file I get `MemoryError`. Following > is the output of the program. > > > > > > source file extracted at C:\rfadump\au\2012.08.07.txt > > parsing started > > current time: 2012-09-16 22:40:16.829000 > > 500000 lines parsed > > 1000000 lines parsed > > 1500000 lines parsed > > 2000000 lines parsed > > 2500000 lines parsed > > 3000000 lines parsed > > 3500000 lines parsed > > 4000000 lines parsed > > 4500000 lines parsed > > 5000000 lines parsed > > parsing done. > > end time is 2012-09-16 23:34:19.931000 > > total time elapsed 0:54:03.102000 > > repacking file > > done > > > s:\users\aaj\projects\pythonhf\rfadumptohdf.py(132)generateFiles() > > -> while single_date <= self.end_date: > > (Pdb) c > > *** 2012-08-08 *** > > source file extracted at C:\rfadump\au\2012.08.08.txt > > cought an exception while generating file for day 2012-08-08. > > Traceback (most recent call last): > > File "rfaDumpToHDF.py", line 175, in generateFile > > lines = self.rawfile.read().split('|\n') > > MemoryError > > > > I am very sure that windows system task manager shows the memory usage > as **50 MB** for this process. It looks like the garbage collector or > memory manager for Python is not calculating the free memory correctly. > There should be lot of free memory but it thinks there is not enough. > > > > Any idea? > > > > Thanks. > > > > > > Alok Jadhav > > CREDIT SUISSE AG > > GAT IT Hong Kong, KVAG 67 > > International Commerce Centre | Hong Kong | Hong Kong > > Phone +852 2101 6274 | Mobile +852 9169 7172 > > alok.jadhav at credit-suisse.com | www.credit-suisse.com > > > > Don't blame CPython. You're trying to do a read() of a large file, which will result in a single large string. Then you split it into lines. Why not just read it in as lines, in which case the large string isn't necessary. Take a look at the readlines() function. Chances are that even that is unnecessary, but i can't tell without seeing more of the code. lines = self.rawfile.read().split('|\n') lines = self.rawfile.readlines() When a single large item is being allocated, it's not enough to have sufficient free space, the space also has to be contiguous. After a program runs for a while, its space naturally gets fragmented more and more. it's the nature of the C runtime, and CPython is stuck with it. -- DaveA =============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html =============================================================================== From alok.jadhav at credit-suisse.com Sun Sep 16 22:49:19 2012 From: alok.jadhav at credit-suisse.com (Jadhav, Alok) Date: Mon, 17 Sep 2012 10:49:19 +0800 Subject: Python garbage collector/memory manager behaving strangely In-Reply-To: <5056871E.7050206@davea.name> References: <5056871E.7050206@davea.name> Message-ID: I am thinking of calling a new subprocess which will do the memory hungry job and then release the memory as specified in the link below http://stackoverflow.com/questions/1316767/how-can-i-explicitly-free-mem ory-in-python/1316799#1316799 Regards, Alok -----Original Message----- From: Dave Angel [mailto:d at davea.name] Sent: Monday, September 17, 2012 10:13 AM To: Jadhav, Alok Cc: python-list at python.org Subject: Re: Python garbage collector/memory manager behaving strangely On 09/16/2012 09:07 PM, Jadhav, Alok wrote: > Hi Everyone, > > > > I have a simple program which reads a large file containing few million > rows, parses each row (`numpy array`) and converts into an array of > doubles (`python array`) and later writes into an `hdf5 file`. I repeat > this loop for multiple days. After reading each file, i delete all the > objects and call garbage collector. When I run the program, First day > is parsed without any error but on the second day i get `MemoryError`. I > monitored the memory usage of my program, during first day of parsing, > memory usage is around **1.5 GB**. When the first day parsing is > finished, memory usage goes down to **50 MB**. Now when 2nd day starts > and i try to read the lines from the file I get `MemoryError`. Following > is the output of the program. > > > > > > source file extracted at C:\rfadump\au\2012.08.07.txt > > parsing started > > current time: 2012-09-16 22:40:16.829000 > > 500000 lines parsed > > 1000000 lines parsed > > 1500000 lines parsed > > 2000000 lines parsed > > 2500000 lines parsed > > 3000000 lines parsed > > 3500000 lines parsed > > 4000000 lines parsed > > 4500000 lines parsed > > 5000000 lines parsed > > parsing done. > > end time is 2012-09-16 23:34:19.931000 > > total time elapsed 0:54:03.102000 > > repacking file > > done > > > s:\users\aaj\projects\pythonhf\rfadumptohdf.py(132)generateFiles() > > -> while single_date <= self.end_date: > > (Pdb) c > > *** 2012-08-08 *** > > source file extracted at C:\rfadump\au\2012.08.08.txt > > cought an exception while generating file for day 2012-08-08. > > Traceback (most recent call last): > > File "rfaDumpToHDF.py", line 175, in generateFile > > lines = self.rawfile.read().split('|\n') > > MemoryError > > > > I am very sure that windows system task manager shows the memory usage > as **50 MB** for this process. It looks like the garbage collector or > memory manager for Python is not calculating the free memory correctly. > There should be lot of free memory but it thinks there is not enough. > > > > Any idea? > > > > Thanks. > > > > > > Alok Jadhav > > CREDIT SUISSE AG > > GAT IT Hong Kong, KVAG 67 > > International Commerce Centre | Hong Kong | Hong Kong > > Phone +852 2101 6274 | Mobile +852 9169 7172 > > alok.jadhav at credit-suisse.com | www.credit-suisse.com > > > > Don't blame CPython. You're trying to do a read() of a large file, which will result in a single large string. Then you split it into lines. Why not just read it in as lines, in which case the large string isn't necessary. Take a look at the readlines() function. Chances are that even that is unnecessary, but i can't tell without seeing more of the code. lines = self.rawfile.read().split('|\n') lines = self.rawfile.readlines() When a single large item is being allocated, it's not enough to have sufficient free space, the space also has to be contiguous. After a program runs for a while, its space naturally gets fragmented more and more. it's the nature of the C runtime, and CPython is stuck with it. -- DaveA =============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html =============================================================================== From wuwei23 at gmail.com Sun Sep 16 23:25:06 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 16 Sep 2012 20:25:06 -0700 (PDT) Subject: Python garbage collector/memory manager behaving strangely References: <5056871E.7050206@davea.name> Message-ID: <59f8c664-8f11-439e-8002-ca76ee24a632@g7g2000pbh.googlegroups.com> On Sep 17, 12:32?pm, "Jadhav, Alok" wrote: > - As you have seen, the line separator is not '\n' but its '|\n'. > Sometimes the data itself has '\n' characters in the middle of the line > and only way to find true end of the line is that previous character > should be a bar '|'. I was not able specify end of line using > readlines() function, but I could do it using split() function. > (One hack would be to readlines and combine them until I find '|\n'. is > there a cleaner way to do this?) You can use a generator to take care of your readlines requirements: def readlines(f): lines = [] while "f is not empty": line = f.readline() if not line: break if len(line) > 2 and line[-2:] == '|\n': lines.append(line) yield ''.join(lines) lines = [] else: lines.append(line) > - Reading whole file at once and processing line by line was must > faster. Though speed is not of very important issue here but I think the > tie it took to parse complete file was reduced to one third of original > time. With the readlines generator above, it'll read lines from the file until it has a complete "line" by your requirement, at which point it'll yield it. If you don't need the entire file in memory for the end result, you'll be able to process each "line" one at a time and perform whatever you need against it before asking for the next. with open(u'infile.txt','r') as infile: for line in readlines(infile): ... Generators are a very efficient way of processing large amounts of data. You can chain them together very easily: real_lines = readlines(infile) marker_lines = (l for l in real_lines if l.startswith('#')) every_second_marker = (l for i,l in enumerate(marker_lines) if (i +1) % 2 == 0) map(some_function, every_second_marker) The real_lines generator returns your definition of a line. The marker_lines generator filters out everything that doesn't start with #, while every_second_marker returns only half of those. (Yes, these could all be written as a single generator, but this is very useful for more complex pipelines). The big advantage of this approach is that nothing is read from the file into memory until map is called, and given the way they're chained together, only one of your lines should be in memory at any given time. From rosuav at gmail.com Mon Sep 17 00:05:38 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 17 Sep 2012 14:05:38 +1000 Subject: Comparing strings from the back? In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> Message-ID: On Mon, Sep 17, 2012 at 11:11 AM, alex23 wrote: > On Sep 15, 1:10 pm, Dwight Hutto wrote: >> On Fri, Sep 14, 2012 at 6:43 PM, Prasad, Ramit >> > Since I was unsure myself if you were trying to be offensive or racist, >> > I would disagree with "everyone can know it wasn't meant as racist". >> >> If you're unsure if it was racist, you should err on the side of >> caution. > > If your comments are mistakable as racism, maybe *you* should be more > cautious and *not make them*. That applies to the most obvious examples (for instance, there's a line in a 19th century opera that uses a six-letter word starting with 'n' to refer to a dark-skinned person - for obvious reasons, that line is usually changed in modern performances, even though it was descriptive and not offensive when the opera was written - like referring to a Caucasian). However, there are many things which could be misinterpreted as racist, and I would hate to see people leaned hard on to make their speech entirely politically correct. Use common sense, on both sides. Don't be offensive, and don't be offended. ChrisA From nikos.gr33k at gmail.com Mon Sep 17 00:25:11 2012 From: nikos.gr33k at gmail.com (Nick the Gr33k) Date: Mon, 17 Sep 2012 07:25:11 +0300 Subject: utcnow Message-ID: <5056A627.3020407@gmail.com> Hello is there a better way of writing this: date = ( datetime.datetime.utcnow() + datetime.timedelta(hours=3) ).strftime( '%y-%m-%d %H:%M:%S') something like: date = datetime.datetime.utcnow(hours=3).strftime( '%y-%m-%d %H:%M:%S') i prefer it if it could be written as this. Also what about dayligh savings time? From dihedral88888 at googlemail.com Mon Sep 17 00:39:05 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 16 Sep 2012 21:39:05 -0700 (PDT) Subject: Python garbage collector/memory manager behaving strangely In-Reply-To: <59f8c664-8f11-439e-8002-ca76ee24a632@g7g2000pbh.googlegroups.com> References: <5056871E.7050206@davea.name> <59f8c664-8f11-439e-8002-ca76ee24a632@g7g2000pbh.googlegroups.com> Message-ID: alex23? 2012?9?17????UTC+8??11?25?06???? > On Sep 17, 12:32?pm, "Jadhav, Alok" > > wrote: > > > - As you have seen, the line separator is not '\n' but its '|\n'. > > > Sometimes the data itself has '\n' characters in the middle of the line > > > and only way to find true end of the line is that previous character > > > should be a bar '|'. I was not able specify end of line using > > > readlines() function, but I could do it using split() function. > > > (One hack would be to readlines and combine them until I find '|\n'. is > > > there a cleaner way to do this?) > > > > You can use a generator to take care of your readlines requirements: > > > > def readlines(f): > > lines = [] > > while "f is not empty": > > line = f.readline() > > if not line: break > > if len(line) > 2 and line[-2:] == '|\n': > > lines.append(line) > > yield ''.join(lines) > > lines = [] > > else: > > lines.append(line) > > > > > - Reading whole file at once and processing line by line was must > > > faster. Though speed is not of very important issue here but I think the > > > tie it took to parse complete file was reduced to one third of original > > > time. > > > > With the readlines generator above, it'll read lines from the file > > until it has a complete "line" by your requirement, at which point > > it'll yield it. If you don't need the entire file in memory for the > > end result, you'll be able to process each "line" one at a time and > > perform whatever you need against it before asking for the next. > > > > with open(u'infile.txt','r') as infile: > > for line in readlines(infile): > > ... > > > > Generators are a very efficient way of processing large amounts of > > data. You can chain them together very easily: > > > > real_lines = readlines(infile) > > marker_lines = (l for l in real_lines if l.startswith('#')) > > every_second_marker = (l for i,l in enumerate(marker_lines) if (i > > +1) % 2 == 0) > > map(some_function, every_second_marker) > > > > The real_lines generator returns your definition of a line. The > > marker_lines generator filters out everything that doesn't start with > > #, while every_second_marker returns only half of those. (Yes, these > > could all be written as a single generator, but this is very useful > > for more complex pipelines). > > > > The big advantage of this approach is that nothing is read from the > > file into memory until map is called, and given the way they're > > chained together, only one of your lines should be in memory at any > > given time. The basic problem is whether the output items really need all lines of the input text file to be buffered to produce the results. From j.j.molenaar at gmail.com Mon Sep 17 00:44:42 2012 From: j.j.molenaar at gmail.com (Joost Molenaar) Date: Mon, 17 Sep 2012 06:44:42 +0200 Subject: utcnow In-Reply-To: <5056A627.3020407@gmail.com> References: <5056A627.3020407@gmail.com> Message-ID: Time zones! So much fun. Looks like you're dealing with UTC offsets yourself, which gets messy as soon as you start thinking about DST. The good news is that there's a timezone database on most systems, which you should almost definitely use. Take a look at python-dateutil (pip install python-dateutil): >>> from datetime import datetime >>> from dateutil import tz >>> datetime.now() datetime.datetime(2012, 9, 17, 6, 33, 57, 158555) This is a so-called "naive datetime", it doesn't know about timezones. On my system, it returns a time in my local time zone. (It could have been GMT or something else entirely.) You have to call .replace() on a "naive datetime" to set the tzinfo member to make it a timezone-aware datetime object: >>> AMS = tz.gettz('Europe/Amsterdam') >>> ATH = tz.gettz('Europe/Athens') >>> datetime.now().replace(tzinfo=AMS).astimezone(ATH) datetime.datetime(2012, 9, 17, 7, 37, 38, 573223, tzinfo=tzfile('/usr/share/zoneinfo/Europe/Athens')) Voila, it seems like you're one hour ahead of me. :-) HTH, Joost On 17 September 2012 06:25, Nick the Gr33k wrote: > Hello is there a better way of writing this: > > date = ( datetime.datetime.utcnow() + datetime.timedelta(hours=3) > ).strftime( '%y-%m-%d %H:%M:%S') > > something like: > > date = datetime.datetime.utcnow(**hours=3).strftime( '%y-%m-%d %H:%M:%S') > > i prefer it if it could be written as this. > > Also what about dayligh savings time? > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Mon Sep 17 00:48:09 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 17 Sep 2012 14:48:09 +1000 Subject: utcnow References: Message-ID: <87vcfdl0fq.fsf@benfinney.id.au> Nick the Gr33k writes: > Hello is there a better way of writing this: > > date = ( datetime.datetime.utcnow() + datetime.timedelta(hours=3) > ).strftime( '%y-%m-%d %H:%M:%S') > > something like: > > date = datetime.datetime.utcnow(hours=3).strftime( '%y-%m-%d %H:%M:%S') > > i prefer it if it could be written as this. Break long complicated statements into simpler statements. You might need to get used to naming your intermediate results. now = datetime.datetime.utcnow() later = now + datetime.timedelta(hours=3) timestamp_text = later.strftime("%Y-%m-%d %H:%M:%S") > Also what about dayligh savings time? What about it? What has your reading of the ?datetime? module documentation taught you? -- \ ?Don't worry about people stealing your ideas. If your ideas | `\ are any good, you'll have to ram them down people's throats.? | _o__) ?Howard Aiken | Ben Finney From wuwei23 at gmail.com Mon Sep 17 02:06:11 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 16 Sep 2012 23:06:11 -0700 (PDT) Subject: Comparing strings from the back? References: <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> Message-ID: <956d4b7e-e548-408d-9f1f-2a5d177e901c@kg10g2000pbc.googlegroups.com> On Sep 17, 2:05?pm, Chris Angelico wrote: > I would hate to see people leaned > hard on to make their speech entirely politically correct. Use common > sense, on both sides. Don't be offensive, and don't be offended. While I would like to agree, this would require there to be no power disparities between the parties involved, which isn't always the case. I hate the term "politically correct", it always seems to be used in an eye-rolling, "what a load of nonsense" way, probably because I believe there's at least some validity in the Sapir/Whorf hypothesis that language dictates thought. If Ramit's name was Barbie and e was told to "get back to your dream home" or some other guff, it would be quite rightly viewed as sexist, whether intentional or not. Such behaviour has been called out on this list in the past, and I'm genuinely surprised to see so little reaction to this. From dwightdhutto at gmail.com Mon Sep 17 02:44:32 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 17 Sep 2012 02:44:32 -0400 Subject: pythonOCC examples doesn't work? In-Reply-To: <5054BA43.60102@mrabarnett.plus.com> References: <5B80DD153D7D744689F57F4FB69AF47416678FC5@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4741667C1C7@SCACMX008.exchad.jpmchase.net> <5054BA43.60102@mrabarnett.plus.com> Message-ID: >> Alan Gauld quotes, "Putting on my moderator's hat", sometimes. >> >>> is as you describe, a monarchy whose head but seldom exercises power; >> >> >> I think it's Rossenbom(or whoever the creator of the interpreter >> written in C is), "who says benevolent dictator for life" >> > [snip] > You don't know the name of the BDFL? I'm appalled! :-) > I know plenty of BDFL's, including that one, but the mods are not the creator. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From __peter__ at web.de Mon Sep 17 03:24:20 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 17 Sep 2012 09:24:20 +0200 Subject: BDFL Rossenbom, was Re: pythonOCC examples doesn't work? References: <5B80DD153D7D744689F57F4FB69AF47416678FC5@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4741667C1C7@SCACMX008.exchad.jpmchase.net> <5054BA43.60102@mrabarnett.plus.com> Message-ID: Dwight Hutto wrote: >>> Alan Gauld quotes, "Putting on my moderator's hat", sometimes. >>> >>>> is as you describe, a monarchy whose head but seldom exercises power; >>> >>> >>> I think it's Rossenbom(or whoever the creator of the interpreter >>> written in C is), "who says benevolent dictator for life" >>> >> [snip] >> You don't know the name of the BDFL? I'm appalled! :-) >> > I know plenty of BDFL's, including that one, but the mods are not the > creator. Cue I kno' plenty o' nuttin', And nuttin's plenty fo' me... to the tune of Josh Kirschwein (or whoever wrote that Ernie and Tess opera) From news at blinne.net Mon Sep 17 04:39:17 2012 From: news at blinne.net (Alexander Blinne) Date: Mon, 17 Sep 2012 10:39:17 +0200 Subject: Python presentations In-Reply-To: <50560df2$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <06a1a81b-246b-4e7b-ba34-4701f46889c8@googlegroups.com> <50525f48$0$6573$9b4e6d93@newsspool3.arcor-online.net> <5053196e$0$6578$9b4e6d93@newsspool3.arcor-online.net> <5055fab1$0$6579$9b4e6d93@newsspool3.arcor-online.net> <50560df2$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5056e1b6$0$6580$9b4e6d93@newsspool3.arcor-online.net> On 16.09.2012 19:35, Steven D'Aprano wrote: > On Sun, 16 Sep 2012 18:13:36 +0200, Alexander Blinne wrote: >> def powerlist2(x,n): >> if n==1: >> return [1] >> p = powerlist3(x,n-1) >> p.append(p[-1]*x) >> return p > > Is that a typo? I think you mean to make a recursive call to powerlist2, > not a non-recursive call to powerlist3. Yes, it is a typo. I originally tested 2 more versions, but tried to change the numbering before posting. Bad idea :) From gandalf at shopzeus.com Mon Sep 17 04:47:41 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 17 Sep 2012 10:47:41 +0200 Subject: reportlab and python 3 Message-ID: <5056E3AD.2050304@shopzeus.com> Reportlab is on the wall of shame. http://python3wos.appspot.com/ Is there other ways to create PDF files from python 3? There is pyPdf. I haven't tried it yet, but it seem that it is a low level library. It does not handle "flowables" that are automatically split across pages. It does not handle "table headers" that are repeated automatically on the top of every page (when the table does not fit on a page). I need a higher level API, with features compareable to reportlab. Is there such thing? Thanks, Laszlo From d at davea.name Mon Sep 17 06:46:55 2012 From: d at davea.name (Dave Angel) Date: Mon, 17 Sep 2012 06:46:55 -0400 Subject: Python garbage collector/memory manager behaving strangely In-Reply-To: <59f8c664-8f11-439e-8002-ca76ee24a632@g7g2000pbh.googlegroups.com> References: <5056871E.7050206@davea.name> <59f8c664-8f11-439e-8002-ca76ee24a632@g7g2000pbh.googlegroups.com> Message-ID: <5056FF9F.1020305@davea.name> On 09/16/2012 11:25 PM, alex23 wrote: > On Sep 17, 12:32 pm, "Jadhav, Alok" > wrote: >> - As you have seen, the line separator is not '\n' but its '|\n'. >> Sometimes the data itself has '\n' characters in the middle of the line >> and only way to find true end of the line is that previous character >> should be a bar '|'. I was not able specify end of line using >> readlines() function, but I could do it using split() function. >> (One hack would be to readlines and combine them until I find '|\n'. is >> there a cleaner way to do this?) > You can use a generator to take care of your readlines requirements: > > def readlines(f): > lines = [] > while "f is not empty": > line = f.readline() > if not line: break > if len(line) > 2 and line[-2:] == '|\n': > lines.append(line) > yield ''.join(lines) > lines = [] > else: > lines.append(line) There's a few changes I'd make: I'd change the name to something else, so as not to shadow the built-in, and to make it clear in caller's code that it's not the built-in one. I'd replace that compound if statement with if line.endswith("|\n": I'd add a comment saying that partial lines at the end of file are ignored. >> - Reading whole file at once and processing line by line was must >> faster. Though speed is not of very important issue here but I think the >> tie it took to parse complete file was reduced to one third of original >> time. You don't say what it was faster than. Chances are you went to the other extreme, of doing a read() of 1 byte at a time. Using Alex's approach of a generator which in turn uses the readline() generator. > With the readlines generator above, it'll read lines from the file > until it has a complete "line" by your requirement, at which point > it'll yield it. If you don't need the entire file in memory for the > end result, you'll be able to process each "line" one at a time and > perform whatever you need against it before asking for the next. > > with open(u'infile.txt','r') as infile: > for line in readlines(infile): > ... > > Generators are a very efficient way of processing large amounts of > data. You can chain them together very easily: > > real_lines = readlines(infile) > marker_lines = (l for l in real_lines if l.startswith('#')) > every_second_marker = (l for i,l in enumerate(marker_lines) if (i > +1) % 2 == 0) > map(some_function, every_second_marker) > > The real_lines generator returns your definition of a line. The > marker_lines generator filters out everything that doesn't start with > #, while every_second_marker returns only half of those. (Yes, these > could all be written as a single generator, but this is very useful > for more complex pipelines). > > The big advantage of this approach is that nothing is read from the > file into memory until map is called, and given the way they're > chained together, only one of your lines should be in memory at any > given time. -- DaveA From alok.jadhav at credit-suisse.com Mon Sep 17 07:00:46 2012 From: alok.jadhav at credit-suisse.com (Jadhav, Alok) Date: Mon, 17 Sep 2012 19:00:46 +0800 Subject: Python garbage collector/memory manager behaving strangely In-Reply-To: <5056FF9F.1020305@davea.name> References: <5056871E.7050206@davea.name><59f8c664-8f11-439e-8002-ca76ee24a632@g7g2000pbh.googlegroups.com> <5056FF9F.1020305@davea.name> Message-ID: Thanks for your valuable inputs. This is very helpful. -----Original Message----- From: Python-list [mailto:python-list-bounces+alok.jadhav=credit-suisse.com at python.org] On Behalf Of Dave Angel Sent: Monday, September 17, 2012 6:47 PM To: alex23 Cc: python-list at python.org Subject: Re: Python garbage collector/memory manager behaving strangely On 09/16/2012 11:25 PM, alex23 wrote: > On Sep 17, 12:32 pm, "Jadhav, Alok" > wrote: >> - As you have seen, the line separator is not '\n' but its '|\n'. >> Sometimes the data itself has '\n' characters in the middle of the line >> and only way to find true end of the line is that previous character >> should be a bar '|'. I was not able specify end of line using >> readlines() function, but I could do it using split() function. >> (One hack would be to readlines and combine them until I find '|\n'. is >> there a cleaner way to do this?) > You can use a generator to take care of your readlines requirements: > > def readlines(f): > lines = [] > while "f is not empty": > line = f.readline() > if not line: break > if len(line) > 2 and line[-2:] == '|\n': > lines.append(line) > yield ''.join(lines) > lines = [] > else: > lines.append(line) There's a few changes I'd make: I'd change the name to something else, so as not to shadow the built-in, and to make it clear in caller's code that it's not the built-in one. I'd replace that compound if statement with if line.endswith("|\n": I'd add a comment saying that partial lines at the end of file are ignored. >> - Reading whole file at once and processing line by line was must >> faster. Though speed is not of very important issue here but I think the >> tie it took to parse complete file was reduced to one third of original >> time. You don't say what it was faster than. Chances are you went to the other extreme, of doing a read() of 1 byte at a time. Using Alex's approach of a generator which in turn uses the readline() generator. > With the readlines generator above, it'll read lines from the file > until it has a complete "line" by your requirement, at which point > it'll yield it. If you don't need the entire file in memory for the > end result, you'll be able to process each "line" one at a time and > perform whatever you need against it before asking for the next. > > with open(u'infile.txt','r') as infile: > for line in readlines(infile): > ... > > Generators are a very efficient way of processing large amounts of > data. You can chain them together very easily: > > real_lines = readlines(infile) > marker_lines = (l for l in real_lines if l.startswith('#')) > every_second_marker = (l for i,l in enumerate(marker_lines) if (i > +1) % 2 == 0) > map(some_function, every_second_marker) > > The real_lines generator returns your definition of a line. The > marker_lines generator filters out everything that doesn't start with > #, while every_second_marker returns only half of those. (Yes, these > could all be written as a single generator, but this is very useful > for more complex pipelines). > > The big advantage of this approach is that nothing is read from the > file into memory until map is called, and given the way they're > chained together, only one of your lines should be in memory at any > given time. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list =============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html =============================================================================== From steve+comp.lang.python at pearwood.info Mon Sep 17 07:47:47 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Sep 2012 11:47:47 GMT Subject: Python garbage collector/memory manager behaving strangely References: <5056871E.7050206@davea.name> <59f8c664-8f11-439e-8002-ca76ee24a632@g7g2000pbh.googlegroups.com> Message-ID: <50570de3$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 17 Sep 2012 06:46:55 -0400, Dave Angel wrote: > On 09/16/2012 11:25 PM, alex23 wrote: >> def readlines(f): >> lines = [] >> while "f is not empty": >> line = f.readline() >> if not line: break >> if len(line) > 2 and line[-2:] == '|\n': >> lines.append(line) >> yield ''.join(lines) >> lines = [] >> else: >> lines.append(line) > > There's a few changes I'd make: > I'd change the name to something else, so as not to shadow the built-in, Which built-in are you referring to? There is no readlines built-in. py> readlines Traceback (most recent call last): File "", line 1, in NameError: name 'readlines' is not defined There is a file.readlines method, but that lives in a different namespace to the function readlines so there should be no confusion. At least not for a moderately experienced programmer, beginners can be confused by the littlest things sometimes. > and to make it clear in caller's code that it's not the built-in one. > I'd replace that compound if statement with > if line.endswith("|\n": > I'd add a comment saying that partial lines at the end of file are > ignored. Or fix the generator so that it doesn't ignore partial lines, or raises an exception, whichever is more appropriate. -- Steven From d at davea.name Mon Sep 17 08:03:47 2012 From: d at davea.name (Dave Angel) Date: Mon, 17 Sep 2012 08:03:47 -0400 Subject: Python garbage collector/memory manager behaving strangely In-Reply-To: <50570de3$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <5056871E.7050206@davea.name> <59f8c664-8f11-439e-8002-ca76ee24a632@g7g2000pbh.googlegroups.com> <50570de3$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <505711A3.9030106@davea.name> On 09/17/2012 07:47 AM, Steven D'Aprano wrote: > On Mon, 17 Sep 2012 06:46:55 -0400, Dave Angel wrote: > >> On 09/16/2012 11:25 PM, alex23 wrote: >>> def readlines(f): >>> lines = [] >>> while "f is not empty": >>> line = f.readline() >>> if not line: break >>> if len(line) > 2 and line[-2:] == '|\n': >>> lines.append(line) >>> yield ''.join(lines) >>> lines = [] >>> else: >>> lines.append(line) >> There's a few changes I'd make: >> I'd change the name to something else, so as not to shadow the built-in, > Which built-in are you referring to? There is no readlines built-in. > > py> readlines > Traceback (most recent call last): > File "", line 1, in > NameError: name 'readlines' is not defined > > > There is a file.readlines method, but that lives in a different namespace > to the function readlines so there should be no confusion. At least not > for a moderately experienced programmer, beginners can be confused by the > littlest things sometimes. You're right of course, and that's not restricted to beginners. I've been at this for over 40 years, and I make that kind of mistake once in a while. Fortunately, when I make such a mistake on this forum, you usually pop in to keep me honest. When I make it in code, I either get a runtime error, or no harm is done. > >> and to make it clear in caller's code that it's not the built-in one. >> I'd replace that compound if statement with >> if line.endswith("|\n": >> I'd add a comment saying that partial lines at the end of file are >> ignored. > Or fix the generator so that it doesn't ignore partial lines, or raises > an exception, whichever is more appropriate. > > > -- DaveA From matteo.boscolo at boscolini.eu Mon Sep 17 08:42:56 2012 From: matteo.boscolo at boscolini.eu (Matteo Boscolo) Date: Mon, 17 Sep 2012 14:42:56 +0200 Subject: gc.get_objects() In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> Message-ID: <50571AD0.4020201@boscolini.eu> Hi All, I'm facing some trouble with a win32com application, it seems, that some com object (win32com) are still in the gc.get_objetc() list, even if I set to non the objetc and I'm out of the scope of that objects. What I'm try to do is to remove this object from the list. but I do know how.. the .__del__() method dose not work on this object... there is someone that can give me some help on this ? Regards, Matteo From jamie at kode5.net Mon Sep 17 09:28:37 2012 From: jamie at kode5.net (Jamie Paul Griffin) Date: Mon, 17 Sep 2012 14:28:37 +0100 Subject: Obnoxious postings from Google Groups (was: datetime issue) In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> <70e4dc2e-4030-4ac3-b78d-a51630816f7c@googlegroups.com> Message-ID: <20120917132837.GD25763@kontrol.kode5.net> [ Joel Goldstick wrote on Sun 16.Sep'12 at 11:57:56 -0400 ] > email client to python-list at python.org If using Windows I would certainly use Thunderbird or even slrn news reader - I believe there is a version for Windows. Or you could install Interix subsystem which provides UNIX tools for Windows 7 Ultimate or Professional. You'd then have some more choice of MUA client or newsreader client in that environment. Cygwin is another alternative. UNIX systems just use whatever email client you like and subscribe to the list as explained several times by others. Fortunately for me I've got procmail deleting double posts because they are annoying. From mayuresh at kathe.in Mon Sep 17 09:59:41 2012 From: mayuresh at kathe.in (Mayuresh Kathe) Date: Mon, 17 Sep 2012 19:29:41 +0530 Subject: gedit : gdp : python word completion Message-ID: has anyone got the above working? From steve+comp.lang.python at pearwood.info Mon Sep 17 10:16:13 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Sep 2012 14:16:13 GMT Subject: gc.get_objects() References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> Message-ID: <505730ad$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 17 Sep 2012 14:42:56 +0200, Matteo Boscolo wrote: > Hi All, > > I'm facing some trouble with a win32com application, it seems, that some > com object (win32com) are still in the gc.get_objetc() list, even if I > set to non the objetc and I'm out of the scope of that objects. You can't set an object to None. An object is itself. It is *always* itself, you can't tell Python to turn it into None. What you can do is re-bind a *name* from an object to None. Suppose you say: x = Spam() then there is a binding between name "x" and the object Spam(), which I will call "spam" from now on. When you then later say: x = None this does *not* convert spam into None, what it does is cuts the binding between name "x" and spam, and binds the name "x" to None. The object spam still exists. If there are no other references to spam, then the garbage collector automatically destroys the spam object. But if there are still references to the spam object, then it will remain alive, and the gc will keep tracking it. References can include: * name bindings: x = spam * list items: mylist.append(spam) * dict keys and values: mydict[spam] = 42; mydict["key"] = spam * attributes: myobject.attr = spam * default values to function parameters: def foo(a, b=spam): ... and probably others. > What I'm try to do is to remove this object from the list. but I do > know how.. If you have a com object being tracked by the garbage collector, that means that it is still in use, somewhere in your program. You can't just tell the gc to stop tracking it. You need to find where you still have a reference to the object. > the .__del__() method dose not work on this object... The __del__ method does not delete an object. Remember, objects are only deleted when there are no references to it. Otherwise you could have some code that tries to use a deleted object, and you would get a system crash or BSOD. The __del__ method is called only when the object is *just about* to be deleted. In general, you should avoid using __del__ methods. They interfere with the garbage collector's ability to resolve cycles. The problem is, what happens if an object contains a link to itself? x = [] x.append(x) Such cycles could be very deep: a = []; b = []; c = []; d = []; ... y = []; z = [] a.append(b) b.append(c) c.append(d) ... y.append(z) z.append(a) ### a cycle appears ### Now you have a cycle of 26 objects, each of which indirectly refers to itself. Normally, Python's garbage collector can recognise such a cycle and safely break it, which then allows all of the objects to be deleted. But if you add a __del__ method to *even one* object, Python can no longer safely break the cycle, and so the objects will remain alive even when you can no longer reach them from your code. So, in general, avoid the __del__ method unless you absolutely need it. -- Steven From jeanmichel at sequans.com Mon Sep 17 10:20:43 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 17 Sep 2012 16:20:43 +0200 (CEST) Subject: Decorators not worth the effort In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4741667C22E@SCACMX008.exchad.jpmchase.net> Message-ID: <246757766.1607257.1347891643781.JavaMail.root@sequans.com> ----- Original Message ----- > Jean-Michel Pichavant wrote: [snip] > One minor note, the style of decorator you are using loses the > docstring > (at least) of the original function. I would add the > @functools.wraps(func) > decorator inside your decorator. Is there a way to not loose the function signature as well ? help (t.api.spuAgc) > spuAgc(self, iterations, backoffTarget, step) method of ... But once decorated with this: def stdApi(func): @functools.wraps(func) def inner(self, *args, **kwargs): rsp = func(self, *args, **kwargs) result = TncCmnResult() result.returnCode = self._getReturnCode(rsp) return result return inner help (t.api.spuAgc) > t.api.spuAgc(self, *args, **kwargs) method of .... Quite annoying :-/ JM From rosuav at gmail.com Mon Sep 17 12:09:25 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Sep 2012 02:09:25 +1000 Subject: gc.get_objects() In-Reply-To: <505730ad$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <505730ad$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 18, 2012 at 12:16 AM, Steven D'Aprano wrote: > The __del__ method does not delete an object. Remember, objects are only > deleted when there are no references to it. Otherwise you could have some > code that tries to use a deleted object, and you would get a system crash > or BSOD. There is a conceptually viable alternative: destroy an object immediately and force all references to it to become some sentinel value (eg None). Python currently doesn't have this, but it would be rather convenient at times. Could be part of a construct like 'with' to say "make this, use it, and then dispose of it". ChrisA From matteo.boscolo at boscolini.eu Mon Sep 17 13:23:23 2012 From: matteo.boscolo at boscolini.eu (Matteo Boscolo) Date: Mon, 17 Sep 2012 19:23:23 +0200 Subject: gc.get_objects() In-Reply-To: References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <505730ad$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50575C8B.3000309@boscolini.eu> from my gc.get_object() I extract the sub system of the object that I would like to delete: this is the object: Class name win32com.gen_py.F4503A16-F637-11D2-BD55-00500400405Bx0x1x0.ITDProperty.ITDProperty that is traked and the reference are: get_referents >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> RefCount 5 >>>> (,) RefCount 5 >>>> '__int__': , '__module__': 'win32com.gen_py.F45 RefCount 8 >>>> ITDProperty RefCount 9 >>>> RefCount 9 >>>> get_referrers >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> RefCount 15 >>>> 'python_version': 34014192, 'defaultUnnamedArg': >>>> >>>> (u'ItemsListCreator', u'trick', u'pVal'), (3, 49, '0', None), (16393, 10, None, RefCount 4 >>>> RefCount 7 >>>> RefCount 5 >>>> '{39AAEA35-F71F-11D2-BD59-00500400405B}': On Tue, Sep 18, 2012 at 12:16 AM, Steven D'Aprano > wrote: >> The __del__ method does not delete an object. Remember, objects are only >> deleted when there are no references to it. Otherwise you could have some >> code that tries to use a deleted object, and you would get a system crash >> or BSOD. > There is a conceptually viable alternative: destroy an object > immediately and force all references to it to become some sentinel > value (eg None). Python currently doesn't have this, but it would be > rather convenient at times. Could be part of a construct like 'with' > to say "make this, use it, and then dispose of it". > > ChrisA From oscar.j.benjamin at gmail.com Mon Sep 17 13:43:06 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 17 Sep 2012 17:43:06 +0000 (UTC) Subject: gc.get_objects() References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <505730ad$0$29981$c3e8da3$5496439d@news.astraweb.com> <50575C8B.3000309@boscolini.eu> Message-ID: On 2012-09-17, Matteo Boscolo wrote: > from my gc.get_object() > I extract the sub system of the object that I would like to delete: > > this is the object: > Class name > win32com.gen_py.F4503A16-F637-11D2-BD55-00500400405Bx0x1x0.ITDProperty.ITDProperty > that is traked and the reference are: > get_referents >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> > >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> > >>>>>>>>>>>> > RefCount 5 > >>>> ( 0x026ACB58>,) > RefCount 5 > >>>> '__int__': , > '__module__': 'win32com.gen_py.F45 > RefCount 8 > >>>> ITDProperty > RefCount 9 > >>>> > RefCount 9 > >>>> > get_referrers >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> > >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> > >>>>>>>>>>>> > RefCount 15 > >>>> 'python_version': 34014192, 'defaultUnnamedArg': > RefCount 6 > >>>> win32com.gen_py.F4503A16-F637-11D2-BD55-00500400405Bx0x1x0.ITDProperty.I > RefCount 4 > >>>> (u'ItemsListCreator', u'trick', u'pVal'), (3, 49, > '0', None), (16393, 10, None, > RefCount 4 > >>>> > RefCount 7 > >>>> > RefCount 5 > >>>> '{39AAEA35-F71F-11D2-BD59-00500400405B}': win32com.gen_py.F4503A16-F637- > > how can I understand how to clean up this situation or were are the > references that I need to delete ? > > From the cad non python script I call an in process python com object, > and before coming back to the cad application I need to clean up all com > reference, because if I do not do that I corrupt the cad application . > > so I urgently need to clean up all reference before coming back to the > cad application. > > any idea? > http://mg.pov.lt/objgraph/ http://mg.pov.lt/blog/hunting-python-memleaks.html I have previously used the code from one of the links above to hunt down a reference leak. It gives a graphical view of the alive references which helps to locate the source of the ref leak. Oscar From nithinmoha at gmail.com Mon Sep 17 15:46:43 2012 From: nithinmoha at gmail.com (nithinmoha at gmail.com) Date: Mon, 17 Sep 2012 12:46:43 -0700 (PDT) Subject: Hiring Python Developer @ CA, USA Message-ID: <11163780-42a0-4fa8-b8ce-42d1e8fbf784@googlegroups.com> From nithinmoha at gmail.com Mon Sep 17 15:48:42 2012 From: nithinmoha at gmail.com (nithinmoha at gmail.com) Date: Mon, 17 Sep 2012 12:48:42 -0700 (PDT) Subject: Hiring Python Developer @ CA, USA Message-ID: Job Title: Python Django Consultant Location: Scotts Valley, CA Duration: Long Term / Full Time Must: ? Python - Must be an export in this language. They currently use Python 2.7 ? Proficient in Unix and source code versioning - They run RedHat and Fedora on the servers and development environments and use Subversion (SVN) for source code control. ? Proficient in Django (Python web framework) Good to have but not necessary: ? PostgreSQL knowledge ? RESTful API development (Tastypie) within Django Please send your updated resume to nithin @ gavsin.com From ethan at stoneleaf.us Mon Sep 17 16:35:01 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 17 Sep 2012 13:35:01 -0700 Subject: Comparing strings from the back? In-Reply-To: References: <504a9785$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> Message-ID: <50578975.2050908@stoneleaf.us> *plonk* From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Sep 17 16:37:12 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 17 Sep 2012 22:37:12 +0200 Subject: using text file to get ip address from hostname In-Reply-To: <0c93c99d-c837-4b20-b78f-8c367ad3cdae@googlegroups.com> References: <0c93c99d-c837-4b20-b78f-8c367ad3cdae@googlegroups.com> Message-ID: Am 15.09.2012 18:20 schrieb Dan Katorza: > hello again friends, > thanks for everyone help on this. > i guess i figured it out in two ways. > the second one i prefer the most. > > i will appreciate if someone can give me some tips. > thanks again > > so... > ------------------------------------------------------------- > First > ------------------------------------------------------------- > #!/usr/bin/env python > #Get the IP Address > > > print("hello, please enter file name here>"), > import socket > for line in open(raw_input()): > hostname = line.strip() > print("IP address for {0} is {1}.".format(hostname,socket.gethostbyname(hostname))) > > ------------------------------------------------------------ > second > ------------------------------------------------------------ > #!/usr/bin/env python > #Get the IP Address > > import os > > print("Hello, please enter file name here>"), > FILENAME = raw_input() > if os.path.isfile(FILENAME): > print("\nFile Exist!") > print("\nGetting ip from host name") > print("\n") > import socket > for line in open (FILENAME): > hostname = line.strip() > print("IP address for {0} is {1}.".format(hostname,socket.gethostbyname(hostname))) > else: > print ("\nFinished the operation") > else: > print ("\nFIle is missing or is not reasable"), > ~ Comparing these, the first one wins if you catch and process exceptions. It is easier to ask for forgiveness than to get permission (EAFP, http://en.wikipedia.org/wiki/EAFP). Bit I wonder that no one has mentionned that socket.gethostbyname(hostname) is quite old-age because it only returns IPv4 addresses (resp. only one of them). OTOH, socket.getaddrinfo(hostname, 0, 0, socket.SOCK_STREAM) gives you a list of parameter tuples for connecting. So which way you go above, you should change the respective lines to for line in ...: hostname = line.strip() for target in socket.getaddrinfo(hostname, 0, socket.AF_UNSPEC, socket.SOCK_STREAM): print("IP address for {0} is {1}.".format(hostname, target[4][0])) Thomas From the.merck at gmail.com Mon Sep 17 17:55:38 2012 From: the.merck at gmail.com (=?ISO-8859-1?Q?Fernando_Jim=E9nez?=) Date: Mon, 17 Sep 2012 23:55:38 +0200 Subject: how to use property? Message-ID: Hi guys! I'm noob in python and I would know how to correctly use the property. I have read some things about it but I do not quite understand. I found this: class C(object): def __init__(self): self._x = None @property def x(self): """I'm the 'x' property.""" return self._x @x.setter def x(self, value): self._x = value @x.deleter def x(self): del self._x But I think it's a bad habit to use _ to change the visibility of the attributes as in JAVA. How to correctly use the property? -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Mon Sep 17 18:07:44 2012 From: d at davea.name (Dave Angel) Date: Mon, 17 Sep 2012 18:07:44 -0400 Subject: how to use property? In-Reply-To: References: Message-ID: <50579F30.20002@davea.name> On 09/17/2012 05:55 PM, Fernando Jim?nez wrote: > Hi guys! > > I'm noob in python and I would know how to correctly use the property. I > have read some things about it but I do not quite understand. > > I found this: > > class C(object): > def __init__(self): > self._x = None > > @property > def x(self): > """I'm the 'x' property.""" > return self._x > > @x.setter > def x(self, value): > self._x = value > > @x.deleter > def x(self): > del self._x > > But I think it's a bad habit to use _ to change the visibility of the > attributes as in JAVA. > > How to correctly use the property? > > That's already correct. But if you don't like _x, then use _rumplestiltskin. -- DaveA From rosuav at gmail.com Mon Sep 17 18:12:26 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Sep 2012 08:12:26 +1000 Subject: how to use property? In-Reply-To: References: Message-ID: On Tue, Sep 18, 2012 at 7:55 AM, Fernando Jim?nez wrote: > Hi guys! > > I'm noob in python and I would know how to correctly use the property. I > have read some things about it but I do not quite understand. > > But I think it's a bad habit to use _ to change the visibility of the > attributes as in JAVA. > > How to correctly use the property? The single leading underscore is nothing to do with visibility; it's a courteous request that external referents not touch something. In a "consenting adults" model, that's usually sufficient. For the most part, in fact, you don't need @property at all. Just make an object's members public and save yourself the trouble! Unlike the recommendation in C++ and Java, Python doesn't ask you to hide things and write code to make them available. Instead of starting with getters and setters, just start with a flat property, and move to getters/setters only when you find you need them. The example you posted is adding nothing to the work flow, but it's a good structure that you can tinker with. For instance, if you need to log all changes for debugging purposes, @property will make that easy. But for the bulk of attributes, it's complete overkill. ChrisA From wanderer at dialup4less.com Mon Sep 17 18:31:08 2012 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 17 Sep 2012 15:31:08 -0700 (PDT) Subject: splitting numpy array unevenly Message-ID: I need to divide a 512x512 image array with the first horizontal and vertical division 49 pixels in. Then every 59 pixels in after that. hsplit and vsplit want to start at the edges and create a bunch of same size arrays. Is there a command to chop off different sized arrays? Thanks From solipsis at pitrou.net Mon Sep 17 18:42:20 2012 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 17 Sep 2012 22:42:20 +0000 (UTC) Subject: Using =?utf-8?b?UHlfQWRkUGVuZGluZ0NhbGw=?= References: Message-ID: css322 gmail.com> writes: > > (1) A worker thread calls Py_AddPendingCall and assigns a handler function. > (2) When the Python interpreter runs, it calls the handler function whenever it yields control to another thread Not exactly. As the documentation says: "If successful, func will be called with the argument arg *at the earliest convenience*." This is a deliberately vague wording to stress that the function will not be called as early as you think. It *should* be called in a timely manner, but not necessarily as soon as the thread switch happens. Which begs the question: > In this example, worker_thread is invoked in C as a pthread worker thread. This > loops infinitely, but the pending call handler is never invoked. What is your main Python thread doing? Is it running Python code (*)? Or do you have a main Python thread at all? The "main Python thread" is the one from which Py_Initialize() was called. (*) for example, running one of the following functions: http://docs.python.org/dev/c-api/veryhigh.html Regards Antoine. From nhodgson at iinet.net.au Mon Sep 17 19:14:05 2012 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Tue, 18 Sep 2012 09:14:05 +1000 Subject: Comparing strings from the back? In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> Message-ID: Ethan Furman: > *plonk* I can't work out who you are plonking. While more than one of the posters on this thread seem worthy of a good plonk, by not including sufficient context, you've left me feeling puzzled. Is there a guideline for this in basic netiquette? Neil From tjreedy at udel.edu Mon Sep 17 19:34:52 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 17 Sep 2012 19:34:52 -0400 Subject: how to use property? In-Reply-To: References: Message-ID: On 9/17/2012 6:12 PM, Chris Angelico wrote: > On Tue, Sep 18, 2012 at 7:55 AM, Fernando Jim?nez wrote: >> Hi guys! >> >> I'm noob in python and I would know how to correctly use the property. I >> have read some things about it but I do not quite understand. >> >> But I think it's a bad habit to use _ to change the visibility of the >> attributes as in JAVA. >> >> How to correctly use the property? > > The single leading underscore is nothing to do with visibility; it's a > courteous request that external referents not touch something. In a > "consenting adults" model, that's usually sufficient. > > For the most part, in fact, you don't need @property at all. Just make > an object's members public and save yourself the trouble! Unlike the > recommendation in C++ and Java, Python doesn't ask you to hide things > and write code to make them available. Instead of starting with > getters and setters, just start with a flat property, and move to > getters/setters only when you find you need them. More examples: A class has a data attribute that really is a simple attribute, no property. You define a subclass that needs a calculation for the attribute. So you use property in the subclass. A class has an attribute that is a constant that must be computed. You do not want to compute is unless and until needed. def get_x(self): try: return self._x except AttributeError: self._x = calculate_x() return self._ For a read-only attribute, don't provide a setter. If you do not like "AttributeError: can't set attribute", provide one with a customized error. But I think most of the data attributes in stdlib classes are straight attributes. -- Terry Jan Reedy From mdekauwe at gmail.com Mon Sep 17 19:43:05 2012 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Mon, 17 Sep 2012 16:43:05 -0700 (PDT) Subject: splitting numpy array unevenly In-Reply-To: References: Message-ID: On Tuesday, September 18, 2012 8:31:09 AM UTC+10, Wanderer wrote: > I need to divide a 512x512 image array with the first horizontal and vertical division 49 pixels in. Then every 59 pixels in after that. hsplit and vsplit want to start at the edges and create a bunch of same size arrays. Is there a command to chop off different sized arrays? > > > > Thanks I don't know that I follow completely, but can't you just slice what you are after? x = np.random.rand(512*512).reshape(512,512) xx = x[0,:49] And put the rest of the slices in a loop...? From d at davea.name Mon Sep 17 19:46:23 2012 From: d at davea.name (Dave Angel) Date: Mon, 17 Sep 2012 19:46:23 -0400 Subject: how to use property? In-Reply-To: References: Message-ID: <5057B64F.2080500@davea.name> On 09/17/2012 07:34 PM, Terry Reedy wrote: > On 9/17/2012 6:12 PM, Chris Angelico wrote: >> On Tue, Sep 18, 2012 at 7:55 AM, Fernando Jim?nez >> wrote: >>> Hi guys! >>> >>> I'm noob in python and I would know how to correctly use the >>> property. I >>> have read some things about it but I do not quite understand. >>> >>> But I think it's a bad habit to use _ to change the visibility of the >>> attributes as in JAVA. >>> >>> How to correctly use the property? >> > > More examples: > > A class has a data attribute that really is a simple attribute, no > property. You define a subclass that needs a calculation for the > attribute. So you use property in the subclass. > > A class has an attribute that is a constant that must be computed. You > do not want to compute is unless and until needed. > > def get_x(self): > try: > return self._x > except AttributeError: > self._x = calculate_x() > return self._ > > For a read-only attribute, don't provide a setter. If you do not like > "AttributeError: can't set attribute", provide one with a customized > error. > > But I think most of the data attributes in stdlib classes are straight > attributes. > An important difference from every other language I've used: The user of the attribute does not need to change his code when you decide it needs reimplementation as a property. In C++ and java, for example, people will define getter and setter methods just so they don't have to change them later. Just "in case" it's needed later. -- DaveA From joshua.landau.ws at gmail.com Mon Sep 17 20:23:33 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Tue, 18 Sep 2012 01:23:33 +0100 Subject: splitting numpy array unevenly In-Reply-To: References: Message-ID: On 17 September 2012 23:31, Wanderer wrote: > I need to divide a 512x512 image array with the first horizontal and > vertical division 49 pixels in. Then every 59 pixels in after that. hsplit > and vsplit want to start at the edges and create a bunch of same size > arrays. Is there a command to chop off different sized arrays? > hsplits = [49] sum_hsplits = 49 while sum_hsplits < 512: hsplits.append(sum_hsplits) sum_hsplits += 59 np.split(np.random.rand(512), hsplits) If I understand correctly, this is a one-dimensional version of what you want. Extending this to the second dimension should be quite easy. However, I am not sure if I do understand what you want. Could you elaborate on what you are trying to achieve? -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Mon Sep 17 20:26:44 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 18 Sep 2012 01:26:44 +0100 Subject: how to use property? In-Reply-To: <5057B64F.2080500@davea.name> References: <5057B64F.2080500@davea.name> Message-ID: <5057BFC4.7020904@mrabarnett.plus.com> On 2012-09-18 00:46, Dave Angel wrote: > On 09/17/2012 07:34 PM, Terry Reedy wrote: >> On 9/17/2012 6:12 PM, Chris Angelico wrote: >>> On Tue, Sep 18, 2012 at 7:55 AM, Fernando Jim?nez >>> wrote: >>>> Hi guys! >>>> >>>> I'm noob in python and I would know how to correctly use the >>>> property. I >>>> have read some things about it but I do not quite understand. >>>> >>>> But I think it's a bad habit to use _ to change the visibility of the >>>> attributes as in JAVA. >>>> >>>> How to correctly use the property? >>> >> > >> More examples: >> >> A class has a data attribute that really is a simple attribute, no >> property. You define a subclass that needs a calculation for the >> attribute. So you use property in the subclass. >> >> A class has an attribute that is a constant that must be computed. You >> do not want to compute is unless and until needed. >> >> def get_x(self): >> try: >> return self._x >> except AttributeError: >> self._x = calculate_x() >> return self._ >> >> For a read-only attribute, don't provide a setter. If you do not like >> "AttributeError: can't set attribute", provide one with a customized >> error. >> >> But I think most of the data attributes in stdlib classes are straight >> attributes. >> > > An important difference from every other language I've used: The user > of the attribute does not need to change his code when you decide it > needs reimplementation as a property. > > In C++ and java, for example, people will define getter and setter > methods just so they don't have to change them later. Just "in case" > it's needed later. > C# and Delphi (IIRC) also support properties. From ian.g.kelly at gmail.com Mon Sep 17 20:35:46 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 17 Sep 2012 18:35:46 -0600 Subject: how to use property? In-Reply-To: <5057BFC4.7020904@mrabarnett.plus.com> References: <5057B64F.2080500@davea.name> <5057BFC4.7020904@mrabarnett.plus.com> Message-ID: On Mon, Sep 17, 2012 at 6:26 PM, MRAB wrote: > On 2012-09-18 00:46, Dave Angel wrote: >> An important difference from every other language I've used: The user >> of the attribute does not need to change his code when you decide it >> needs reimplementation as a property. >> >> In C++ and java, for example, people will define getter and setter >> methods just so they don't have to change them later. Just "in case" >> it's needed later. >> > C# and Delphi (IIRC) also support properties. I don't know about Delphi, but in .NET changing between a public field and a property breaks ABI. From rivera at joel.mx Mon Sep 17 20:48:45 2012 From: rivera at joel.mx (Joel Rivera) Date: Mon, 17 Sep 2012 19:48:45 -0500 Subject: reportlab and python 3 In-Reply-To: <5056E3AD.2050304@shopzeus.com> References: <5056E3AD.2050304@shopzeus.com> Message-ID: On 2012-09-17 03:47, Laszlo Nagy wrote: > Reportlab is on the wall of shame. http://python3wos.appspot.com/ > > Is there other ways to create PDF files from python 3? There is > pyPdf. I haven't tried it yet, but it seem that it is a low level > library. It does not handle "flowables" that are automatically split > across pages. It does not handle "table headers" that are repeated > automatically on the top of every page (when the table does not fit > on > a page). I need a higher level API, with features compareable to > reportlab. Is there such thing? > > Thanks, > > Laszlo On 2012-09-17 03:47, Laszlo Nagy wrote: > Reportlab is on the wall of shame. http://python3wos.appspot.com/ > > Is there other ways to create PDF files from python 3? There is > pyPdf. I haven't tried it yet, but it seem that it is a low level > library. It does not handle "flowables" that are automatically split > across pages. It does not handle "table headers" that are repeated > automatically on the top of every page (when the table does not fit > on > a page). I need a higher level API, with features compareable to > reportlab. Is there such thing? > > Thanks, > > Laszlo I'm afraid that, no, and this is my story of suffering: I been looking for something like that since the past month, first I try to port a library pypdflib[1] with no success, cairo is not well supported yet and the different forks of PIL aren't working nicely with 3.2 also carries a lot of dependencies, so I desist on that. Then I try this pyfpdf [2] to improve another port, but.. I end up spending a LOT of time reading the PDF and PNG SPEC and trying to unphpfy the code (In fact I couldn't make it work png images with alpha mask), so I start to get desperate and I took another approach, wrap another command. First, I try with xhtml2pdf [3], but It does not have a great support for the css rule "@page" which is pretty indispensable for me and in general wasn't very nice to generate precise pdf's, the commercial alternative "prince" have some fame of being good but I'm not willing to spend $3,800 on the license [4], also exists a few other commercial alternatives like pdftron [5] which support python3. And then after all of that my current effort is wrapping FOP [6], but instead of using XSL I reuse mako to generate the fo file, I leverage the pain of writing XML by hand with mako which provides the fo: namespace and some other tricks, at the time it seems robust and feature rich because of the nature of xsl-fo, but who now's I'm just starting with this I'll be working in this approach the following weeks. And if by any mean you found a better alternative please let me know and if you are so kind put the answer in this [7] stackoverflow question. Cheers. [1]: https://github.com/cyraxjoe/pypdflib [2]: https://bitbucket.org/cyraxjoe/py3fpdf [3]: https://github.com/chrisglass/xhtml2pdf [4]: http://www.princexml.com/purchase [5]: http://www.pdftron.com/ [6]: http://xmlgraphics.apache.org/fop/ [7]: http://stackoverflow.com/q/12021216/298371 -- Rivera? From davids at invtools.com Mon Sep 17 21:08:32 2012 From: davids at invtools.com (David Smith) Date: Mon, 17 Sep 2012 21:08:32 -0400 Subject: 'indent'ing Python in windows bat In-Reply-To: References: Message-ID: <5057C990.8080809@invtools.com> Hello, I'm essentially a newbie in Python. My problem in searching the archives is not knowing what words to use to ask. I'm converting windows bat files little by little to Python 3 as I find time and learn Python. The most efficient method for some lines is to call Python like: python -c "import sys; sys.exit(3)" How do I "indent" if I have something like: if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else sys.exit(3) My sole result in many attempts is "Syntax Error." Thank you for any help. From d at davea.name Mon Sep 17 21:22:04 2012 From: d at davea.name (Dave Angel) Date: Mon, 17 Sep 2012 21:22:04 -0400 Subject: 'indent'ing Python in windows bat In-Reply-To: <5057C990.8080809@invtools.com> References: <5057C990.8080809@invtools.com> Message-ID: <5057CCBC.4000809@davea.name> On 09/17/2012 09:08 PM, David Smith wrote: > Hello, I'm essentially a newbie in Python. > My problem in searching the archives is not knowing what words to use > to ask. > > I'm converting windows bat files little by little to Python 3 as I > find time and learn Python. > The most efficient method for some lines is to call Python like: > python -c "import sys; sys.exit(3)" > > How do I "indent" if I have something like: > if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else > sys.exit(3) > > My sole result in many attempts is "Syntax Error." > > Thank you for any help. > I don't understand your actual problem. Python is much more expressive than batch, so why not actually convert it? Write a file with an extension of .py, and run it the same way you'd run a batch file. This assumes you have Python 3 associated with the .py extension. Now it won't matter if the python code has one line, or 100. -- DaveA From huhai1003 at gmail.com Mon Sep 17 21:40:31 2012 From: huhai1003 at gmail.com (hai1003 hu) Date: Mon, 17 Sep 2012 18:40:31 -0700 (PDT) Subject: =?UTF-8?Q?Cheap_Jordan_Shoes=EF=BC=88www=2Enike=2Dblack=2Ecom=EF=BC=89wholesale_?= =?UTF-8?Q?basketball_shoes?= Message-ID: <81ed21b3-2f13-4f96-9b3c-c29a68b2616f@k3g2000pbr.googlegroups.com>

wholesale air jordan shoes
cheap wholesale air jordan shoes
cheap air jordan shoes free shipping
cheap air jordan shoes for sale
cheap air jordan shoes for men
cheap air jordan basketball shoes
cheap air jordan shoes paypal free shipping
cheap air jordan shoes usa

wholesale air jordans
air jordan shoes suppliers
wholesale nike shoes
wholesale air jordan shoes china
wholesale air jordan shoes paypal
wholesale air jordan shoes free shipping
wholesale basketball shoes
wholesale lebron james shoes

discount michael jordan shoes
discount nike shoes
discount basketball shoes
discount lebron james shoes
discount footlocker
discount nike
discount finish line
discount air force ones

buy authentic air jordan shoes
buy michael jordan shoes
buy nike jordan shoes
buy air jordan sneakers
buy air jordan retro
buy nike shoes
buy air force ones shoes
buy basketball shoes

authentic air jordan shoes for sale
air jordan shoes for cheap
air jordan shoes for sale cheap
jordan shoes for sale
air jordan shoes history
air jordans
air jordan release dates
air jordans for sale

air jordan shoes for sale
authentic air jordan shoes
air jordan shoes list
air jordan shoes history
air jordan nike shoes
air jordan skate shoes
air jordan basketball shoes
air jordan running shoes

authentic jordan shoes
jordan shoes for sale
retro jordan shoes
custom jordan shoes
jordan shoes release dates
air jordan
jordan shoes wiki
jordan nike shoes

wholesale jordan shoes
cheap authentic jordan shoes
cheap jordan shoes for sale
cheap jordan shoes free shipping
cheap jordan shoes online
cheap jordan shoes for kids
cheap jordan nike shoes
cheap jordan basketball shoes

wholesale jordan shoes
discount jordan shoes wholesale
cheap jordan shoes
discount michael jordan shoes
discount nike shoes
discount jordan basketball shoes
discount jordan shoes online
discount jordans

 

website: http://www.nike-black.com From ben+python at benfinney.id.au Mon Sep 17 22:03:09 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 18 Sep 2012 12:03:09 +1000 Subject: Docstring parsing and formatting Message-ID: <7wk3vskrz6.fsf@benfinney.id.au> Howdy all, Where can I find a standard implementation of the docstring parsing and splitting algorithm from PEP 257? PEP 257 describes a convention of structure and formatting for docstrings . Docstrings that conform to this convention can therefore be parsed into their component parts, and re-formatted. The PEP describes and algorithm for parsing the docstring as found in the string literal. It says ?Docstring processing tools will ?? and goes on to describe, in prose and example code, how the parsing should be done. Where is a common implementation of that algorithm? It seems that it should be in the Python standard library, but I can't find it. Ideally what I want is to be able to write: import textwrap (summary, description) = textwrap.pep257_parse(foo.__doc__) and have ?summary? as the docstring's summary line, and ?description? as the docstring's description (as described in ). From ian.g.kelly at gmail.com Mon Sep 17 23:01:14 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 17 Sep 2012 21:01:14 -0600 Subject: 'indent'ing Python in windows bat In-Reply-To: <5057C990.8080809@invtools.com> References: <5057C990.8080809@invtools.com> Message-ID: On Mon, Sep 17, 2012 at 7:08 PM, David Smith wrote: > How do I "indent" if I have something like: > if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else > sys.exit(3) How about: if sR == 'Cope': sys.exit(1) elif sR == 'Perform': sys.exit(2) else: sys.exit(3) I don't really understand why you're trying to keep it all on one line. From roy at panix.com Mon Sep 17 23:17:54 2012 From: roy at panix.com (Roy Smith) Date: Mon, 17 Sep 2012 23:17:54 -0400 Subject: 'indent'ing Python in windows bat References: <5057C990.8080809@invtools.com> Message-ID: In article , Ian Kelly wrote: > On Mon, Sep 17, 2012 at 7:08 PM, David Smith wrote: > > How do I "indent" if I have something like: > > if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else > > sys.exit(3) > > How about: > > if sR == 'Cope': > sys.exit(1) > elif sR == 'Perform': > sys.exit(2) > else: > sys.exit(3) > > I don't really understand why you're trying to keep it all on one line. sys.exit({'Cope':1, 'Perform':2}.get(sR, 3)) From timr at probo.com Mon Sep 17 23:59:44 2012 From: timr at probo.com (Tim Roberts) Date: Mon, 17 Sep 2012 20:59:44 -0700 Subject: 'indent'ing Python in windows bat References: Message-ID: <67sf58h6gtfl8m044rn25un89ic99ur93n@4ax.com> David Smith wrote: > >I'm converting windows bat files little by little to Python 3 as I find >time and learn Python. >The most efficient method for some lines is to call Python like: >python -c "import sys; sys.exit(3)" > >How do I "indent" if I have something like: >if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else >sys.exit(3) > >My sole result in many attempts is "Syntax Error." The other responses asking "why" are excellent, but this will do that specific job: sys.exit( {'Cope':1,'Perform':2}.get(sR,3) ) The best way to convert a batch file to Python is to convert the whole file to a Python script. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From clp2 at rebertia.com Tue Sep 18 00:22:19 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 17 Sep 2012 21:22:19 -0700 Subject: 'indent'ing Python in windows bat In-Reply-To: References: <5057C990.8080809@invtools.com> Message-ID: On Mon, Sep 17, 2012 at 8:28 PM, Dennis Lee Bieber wrote: > On Mon, 17 Sep 2012 21:08:32 -0400, David Smith > declaimed the following in gmane.comp.python.general: > >> >> How do I "indent" if I have something like: >> if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else >> sys.exit(3) >> > If the sole purpose of the BAT file is to set return codes, I > wouldn't bother using Python... Python is /not/ a shell language > substitute FWIW, it kinda was, for the Amoeba OS, originally: http://docs.python.org/faq/general#why-was-python-created-in-the-first-place Cheers, Chris From dhananjay.c.joshi at gmail.com Tue Sep 18 00:56:02 2012 From: dhananjay.c.joshi at gmail.com (Dhananjay) Date: Tue, 18 Sep 2012 12:56:02 +0800 Subject: How to queue functions Message-ID: Dear all, I am trying to use multiprocessing module. I have 5 functions and 2000 input files. First, I want to make sure that these 5 functions execute one after the other. Is there any way that I could queue these 5 functions within the same script ? Next, as there are 2000 input files. I could queue them by queue.put() and get back to run one by one using queue.get() as follows: for file in files: if '.dat.gz' in file: q.put(file) while True: item = q.get() x1 = f1(item) x2 = f2(x1) x3 = f3(x2) x4 = f4(x3) final_output = f5(x4) However, how can I input them on my 8 core machine, so that at a time 8 files will be processed (to the set of 5 functions; each function one after the other) ? I am bit confused with the multiprocessing, please suggest me some directions .... Thank you -- Joshi -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Sep 18 01:03:12 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 18 Sep 2012 01:03:12 -0400 Subject: Docstring parsing and formatting In-Reply-To: <7wk3vskrz6.fsf@benfinney.id.au> References: <7wk3vskrz6.fsf@benfinney.id.au> Message-ID: On 9/17/2012 10:03 PM, Ben Finney wrote: > Howdy all, > > Where can I find a standard implementation of the docstring parsing and > splitting algorithm from PEP 257? I presume there is something in the code behind help(). -- Terry Jan Reedy From tjreedy at udel.edu Tue Sep 18 01:08:54 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 18 Sep 2012 01:08:54 -0400 Subject: 'indent'ing Python in windows bat In-Reply-To: <5057C990.8080809@invtools.com> References: <5057C990.8080809@invtools.com> Message-ID: On 9/17/2012 9:08 PM, David Smith wrote: > Hello, I'm essentially a newbie in Python. > My problem in searching the archives is not knowing what words to use to > ask. > > I'm converting windows bat files little by little to Python 3 as I find > time and learn Python. > The most efficient method for some lines is to call Python like: > python -c "import sys; sys.exit(3)" > > How do I "indent" if I have something like: > if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else > sys.exit(3) Quite aside from whether this is good idea, I believe putting \n followed by spaces or \t in the quoted string should work. It does for exec. -- Terry Jan Reedy From d at davea.name Tue Sep 18 01:16:25 2012 From: d at davea.name (Dave Angel) Date: Tue, 18 Sep 2012 01:16:25 -0400 Subject: 'indent'ing Python in windows bat In-Reply-To: References: <5057C990.8080809@invtools.com> Message-ID: <505803A9.4000409@davea.name> On 09/18/2012 01:08 AM, Terry Reedy wrote: > On 9/17/2012 9:08 PM, David Smith wrote: >> Hello, I'm essentially a newbie in Python. >> My problem in searching the archives is not knowing what words to use to >> ask. >> >> I'm converting windows bat files little by little to Python 3 as I find >> time and learn Python. >> The most efficient method for some lines is to call Python like: >> python -c "import sys; sys.exit(3)" >> >> How do I "indent" if I have something like: >> if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else >> sys.exit(3) > > Quite aside from whether this is good idea, I believe putting \n > followed by spaces or \t in the quoted string should work. It does for > exec. > Don't forget, the OP uses Windows. Last I looked, the cmd processor had miserable escaping features. But I could easily be wrong -- I haven't used Windows deliberately for quite a while now. -- DaveA From wxjmfauth at gmail.com Tue Sep 18 03:16:03 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 18 Sep 2012 00:16:03 -0700 (PDT) Subject: reportlab and python 3 In-Reply-To: References: Message-ID: <9aa9f1dd-f6b1-4de4-8606-e83a54318765@googlegroups.com> Le lundi 17 septembre 2012 10:48:30 UTC+2, Laszlo Nagy a ?crit?: > Reportlab is on the wall of shame. http://python3wos.appspot.com/ > > > > Is there other ways to create PDF files from python 3? There is pyPdf. I > > haven't tried it yet, but it seem that it is a low level library. It > > does not handle "flowables" that are automatically split across pages. > > It does not handle "table headers" that are repeated automatically on > > the top of every page (when the table does not fit on a page). I need a > > higher level API, with features compareable to reportlab. Is there such > > thing? > > > > Thanks, > > > > Laszlo A big yes and it is very easy. I assume you know how to write a plain text file with Python :-). Use your Python to generate a .tex file and let it compile with one of the pdf TeX engines. Potential problems: - It requires a TeX installation (a no problem). - Of course I requires some TeX knowledge. Learning it is not so complicate. Learn how to use TeX with a text editor and you will quickly understand what you have to program in Python. Bonus: you learn at the same time a good text editing engine. I can not figure out something more simple, versatile and powerful. jmf From wxjmfauth at gmail.com Tue Sep 18 03:16:03 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 18 Sep 2012 00:16:03 -0700 (PDT) Subject: reportlab and python 3 In-Reply-To: References: Message-ID: <9aa9f1dd-f6b1-4de4-8606-e83a54318765@googlegroups.com> Le lundi 17 septembre 2012 10:48:30 UTC+2, Laszlo Nagy a ?crit?: > Reportlab is on the wall of shame. http://python3wos.appspot.com/ > > > > Is there other ways to create PDF files from python 3? There is pyPdf. I > > haven't tried it yet, but it seem that it is a low level library. It > > does not handle "flowables" that are automatically split across pages. > > It does not handle "table headers" that are repeated automatically on > > the top of every page (when the table does not fit on a page). I need a > > higher level API, with features compareable to reportlab. Is there such > > thing? > > > > Thanks, > > > > Laszlo A big yes and it is very easy. I assume you know how to write a plain text file with Python :-). Use your Python to generate a .tex file and let it compile with one of the pdf TeX engines. Potential problems: - It requires a TeX installation (a no problem). - Of course I requires some TeX knowledge. Learning it is not so complicate. Learn how to use TeX with a text editor and you will quickly understand what you have to program in Python. Bonus: you learn at the same time a good text editing engine. I can not figure out something more simple, versatile and powerful. jmf From paul.nospam at rudin.co.uk Tue Sep 18 03:40:05 2012 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 18 Sep 2012 08:40:05 +0100 Subject: Hiring Python Developer @ CA, USA References: Message-ID: <87pq5jg4oa.fsf@no-fixed-abode.cable.virginmedia.net> nithinmoha at gmail.com writes: > ...Must be an export in this language... Are you hiring proof readers as well? :) From sergeiiv65 at gmail.com Tue Sep 18 03:52:53 2012 From: sergeiiv65 at gmail.com (sergeiiv65 at gmail.com) Date: Tue, 18 Sep 2012 00:52:53 -0700 (PDT) Subject: How to use __getattr__ to the current module, for automatically add attributes of the real-time Message-ID: <74247047-c5b5-42a0-af69-4c520a1d5d8d@googlegroups.com> Want to work so: import sys class Foo(object): def __getattr__(self, t): print 'use __getattr__ - ', t return type(t, (object,), {}) def funct1(self): pass def funct2(self): pass sys.modules[__name__] = Foo() ttt('yy') name 'ttt' is not defined. __getattr__ not work (((. From kushal.kumaran+python at gmail.com Tue Sep 18 04:31:55 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Tue, 18 Sep 2012 14:01:55 +0530 Subject: How to queue functions In-Reply-To: References: Message-ID: On Tue, Sep 18, 2012 at 10:26 AM, Dhananjay wrote: > Dear all, > > I am trying to use multiprocessing module. > I have 5 functions and 2000 input files. > > First, I want to make sure that these 5 functions execute one after the > other. > Is there any way that I could queue these 5 functions within the same script > ? > > > Next, as there are 2000 input files. > I could queue them by queue.put() and get back to run one by one using > queue.get() as follows: > > for file in files: > if '.dat.gz' in file: > q.put(file) > > while True: > item = q.get() > x1 = f1(item) > x2 = f2(x1) > x3 = f3(x2) > x4 = f4(x3) > final_output = f5(x4) > > > However, how can I input them on my 8 core machine, so that at a time 8 > files will be processed (to the set of 5 functions; each function one after > the other) ? > The multiprocessing.Pool class seems to be what you need. Documentation at http://docs.python.org/py3k/library/multiprocessing.html#using-a-pool-of-workers Example: #!/usr/bin/env python3 import multiprocessing def file_handler(filename): # do processing on filename, return the final_output print('working on {}'.format(filename)) return 'processed-{}'.format(filename) def main(): p = multiprocessing.Pool(8) files = [ 'a', 'b', 'c' ] result = p.map(file_handler, files) print(result) if __name__ == '__main__': main() If you want, you can also implement everything using multiprocessing.Process and multiprocessing.Queue, but using pools should be simpler. -- regards, kushal From info at egenix.com Tue Sep 18 04:41:28 2012 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 18 Sep 2012 10:41:28 +0200 Subject: ANN: eGenix mxODBC Zope/Plone Database Adapter 2.1.0 Message-ID: <505833B8.2090707@egenix.com> ________________________________________________________________________ ANNOUNCEMENT mxODBC Zope/Plone Database Adapter Version 2.1.0 for Zope and the Plone CMS Available for Plone 4.0, 4.1 and 4.2, Zope 2.12 and 2.13, on Windows, Linux, Mac OS X, FreeBSD and other platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-Zope-DA-2.1.0-GA.html ________________________________________________________________________ INTRODUCTION The eGenix mxODBC Zope DA allows you to easily connect your Zope or Plone CMS installation to just about any database backend on the market today, giving you the reliability of the commercially supported eGenix product mxODBC and the flexibility of the ODBC standard as middle-tier architecture. The mxODBC Zope Database Adapter is highly portable, just like Zope itself and provides a high performance interface to all your ODBC data sources, using a single well-supported interface on Windows, Linux, Mac OS X, FreeBSD and other platforms. This makes it ideal for deployment in ZEO Clusters and Zope hosting environments where stability and high performance are a top priority, establishing an excellent basis and scalable solution for your Plone CMS. Product page: http://www.egenix.com/products/zope/mxODBCZopeDA/ ________________________________________________________________________ NEWS We are pleased to announce a new version 2.1.0 of our mxODBC Zope/Plone Database Adapter product. Updated Plone Support --------------------- In this new release, we have focused on a simplified zc.buildout deployment as used in Plone 4.x and the latest Zope 2.13 releases. The mxODBC Zope DA is now again compatible with all recent Plone versions. Please see the mxODBC Zope DA documentation for details on how to install the product for use in Plone. For the full list of features, please see the mxODBC Zope DA feature list: http://www.egenix.com/products/zope/mxODBCZopeDA/#Features Enhanced ODBC Driver Support ---------------------------- We have also updated the integrated mxODBC Python Extension to the latest 3.2 release, which includes a number of important new features and ODBC driver compatibility enhancements: * Added support for the DataDirect ODBC manager on Linux which is used by several data warehouse database backends * Added MS SQL Server ODBC Driver 1.0 for Linux support * Added Teradata support * Added Netezza support * Switched to unixODBC 2.3.1+ API for better 64-bit support on Linux * Enhanced Oracle Instance Client support * Enhanced IBM DB2 driver support * Enhanced Sybase ASE driver support * Enhanced FreeTDS ODBC driver support * Enhanced PostgreSQL driver support * Enhanced generic support for many other ODBC compatible databases Please see the mxODBC 3.2 release announcement for a complete set of changes available in the underlying mxODBC 3.2 package used in mxODBC Zope/Plone DA 2.1: http://www.egenix.com/company/news/eGenix-mxODBC-3.2.0-GA.html Lowered Overall Licensing Costs ------------------------------- Starting with version 2.1, we have also simplified our license terms to clarify the situation on multi-core and virtual machines. In most cases, you no longer need to purchase more than one license per Zope/Plone instance, if you are running on a multi-core processor or virtual machine, scaling down the overall license costs significantly compared to earlier mxODBC Zope DA releases. Minor other changes ------------------- * Error screens have been changed to plain text after the recent hot fix which disabled showing HTML in error messages * The "Security" tab now also works in Zope 2.13 ________________________________________________________________________ UPGRADING Users are encouraged to upgrade to this latest mxODBC Zope/Plone DA release to benefit from the new features and updated ODBC driver support. We have taken special care not to introduce backwards incompatible changes, making the upgrade experience as smooth as possible. For upgrade purchases, we will give out 20% discount coupons going from mxODBC Zope DA 1.x to 2.1 and 50% coupons for upgrades from mxODBC 2.x to 2.1. After upgrade, use of the original license from which you upgraded is no longer permitted. Please contact the eGenix.com Sales Team with your existing license serials for details for an upgrade discount coupon. If you want to try the new release before purchace, you can request 30-day evaluation licenses by visiting our web-site or writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. ________________________________________________________________________ MORE INFORMATION For more information on the mxODBC Zope Database Adapter, licensing and download instructions, please visit our web-site: http://www.egenix.com/products/zope/mxODBCZopeDA/ You can buy mxODBC Zope DA licenses online from the eGenix.com shop at: http://shop.egenix.com/ ________________________________________________________________________ Thank you, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 18 2012) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2012-10-29: PyCon DE 2012, Leipzig, Germany ... 41 days to go 2012-10-23: Python Meeting Duesseldorf ... 35 days to go 2012-08-28: Released mxODBC 3.2.0 ... http://egenix.com/go31 2012-08-20: Released mxODBC.Connect 2.0.0 ... http://egenix.com/go30 eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From gandalf at shopzeus.com Tue Sep 18 05:04:04 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 18 Sep 2012 11:04:04 +0200 Subject: reportlab and python 3 In-Reply-To: <9aa9f1dd-f6b1-4de4-8606-e83a54318765@googlegroups.com> References: <9aa9f1dd-f6b1-4de4-8606-e83a54318765@googlegroups.com> Message-ID: <50583904.4020601@shopzeus.com> > A big yes and it is very easy. I assume you know how > to write a plain text file with Python :-). > > Use your Python to generate a .tex file and let it compile > with one of the pdf TeX engines. > > Potential problems: > - It requires a TeX installation (a no problem). > - Of course I requires some TeX knowledge. Learning it > is not so complicate. Learn how to use TeX with a text > editor and you will quickly understand what you have to > program in Python. Bonus: you learn at the same time > a good text editing engine. > > I can not figure out something more simple, versatile and > powerful. > > jmf > This is a good idea. Thank you. I wanted to learn TeX anyway. The TeX installation is problematic. I also want to use this under MS Windows. Yes, I know here is MikTeX for Windows. But there is significant difference. ReportLab can be embedded into a small program created with py2exe. LaTeX on the other side is a 150MB separate installation package that must be installed separately by hand. But in my particular case, it is still a good solution. Thanks, Laszlo From jeanmichel at sequans.com Tue Sep 18 05:26:24 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 18 Sep 2012 11:26:24 +0200 (CEST) Subject: How to use __getattr__ to the current module, for automatically add attributes of the real-time In-Reply-To: <74247047-c5b5-42a0-af69-4c520a1d5d8d@googlegroups.com> Message-ID: <2127070901.1931695.1347960384025.JavaMail.root@sequans.com> ----- Original Message ----- > Want to work so: > > import sys > class Foo(object): > def __getattr__(self, t): > print 'use __getattr__ - ', t > return type(t, (object,), {}) > def funct1(self): pass > def funct2(self): pass > > sys.modules[__name__] = Foo() > ttt('yy') > > name 'ttt' is not defined. > __getattr__ not work (((. > -- > http://mail.python.org/mailman/listinfo/python-list > I think __getattr__ would be triggered by using Foo().ttt or getattr(Foo(), 'ttt'). I think this hack is meant to work on modules object only, not in the global namespace where locals() and globals() are used instead (global namespace may not be the proper word, I don't know if there is a technical term for that). Here's how to make it work: foo.py import sys class Foo(object): def __getattr__(self, t): print 'use __getattr__ - ', t return type(t, (object,), {}) def funct1(self): pass def funct2(self): pass sys.modules[__name__] = Foo() Now in a python shell, or in another file: import foo foo.ttt use __getattr__ - ttt use __getattr__ - ttt < JM PS : Looks like a hell of a hack From joel.goldstick at gmail.com Tue Sep 18 06:22:56 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 18 Sep 2012 06:22:56 -0400 Subject: Docstring parsing and formatting In-Reply-To: References: <7wk3vskrz6.fsf@benfinney.id.au> Message-ID: On Tue, Sep 18, 2012 at 1:03 AM, Terry Reedy wrote: > On 9/17/2012 10:03 PM, Ben Finney wrote: >> >> Howdy all, >> >> Where can I find a standard implementation of the docstring parsing and >> splitting algorithm from PEP 257? Do you know about pydoc? I haven't looked at its source, but since it does a great job of printing documentation from docstrings it might contain what you need -- Joel Goldstick From jonathan.holloway at gmail.com Tue Sep 18 06:35:28 2012 From: jonathan.holloway at gmail.com (Jonathan Holloway) Date: Tue, 18 Sep 2012 11:35:28 +0100 Subject: Hiring Python Developer @ CA, USA In-Reply-To: <87pq5jg4oa.fsf@no-fixed-abode.cable.virginmedia.net> References: <87pq5jg4oa.fsf@no-fixed-abode.cable.virginmedia.net> Message-ID: Incidentally and I know this is region specific, but what's the average salary approximately in the US/UK for a Senior Python programmer? ITJobsWatch in the UK says - http://www.itjobswatch.co.uk/jobs/uk/python.do Is that about right? Jon. On 18 September 2012 08:40, Paul Rudin wrote: > nithinmoha at gmail.com writes: > > > ...Must be an export in this language... > > Are you hiring proof readers as well? :) > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Tue Sep 18 07:17:19 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 18 Sep 2012 04:17:19 -0700 (PDT) Subject: reportlab and python 3 In-Reply-To: References: <9aa9f1dd-f6b1-4de4-8606-e83a54318765@googlegroups.com> Message-ID: Le mardi 18 septembre 2012 11:04:19 UTC+2, Laszlo Nagy a ?crit?: > > A big yes and it is very easy. I assume you know how > > > to write a plain text file with Python :-). > > > > > > Use your Python to generate a .tex file and let it compile > > > with one of the pdf TeX engines. > > > > > > Potential problems: > > > - It requires a TeX installation (a no problem). > > > - Of course I requires some TeX knowledge. Learning it > > > is not so complicate. Learn how to use TeX with a text > > > editor and you will quickly understand what you have to > > > program in Python. Bonus: you learn at the same time > > > a good text editing engine. > > > > > > I can not figure out something more simple, versatile and > > > powerful. > > > > > > jmf > > > > > This is a good idea. Thank you. I wanted to learn TeX anyway. The TeX > > installation is problematic. I also want to use this under MS Windows. > > Yes, I know here is MikTeX for Windows. But there is significant > > difference. ReportLab can be embedded into a small program created with > > py2exe. LaTeX on the other side is a 150MB separate installation package > > that must be installed separately by hand. > > > > But in my particular case, it is still a good solution. > > > > Thanks, > > > > Laszlo I understood, you have Python on a platform and starting from this you wish to create pdf files. Obviously, embedding "TeX" is practically a no solution, although distibuting a portable standalone TeX distribution is a perfectly viable solution, especially on Windows! To "I wanted to learn TeX anyway.": I can only warmly recommend to start with one of the two unicode compliant engines, LuaTeX or XeTeX. jmf From wxjmfauth at gmail.com Tue Sep 18 07:17:19 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 18 Sep 2012 04:17:19 -0700 (PDT) Subject: reportlab and python 3 In-Reply-To: References: <9aa9f1dd-f6b1-4de4-8606-e83a54318765@googlegroups.com> Message-ID: Le mardi 18 septembre 2012 11:04:19 UTC+2, Laszlo Nagy a ?crit?: > > A big yes and it is very easy. I assume you know how > > > to write a plain text file with Python :-). > > > > > > Use your Python to generate a .tex file and let it compile > > > with one of the pdf TeX engines. > > > > > > Potential problems: > > > - It requires a TeX installation (a no problem). > > > - Of course I requires some TeX knowledge. Learning it > > > is not so complicate. Learn how to use TeX with a text > > > editor and you will quickly understand what you have to > > > program in Python. Bonus: you learn at the same time > > > a good text editing engine. > > > > > > I can not figure out something more simple, versatile and > > > powerful. > > > > > > jmf > > > > > This is a good idea. Thank you. I wanted to learn TeX anyway. The TeX > > installation is problematic. I also want to use this under MS Windows. > > Yes, I know here is MikTeX for Windows. But there is significant > > difference. ReportLab can be embedded into a small program created with > > py2exe. LaTeX on the other side is a 150MB separate installation package > > that must be installed separately by hand. > > > > But in my particular case, it is still a good solution. > > > > Thanks, > > > > Laszlo I understood, you have Python on a platform and starting from this you wish to create pdf files. Obviously, embedding "TeX" is practically a no solution, although distibuting a portable standalone TeX distribution is a perfectly viable solution, especially on Windows! To "I wanted to learn TeX anyway.": I can only warmly recommend to start with one of the two unicode compliant engines, LuaTeX or XeTeX. jmf From nobody at dizum.com Tue Sep 18 07:36:13 2012 From: nobody at dizum.com (Nomen Nescio) Date: Tue, 18 Sep 2012 13:36:13 +0200 (CEST) Subject: a few questions about scrapy Message-ID: <762702f8ad5d3fc831efd1e8b3c8e97c@dizum.com> I've installed scrapy and gotten a basic set-up working, and I have a few odd questions that I haven't been able to find in the documentation. I plan to run it occasionally from the command line or as a cron job, to scrape new content from a few sites. To avoid duplication, I have in memory two sets of long with the md5 hashes of the URLs and files crawled, and the spider ignores any that it has seen before. I need to load them from two disk files when the scrapy job starts, and save them to disk when it ends. Are there hooks or something similar for start-up and shut-down tasks? How can I put a random waiting interval between HTTP GET calls? Is there any way to set the proxy configuration in my Python code, or do I have so set the environment variables http_proxy and https_proxy before running scrapy? thanks From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Sep 18 08:16:18 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 18 Sep 2012 14:16:18 +0200 Subject: Decorators not worth the effort In-Reply-To: <331d26cd-8bb9-4994-9adf-fa2462bcfd6e@googlegroups.com> References: <20120914021211.GA15642@cskk.homeip.net> <5053c030$0$29981$c3e8da3$5496439d@news.astraweb.com> <331d26cd-8bb9-4994-9adf-fa2462bcfd6e@googlegroups.com> Message-ID: Am 15.09.2012 16:18 schrieb 88888 Dihedral: > The concept of decorators is just a mapping from a function ... or class ... > to another function ... or any other object ... > with the same name in python. Thomas From ben+python at benfinney.id.au Tue Sep 18 08:34:11 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 18 Sep 2012 22:34:11 +1000 Subject: SOLVED: Docstring parsing and formatting References: <7wk3vskrz6.fsf@benfinney.id.au> Message-ID: <7w7grrse64.fsf_-_@benfinney.id.au> Joel Goldstick writes: > On Tue, Sep 18, 2012 at 1:03 AM, Terry Reedy wrote: > > On 9/17/2012 10:03 PM, Ben Finney wrote: > >> Where can I find a standard implementation of the docstring parsing > >> and splitting algorithm from PEP 257? > > Do you know about pydoc? I haven't looked at its source, but since it > does a great job of printing documentation from docstrings it might > contain what you need Yes, I have now learned about the ?pydoc? module following the lead from investigating the interactive interpreter's ?help? function . The ?pydoc.splitdoc? function, though not documented in the library documentation, does what I need. It takes a docstring as input, and returns a tuple of (synopsis, description). Thanks to everyone who helped. -- \ ?Value your freedom or you will lose it, teaches history. | `\ ?Don't bother us with politics,? respond those who don't want | _o__) to learn.? ?Richard Stallman, 2002 | Ben Finney From neilc at norwich.edu Tue Sep 18 08:40:13 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 18 Sep 2012 12:40:13 GMT Subject: Batching HTTP requests with httplib (Python 2.7) References: Message-ID: On 2012-09-14, Xavier Combelle wrote: > Le 14/09/2012 12:56, Dwight Hutto a ?crit : >> service_num_list = [num for num in range(0,5)] >> for service_num in service_num_list: >> eval("web_service_call%i(%i)" % (service_num,service_num)) >> >> > service_num_list = [num for num in range(0,5)] service_num_list = list(range(5)) -- Neil Cerutti From davids at invtools.com Tue Sep 18 09:03:19 2012 From: davids at invtools.com (David Smith) Date: Tue, 18 Sep 2012 09:03:19 -0400 Subject: 'indent'ing Python in windows bat In-Reply-To: <505803A9.4000409@davea.name> References: <5057C990.8080809@invtools.com> <505803A9.4000409@davea.name> Message-ID: <50587117.1040208@invtools.com> Thank you all. Roy Smith gets the most thanks, though he didn't answer my general question -- he showed me how to look at that specific structure differently. Terry Reedy might get thanks for her idea if I can ever figure the correct escape sequences that will make both windows and the Python interpreter happy. Bat makes bash/sed combos look like a breeze... I thought you guys wouldn't want a treatise about WHY I was doing it this way and left it at one sentence. For whatever record, this is the sentence most missed. > I'm converting windows bat files little by little to Python 3 as I find time and learn Python. I COULD stop doing all my other work to learn Python and convert all the batch files in one fell swoop. Efficiency? Fast way to get fired. Better to fit this in during the many small breaks I have. That's how the bat files were built over time in the first place. Or this email. I COULD break down each batch file and write dozens of mini python scripts to be called. I already have a few, too. Efficiency? Speed is bad, but these are bat files, after all. The cost of trying to work with a multitude of small files is high, though, and I realized I had better go to a mix. Some sections can be broken down to one liners. Efficiency? Speed is terrible, but it's far faster than typing commands. OTOH, I have the organization I need on the original bat file, which is slowly being rem'ed out. As I learn and have the time, the one-liners will melt together into a py file to be called from the bat file. Eventually, the bat will disappear back into the broken Window from whence it came. Ugly, eh? I have under my belt scads of different languages from Fortran (using JCL!), Pascal, C++ to bash, sed, awk to Forth, assembly and a large cast of others. No big deal. My brain and Python, however, do NOT mix. I have been trying to learn the thing for over a decade and figure this will either force my brain into seeing the heart of the beast, or be swallowed in the attempt. Bat files are ugly cripples, but even on Windows a two-legged quick and dirty dog is better than mistake-prone typing and button clicking. After conversion, I'm aiming to make these erstwhile ugly cripples fly when I find the time and as I stuff more Python down my gullet. I agree. For those who have the unbroken time and understanding of Python, this is idiotic. back to work, From neilc at norwich.edu Tue Sep 18 09:19:00 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 18 Sep 2012 13:19:00 GMT Subject: Decorators not worth the effort References: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> Message-ID: On 2012-09-14, Chris Angelico wrote: > But then again, who actually ever needs fibonacci numbers? If it should happen that your question is not facetious: http://en.wikipedia.org/wiki/Fibonacci_number#Applications -- Neil Cerutti From rosuav at gmail.com Tue Sep 18 09:25:01 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Sep 2012 23:25:01 +1000 Subject: Decorators not worth the effort In-Reply-To: References: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> Message-ID: On Tue, Sep 18, 2012 at 11:19 PM, Neil Cerutti wrote: > On 2012-09-14, Chris Angelico wrote: >> But then again, who actually ever needs fibonacci numbers? > > If it should happen that your question is not facetious: > > http://en.wikipedia.org/wiki/Fibonacci_number#Applications It wasn't entirely facetious. I know there are a few cases where they're needed, but I think they're calculated far more often to demonstrate algorithms than because you actually have use of them. :) Though it's as well to mention these sorts of things now and then. I remember one time writing up something or other, and my dad was looking over my shoulder and asked me why I'd written a little Pascal's Triangle generator. He didn't know that it had direct application to whatever-it-was. And unfortunately I don't remember what I was even writing at the time :) ChrisA From gandalf at shopzeus.com Tue Sep 18 09:31:04 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 18 Sep 2012 15:31:04 +0200 Subject: reportlab and python 3 In-Reply-To: References: <9aa9f1dd-f6b1-4de4-8606-e83a54318765@googlegroups.com> Message-ID: <50587798.2090402@shopzeus.com> > I understood, you have Python on a platform and starting > from this you wish to create pdf files. > Obviously, embedding "TeX" is practically a no solution, > although distibuting a portable standalone TeX distribution > is a perfectly viable solution, especially on Windows! > > To "I wanted to learn TeX anyway.": > I can only warmly recommend to start with one of the two > unicode compliant engines, LuaTeX or XeTeX. All right. Which one is the better? :-) I'm totally a beginner. I would also like to use mathematical expressions but I guess they are both capable of that. Another requirement would be: easy installation under unix and windows, good multilingual support. From andrea.crotti.0 at gmail.com Tue Sep 18 09:54:41 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Tue, 18 Sep 2012 14:54:41 +0100 Subject: subprocess call is not waiting. In-Reply-To: <0405db16-6a4c-4189-a32c-2311d45eead3@googlegroups.com> References: <0b598d7f-7137-47cc-8eed-80ab450536c5@googlegroups.com> <0405db16-6a4c-4189-a32c-2311d45eead3@googlegroups.com> Message-ID: I have a similar problem, something which I've never quite understood about subprocess... Suppose I do this: proc = subprocess.Popen(['ls', '-lR'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) now I created a process, which has a PID, but it's not running apparently... It only seems to run when I actually do the wait. I don't want to make it waiting, so an easy solution is just to use a thread, but is there a way with subprocess? From wanderer at dialup4less.com Tue Sep 18 10:02:02 2012 From: wanderer at dialup4less.com (Wanderer) Date: Tue, 18 Sep 2012 07:02:02 -0700 (PDT) Subject: splitting numpy array unevenly In-Reply-To: References: Message-ID: On Monday, September 17, 2012 7:43:06 PM UTC-4, Martin De Kauwe wrote: > On Tuesday, September 18, 2012 8:31:09 AM UTC+10, Wanderer wrote: > > > I need to divide a 512x512 image array with the first horizontal and vertical division 49 pixels in. Then every 59 pixels in after that. hsplit and vsplit want to start at the edges and create a bunch of same size arrays. Is there a command to chop off different sized arrays? > > > > > > > > > > > > Thanks > > > > I don't know that I follow completely, but can't you just slice what you are after? > > > > x = np.random.rand(512*512).reshape(512,512) > > xx = x[0,:49] > > And put the rest of the slices in a loop...? I was trying to avoid the loop. I figured it out. hsplit and vsplit will work. I just need to give it a list of break points. I still need a loop though. breakPoints = range(49,512,59) rowArrays = hsplit(InputArray, breakPoints) OutArrays = [] for r in rowArrays: OutArrays.append(vsplit(r, breakPoints)) From jonas at geiregat.org Tue Sep 18 10:49:11 2012 From: jonas at geiregat.org (Jonas Geiregat) Date: Tue, 18 Sep 2012 16:49:11 +0200 Subject: [Ann] pyBug - Python Belgian User Group Message-ID: Hello everyone and, especially all python user from Belgium. I'm proud to announce the creation of a User Group around Python for the Belgium community. It has been baptized pyBug which stands for Python Belgian User Group. We're just starting out and will need all the help we can get , even if it's just becoming a member. Our main focus is enjoying ourself by organizing events where we can talk, collaborate around everything that is related to Python. If you care to join or just listen what's going on, we've registered a mailing list at google groups. It's located at: https://groups.google.com/forum/?fromgroups#!forum/python-belgian-user-group You can also subscribe by sending an email to python-belgian-user-group+subscribe at googlegroups.com Hope to see you there. Yours sincerely, Jonas Geiregat. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Tue Sep 18 11:12:32 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 18 Sep 2012 08:12:32 -0700 Subject: Comparing strings from the back? In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> Message-ID: <50588F60.7090608@stoneleaf.us> Neil Hodgson wrote: > Ethan Furman: >> *plonk* > > I can't work out who you are plonking. While more than one of the > posters on this thread seem worthy of a good plonk, by not including > sufficient context, you've left me feeling puzzled. Is there a guideline > for this in basic netiquette? You're right, my apologies. Dwight Hutto is the one I plonked. His signal to noise ratio seems incredibly low. alex23 can definitely be abrasive, but his ratio is high. (Now I'm wondering what that says about me as far as who I agree with and why... I'll have to think about that.) ~Ethan~ From dihedral88888 at googlemail.com Tue Sep 18 11:14:42 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 18 Sep 2012 08:14:42 -0700 (PDT) Subject: Decorators not worth the effort In-Reply-To: References: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> Message-ID: <2c1df918-2d60-418b-9ecc-da1423a8a113@googlegroups.com> Chris Angelico? 2012?9?18????UTC+8??9?25?04???? > On Tue, Sep 18, 2012 at 11:19 PM, Neil Cerutti wrote: > > > On 2012-09-14, Chris Angelico wrote: > > >> But then again, who actually ever needs fibonacci numbers? > > > > > > If it should happen that your question is not facetious: > > > > > > http://en.wikipedia.org/wiki/Fibonacci_number#Applications > > > > It wasn't entirely facetious. I know there are a few cases where > > they're needed, but I think they're calculated far more often to > > demonstrate algorithms than because you actually have use of them. :) > > > > Though it's as well to mention these sorts of things now and then. I > > remember one time writing up something or other, and my dad was > > looking over my shoulder and asked me why I'd written a little > > Pascal's Triangle generator. He didn't know that it had direct > > application to whatever-it-was. And unfortunately I don't remember > > what I was even writing at the time :) > > > > ChrisA I would suggest one should solve the Fibnaci(50000) first and fast in Python. Then one can think about computing c(n,k) in Python for large n. Then From dihedral88888 at googlemail.com Tue Sep 18 11:14:42 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 18 Sep 2012 08:14:42 -0700 (PDT) Subject: Decorators not worth the effort In-Reply-To: References: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> Message-ID: <2c1df918-2d60-418b-9ecc-da1423a8a113@googlegroups.com> Chris Angelico? 2012?9?18????UTC+8??9?25?04???? > On Tue, Sep 18, 2012 at 11:19 PM, Neil Cerutti wrote: > > > On 2012-09-14, Chris Angelico wrote: > > >> But then again, who actually ever needs fibonacci numbers? > > > > > > If it should happen that your question is not facetious: > > > > > > http://en.wikipedia.org/wiki/Fibonacci_number#Applications > > > > It wasn't entirely facetious. I know there are a few cases where > > they're needed, but I think they're calculated far more often to > > demonstrate algorithms than because you actually have use of them. :) > > > > Though it's as well to mention these sorts of things now and then. I > > remember one time writing up something or other, and my dad was > > looking over my shoulder and asked me why I'd written a little > > Pascal's Triangle generator. He didn't know that it had direct > > application to whatever-it-was. And unfortunately I don't remember > > what I was even writing at the time :) > > > > ChrisA I would suggest one should solve the Fibnaci(50000) first and fast in Python. Then one can think about computing c(n,k) in Python for large n. Then From dwightdhutto at gmail.com Tue Sep 18 11:55:41 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 18 Sep 2012 11:55:41 -0400 Subject: Comparing strings from the back? In-Reply-To: <50588F60.7090608@stoneleaf.us> References: <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> <50588F60.7090608@stoneleaf.us> Message-ID: On Tue, Sep 18, 2012 at 11:12 AM, Ethan Furman wrote: > Neil Hodgson wrote: >> >> Ethan Furman: >>> >>> *plonk* >> >> >> I can't work out who you are plonking. While more than one of the >> posters on this thread seem worthy of a good plonk, by not including >> sufficient context, you've left me feeling puzzled. Is there a guideline for >> this in basic netiquette? > > > You're right, my apologies. Dwight Hutto is the one I plonked. His signal > to noise ratio seems incredibly low. Is this just because of the lack of context, or because of the content of my response to the OP following the question? And with all the netiquette talk being passed around, why isn't this a new thread instead of hijacking the OP's original question, and engaging in bickering about netiquette that goes on all the time? And it seems redundant to argue this topic other than to comment, and let it pass, unless there's seems to be a legitimate reason why someone 'disobeyed' posting policy. > > alex23 can definitely be abrasive, but his ratio is high. > > (Now I'm wondering what that says about me as far as who I agree with and > why... I'll have to think about that.) > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Tue Sep 18 11:59:24 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 18 Sep 2012 11:59:24 -0400 Subject: Comparing strings from the back? In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> <50588F60.7090608@stoneleaf.us> Message-ID: >>> sufficient context, you've left me feeling puzzled. Is there a guideline for >>> this in basic netiquette? >> www.woodgate.org/FAQs/netiquette.html -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Tue Sep 18 12:17:40 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 18 Sep 2012 12:17:40 -0400 Subject: Comparing strings from the back? In-Reply-To: <50588F60.7090608@stoneleaf.us> References: <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> <50588F60.7090608@stoneleaf.us> Message-ID: > > You're right, my apologies. Dwight Hutto is the one I plonked. You can call me David. I go by my middle name. And it seem to me I made some valid points about a few simple trimming of postings, that didn't seem necessary in the context of a small quick conversation. From rosuav at gmail.com Tue Sep 18 12:20:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 19 Sep 2012 02:20:29 +1000 Subject: Comparing strings from the back? In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> <50588F60.7090608@stoneleaf.us> Message-ID: On Wed, Sep 19, 2012 at 2:17 AM, Dwight Hutto wrote: >> >> You're right, my apologies. Dwight Hutto is the one I plonked. > You can call me David. I go by my middle name. You're most often going to be addressed by the name that's given in your post headers. In this case "David" has been reduced to an initial, and is visible only in your email address, whereas "Dwight" is right there in your real-name. ChrisA From wxjmfauth at gmail.com Tue Sep 18 13:10:46 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 18 Sep 2012 10:10:46 -0700 (PDT) Subject: reportlab and python 3 In-Reply-To: References: <9aa9f1dd-f6b1-4de4-8606-e83a54318765@googlegroups.com> Message-ID: <087d1d62-f676-4451-b88c-6411f06ed73d@googlegroups.com> Le mardi 18 septembre 2012 15:31:52 UTC+2, Laszlo Nagy a ?crit?: > > I understood, you have Python on a platform and starting > > > from this you wish to create pdf files. > > > Obviously, embedding "TeX" is practically a no solution, > > > although distibuting a portable standalone TeX distribution > > > is a perfectly viable solution, especially on Windows! > > > > > > To "I wanted to learn TeX anyway.": > > > I can only warmly recommend to start with one of the two > > > unicode compliant engines, LuaTeX or XeTeX. > > All right. Which one is the better? :-) I'm totally a beginner. I would > > also like to use mathematical expressions but I guess they are both > > capable of that. Another requirement would be: easy installation under > > unix and windows, good multilingual support. I basically recommend nothing. I pointed the LuaTeX or Xe(La)TeX engines because there are the unicode compliant engines. Today, most of the work target these engines. By Unicode compliance, you should not understand only the coding of characters, but everything which is related to the unicode technology (characters, unicode features, typography, font technology). "...good multilingual support. ..." Don't worry. It's much better than the future of Python ;-) FYI I'm not a expert. I have only accumulated experience, I wrote my first TeX document 20(?) years ago. Now, I use XeLaTeX from MiKTeX on Win7. Why? Answer: why not? jmf From wxjmfauth at gmail.com Tue Sep 18 13:10:46 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 18 Sep 2012 10:10:46 -0700 (PDT) Subject: reportlab and python 3 In-Reply-To: References: <9aa9f1dd-f6b1-4de4-8606-e83a54318765@googlegroups.com> Message-ID: <087d1d62-f676-4451-b88c-6411f06ed73d@googlegroups.com> Le mardi 18 septembre 2012 15:31:52 UTC+2, Laszlo Nagy a ?crit?: > > I understood, you have Python on a platform and starting > > > from this you wish to create pdf files. > > > Obviously, embedding "TeX" is practically a no solution, > > > although distibuting a portable standalone TeX distribution > > > is a perfectly viable solution, especially on Windows! > > > > > > To "I wanted to learn TeX anyway.": > > > I can only warmly recommend to start with one of the two > > > unicode compliant engines, LuaTeX or XeTeX. > > All right. Which one is the better? :-) I'm totally a beginner. I would > > also like to use mathematical expressions but I guess they are both > > capable of that. Another requirement would be: easy installation under > > unix and windows, good multilingual support. I basically recommend nothing. I pointed the LuaTeX or Xe(La)TeX engines because there are the unicode compliant engines. Today, most of the work target these engines. By Unicode compliance, you should not understand only the coding of characters, but everything which is related to the unicode technology (characters, unicode features, typography, font technology). "...good multilingual support. ..." Don't worry. It's much better than the future of Python ;-) FYI I'm not a expert. I have only accumulated experience, I wrote my first TeX document 20(?) years ago. Now, I use XeLaTeX from MiKTeX on Win7. Why? Answer: why not? jmf From dieter at handshake.de Tue Sep 18 13:22:32 2012 From: dieter at handshake.de (Dieter Maurer) Date: Tue, 18 Sep 2012 19:22:32 +0200 Subject: Decorators not worth the effort References: <5B80DD153D7D744689F57F4FB69AF4741667C22E@SCACMX008.exchad.jpmchase.net> <246757766.1607257.1347891643781.JavaMail.root@sequans.com> Message-ID: <87txuvxn3b.fsf@handshake.de> Jean-Michel Pichavant writes: > ----- Original Message ----- >> Jean-Michel Pichavant wrote: > [snip] >> One minor note, the style of decorator you are using loses the >> docstring >> (at least) of the original function. I would add the >> @functools.wraps(func) >> decorator inside your decorator. > > Is there a way to not loose the function signature as well ? Look at the "decorator" module. From tjreedy at udel.edu Tue Sep 18 13:33:46 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 18 Sep 2012 13:33:46 -0400 Subject: reportlab and python 3 In-Reply-To: <50587798.2090402@shopzeus.com> References: <9aa9f1dd-f6b1-4de4-8606-e83a54318765@googlegroups.com> <50587798.2090402@shopzeus.com> Message-ID: On 9/18/2012 9:31 AM, Laszlo Nagy wrote: > capable of that. Another requirement would be: easy installation under > unix and windows, good multilingual support. By using 3.3, your Python string manipulations will act the same on all platforms, even when using extended plane (non-BMP) characters. -- Terry Jan Reedy From subhabangalore at gmail.com Tue Sep 18 14:35:24 2012 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Tue, 18 Sep 2012 11:35:24 -0700 (PDT) Subject: HMM based Chunker NLTK Message-ID: Dear Group, If anyone of the learned members can kindly help with a HMM/CRF based chunker on NLTK. Regards, Subhabrata. From breamoreboy at yahoo.co.uk Tue Sep 18 15:12:19 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 18 Sep 2012 20:12:19 +0100 Subject: HMM based Chunker NLTK In-Reply-To: References: Message-ID: On 18/09/2012 19:35, subhabangalore at gmail.com wrote: > Dear Group, > If anyone of the learned members can kindly help with a HMM/CRF based chunker on NLTK. > > Regards, > Subhabrata. > Certainly but how do you intend paying us? :) An alternative approach is to provide us with an idea of what you've researched, what code you've written and what problems you've got with it. If you get a code exception please provide the complete traceback and a mimimal code snippet that reproduces the issue. This way you're much more likely to get help. -- Cheers. Mark Lawrence. From subhabangalore at gmail.com Tue Sep 18 15:17:20 2012 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Tue, 18 Sep 2012 12:17:20 -0700 (PDT) Subject: HMM based Chunker NLTK In-Reply-To: References: Message-ID: <971374e6-34cc-4529-be3b-7983a2d57847@googlegroups.com> On Wednesday, September 19, 2012 12:40:00 AM UTC+5:30, Mark Lawrence wrote: > On 18/09/2012 19:35, subhabangalore at gmail.com wrote: > > > Dear Group, > > > If anyone of the learned members can kindly help with a HMM/CRF based chunker on NLTK. > > > > > > Regards, > > > Subhabrata. > > > > > > > Certainly but how do you intend paying us? :) > > > > An alternative approach is to provide us with an idea of what you've > > researched, what code you've written and what problems you've got with > > it. If you get a code exception please provide the complete traceback > > and a mimimal code snippet that reproduces the issue. This way you're > > much more likely to get help. > > > > -- > > Cheers. > > > > Mark Lawrence. Two possibilities Mark, either nltk.chunk.(something) or nltk.tag.hmm etc. I am thinking to experiment Regular Expressions, Unigram/Bigram based chunkers are running good even with Indian languages. HMM tag is also going great. I am thinking on the issue. Regards, Subhabrata. From subhabangalore at gmail.com Tue Sep 18 15:17:20 2012 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Tue, 18 Sep 2012 12:17:20 -0700 (PDT) Subject: HMM based Chunker NLTK In-Reply-To: References: Message-ID: <971374e6-34cc-4529-be3b-7983a2d57847@googlegroups.com> On Wednesday, September 19, 2012 12:40:00 AM UTC+5:30, Mark Lawrence wrote: > On 18/09/2012 19:35, subhabangalore at gmail.com wrote: > > > Dear Group, > > > If anyone of the learned members can kindly help with a HMM/CRF based chunker on NLTK. > > > > > > Regards, > > > Subhabrata. > > > > > > > Certainly but how do you intend paying us? :) > > > > An alternative approach is to provide us with an idea of what you've > > researched, what code you've written and what problems you've got with > > it. If you get a code exception please provide the complete traceback > > and a mimimal code snippet that reproduces the issue. This way you're > > much more likely to get help. > > > > -- > > Cheers. > > > > Mark Lawrence. Two possibilities Mark, either nltk.chunk.(something) or nltk.tag.hmm etc. I am thinking to experiment Regular Expressions, Unigram/Bigram based chunkers are running good even with Indian languages. HMM tag is also going great. I am thinking on the issue. Regards, Subhabrata. From weissman.mark at gmail.com Tue Sep 18 16:10:32 2012 From: weissman.mark at gmail.com (porkfried) Date: Tue, 18 Sep 2012 13:10:32 -0700 (PDT) Subject: User defined lexical scoping... can I do this? Message-ID: I want to define a 'with' command that makes entries in dictionary available within the local scope, and stores new local variables into that dictionary. The original scope should be restored on exit, and called functions should not see anything special. Can I do this? my_dict = dict(a=1, b=2) with MyScope(my_dict): print "A", a, "B", b x = 3 print my_dict["x"] print x # FAIL, unbound From t at jollybox.de Tue Sep 18 16:31:41 2012 From: t at jollybox.de (Thomas Jollans) Date: Tue, 18 Sep 2012 22:31:41 +0200 Subject: User defined lexical scoping... can I do this? In-Reply-To: References: Message-ID: <5058DA2D.1040107@jollybox.de> On 09/18/2012 10:10 PM, porkfried wrote: > I want to define a 'with' command that makes entries > in dictionary available within the local scope, and > stores new local variables into that dictionary. The > original scope should be restored on exit, and called > functions should not see anything special. Can I do this? No.* It is not possible to set locals by ways other than an assignment**, and it is certainly not possible to set locals in a scope other than the one you're in**. You should simply type out the dict's name. This is a lot clearer. If you want to minimize typing, you can give the variable a one-character name. Also, Python scope simply doesn't work like that. There is no block scope, only local (=function) scope, and global scope, with a dash of non-locals to spice things up a bit. > > my_dict = dict(a=1, b=2) > with MyScope(my_dict): > print "A", a, "B", b > x = 3 > print my_dict["x"] > print x # FAIL, unbound > *You could set global variables, and remove them on exit, but this is ugly for a number of reasons: this could overwrite existing globals if you're not very careful, called functions would see these globals, and they would also be exposed to other threads. **I believe there is actually a way to edit a caller's locals, but this is not documented, not portable across Python implementations and versions, and you couldn't create new locals like this, so it'd be fairly pointless here From dwightdhutto at gmail.com Tue Sep 18 16:40:12 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 18 Sep 2012 16:40:12 -0400 Subject: Comparing strings from the back? In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47416678A53@SCACMX008.exchad.jpmchase.net> <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> <50588F60.7090608@stoneleaf.us> Message-ID: > You're most often going to be addressed by the name that's given in > your post headers. In this case "David" has been reduced to an > initial, and is visible only in your email address, whereas "Dwight" My sig says David, but it was just to let him know he can call me by my used name. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From weissman.mark at gmail.com Tue Sep 18 16:50:53 2012 From: weissman.mark at gmail.com (weissman.mark at gmail.com) Date: Tue, 18 Sep 2012 13:50:53 -0700 (PDT) Subject: User defined lexical scoping... can I do this? In-Reply-To: References: Message-ID: On Tuesday, September 18, 2012 4:10:32 PM UTC-4, porkfried wrote: > I want to define a 'with' command that makes entries > > in dictionary available within the local scope, and > > stores new local variables into that dictionary. The > > original scope should be restored on exit, and called > > functions should not see anything special. Can I do this? > > > > my_dict = dict(a=1, b=2) > > with MyScope(my_dict): > > print "A", a, "B", b > > x = 3 > > print my_dict["x"] > > print x # FAIL, unbound Well there's wired stuff like this: In [1]: locals()["x"] = 5 In [2]: print x 5 In [3]: but it didn't help me do what I wanted. From t at jollybox.de Tue Sep 18 17:51:13 2012 From: t at jollybox.de (Thomas Jollans) Date: Tue, 18 Sep 2012 23:51:13 +0200 Subject: User defined lexical scoping... can I do this? In-Reply-To: References: Message-ID: <5058ECD1.1050801@jollybox.de> On 09/18/2012 10:50 PM, weissman.mark at gmail.com wrote: > Well there's wired stuff like this: > > In [1]: locals()["x"] = 5 > > In [2]: print x > 5 > No, there isn't. Modifying the dictionary returned by locals() has no effect. >>> def f (): ... locals()["x"] = 1 ... return x ... >>> f () Traceback (most recent call last): File "", line 1, in File "", line 3, in f NameError: global name 'x' is not defined >>> >>> locals()["x"] = 1 >>> x 1 >>> #this works because ... locals() is globals() True >>> The exception is the case when local scope is identical to global scope. In this case, locals() has globals() semantics. From breamoreboy at yahoo.co.uk Tue Sep 18 19:47:07 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 19 Sep 2012 00:47:07 +0100 Subject: User defined lexical scoping... can I do this? In-Reply-To: References: Message-ID: On 18/09/2012 21:10, porkfried wrote: > I want to define a 'with' command that makes entries > in dictionary available within the local scope, and > stores new local variables into that dictionary. The > original scope should be restored on exit, and called > functions should not see anything special. Can I do this? > > my_dict = dict(a=1, b=2) > with MyScope(my_dict): > print "A", a, "B", b > x = 3 > print my_dict["x"] > print x # FAIL, unbound > If you could state what you're trying to achieve rather than how you're trying to achieve it then perhaps people could give you a solution to your problem. -- Cheers. Mark Lawrence. From dihedral88888 at googlemail.com Tue Sep 18 19:47:44 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 18 Sep 2012 16:47:44 -0700 (PDT) Subject: Decorators not worth the effort In-Reply-To: References: <732807993.849639.1347614902104.JavaMail.root@sequans.com> Message-ID: <5995c4c4-42f0-4af1-9154-eb3378230cf9@googlegroups.com> Terry Reedy? 2012?9?15????UTC+8??4?40?32???? > 2nd try, hit send button by mistake before > > > > On 9/14/2012 5:28 AM, Jean-Michel Pichavant wrote: > > > > > Decorators are very popular so I kinda already know that the fault is > > > mine. Now to the reason why I have troubles writing them, I don't > > > know. Every time I did use decorators, I spent way too much time > > > writing it (and debugging it). > > > > You are writing parameterized decorators, which require inverted > > currying of the wrapper maker. Perhaps that is why you have trouble. As > > I showed in response to Cameron, it may be easier to avoid that by using > > a traditional post-def wrapping call instead of decorator syntax. > > > > -- > > Terry Jan Reedy I'll give another example to show the decorators in python in versions above 2.4 . # a general function with the variable input : def fname( *argc, **argn) # a deco is a mapping from an input funtion to another function def deco( fn, *list_in, **dict_in): # use list_in and dict_in to modify fn """ deco wrapper """ # deco.__doc__ #print list_in, dict_in, " in the deco" def wrapper( fn, *argc, **argan): # to be returned as a function # do things one wants before calling fn result=fn(*argc, **argn) # call the original, save the result # do things after calling fn return result # enhance the wrapper and get info of fn wrapper.__doc__=fn.__doc__ # enhance wrapper with result, fn, list_in, dict_in #.... return wrapper def f1(): """ doc of f1""" print "inside f1" f2=deco(f1, 2,3,4,5,6, MSG="deco f1 to f2") f2() # invoke the decorated function from f1 # For a deco maps a deco to another deco can be done similarly From dihedral88888 at googlemail.com Tue Sep 18 19:47:44 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 18 Sep 2012 16:47:44 -0700 (PDT) Subject: Decorators not worth the effort In-Reply-To: References: <732807993.849639.1347614902104.JavaMail.root@sequans.com> Message-ID: <5995c4c4-42f0-4af1-9154-eb3378230cf9@googlegroups.com> Terry Reedy? 2012?9?15????UTC+8??4?40?32???? > 2nd try, hit send button by mistake before > > > > On 9/14/2012 5:28 AM, Jean-Michel Pichavant wrote: > > > > > Decorators are very popular so I kinda already know that the fault is > > > mine. Now to the reason why I have troubles writing them, I don't > > > know. Every time I did use decorators, I spent way too much time > > > writing it (and debugging it). > > > > You are writing parameterized decorators, which require inverted > > currying of the wrapper maker. Perhaps that is why you have trouble. As > > I showed in response to Cameron, it may be easier to avoid that by using > > a traditional post-def wrapping call instead of decorator syntax. > > > > -- > > Terry Jan Reedy I'll give another example to show the decorators in python in versions above 2.4 . # a general function with the variable input : def fname( *argc, **argn) # a deco is a mapping from an input funtion to another function def deco( fn, *list_in, **dict_in): # use list_in and dict_in to modify fn """ deco wrapper """ # deco.__doc__ #print list_in, dict_in, " in the deco" def wrapper( fn, *argc, **argan): # to be returned as a function # do things one wants before calling fn result=fn(*argc, **argn) # call the original, save the result # do things after calling fn return result # enhance the wrapper and get info of fn wrapper.__doc__=fn.__doc__ # enhance wrapper with result, fn, list_in, dict_in #.... return wrapper def f1(): """ doc of f1""" print "inside f1" f2=deco(f1, 2,3,4,5,6, MSG="deco f1 to f2") f2() # invoke the decorated function from f1 # For a deco maps a deco to another deco can be done similarly From breamoreboy at yahoo.co.uk Tue Sep 18 19:48:03 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 19 Sep 2012 00:48:03 +0100 Subject: Comparing strings from the back? In-Reply-To: References: <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> <50588F60.7090608@stoneleaf.us> Message-ID: On 18/09/2012 21:40, Dwight Hutto wrote: >> You're most often going to be addressed by the name that's given in >> your post headers. In this case "David" has been reduced to an >> initial, and is visible only in your email address, whereas "Dwight" > My sig says David, but it was just to let him know he can call me by > my used name. > > Any particular him? -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Tue Sep 18 20:47:38 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Sep 2012 00:47:38 GMT Subject: Comparing strings from the back? References: <4cfea2fe-c0db-4c72-b1cb-ddef88f6e86d@wz4g2000pbc.googlegroups.com> <9280d4ca-b047-4896-bf7b-7cc4a728d721@sd5g2000pbc.googlegroups.com> <5B80DD153D7D744689F57F4FB69AF4741667C1AD@SCACMX008.exchad.jpmchase.net> <50588F60.7090608@stoneleaf.us> Message-ID: <5059162a$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 18 Sep 2012 12:17:40 -0400, Dwight Hutto wrote: > You can call me David. I go by my middle name. If you want to be known as David, why do you give your name as Dwight? In your email client or newsreader, set your name as David and attributions will be to David, and people will know to call you David. Otherwise, people will continue to call you Dwight. -- Steven From njspicy at gmail.com Tue Sep 18 20:47:45 2012 From: njspicy at gmail.com (Nathan Spicer) Date: Tue, 18 Sep 2012 20:47:45 -0400 Subject: Fwd: Programming Issues In-Reply-To: References: Message-ID: ---------- Forwarded message ---------- From: Nathan Spicer Date: Tue, Sep 18, 2012 at 8:32 PM Subject: Programming Issues To: webmaster at python.org Hello, My name is Nathan Spicer. I'm taking a computer programming class using python. I have a project that's due in a week and I'm not certain how to d this. I'm totally new to this form of programming. I've stated the scope of the project below. Any form of help would be great. Ask the user for the amount of change expressed in cents. Your program must compute and display the number of half-dollars, quarters, dimes, nickels, and pennies to be returned. Return as many half-dollars as possible, then quarters, dimes, nickels, and pennies, in that order. Your program must allow the user to continue entering different amounts of change until they enter 0 to indicate they are finished. If the user enters a negative number, inform them of their mistake and ask them to enter a correct value. -Code that is formatted to be easy to read Thank you for your time, Nathan Spicer -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Tue Sep 18 21:20:44 2012 From: d at davea.name (Dave Angel) Date: Tue, 18 Sep 2012 21:20:44 -0400 Subject: Fwd: Programming Issues In-Reply-To: References: Message-ID: <50591DEC.6040904@davea.name> On 09/18/2012 08:47 PM, Nathan Spicer wrote: > ---------- Forwarded message ---------- > From: Nathan Spicer > Date: Tue, Sep 18, 2012 at 8:32 PM > Subject: Programming Issues > To: webmaster at python.org > > > Hello, > > My name is Nathan Spicer. I'm taking a computer programming class using > python. I have a project that's due in a week and I'm not certain how to d > this. I'm totally new to this form of programming. I've stated the scope of > the project below. Any form of help would be great. > > > Ask the user for the amount of change expressed in cents. Your program must > compute and display the number of half-dollars, quarters, dimes, nickels, > and pennies to be returned. > Return as many half-dollars as possible, then quarters, dimes, nickels, and > pennies, in that order. > Your program must allow the user to continue entering different amounts of > change until they enter 0 to indicate they are finished. If the user enters > a negative number, inform them of their mistake and ask them to enter a > correct value. > > -Code that is formatted to be easy to read > > Thank you for your time, > Nathan Spicer > > > What version of Python are you learning? And you're stuck where? There are lots of ways to ask a user a question, ranging from raw_input() to presenting a wxPython dialog box. The choice depends on what version you're using, and what GUI library if any you have available. Then you have to validate the string you get, and then do some computations, displaying the result. The whole thing needs to be inside a loop. Show us the code you've got so far, and indicate where the exception is happening, with full traceback. -- DaveA From tjreedy at udel.edu Tue Sep 18 21:38:19 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 18 Sep 2012 21:38:19 -0400 Subject: User defined lexical scoping... can I do this? In-Reply-To: <5058ECD1.1050801@jollybox.de> References: <5058ECD1.1050801@jollybox.de> Message-ID: On 9/18/2012 5:51 PM, Thomas Jollans wrote: > On 09/18/2012 10:50 PM, weissman.mark at gmail.com wrote: >> Well there's wired stuff like this: >> >> In [1]: locals()["x"] = 5 >> >> In [2]: print x >> 5 >> > > No, there isn't. Modifying the dictionary returned by locals() has no > effect. Last time I tried it, it does within a class -- in cpython at least. That locals dict usually becomes the __dict__ of the class. But not to be depended on indefinitely and across implmentations. -- Terry Jan Reedy From trent at snakebite.org Tue Sep 18 22:20:04 2012 From: trent at snakebite.org (Trent Nelson) Date: Tue, 18 Sep 2012 22:20:04 -0400 Subject: Python presentations In-Reply-To: References: Message-ID: <20120919022003.GB61866@snakebite.org> On Thu, Sep 13, 2012 at 09:00:19AM -0700, andrea crotti wrote: > I have to give a couple of Python presentations in the next weeks, and > I'm still thinking what is the best approach. > > In one presentation for example I will present decorators and context > managers, and my biggest doubt is how much I should show and explain in > slides and how much in an interactive way (with ipython for example). FWIW, I gave a presentation on decorators to the New York Python User Group back in 2008. Relevant blog post: http://blogs.onresolve.com/?p=48 There's a link to the PowerPoint presentation I used in the first paragraph. It's in .pptx format; let me know if you'd like it in some other form. Regards, Trent. From steve+comp.lang.python at pearwood.info Wed Sep 19 00:03:02 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Sep 2012 04:03:02 GMT Subject: User defined lexical scoping... can I do this? References: <5058ECD1.1050801@jollybox.de> Message-ID: <505943f6$0$29890$c3e8da3$5496439d@news.astraweb.com> On Tue, 18 Sep 2012 21:38:19 -0400, Terry Reedy wrote: > On 9/18/2012 5:51 PM, Thomas Jollans wrote: >> On 09/18/2012 10:50 PM, weissman.mark at gmail.com wrote: >>> Well there's wired stuff like this: >>> >>> In [1]: locals()["x"] = 5 >>> >>> In [2]: print x >>> 5 >>> >>> >> No, there isn't. Modifying the dictionary returned by locals() has no >> effect. > > Last time I tried it, it does within a class -- in cpython at least. > That locals dict usually becomes the __dict__ of the class. But not to > be depended on indefinitely and across implmentations. Exactly. The behaviour of modifying the dict returned by locals() is not defined. For example, this is what happens under Python 2.6, Jython 2.5, and IronPython 2.6: steve at runes:~$ cat test.py a = b = 'global' def test(): a = None locals()['a'] = 'local' locals()['b'] = 'local' print a, b test() steve at runes:~$ python test.py None global steve at runes:~$ jython test.py None global steve at runes:~$ ipy test.py local global Other Python implementations may do differently. -- Steven From showell30 at yahoo.com Wed Sep 19 00:12:12 2012 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 18 Sep 2012 21:12:12 -0700 (PDT) Subject: python immersion Message-ID: <93573741-ea5c-4e84-bfc4-cddd622a1ec3@r10g2000vby.googlegroups.com> It's been several years since I announced this page the first time, so I feel like it's okay to announce it again, possibly introducing a few new people to Python's elegance and simplicity. This is my attempt to teach Python to programmers who have experience in other languages, using gentle immersion: http://wiki.python.org/moin/SimplePrograms From jason at powerpull.net Wed Sep 19 00:12:41 2012 From: jason at powerpull.net (Jason Friedman) Date: Tue, 18 Sep 2012 22:12:41 -0600 Subject: 'indent'ing Python in windows bat In-Reply-To: <5057C990.8080809@invtools.com> References: <5057C990.8080809@invtools.com> Message-ID: > I'm converting windows bat files little by little to Python 3 as I find time > and learn Python. > The most efficient method for some lines is to call Python like: > python -c "import sys; sys.exit(3)" > > How do I "indent" if I have something like: > if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else > sys.exit(3) Some months ago I posted what I think is a similar question in the Unix world: I wanted to call a small portion of Python from within a Bash script. Someone on this list answered (for Bash): #!/bin/bash command1 command2 python -c "if True: import module if condition: do_this else: do_that " command4 # end code Perhaps something similar would work for a .bat file. From qunxfum943 at gmail.com Wed Sep 19 01:44:45 2012 From: qunxfum943 at gmail.com (qunxfum943 at gmail.com) Date: Tue, 18 Sep 2012 22:44:45 -0700 (PDT) Subject: iPhone App To Help You Learn Chinese (Mandarin) Faster By Using Flashcards With Pictures Message-ID: <6d1e958b-4eea-4132-909e-5fc221a03d11@googlegroups.com> http://goo.gl/lCAUy - "Chinese Flashcards with Pictures" is an iPhone app that will help you learn Chinese (Mandarin) faster by using flashcards with pictures (learn over 300 most commonly used words in the English / Chinese language from A to Z), thanks. From hansmu at xs4all.nl Wed Sep 19 02:26:46 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 19 Sep 2012 08:26:46 +0200 Subject: splitting numpy array unevenly In-Reply-To: References: Message-ID: <505965a6$0$6912$e4fe514c@news2.news.xs4all.nl> On 18/09/12 16:02:02, Wanderer wrote: > On Monday, September 17, 2012 7:43:06 PM UTC-4, Martin De Kauwe wrote: >> On Tuesday, September 18, 2012 8:31:09 AM UTC+10, Wanderer wrote: >>> I need to divide a 512x512 image array with the first horizontal >>> and vertical division 49 pixels in. Then every 59 pixels in after >>> that. hsplit and vsplit want to start at the edges and create a >>> bunch of same size arrays. Is there a command to chop off >>> different sized arrays? >> I don't know that I follow completely, but can't you just slice >> what you are after? >> x = np.random.rand(512*512).reshape(512,512) >> xx = x[0,:49] >> And put the rest of the slices in a loop...? > I was trying to avoid the loop. I figured it out. hsplit and vsplit > will work. I just need to give it a list of break points. I still > need a loop though. > breakPoints = range(49,512,59) > rowArrays = hsplit(InputArray, breakPoints) > OutArrays = [] > for r in rowArrays: > OutArrays.append(vsplit(r, breakPoints)) How about a list display: breakPoints = range(49,512,59) rowArrays = hsplit(InputArray, breakPoints) OutArrays = [vsplit(r, breakPoints) for r in rowArrays] In some sense, it's still a loop, but at least it doesn't look like one. Hope this helps, -- HansM From dkatorza at gmail.com Wed Sep 19 03:41:36 2012 From: dkatorza at gmail.com (Dan Katorza) Date: Wed, 19 Sep 2012 00:41:36 -0700 (PDT) Subject: using text file to get ip address from hostname In-Reply-To: <3359a0e7-f7bb-4b1f-b586-e83f337566b7@googlegroups.com> References: <3359a0e7-f7bb-4b1f-b586-e83f337566b7@googlegroups.com> Message-ID: ?????? ??? ?????, 16 ??????? 2012 01:43:31 UTC+3, ??? Dan Katorza: > ?????? ??? ?????, 12 ??????? 2012 17:24:50 UTC+3, ??? Dan Katorza: > > > hello , > > > > > > > > > > > > i'm new to Python and i searched the web and could not find an answer for my issue. > > > > > > > > > > > > i need to get an ip address from list of hostnames which are in a textfile. > > > > > > > > > > > > this is what i have so far > > > > > > -------------------------------------------------------------------------- > > > > > > #!/usr/bin/env python > > > > > > #Get the IP Address > > > > > > > > > > > > import socket > > > > > > hostname = 'need it to read from a text file' > > > > > > addr = socket.gethostbyname(hostname) > > > > > > print 'The address of ', hostname, 'is', addr > > > > > > > > > > > > --------------------------------------------------------------------------- > > > > > > > > > > > > any idea ? > > > > > > sorry for my english > > > > > > > > > > > > thanks. > > > > Hi Hans, > > thank you very much for the tips. > > as i mentioned before I'm new to python and I'm trying to learn it step by step. > > thank you for showing me other ways, i will explore them. Hello again, I have another question and i hope you will understand me.. Is there any option where you can set the program to go back to lets say the top of the code? I mean if the program finished the operation and i want to stay in the program and go back ro the start. after any operation i want the option to do it again , go back to the main menu or full exit from the program, and i want it every time. i hope i'm clear :) From hansmu at xs4all.nl Wed Sep 19 03:53:44 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 19 Sep 2012 09:53:44 +0200 Subject: 'indent'ing Python in windows bat In-Reply-To: References: <5057C990.8080809@invtools.com> Message-ID: <50597a08$0$6961$e4fe514c@news2.news.xs4all.nl> On 18/09/12 05:01:14, Ian Kelly wrote: > On Mon, Sep 17, 2012 at 7:08 PM, David Smith wrote: >> How do I "indent" if I have something like: >> if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else >> sys.exit(3) > > How about: > > if sR == 'Cope': > sys.exit(1) > elif sR == 'Perform': > sys.exit(2) > else: > sys.exit(3) > > I don't really understand why you're trying to keep it all on one line. He's using Windows. If he were on Unix, there'd be no problem: python -c 'import sys if sR == "Cope": sys.exit(1) elif sR == "Perform": sys.exit(2) else: sys.exit(3) ' Unfortunately, the Windows shell doesn't do multi-line strings, so he has to cram it all on one line. -- HansM From rosuav at gmail.com Wed Sep 19 04:14:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 19 Sep 2012 18:14:20 +1000 Subject: using text file to get ip address from hostname In-Reply-To: References: <3359a0e7-f7bb-4b1f-b586-e83f337566b7@googlegroups.com> Message-ID: On Wed, Sep 19, 2012 at 5:41 PM, Dan Katorza wrote: > > Hello again, > I have another question and i hope you will understand me.. > Is there any option where you can set the program to go back to lets say the top of the code? > I mean if the program finished the operation and i want to stay in the program and go back ro the start. > after any operation i want the option to do it again , go back to the main menu or full exit from the program, and i want it every time. > > i hope i'm clear :) Yep! Look up the docs and tutorial on "control flow" and "looping constructs". Sounds like what you want here is a 'while' loop. ChrisA From dkatorza at gmail.com Wed Sep 19 04:50:47 2012 From: dkatorza at gmail.com (Dan Katorza) Date: Wed, 19 Sep 2012 01:50:47 -0700 (PDT) Subject: using text file to get ip address from hostname In-Reply-To: References: <3359a0e7-f7bb-4b1f-b586-e83f337566b7@googlegroups.com> Message-ID: ?????? ??? ?????, 19 ??????? 2012 11:14:29 UTC+3, ??? Chris Angelico: > On Wed, Sep 19, 2012 at 5:41 PM, Dan Katorza wrote: > > > > > > Hello again, > > > I have another question and i hope you will understand me.. > > > Is there any option where you can set the program to go back to lets say the top of the code? > > > I mean if the program finished the operation and i want to stay in the program and go back ro the start. > > > after any operation i want the option to do it again , go back to the main menu or full exit from the program, and i want it every time. > > > > > > i hope i'm clear :) > > > > Yep! Look up the docs and tutorial on "control flow" and "looping > > constructs". Sounds like what you want here is a 'while' loop. > > > > ChrisA Hi Chris, this is my code: #!/usr/bin/env python #Get the IP Address import sys, socket print ("\n\n#########################################################") print ("# Get IP from Host v 1.0 #") print ("#########################################################") print ("# Choose from the options below #") print ("# 1- url , 2-File(Text file only.txt) #") print ("#########################################################\n") mchoice = int(raw_input("Please enter your choice> ")) while mchoice !=1 and mchoice !=2: print("{0} is not a menu option.".format(mchoice)) mchoice = int(raw_input("Please try again> ")) if mchoice == 2: filename = raw_input("Hello, please enter file name here> ") if filename.endswith(".txt"): try: infile = open(filename) except EnvironmentError as e: print(e) sys.exit(1) print("\nFile {0} exists!".format(filename)) print("\nGetting IP addresses for hosts") print("\n") else: print("{0} is not a Text file.".format(filename)) sys.exit(1) for line in infile: hostname = line.strip() try: ip_address = socket.gethostbyname(hostname) except EnvironmentError as e: print("Couldn't find IP address for {0}: {1}".format(hostname, e)) continue print("IP address for {0} is {1}.".format(hostname, ip_address)) else: print ("\nFinished the operation") if mchoice == 1: murl = raw_input("Enter URL here> ") try: print("Checking URL...") ip_address = socket.gethostbyname(murl) except EnvironmentError as d: print(d) sys.exit(1) print("Valid URL") print("\nIP address for {0} is {1}.".format(murl, ip_address)) print ("\nFinished the operation") ===================================================================== now where it says Finsihed the operation i want it to show (another search /main menu/exit program) i know about the while loop , but forgive me i just don't have a clue how to use it for this situation. i don't want you to give me the code:) just the idea. i did read the section about the while loop but still i do not know how to use it in this situation. thanks. From dkatorza at gmail.com Wed Sep 19 04:50:47 2012 From: dkatorza at gmail.com (Dan Katorza) Date: Wed, 19 Sep 2012 01:50:47 -0700 (PDT) Subject: using text file to get ip address from hostname In-Reply-To: References: <3359a0e7-f7bb-4b1f-b586-e83f337566b7@googlegroups.com> Message-ID: ?????? ??? ?????, 19 ??????? 2012 11:14:29 UTC+3, ??? Chris Angelico: > On Wed, Sep 19, 2012 at 5:41 PM, Dan Katorza wrote: > > > > > > Hello again, > > > I have another question and i hope you will understand me.. > > > Is there any option where you can set the program to go back to lets say the top of the code? > > > I mean if the program finished the operation and i want to stay in the program and go back ro the start. > > > after any operation i want the option to do it again , go back to the main menu or full exit from the program, and i want it every time. > > > > > > i hope i'm clear :) > > > > Yep! Look up the docs and tutorial on "control flow" and "looping > > constructs". Sounds like what you want here is a 'while' loop. > > > > ChrisA Hi Chris, this is my code: #!/usr/bin/env python #Get the IP Address import sys, socket print ("\n\n#########################################################") print ("# Get IP from Host v 1.0 #") print ("#########################################################") print ("# Choose from the options below #") print ("# 1- url , 2-File(Text file only.txt) #") print ("#########################################################\n") mchoice = int(raw_input("Please enter your choice> ")) while mchoice !=1 and mchoice !=2: print("{0} is not a menu option.".format(mchoice)) mchoice = int(raw_input("Please try again> ")) if mchoice == 2: filename = raw_input("Hello, please enter file name here> ") if filename.endswith(".txt"): try: infile = open(filename) except EnvironmentError as e: print(e) sys.exit(1) print("\nFile {0} exists!".format(filename)) print("\nGetting IP addresses for hosts") print("\n") else: print("{0} is not a Text file.".format(filename)) sys.exit(1) for line in infile: hostname = line.strip() try: ip_address = socket.gethostbyname(hostname) except EnvironmentError as e: print("Couldn't find IP address for {0}: {1}".format(hostname, e)) continue print("IP address for {0} is {1}.".format(hostname, ip_address)) else: print ("\nFinished the operation") if mchoice == 1: murl = raw_input("Enter URL here> ") try: print("Checking URL...") ip_address = socket.gethostbyname(murl) except EnvironmentError as d: print(d) sys.exit(1) print("Valid URL") print("\nIP address for {0} is {1}.".format(murl, ip_address)) print ("\nFinished the operation") ===================================================================== now where it says Finsihed the operation i want it to show (another search /main menu/exit program) i know about the while loop , but forgive me i just don't have a clue how to use it for this situation. i don't want you to give me the code:) just the idea. i did read the section about the while loop but still i do not know how to use it in this situation. thanks. From rosuav at gmail.com Wed Sep 19 04:59:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 19 Sep 2012 18:59:20 +1000 Subject: using text file to get ip address from hostname In-Reply-To: References: <3359a0e7-f7bb-4b1f-b586-e83f337566b7@googlegroups.com> Message-ID: On Wed, Sep 19, 2012 at 6:50 PM, Dan Katorza wrote: > i know about the while loop , but forgive me i just don't have a clue how to use it for this situation. You've already used one. What you need to do is surround your entire code with the loop, so that as soon as it gets to the bottom, it goes back to the top. Tip: You'll be indenting the bulk of your code. ChrisA From dkatorza at gmail.com Wed Sep 19 05:10:54 2012 From: dkatorza at gmail.com (Dan Katorza) Date: Wed, 19 Sep 2012 02:10:54 -0700 (PDT) Subject: using text file to get ip address from hostname In-Reply-To: References: <3359a0e7-f7bb-4b1f-b586-e83f337566b7@googlegroups.com> Message-ID: ?????? ??? ?????, 19 ??????? 2012 11:50:56 UTC+3, ??? Dan Katorza: > ?????? ??? ?????, 19 ??????? 2012 11:14:29 UTC+3, ??? Chris Angelico: > > > On Wed, Sep 19, 2012 at 5:41 PM, Dan Katorza wrote: > > > > > > > > > > > > > > Hello again, > > > > > > > I have another question and i hope you will understand me.. > > > > > > > Is there any option where you can set the program to go back to lets say the top of the code? > > > > > > > I mean if the program finished the operation and i want to stay in the program and go back ro the start. > > > > > > > after any operation i want the option to do it again , go back to the main menu or full exit from the program, and i want it every time. > > > > > > > > > > > > > > i hope i'm clear :) > > > > > > > > > > > > Yep! Look up the docs and tutorial on "control flow" and "looping > > > > > > constructs". Sounds like what you want here is a 'while' loop. > > > > > > > > > > > > ChrisA > > > > Hi Chris, > > this is my code: > > > > #!/usr/bin/env python > > #Get the IP Address > > > > import sys, socket > > > > print ("\n\n#########################################################") > > print ("# Get IP from Host v 1.0 #") > > print ("#########################################################") > > print ("# Choose from the options below #") > > print ("# 1- url , 2-File(Text file only.txt) #") > > print ("#########################################################\n") > > > > mchoice = int(raw_input("Please enter your choice> ")) > > while mchoice !=1 and mchoice !=2: > > print("{0} is not a menu option.".format(mchoice)) > > mchoice = int(raw_input("Please try again> ")) > > > > > > if mchoice == 2: > > filename = raw_input("Hello, please enter file name here> ") > > if filename.endswith(".txt"): > > > > try: > > infile = open(filename) > > except EnvironmentError as e: > > print(e) > > sys.exit(1) > > > > print("\nFile {0} exists!".format(filename)) > > print("\nGetting IP addresses for hosts") > > print("\n") > > else: > > print("{0} is not a Text file.".format(filename)) > > sys.exit(1) > > for line in infile: > > hostname = line.strip() > > try: > > ip_address = socket.gethostbyname(hostname) > > except EnvironmentError as e: > > print("Couldn't find IP address for {0}: {1}".format(hostname, e)) > > continue > > print("IP address for {0} is {1}.".format(hostname, ip_address)) > > else: > > print ("\nFinished the operation") > > > > if mchoice == 1: > > murl = raw_input("Enter URL here> ") > > try: > > print("Checking URL...") > > ip_address = socket.gethostbyname(murl) > > except EnvironmentError as d: > > print(d) > > sys.exit(1) > > print("Valid URL") > > print("\nIP address for {0} is {1}.".format(murl, ip_address)) > > print ("\nFinished the operation") > > ===================================================================== > > > > now where it says Finsihed the operation i want it to show (another search /main menu/exit program) > > > > i know about the while loop , but forgive me i just don't have a clue how to use it for this situation. > > > > i don't want you to give me the code:) just the idea. > > i did read the section about the while loop but still i do not know how to use it in this situation. > > thanks. o.k a giant while loop :) thanks. From dkatorza at gmail.com Wed Sep 19 05:10:54 2012 From: dkatorza at gmail.com (Dan Katorza) Date: Wed, 19 Sep 2012 02:10:54 -0700 (PDT) Subject: using text file to get ip address from hostname In-Reply-To: References: <3359a0e7-f7bb-4b1f-b586-e83f337566b7@googlegroups.com> Message-ID: ?????? ??? ?????, 19 ??????? 2012 11:50:56 UTC+3, ??? Dan Katorza: > ?????? ??? ?????, 19 ??????? 2012 11:14:29 UTC+3, ??? Chris Angelico: > > > On Wed, Sep 19, 2012 at 5:41 PM, Dan Katorza wrote: > > > > > > > > > > > > > > Hello again, > > > > > > > I have another question and i hope you will understand me.. > > > > > > > Is there any option where you can set the program to go back to lets say the top of the code? > > > > > > > I mean if the program finished the operation and i want to stay in the program and go back ro the start. > > > > > > > after any operation i want the option to do it again , go back to the main menu or full exit from the program, and i want it every time. > > > > > > > > > > > > > > i hope i'm clear :) > > > > > > > > > > > > Yep! Look up the docs and tutorial on "control flow" and "looping > > > > > > constructs". Sounds like what you want here is a 'while' loop. > > > > > > > > > > > > ChrisA > > > > Hi Chris, > > this is my code: > > > > #!/usr/bin/env python > > #Get the IP Address > > > > import sys, socket > > > > print ("\n\n#########################################################") > > print ("# Get IP from Host v 1.0 #") > > print ("#########################################################") > > print ("# Choose from the options below #") > > print ("# 1- url , 2-File(Text file only.txt) #") > > print ("#########################################################\n") > > > > mchoice = int(raw_input("Please enter your choice> ")) > > while mchoice !=1 and mchoice !=2: > > print("{0} is not a menu option.".format(mchoice)) > > mchoice = int(raw_input("Please try again> ")) > > > > > > if mchoice == 2: > > filename = raw_input("Hello, please enter file name here> ") > > if filename.endswith(".txt"): > > > > try: > > infile = open(filename) > > except EnvironmentError as e: > > print(e) > > sys.exit(1) > > > > print("\nFile {0} exists!".format(filename)) > > print("\nGetting IP addresses for hosts") > > print("\n") > > else: > > print("{0} is not a Text file.".format(filename)) > > sys.exit(1) > > for line in infile: > > hostname = line.strip() > > try: > > ip_address = socket.gethostbyname(hostname) > > except EnvironmentError as e: > > print("Couldn't find IP address for {0}: {1}".format(hostname, e)) > > continue > > print("IP address for {0} is {1}.".format(hostname, ip_address)) > > else: > > print ("\nFinished the operation") > > > > if mchoice == 1: > > murl = raw_input("Enter URL here> ") > > try: > > print("Checking URL...") > > ip_address = socket.gethostbyname(murl) > > except EnvironmentError as d: > > print(d) > > sys.exit(1) > > print("Valid URL") > > print("\nIP address for {0} is {1}.".format(murl, ip_address)) > > print ("\nFinished the operation") > > ===================================================================== > > > > now where it says Finsihed the operation i want it to show (another search /main menu/exit program) > > > > i know about the while loop , but forgive me i just don't have a clue how to use it for this situation. > > > > i don't want you to give me the code:) just the idea. > > i did read the section about the while loop but still i do not know how to use it in this situation. > > thanks. o.k a giant while loop :) thanks. From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed Sep 19 05:22:32 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 19 Sep 2012 11:22:32 +0200 Subject: 'indent'ing Python in windows bat In-Reply-To: References: <5057C990.8080809@invtools.com> <505803A9.4000409@davea.name> Message-ID: Am 18.09.2012 15:03 schrieb David Smith: > I COULD break down each batch file and write dozens of mini python > scripts to be called. I already have a few, too. Efficiency? Speed is > bad, but these are bat files, after all. The cost of trying to work with > a multitude of small files is high, though, and I realized I had better > go to a mix. In order to achieve this, it might be very useful to either have a module for each (bigger) part to be achieved which you can call with python -m modulename arg1 arg2 arg3 and putting the Python code into modulename.py. Or you have one big "interpreter" which works this way: class Cmd(object): """ Command collector """ def __init__(self): self.cmds = {} def cmd(self, f): # register a function self.cmds[f.__name__] = f return f def main(self): import sys sys.exit(self.cmds[sys.argv[1]](*sys.argv[2:])) cmd = Cmd() @cmd.cmd def cmd1(arg1, arg2): do_stuff() ... return 1 # error -> exit() @cmd.cmd def cmd2(): ... if __name__ == '__main__': cmd.main() This is suitable for many small things and can be used this way: bat cmds python -m thismodule cmd1 a b other bat cmds python -m thismodule cmd2 ... HTH, Thomas From tardyp at gmail.com Wed Sep 19 06:24:41 2012 From: tardyp at gmail.com (Pierre Tardy) Date: Wed, 19 Sep 2012 03:24:41 -0700 (PDT) Subject: Using dict as object Message-ID: <345da32c-a22b-4025-bb50-794d684885b1@googlegroups.com> One thing that is cooler with java-script than in python is that dictionaries and objects are the same thing. It allows browsing of complex hierarchical data syntactically easy. For manipulating complex jsonable data, one will always prefer writing: buildrequest.properties.myprop rather than brdict['properties']['myprop'] This ability in JS is well known for its flaws (e.g. http://drupal.org/node/172169#forin ), and I understand why this is not a feature that we want in python by default. I did work on class that adds this feature, and that I wish to use for manipulating my json data. The following github pull request to buildbot has tests that defines specification of such a class, and has several commits, which gives several implementation of the same thing. https://github.com/buildbot/buildbot/pull/525 All implementation I tried are much slower than a pure native dict access. Each implementation have bench results in commit comment. All of them are 20+x slower than plain dict! I would like to have python guys advices on how one could optimize this. I'd like to eventually post this to python-dev, please tell if this is really not a good idea. Regards, Pierre From andrea.crotti.0 at gmail.com Wed Sep 19 06:26:30 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 19 Sep 2012 11:26:30 +0100 Subject: subprocess call is not waiting. In-Reply-To: <28ih585cvob222k24v7ccfapgvav7nfgur@invalid.netcom.com> References: <0b598d7f-7137-47cc-8eed-80ab450536c5@googlegroups.com> <0405db16-6a4c-4189-a32c-2311d45eead3@googlegroups.com> <28ih585cvob222k24v7ccfapgvav7nfgur@invalid.netcom.com> Message-ID: 2012/9/18 Dennis Lee Bieber : > > Unless you have a really massive result set from that "ls", that > command probably ran so fast that it is blocked waiting for someone to > read the PIPE. I tried also with "ls -lR /" and that definitively takes a while to run, when I do this: proc = subprocess.Popen(['ls', '-lR', '/'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) nothing is running, only when I actually do proc.communicate() I see the process running in top.. Is it still an observation problem? Anyway I also need to know when the process is over while waiting, so probably a thread is the only way.. From ndbecker2 at gmail.com Wed Sep 19 07:17:00 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 19 Sep 2012 07:17 -0400 Subject: A little morning puzzle Message-ID: I have a list of dictionaries. They all have the same keys. I want to find the set of keys where all the dictionaries have the same values. Suggestions? From __peter__ at web.de Wed Sep 19 07:33:04 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 19 Sep 2012 13:33:04 +0200 Subject: A little morning puzzle References: Message-ID: Neal Becker wrote: > I have a list of dictionaries. They all have the same keys. I want to > find the set of keys where all the dictionaries have the same values. Suggestions? >>> items = [ ... {1:2, 2:2}, ... {1:1, 2:2}, ... ] >>> first = items[0].items() >>> [key for key, value in first if all(item[key] == value for item in items)] [2] From jpiitula at ling.helsinki.fi Wed Sep 19 07:34:41 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 19 Sep 2012 14:34:41 +0300 Subject: A little morning puzzle References: Message-ID: Neal Becker writes: > I have a list of dictionaries. They all have the same keys. I want > to find the set of keys where all the dictionaries have the same > values. Suggestions? Literally-ish: { key for key, val in ds[0].items() if all(val == d[key] for d in ds) } From d at davea.name Wed Sep 19 07:45:38 2012 From: d at davea.name (Dave Angel) Date: Wed, 19 Sep 2012 07:45:38 -0400 Subject: Using dict as object In-Reply-To: <345da32c-a22b-4025-bb50-794d684885b1@googlegroups.com> References: <345da32c-a22b-4025-bb50-794d684885b1@googlegroups.com> Message-ID: <5059B062.8020108@davea.name> On 09/19/2012 06:24 AM, Pierre Tardy wrote: > One thing that is cooler with java-script than in python is that dictionaries and objects are the same thing. It allows browsing of complex hierarchical data syntactically easy. You probably need some different terminology, since a dictionary is already an object. So's an int, or a list, or anything else visible in python. You're trying to blur the distinction between attribute access and access by key (square brackets). > > For manipulating complex jsonable data, one will always prefer writing: > buildrequest.properties.myprop > rather than > brdict['properties']['myprop'] So what you want is to provide a dict-like class which has both a __getitem__ and a __getattribute__, which produces mostly the same results, if the parameters happen to be reasonable and not conflict with other methods. (Similar for *set*, *del*, and __contains__ and maybe others). This has been proposed and discussed and even implemented many times on this list and others. > This ability in JS is well known for its flaws (e.g. http://drupal.org/node/172169#forin ), and I understand why this is not a feature that we want in python by default. I did work on class that adds this feature, and that I wish to use for manipulating my json data. There are many more flaws than just the hiding of certain items because of existing attributes. Additionally, this would only work for items whose keys are strings, and are strings that happen to be legal symbol names and not keywords. If you also support __setitem__ or __delitem__ you run the risk of arbitrary code trashing the code that makes the class work. > The following github pull request to buildbot has tests that defines specification of such a class, and has several commits, which gives several implementation of the same thing. > https://github.com/buildbot/buildbot/pull/525 > > All implementation I tried are much slower than a pure native dict access. > Each implementation have bench results in commit comment. All of them are 20+x slower than plain dict! Assuming you're talking about CPython benchmarks, the dict is highly optimized, C code. And when you provide your own __getitem__ implementation in pure python, there are many attribute accesses, just to make the code work. > I would like to have python guys advices on how one could optimize this. Use C code and slots. > I'd like to eventually post this to python-dev, please tell if this is really not a good idea. > > Regards, > Pierre if you're proposing a new module for the stdlib, one of the (unstated?) requirements is that it be in regular use by a fairly large audience for a while. -- DaveA From dwightdhutto at gmail.com Wed Sep 19 08:01:11 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 19 Sep 2012 08:01:11 -0400 Subject: A little morning puzzle In-Reply-To: References: Message-ID: > I have a list of dictionaries. They all have the same keys. I want to find the > set of keys where all the dictionaries have the same values. Suggestions? Here is my solution: a = {} a['dict'] = 1 b = {} b['dict'] = 2 c = {} c['dict'] = 1 d = {} d['dict'] = 3 e = {} e['dict'] = 1 x = [a,b,c,d,e] collection_count = 0 for dict_key_search in x: if dict_key_search['dict'] == 1: collection_count += 1 print dict_key_search['dict'] Might be better ones though. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From __peter__ at web.de Wed Sep 19 08:09:01 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 19 Sep 2012 14:09:01 +0200 Subject: A little morning puzzle References: Message-ID: Dwight Hutto wrote: >> I have a list of dictionaries. They all have the same keys. I want to >> find the >> set of keys where all the dictionaries have the same values. >> Suggestions? > > Here is my solution: > > > a = {} > a['dict'] = 1 > > b = {} > b['dict'] = 2 > > c = {} > c['dict'] = 1 > > d = {} > d['dict'] = 3 > > e = {} > e['dict'] = 1 > > > x = [a,b,c,d,e] > collection_count = 0 > > for dict_key_search in x: > if dict_key_search['dict'] == 1: > collection_count += 1 > print dict_key_search['dict'] > > > Might be better ones though. Unlikely. From antoon.pardon at rece.vub.ac.be Wed Sep 19 08:13:17 2012 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 19 Sep 2012 14:13:17 +0200 Subject: A little morning puzzle In-Reply-To: References: Message-ID: <5059B6DD.8030100@rece.vub.ac.be> On 19-09-12 13:17, Neal Becker wrote: > I have a list of dictionaries. They all have the same keys. I want to find the > set of keys where all the dictionaries have the same values. Suggestions? common_items = reduce(opereator.__and__, [set(dct.iteritems()) for dct in lst]) common_keys = set([item[0] for item in common_items]) -- Antoon Pardon From dwightdhutto at gmail.com Wed Sep 19 08:22:27 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 19 Sep 2012 08:22:27 -0400 Subject: A little morning puzzle In-Reply-To: References: Message-ID: On Wed, Sep 19, 2012 at 8:01 AM, Dwight Hutto wrote: >> I have a list of dictionaries. They all have the same keys. I want to find the >> set of keys where all the dictionaries have the same values. Suggestions? > This one is better: a = {} a['dict'] = 1 b = {} b['dict'] = 2 c = {} c['dict'] = 1 d = {} d['dict'] = 3 e = {} e['dict'] = 1 x = [a,b,c,d,e] count = 0 collection_count = 0 search_variable = 1 for dict_key_search in x: if dict_key_search['dict'] == search_variable: print "Match count found: #%i = %i" % (count,search_variable) collection_count += 1 count += 1 print collection_count -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From davids at invtools.com Wed Sep 19 08:27:20 2012 From: davids at invtools.com (David Smith) Date: Wed, 19 Sep 2012 08:27:20 -0400 Subject: 'indent'ing Python in windows bat In-Reply-To: References: <5057C990.8080809@invtools.com> <505803A9.4000409@davea.name> Message-ID: <5059BA28.2090803@invtools.com> On 2012-09-19 05:22, Thomas Rachel wrote: > Am 18.09.2012 15:03 schrieb David Smith: > >> I COULD break down each batch file and write dozens of mini python >> scripts to be called. I already have a few, too. Efficiency? Speed is >> bad, but these are bat files, after all. The cost of trying to work with >> a multitude of small files is high, though, and I realized I had better >> go to a mix. > > In order to achieve this, it might be very useful to either have a > module for each (bigger) part to be achieved which you can call with ... > Or you have one big "interpreter" which works this way: > > class Cmd(object): > """ > Command collector > """ ... ... > > This is suitable for many small things and can be used this way: ... > Thomas Thomas, Beautiful. Gotta love it. I'll see if I can get the "interpreter" going. I particularly like it because I will be able to copy and paste wholesale when I stitch the final product back together again. Many thanks. Going back to the one-liner, I discovered the following individual lines work: print('hi') if 1: print('hi') print('hi');print('hi2') if 1: print('hi');print('hi2') but not: print('hi');if 1: print('hi') Chokes on the 'if'. On the surface, this is not consistent. I'll drop the one-liners for now since I have something that I can work with as I learn to wrestle with Python. thanks again. From dkatorza at gmail.com Wed Sep 19 08:28:19 2012 From: dkatorza at gmail.com (Dan Katorza) Date: Wed, 19 Sep 2012 05:28:19 -0700 (PDT) Subject: using text file to get ip address from hostname In-Reply-To: References: <3359a0e7-f7bb-4b1f-b586-e83f337566b7@googlegroups.com> Message-ID: <1ac7b836-abfb-401b-b6ac-3ae4ad6c1ce7@googlegroups.com> ?????? ??? ?????, 19 ??????? 2012 12:11:04 UTC+3, ??? Dan Katorza: > ?????? ??? ?????, 19 ??????? 2012 11:50:56 UTC+3, ??? Dan Katorza: > > > ?????? ??? ?????, 19 ??????? 2012 11:14:29 UTC+3, ??? Chris Angelico: > > > > > > > On Wed, Sep 19, 2012 at 5:41 PM, Dan Katorza wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Hello again, > > > > > > > > > > > > > > > I have another question and i hope you will understand me.. > > > > > > > > > > > > > > > Is there any option where you can set the program to go back to lets say the top of the code? > > > > > > > > > > > > > > > I mean if the program finished the operation and i want to stay in the program and go back ro the start. > > > > > > > > > > > > > > > after any operation i want the option to do it again , go back to the main menu or full exit from the program, and i want it every time. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > i hope i'm clear :) > > > > > > > > > > > > > > > > > > > > > > > > > > > > Yep! Look up the docs and tutorial on "control flow" and "looping > > > > > > > > > > > > > > constructs". Sounds like what you want here is a 'while' loop. > > > > > > > > > > > > > > > > > > > > > > > > > > > > ChrisA > > > > > > > > > > > > Hi Chris, > > > > > > this is my code: > > > > > > > > > > > > #!/usr/bin/env python > > > > > > #Get the IP Address > > > > > > > > > > > > import sys, socket > > > > > > > > > > > > print ("\n\n#########################################################") > > > > > > print ("# Get IP from Host v 1.0 #") > > > > > > print ("#########################################################") > > > > > > print ("# Choose from the options below #") > > > > > > print ("# 1- url , 2-File(Text file only.txt) #") > > > > > > print ("#########################################################\n") > > > > > > > > > > > > mchoice = int(raw_input("Please enter your choice> ")) > > > > > > while mchoice !=1 and mchoice !=2: > > > > > > print("{0} is not a menu option.".format(mchoice)) > > > > > > mchoice = int(raw_input("Please try again> ")) > > > > > > > > > > > > > > > > > > if mchoice == 2: > > > > > > filename = raw_input("Hello, please enter file name here> ") > > > > > > if filename.endswith(".txt"): > > > > > > > > > > > > try: > > > > > > infile = open(filename) > > > > > > except EnvironmentError as e: > > > > > > print(e) > > > > > > sys.exit(1) > > > > > > > > > > > > print("\nFile {0} exists!".format(filename)) > > > > > > print("\nGetting IP addresses for hosts") > > > > > > print("\n") > > > > > > else: > > > > > > print("{0} is not a Text file.".format(filename)) > > > > > > sys.exit(1) > > > > > > for line in infile: > > > > > > hostname = line.strip() > > > > > > try: > > > > > > ip_address = socket.gethostbyname(hostname) > > > > > > except EnvironmentError as e: > > > > > > print("Couldn't find IP address for {0}: {1}".format(hostname, e)) > > > > > > continue > > > > > > print("IP address for {0} is {1}.".format(hostname, ip_address)) > > > > > > else: > > > > > > print ("\nFinished the operation") > > > > > > > > > > > > if mchoice == 1: > > > > > > murl = raw_input("Enter URL here> ") > > > > > > try: > > > > > > print("Checking URL...") > > > > > > ip_address = socket.gethostbyname(murl) > > > > > > except EnvironmentError as d: > > > > > > print(d) > > > > > > sys.exit(1) > > > > > > print("Valid URL") > > > > > > print("\nIP address for {0} is {1}.".format(murl, ip_address)) > > > > > > print ("\nFinished the operation") > > > > > > ===================================================================== > > > > > > > > > > > > now where it says Finsihed the operation i want it to show (another search /main menu/exit program) > > > > > > > > > > > > i know about the while loop , but forgive me i just don't have a clue how to use it for this situation. > > > > > > > > > > > > i don't want you to give me the code:) just the idea. > > > > > > i did read the section about the while loop but still i do not know how to use it in this situation. > > > > > > thanks. > > > > o.k a giant while loop :) > > thanks. hi, found a solution, it's not quite like Chris advised but it works. #!/usr/bin/env python #Get the IP Address import sys, socket, os def restart_program(): python = sys.executable os.execl(python, python, * sys.argv) print ("\n\n#########################################################") print ("# Get IP from Host v 1.0 #") print ("#########################################################") print ("# Choose from the options below #") print ("# 1- url , 2-File(Text file only.txt) #") print ("#########################################################\n") mchoice = int(raw_input("Please enter your choice> ")) while mchoice !=1 and mchoice !=2: print("{0} is not a menu option.".format(mchoice)) mchoice = int(raw_input("Please try again> ")) while mchoice == 2: filename = raw_input("Please enter file name here> ") if filename.endswith(".txt"): try: infile = open(filename) except EnvironmentError as e: print(e) sys.exit(1) print("\nFile {0} exists!".format(filename)) print("\nGetting IP addresses for hosts") print("\n") else: print("{0} is not a Text file.".format(filename)) sys.exit(1) for line in infile: hostname = line.strip() try: ip_address = socket.gethostbyname(hostname) except EnvironmentError as e: print("Couldn't find IP address for {0}: {1}".format(hostname, e)) continue print("IP address for {0} is {1}.".format(hostname, ip_address)) else: print ("\nFinished the operation") print ("A=another search, M=main menu, E=exit") waction=raw_input("Please choose your action > ") while waction !='A' and waction !='M' and waction !='E': print("{0} is not a valid action.".format(waction)) waction=raw_input("Please try again> ") if waction =='E': sys.exit(1) if waction =='A': continue if waction =='M': print ("#########################################################") print ("# Choose from the options below #") print ("# 1- url , 2-File(Text file only.txt) #") print ("#########################################################\n") mchoice = int(raw_input("Please enter your choice> ")) while mchoice !=1 and mchoice !=2: print("{0} is not a menu option.".format(mchoice)) mchoice = int(raw_input("Please try again> ")) while mchoice == 1: murl = raw_input("Enter URL here> ") try: print("Checking URL...") ip_address = socket.gethostbyname(murl) except EnvironmentError as d: print(d) sys.exit(1) print("Valid URL") print("\nIP address for {0} is {1}.".format(murl, ip_address)) print ("\nFinished the operation") print ("A=another search, M=main menu, E=exit") waction=raw_input("Please choose your action > ") while waction !='A' and waction !='M' and waction !='E': print("{0} is not a valid action.".format(waction)) waction=raw_input("Please try again> ") if waction =='E': sys.exit(1) if waction =='A': continue if waction =='M': restart_program() From dkatorza at gmail.com Wed Sep 19 08:28:19 2012 From: dkatorza at gmail.com (Dan Katorza) Date: Wed, 19 Sep 2012 05:28:19 -0700 (PDT) Subject: using text file to get ip address from hostname In-Reply-To: References: <3359a0e7-f7bb-4b1f-b586-e83f337566b7@googlegroups.com> Message-ID: <1ac7b836-abfb-401b-b6ac-3ae4ad6c1ce7@googlegroups.com> ?????? ??? ?????, 19 ??????? 2012 12:11:04 UTC+3, ??? Dan Katorza: > ?????? ??? ?????, 19 ??????? 2012 11:50:56 UTC+3, ??? Dan Katorza: > > > ?????? ??? ?????, 19 ??????? 2012 11:14:29 UTC+3, ??? Chris Angelico: > > > > > > > On Wed, Sep 19, 2012 at 5:41 PM, Dan Katorza wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Hello again, > > > > > > > > > > > > > > > I have another question and i hope you will understand me.. > > > > > > > > > > > > > > > Is there any option where you can set the program to go back to lets say the top of the code? > > > > > > > > > > > > > > > I mean if the program finished the operation and i want to stay in the program and go back ro the start. > > > > > > > > > > > > > > > after any operation i want the option to do it again , go back to the main menu or full exit from the program, and i want it every time. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > i hope i'm clear :) > > > > > > > > > > > > > > > > > > > > > > > > > > > > Yep! Look up the docs and tutorial on "control flow" and "looping > > > > > > > > > > > > > > constructs". Sounds like what you want here is a 'while' loop. > > > > > > > > > > > > > > > > > > > > > > > > > > > > ChrisA > > > > > > > > > > > > Hi Chris, > > > > > > this is my code: > > > > > > > > > > > > #!/usr/bin/env python > > > > > > #Get the IP Address > > > > > > > > > > > > import sys, socket > > > > > > > > > > > > print ("\n\n#########################################################") > > > > > > print ("# Get IP from Host v 1.0 #") > > > > > > print ("#########################################################") > > > > > > print ("# Choose from the options below #") > > > > > > print ("# 1- url , 2-File(Text file only.txt) #") > > > > > > print ("#########################################################\n") > > > > > > > > > > > > mchoice = int(raw_input("Please enter your choice> ")) > > > > > > while mchoice !=1 and mchoice !=2: > > > > > > print("{0} is not a menu option.".format(mchoice)) > > > > > > mchoice = int(raw_input("Please try again> ")) > > > > > > > > > > > > > > > > > > if mchoice == 2: > > > > > > filename = raw_input("Hello, please enter file name here> ") > > > > > > if filename.endswith(".txt"): > > > > > > > > > > > > try: > > > > > > infile = open(filename) > > > > > > except EnvironmentError as e: > > > > > > print(e) > > > > > > sys.exit(1) > > > > > > > > > > > > print("\nFile {0} exists!".format(filename)) > > > > > > print("\nGetting IP addresses for hosts") > > > > > > print("\n") > > > > > > else: > > > > > > print("{0} is not a Text file.".format(filename)) > > > > > > sys.exit(1) > > > > > > for line in infile: > > > > > > hostname = line.strip() > > > > > > try: > > > > > > ip_address = socket.gethostbyname(hostname) > > > > > > except EnvironmentError as e: > > > > > > print("Couldn't find IP address for {0}: {1}".format(hostname, e)) > > > > > > continue > > > > > > print("IP address for {0} is {1}.".format(hostname, ip_address)) > > > > > > else: > > > > > > print ("\nFinished the operation") > > > > > > > > > > > > if mchoice == 1: > > > > > > murl = raw_input("Enter URL here> ") > > > > > > try: > > > > > > print("Checking URL...") > > > > > > ip_address = socket.gethostbyname(murl) > > > > > > except EnvironmentError as d: > > > > > > print(d) > > > > > > sys.exit(1) > > > > > > print("Valid URL") > > > > > > print("\nIP address for {0} is {1}.".format(murl, ip_address)) > > > > > > print ("\nFinished the operation") > > > > > > ===================================================================== > > > > > > > > > > > > now where it says Finsihed the operation i want it to show (another search /main menu/exit program) > > > > > > > > > > > > i know about the while loop , but forgive me i just don't have a clue how to use it for this situation. > > > > > > > > > > > > i don't want you to give me the code:) just the idea. > > > > > > i did read the section about the while loop but still i do not know how to use it in this situation. > > > > > > thanks. > > > > o.k a giant while loop :) > > thanks. hi, found a solution, it's not quite like Chris advised but it works. #!/usr/bin/env python #Get the IP Address import sys, socket, os def restart_program(): python = sys.executable os.execl(python, python, * sys.argv) print ("\n\n#########################################################") print ("# Get IP from Host v 1.0 #") print ("#########################################################") print ("# Choose from the options below #") print ("# 1- url , 2-File(Text file only.txt) #") print ("#########################################################\n") mchoice = int(raw_input("Please enter your choice> ")) while mchoice !=1 and mchoice !=2: print("{0} is not a menu option.".format(mchoice)) mchoice = int(raw_input("Please try again> ")) while mchoice == 2: filename = raw_input("Please enter file name here> ") if filename.endswith(".txt"): try: infile = open(filename) except EnvironmentError as e: print(e) sys.exit(1) print("\nFile {0} exists!".format(filename)) print("\nGetting IP addresses for hosts") print("\n") else: print("{0} is not a Text file.".format(filename)) sys.exit(1) for line in infile: hostname = line.strip() try: ip_address = socket.gethostbyname(hostname) except EnvironmentError as e: print("Couldn't find IP address for {0}: {1}".format(hostname, e)) continue print("IP address for {0} is {1}.".format(hostname, ip_address)) else: print ("\nFinished the operation") print ("A=another search, M=main menu, E=exit") waction=raw_input("Please choose your action > ") while waction !='A' and waction !='M' and waction !='E': print("{0} is not a valid action.".format(waction)) waction=raw_input("Please try again> ") if waction =='E': sys.exit(1) if waction =='A': continue if waction =='M': print ("#########################################################") print ("# Choose from the options below #") print ("# 1- url , 2-File(Text file only.txt) #") print ("#########################################################\n") mchoice = int(raw_input("Please enter your choice> ")) while mchoice !=1 and mchoice !=2: print("{0} is not a menu option.".format(mchoice)) mchoice = int(raw_input("Please try again> ")) while mchoice == 1: murl = raw_input("Enter URL here> ") try: print("Checking URL...") ip_address = socket.gethostbyname(murl) except EnvironmentError as d: print(d) sys.exit(1) print("Valid URL") print("\nIP address for {0} is {1}.".format(murl, ip_address)) print ("\nFinished the operation") print ("A=another search, M=main menu, E=exit") waction=raw_input("Please choose your action > ") while waction !='A' and waction !='M' and waction !='E': print("{0} is not a valid action.".format(waction)) waction=raw_input("Please try again> ") if waction =='E': sys.exit(1) if waction =='A': continue if waction =='M': restart_program() From jeanmichel at sequans.com Wed Sep 19 08:47:54 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 19 Sep 2012 14:47:54 +0200 (CEST) Subject: Decorators not worth the effort In-Reply-To: <87txuvxn3b.fsf@handshake.de> Message-ID: <742104083.476223.1348058874685.JavaMail.root@sequans.com> ----- Original Message ----- > Jean-Michel Pichavant writes: > > > ----- Original Message ----- > >> Jean-Michel Pichavant wrote: > > [snip] > >> One minor note, the style of decorator you are using loses the > >> docstring > >> (at least) of the original function. I would add the > >> @functools.wraps(func) > >> decorator inside your decorator. > > > > Is there a way to not loose the function signature as well ? > > Look at the "decorator" module. > Great, thank you. JM From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed Sep 19 09:02:47 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 19 Sep 2012 15:02:47 +0200 Subject: Using dict as object In-Reply-To: <345da32c-a22b-4025-bb50-794d684885b1@googlegroups.com> References: <345da32c-a22b-4025-bb50-794d684885b1@googlegroups.com> Message-ID: Am 19.09.2012 12:24 schrieb Pierre Tardy: > One thing that is cooler with java-script than in python is that dictionaries and objects are the same thing. It allows browsing of complex hierarchical data syntactically easy. > > For manipulating complex jsonable data, one will always prefer writing: > buildrequest.properties.myprop > rather than > brdict['properties']['myprop'] This is quite easy to achieve (but not so easy to understand): class JsObject(dict): def __init__(self, *args, **kwargs): super(JsObject, self).__init__(*args, **kwargs) self.__dict__ = self (Google for JSObject; this is not my courtesy). What does it do? Well, an object's attributes are stored in a dict. If I subclass dict, the resulting class can be used for this as well. In this case, a subclass of a dict gets itself as its __dict__. What happens now is d = JsObject() d.a = 1 print d['a'] # This results in d.__dict__['a'] = 1. # As d.__dict__ is d, this is equivalent to d['a'] = 1. # Now the other way: d['b'] = 42 print d.b # here as well: d.b reads d.__dict__['b'], which is essentially d['b']. Thomas From hansmu at xs4all.nl Wed Sep 19 09:23:49 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 19 Sep 2012 15:23:49 +0200 Subject: subprocess call is not waiting. In-Reply-To: References: <0b598d7f-7137-47cc-8eed-80ab450536c5@googlegroups.com> <0405db16-6a4c-4189-a32c-2311d45eead3@googlegroups.com> <28ih585cvob222k24v7ccfapgvav7nfgur@invalid.netcom.com> Message-ID: <5059c765$0$6952$e4fe514c@news2.news.xs4all.nl> On 19/09/12 12:26:30, andrea crotti wrote: > 2012/9/18 Dennis Lee Bieber : >> >> Unless you have a really massive result set from that "ls", that >> command probably ran so fast that it is blocked waiting for someone to >> read the PIPE. > > I tried also with "ls -lR /" and that definitively takes a while to run, > when I do this: > > proc = subprocess.Popen(['ls', '-lR', '/'], stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > > nothing is running, only when I actually do > proc.communicate() > > I see the process running in top.. > Is it still an observation problem? Yes: using "top" is an observation problem. "Top", as the name suggests, shows only the most active processes. It's quite possible that your 'ls' process is not active, because it's waiting for your Python process to read some data from the pipe. Try using "ps" instead. Look in thte man page for the correct options (they differ between platforms). The default options do not show all processes, so they may not show the process you're looking for. > Anyway I also need to know when the process is over while waiting, so > probably a thread is the only way.. This sounds confused. You don't need threads. When 'ls' finishes, you'll read end-of-file on the proc.stdout pipe. You should then call proc.wait() to reap its exit status (if you don't, you'll leave a zombie process). Since the process has already finished, the proc.wait() call will not actually do any waiting. Hope this helps, -- HansM From oscar.j.benjamin at gmail.com Wed Sep 19 10:04:07 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 19 Sep 2012 14:04:07 +0000 (UTC) Subject: Using dict as object References: <345da32c-a22b-4025-bb50-794d684885b1@googlegroups.com> <5059B062.8020108@davea.name> Message-ID: On 2012-09-19, Dave Angel wrote: > On 09/19/2012 06:24 AM, Pierre Tardy wrote: >> All implementation I tried are much slower than a pure native dict access. >> Each implementation have bench results in commit comment. All of them >> are 20+x slower than plain dict! > > Assuming you're talking about CPython benchmarks, the dict is highly > optimized, C code. And when you provide your own __getitem__ > implementation in pure python, there are many attribute accesses, just to > make the code work. > >> I would like to have python guys advices on how one could optimize this. > I agree with all of Dave's objections to this idea. It is possible, however, to make a more efficient implementation than the one that you have: class Namespace(dict): def __init__(self, *args, **kwargs): dict.__init__(self, *args, **kwargs) self.__dict__ = self This implementation is not really sane, though, as it doesn't hide any of the dict methods as attributes. It does, however, demonstrate something that be a potentially simple way of making an alternate type object in C. Oscar From franck at ditter.org Wed Sep 19 10:41:20 2012 From: franck at ditter.org (Franck Ditter) Date: Wed, 19 Sep 2012 16:41:20 +0200 Subject: sum works in sequences (Python 3) Message-ID: Hello, I wonder why sum does not work on the string sequence in Python 3 : >>> sum((8,5,9,3)) 25 >>> sum([5,8,3,9,2]) 27 >>> sum('rtarze') TypeError: unsupported operand type(s) for +: 'int' and 'str' I naively thought that sum('abc') would expand to 'a'+'b'+'c' And the error message is somewhat cryptic... franck From joel.goldstick at gmail.com Wed Sep 19 10:57:07 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 19 Sep 2012 10:57:07 -0400 Subject: sum works in sequences (Python 3) In-Reply-To: References: Message-ID: On Wed, Sep 19, 2012 at 10:41 AM, Franck Ditter wrote: > Hello, > I wonder why sum does not work on the string sequence in Python 3 : > >>>> sum((8,5,9,3)) > 25 >>>> sum([5,8,3,9,2]) > 27 >>>> sum('rtarze') > TypeError: unsupported operand type(s) for +: 'int' and 'str' > > I naively thought that sum('abc') would expand to 'a'+'b'+'c' > And the error message is somewhat cryptic... > > franck > -- > http://mail.python.org/mailman/listinfo/python-list Help on built-in function sum in module __builtin__: sum(...) sum(sequence[, start]) -> value Returns the sum of a sequence of numbers (NOT strings) plus the value of parameter 'start' (which defaults to 0). When the sequence is empty, returns start. ~ -- Joel Goldstick From neilc at norwich.edu Wed Sep 19 10:57:56 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 19 Sep 2012 14:57:56 GMT Subject: sum works in sequences (Python 3) References: Message-ID: On 2012-09-19, Franck Ditter wrote: > Hello, > I wonder why sum does not work on the string sequence in Python 3 : > >>>> sum((8,5,9,3)) > 25 >>>> sum([5,8,3,9,2]) > 27 >>>> sum('rtarze') > TypeError: unsupported operand type(s) for +: 'int' and 'str' > > I naively thought that sum('abc') would expand to 'a'+'b'+'c' > And the error message is somewhat cryptic... You got that error message because the default value for the second 'start' argument is 0. The function tried to add 'r' to 0. That said: >>> sum('rtarze', '') Traceback (most recent call last): File "", line 1, in TypeError: sum() can't sum strings [use ''.join(seq) instead] -- Neil Cerutti From ian.g.kelly at gmail.com Wed Sep 19 11:03:03 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 19 Sep 2012 09:03:03 -0600 Subject: sum works in sequences (Python 3) In-Reply-To: References: Message-ID: On Wed, Sep 19, 2012 at 8:41 AM, Franck Ditter wrote: > Hello, > I wonder why sum does not work on the string sequence in Python 3 : > >>>> sum((8,5,9,3)) > 25 >>>> sum([5,8,3,9,2]) > 27 >>>> sum('rtarze') > TypeError: unsupported operand type(s) for +: 'int' and 'str' > > I naively thought that sum('abc') would expand to 'a'+'b'+'c' > And the error message is somewhat cryptic... It notes in the doc string that it does not work on strings: sum(...) sum(sequence[, start]) -> value Returns the sum of a sequence of numbers (NOT strings) plus the value of parameter 'start' (which defaults to 0). When the sequence is empty, returns start. I think this restriction is mainly for efficiency. sum(['a', 'b', 'c', 'd', 'e']) would be the equivalent of 'a' + 'b' + 'c' + 'd' + 'e', which is an inefficient way to add together strings. You should use ''.join instead: >>> ''.join('abc') 'abc' From neilc at norwich.edu Wed Sep 19 11:06:43 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 19 Sep 2012 15:06:43 GMT Subject: sum works in sequences (Python 3) References: Message-ID: On 2012-09-19, Ian Kelly wrote: > It notes in the doc string that it does not work on strings: > > sum(...) > sum(sequence[, start]) -> value > > Returns the sum of a sequence of numbers (NOT strings) plus > the value of parameter 'start' (which defaults to 0). When > the sequence is empty, returns start. > > I think this restriction is mainly for efficiency. sum(['a', > 'b', 'c', 'd', 'e']) would be the equivalent of 'a' + 'b' + 'c' > + 'd' + 'e', which is an inefficient way to add together > strings. You should use ''.join instead: While the docstring is still useful, it has diverged from the documentation a little bit. sum(iterable[, start]) Sums start and the items of an iterable from left to right and returns the total. start defaults to 0. The iterable?s items are normally numbers, and the start value is not allowed to be a string. For some use cases, there are good alternatives to sum(). The preferred, fast way to concatenate a sequence of strings is by calling ''.join(sequence). To add floating point values with extended precision, see math.fsum(). To concatenate a series of iterables, consider using itertools.chain(). Are iterables and sequences different enough to warrant posting a bug report? -- Neil Cerutti From alister.ware at ntlworld.com Wed Sep 19 11:07:04 2012 From: alister.ware at ntlworld.com (Alister) Date: Wed, 19 Sep 2012 15:07:04 GMT Subject: sum works in sequences (Python 3) References: Message-ID: On Wed, 19 Sep 2012 16:41:20 +0200, Franck Ditter wrote: > Hello, > I wonder why sum does not work on the string sequence in Python 3 : > >>>> sum((8,5,9,3)) > 25 >>>> sum([5,8,3,9,2]) > 27 >>>> sum('rtarze') > TypeError: unsupported operand type(s) for +: 'int' and 'str' > > I naively thought that sum('abc') would expand to 'a'+'b'+'c' > And the error message is somewhat cryptic... > > franck Summation is a mathematical function that works on numbers Concatenation is the process of appending 1 string to another although they are not related to each other they do share the same operator(+) which is the cause of confusion. attempting to duck type this function would cause ambiguity for example what would you expect from sum ('a','b',3,4) 'ab34' or 'ab7' ? even 'A' + 7 would return this error for same reason. -- It is the nature of extreme self-lovers, as they will set an house on fire, and it were but to roast their eggs. -- Francis Bacon From ian.g.kelly at gmail.com Wed Sep 19 11:16:23 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 19 Sep 2012 09:16:23 -0600 Subject: A little morning puzzle In-Reply-To: <5059B6DD.8030100@rece.vub.ac.be> References: <5059B6DD.8030100@rece.vub.ac.be> Message-ID: On Wed, Sep 19, 2012 at 6:13 AM, Antoon Pardon wrote: > On 19-09-12 13:17, Neal Becker wrote: >> I have a list of dictionaries. They all have the same keys. I want to find the >> set of keys where all the dictionaries have the same values. Suggestions? > common_items = reduce(opereator.__and__, [set(dct.iteritems()) for dct > in lst]) > common_keys = set([item[0] for item in common_items]) You can use dictviews for that: common_items = reduce(operator.__and__, (d.viewitems() for d in ds)) common_keys = [item[0] for item in common_items] From ian.g.kelly at gmail.com Wed Sep 19 11:24:49 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 19 Sep 2012 09:24:49 -0600 Subject: sum works in sequences (Python 3) In-Reply-To: References: Message-ID: On Wed, Sep 19, 2012 at 9:06 AM, Neil Cerutti wrote: > Are iterables and sequences different enough to warrant posting a > bug report? The glossary is specific about the definitions of both, so I would say yes. http://docs.python.org/dev/glossary.html#term-iterable http://docs.python.org/dev/glossary.html#term-sequence From showell30 at yahoo.com Wed Sep 19 11:37:00 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 19 Sep 2012 08:37:00 -0700 (PDT) Subject: sum works in sequences (Python 3) References: Message-ID: On Sep 19, 8:06?am, Neil Cerutti wrote: > On 2012-09-19, Ian Kelly wrote: > > > It notes in the doc string that it does not work on strings: > > > sum(...) > > ? ? sum(sequence[, start]) -> value > > > ? ? Returns the sum of a sequence of numbers (NOT strings) plus > > ? ? the value of parameter 'start' (which defaults to 0). ?When > > ? ? the sequence is empty, returns start. > > > I think this restriction is mainly for efficiency. ?sum(['a', > > 'b', 'c', 'd', 'e']) would be the equivalent of 'a' + 'b' + 'c' > > + 'd' + 'e', which is an inefficient way to add together > > strings. ?You should use ''.join instead: > > While the docstring is still useful, it has diverged from the > documentation a little bit. > > ? sum(iterable[, start]) > > ? Sums start and the items of an iterable from left to right and > ? returns the total. start defaults to 0. The iterable?s items > ? are normally numbers, and the start value is not allowed to be > ? a string. > > ? For some use cases, there are good alternatives to sum(). The > ? preferred, fast way to concatenate a sequence of strings is by > ? calling ''.join(sequence). To add floating point values with > ? extended precision, see math.fsum(). To concatenate a series of > ? iterables, consider using itertools.chain(). > > Are iterables and sequences different enough to warrant posting a > bug report? > Sequences are iterables, so I'd say the docs are technically correct, but maybe I'm misunderstanding what you would be trying to clarify. From gheskett at wdtv.com Wed Sep 19 11:57:47 2012 From: gheskett at wdtv.com (Gene Heskett) Date: Wed, 19 Sep 2012 11:57:47 -0400 Subject: subprocess call is not waiting. In-Reply-To: <5059c765$0$6952$e4fe514c@news2.news.xs4all.nl> References: <5059c765$0$6952$e4fe514c@news2.news.xs4all.nl> Message-ID: <201209191157.47847.gheskett@wdtv.com> On Wednesday 19 September 2012 11:56:44 Hans Mulder did opine: > On 19/09/12 12:26:30, andrea crotti wrote: > > 2012/9/18 Dennis Lee Bieber : > >> Unless you have a really massive result set from that "ls", > >> that > >> > >> command probably ran so fast that it is blocked waiting for someone > >> to read the PIPE. > > > > I tried also with "ls -lR /" and that definitively takes a while to > > run, when I do this: > > > > proc = subprocess.Popen(['ls', '-lR', '/'], stdout=subprocess.PIPE, > > stderr=subprocess.PIPE) > > > > nothing is running, only when I actually do > > proc.communicate() > > > > I see the process running in top.. > > Is it still an observation problem? > > Yes: using "top" is an observation problem. > > "Top", as the name suggests, shows only the most active processes. > Which is why I run htop in a shell 100% of the time. With htop, you can scroll down and see everything. > It's quite possible that your 'ls' process is not active, because > it's waiting for your Python process to read some data from the pipe. > > Try using "ps" instead. Look in thte man page for the correct > options (they differ between platforms). The default options do > not show all processes, so they may not show the process you're > looking for. > > > Anyway I also need to know when the process is over while waiting, so > > probably a thread is the only way.. > > This sounds confused. > > You don't need threads. When 'ls' finishes, you'll read end-of-file > on the proc.stdout pipe. You should then call proc.wait() to reap > its exit status (if you don't, you'll leave a zombie process). > Since the process has already finished, the proc.wait() call will > not actually do any waiting. > > > Hope this helps, > > -- HansM 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) My web page: is up! To know Edina is to reject it. -- Dudley Riggs, "The Year the Grinch Stole the Election" From steve+comp.lang.python at pearwood.info Wed Sep 19 12:14:26 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Sep 2012 16:14:26 GMT Subject: sum works in sequences (Python 3) References: Message-ID: <5059ef62$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 19 Sep 2012 09:03:03 -0600, Ian Kelly wrote: > I think this restriction is mainly for efficiency. sum(['a', 'b', 'c', > 'd', 'e']) would be the equivalent of 'a' + 'b' + 'c' + 'd' + 'e', which > is an inefficient way to add together strings. It might not be obvious to some people why repeated addition is so inefficient, and in fact if people try it with modern Python (version 2.3 or better), they may not notice any inefficiency. But the example given, 'a' + 'b' + 'c' + 'd' + 'e', potentially ends up creating four strings, only to immediately throw away three of them: * first it concats 'a' to 'b', giving the new string 'ab' * then 'ab' + 'c', creating a new string 'abc' * then 'abc' + 'd', creating a new string 'abcd' * then 'abcd' + 'e', creating a new string 'abcde' Each new string requires a block of memory to be allocated, potentially requiring other blocks of memory to be moved out of the way (at least for large blocks). With only five characters in total, you won't really notice any slowdown, but with large enough numbers of strings, Python could potentially spend a lot of time building, and throwing away, intermediate strings. Pure wasted effort. For another look at this, see: http://www.joelonsoftware.com/articles/fog0000000319.html I say "could" because starting in about Python 2.3, there is a nifty optimization in Python (CPython only, not Jython or IronPython) that can *sometimes* recognise repeated string concatenation and make it less inefficient. It depends on the details of the specific strings used, and the operating system's memory management. When it works, it can make string concatenation almost as efficient as ''.join(). When it doesn't work, repeated concatenation is PAINFULLY slow, hundreds or thousands of times slower than join. -- Steven From steve+comp.lang.python at pearwood.info Wed Sep 19 12:18:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Sep 2012 16:18:11 GMT Subject: sum works in sequences (Python 3) References: Message-ID: <5059f042$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 19 Sep 2012 15:07:04 +0000, Alister wrote: > Summation is a mathematical function that works on numbers Concatenation > is the process of appending 1 string to another > > although they are not related to each other they do share the same > operator(+) which is the cause of confusion. attempting to duck type > this function would cause ambiguity for example what would you expect > from > > sum ('a','b',3,4) > > 'ab34' or 'ab7' ? Neither. I would expect sum to do exactly what the + operator does if given two incompatible arguments: raise an exception. And in fact, that's exactly what it does. py> sum ([1, 2, 'a']) Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'int' and 'str' -- Steven From tardyp at gmail.com Wed Sep 19 12:19:22 2012 From: tardyp at gmail.com (Pierre Tardy) Date: Wed, 19 Sep 2012 18:19:22 +0200 Subject: Using dict as object In-Reply-To: <5059B062.8020108@davea.name> References: <345da32c-a22b-4025-bb50-794d684885b1@googlegroups.com> <5059B062.8020108@davea.name> Message-ID: > > This has been proposed and discussed and even implemented many > times on this list and others. > I can find this question on SO http://stackoverflow.com/questions/4984647/accessing-dict-keys-like-an-attribute-in-python which is basically answered with this solution class AttributeDict(dict): __getattr__ = dict.__getitem__ __setattr__ = dict.__setitem__ but this does not allow recursive access, you would need to first convert all nested dictionaries to AttributeDict. a.b.c.d = 2 # fail a.b = dict(c=3) a.b.c=4 # fail > I would like to have python guys advices on how one could optimize this. > > Use C code and slots. > I tried adding __slots__= [], to my class, but my benchmarks do not show significant changes. if you're proposing a new module for the stdlib, one of the (unstated?) > requirements is that it be in regular use by a fairly large audience for > a while. > I was talking about escalading to python-dev as a way to hit more expertize, but it looks like this one is already -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrea.crotti.0 at gmail.com Wed Sep 19 12:34:58 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 19 Sep 2012 17:34:58 +0100 Subject: subprocess call is not waiting. In-Reply-To: <5059c765$0$6952$e4fe514c@news2.news.xs4all.nl> References: <0b598d7f-7137-47cc-8eed-80ab450536c5@googlegroups.com> <0405db16-6a4c-4189-a32c-2311d45eead3@googlegroups.com> <28ih585cvob222k24v7ccfapgvav7nfgur@invalid.netcom.com> <5059c765$0$6952$e4fe514c@news2.news.xs4all.nl> Message-ID: 2012/9/19 Hans Mulder : > Yes: using "top" is an observation problem. > > "Top", as the name suggests, shows only the most active processes. Sure but "ls -lR /" is a very active process if you try to run it.. Anyway as written below I don't need this anymore. > > It's quite possible that your 'ls' process is not active, because > it's waiting for your Python process to read some data from the pipe. > > Try using "ps" instead. Look in thte man page for the correct > options (they differ between platforms). The default options do > not show all processes, so they may not show the process you're > looking for. > >> Anyway I also need to know when the process is over while waiting, so >> probably a thread is the only way.. > > This sounds confused. > > You don't need threads. When 'ls' finishes, you'll read end-of-file > on the proc.stdout pipe. You should then call proc.wait() to reap > its exit status (if you don't, you'll leave a zombie process). > Since the process has already finished, the proc.wait() call will > not actually do any waiting. > > > Hope this helps, > Well there is a process which has to do two things, monitor periodically some external conditions (filesystem / db), and launch a process that can take very long time. So I can't put a wait anywhere, or I'll stop everything else. But at the same time I need to know when the process is finished, which I could do but without a wait might get hacky. So I'm quite sure I just need to run the subprocess in a subthread unless I'm missing something obvious.. From andrea.crotti.0 at gmail.com Wed Sep 19 12:42:23 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 19 Sep 2012 17:42:23 +0100 Subject: Python presentations In-Reply-To: <20120919022003.GB61866@snakebite.org> References: <20120919022003.GB61866@snakebite.org> Message-ID: 2012/9/19 Trent Nelson : > > FWIW, I gave a presentation on decorators to the New York Python > User Group back in 2008. Relevant blog post: > > http://blogs.onresolve.com/?p=48 > > There's a link to the PowerPoint presentation I used in the first > paragraph. It's in .pptx format; let me know if you'd like it in > some other form. > > Regards, > > Trent. Ok thanks a lot, how long did it take for you to present that material? Interesting the part about the learning process, I had a similar experience, but probably skip this since I only have 30 minutes. Another thing which I would skip or only explain how it works are parametrized decorators, in the triple-def form they just look to ugly to be worth the effort (but at least should be understood). From benjamin.kaplan at case.edu Wed Sep 19 13:10:11 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 19 Sep 2012 10:10:11 -0700 Subject: subprocess call is not waiting. In-Reply-To: References: <0b598d7f-7137-47cc-8eed-80ab450536c5@googlegroups.com> <0405db16-6a4c-4189-a32c-2311d45eead3@googlegroups.com> <28ih585cvob222k24v7ccfapgvav7nfgur@invalid.netcom.com> <5059c765$0$6952$e4fe514c@news2.news.xs4all.nl> Message-ID: On Sep 19, 2012 9:37 AM, "andrea crotti" wrote: > Well there is a process which has to do two things, monitor > periodically some external conditions (filesystem / db), and launch a > process that can take very long time. > > So I can't put a wait anywhere, or I'll stop everything else. But at > the same time I need to know when the process is finished, which I > could do but without a wait might get hacky. > > So I'm quite sure I just need to run the subprocess in a subthread > unless I'm missing something obvious. If you want to see if a processes has terminated without waiting, use poll. -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Wed Sep 19 13:12:59 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 19 Sep 2012 10:12:59 -0700 Subject: A little morning puzzle References: Message-ID: <7x627andgk.fsf@ruckus.brouhaha.com> Neal Becker writes: > I have a list of dictionaries. They all have the same keys. I want to find the > set of keys where all the dictionaries have the same values. Suggestions? Untested, and uses a few more comparisons than necessary: # ds = [dict1, dict2 ... ] d0 = ds[0] ks = set(k for k in d0 if all(d[k]==d0[k] for d in ds)) From hansmu at xs4all.nl Wed Sep 19 13:31:59 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 19 Sep 2012 19:31:59 +0200 Subject: subprocess call is not waiting. In-Reply-To: References: <0b598d7f-7137-47cc-8eed-80ab450536c5@googlegroups.com> <0405db16-6a4c-4189-a32c-2311d45eead3@googlegroups.com> <28ih585cvob222k24v7ccfapgvav7nfgur@invalid.netcom.com> <5059c765$0$6952$e4fe514c@news2.news.xs4all.nl> Message-ID: <505a018f$0$6946$e4fe514c@news2.news.xs4all.nl> On 19/09/12 18:34:58, andrea crotti wrote: > 2012/9/19 Hans Mulder : >> Yes: using "top" is an observation problem. >> >> "Top", as the name suggests, shows only the most active processes. > > Sure but "ls -lR /" is a very active process if you try to run it.. Not necessarily: >> It's quite possible that your 'ls' process is not active because >> it's waiting for your Python process to read some data from the pipe. Hope this helps, -- HansM From sulfurfff at gmail.com Wed Sep 19 13:34:25 2012 From: sulfurfff at gmail.com (=?UTF-8?Q?Ismael_Farf=C3=A1n?=) Date: Wed, 19 Sep 2012 12:34:25 -0500 Subject: How to get the list of all my open file(descriptor)s and locks? Message-ID: Hello list >From man 2 EXECVE "By default, file descriptors remain open across an execve()" And from man 2 FCNTL "Record locks are... preserved across an execve(2)." So the question: * If I execve a python script (from C), how can I retrieve the list of files, and optionally the list of locks, from within the execve(d) python process so that I can use them? Some more info: I'm working with exotic stuff like AIX and Solaris 10 (Windows and linux too :) and my lowest common denominator is python 2.3. >From a standalone test within the interpreter I'd expect to get (at least) std(in/out/err). If more information is needed in order to help me, please let me know. Cheers Ismael -- Do not let me induce you to satisfy my curiosity, from an expectation, that I shall gratify yours. What I may judge proper to conceal, does not concern myself alone. From marduk at letterboxes.org Wed Sep 19 13:51:44 2012 From: marduk at letterboxes.org (Albert Hopkins) Date: Wed, 19 Sep 2012 13:51:44 -0400 Subject: 'indent'ing Python in windows bat In-Reply-To: References: <5057C990.8080809@invtools.com> Message-ID: <1348077104.255761.4.camel@stretch.nbk> On Tue, 2012-09-18 at 22:12 -0600, Jason Friedman wrote: > > I'm converting windows bat files little by little to Python 3 as I find time > > and learn Python. > > The most efficient method for some lines is to call Python like: > > python -c "import sys; sys.exit(3)" > > > > How do I "indent" if I have something like: > > if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else > > sys.exit(3) > > Some months ago I posted what I think is a similar question in the > Unix world: I wanted to call a small portion of Python from within a > Bash script. > > Someone on this list answered (for Bash): > > #!/bin/bash > command1 > command2 > python -c "if True: > import module > if condition: > do_this > else: > do_that > " > command4 > # end code A better way (in *nix) would be, e.g.: #!/bin/sh read -p 'Enter a number ' count python << EOF print 'Odd numbers between 0 and ${count}' for i in range(${count}): if i % 2: print i EOF Horribly bad example, but you get the idea. From tyler at tysdomain.com Wed Sep 19 14:14:00 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Wed, 19 Sep 2012 12:14:00 -0600 Subject: using uwsgi to get flask going Message-ID: <505A0B68.3050606@tysdomain.com> Hello all: This is my first shot with UWSGI and Python on Nginx, and I'm getting kind of confused. My uwsgi init script looks like: #!/bin/sh #/etc/init.d/uwsgi ### BEGIN INIT INFO # Provides: uwsgi # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 ### END INIT INFO PID="/var/run/uwsgi/uwsgi.pid" SOCKET="/var/run/uwsgi/uwsgi.sock" DAEMON="/usr/local/bin/uwsgi" LOGFILE="/var/log/uwsgi.log" ARGS="--master --socket $SOCKET -d --workers 4 --pidfile $PID --vacuum --max-requests 400 --gid uwsgi --uid uwsgi --logto2 $LOGFILE --chdir2 /opt/nginx/html/falcon -w app:app" case "$1" in start) echo "Starting uwsgi" touch $SOCKET touch $LOGFILE chown uwsgi:uwsgi $LOGFILE chmod 660 $LOGFILE chown -R www-data:uwsgi $SOCKET chmod 660 $SOCKET start-stop-daemon -p $PID --start --exec $DAEMON -- $ARGS ;; stop) echo "Stopping uwsgi." start-stop-daemon --signal INT -p $PID --stop $DAEMON -- $ARGS ;; restart) echo "Stopping uwsgi." start-stop-daemon --signal INT -p $PID --stop $DAEMON -- $ARGS echo "Starting uwsgi" start-stop-daemon -p $PID --start --exec $DAEMON -- $ARGS ;; *) echo "Usage: /etc/init.d/uwsgi stop|stop|restart." exit 1 ;; esac I'm trying to chdir so I can use app:app (ap.py is the script, app is the application in app.py). From what I understand, uwsgi just spawns a Python process and runs app.py to handle requests? It doesn't spawn a process per instance? How easy would it be to force it to use PyPy for example? Also my nginx config: server { server_name www.dev.tds-solutions.net dev.tds-solutions.net; listen 80; access_log logs/dev.access.log; location / { root html/falcon; index index.html index.htm; try_files $uri @uwsgi; } location ~ /\.ht { deny all; } location @uwsgi { include /opt/nginx/conf/uwsgi_params; uwsgi_pass unix:/var/run/uwsgi/uwsgi.sock; } } anyone see anything wrong? Any info would be greatly appreciated. -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From tjreedy at udel.edu Wed Sep 19 14:18:26 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 19 Sep 2012 14:18:26 -0400 Subject: 'indent'ing Python in windows bat In-Reply-To: <5059BA28.2090803@invtools.com> References: <5057C990.8080809@invtools.com> <505803A9.4000409@davea.name> <5059BA28.2090803@invtools.com> Message-ID: On 9/19/2012 8:27 AM, David Smith wrote: > but not: > print('hi');if 1: print('hi') > > Chokes on the 'if'. On the surface, this is not consistent. Yes it is. ; can only be followed by simple statements. The keyword for compound statememts must be the first non-indent token on a line. That is why I suggested at the beginning of the thread to insert '\n', stating correctly that it works for exec(). >>> exec("print('hi');if 1: print('hi')") Traceback (most recent call last): File "", line 1, in exec("print('hi');if 1: print('hi')") File "", line 1 print('hi');if 1: print('hi') ^ SyntaxError: invalid syntax >>> exec("print('hi');\nif 1: print('hi')") hi hi >>> exec("print('hi')\nif 1: print('hi')") hi hi Someone raised the issue of whether the bat interpreter passes along the quoted string unchanged or if it interprets '\' or '\n' itself and in the latter case whether one to do anything so that python will see '\n' after any fiddling by the bat interpreter. It seems that \ is not interpreted within strngs by bat, but the problem is that the string is then seen by python as code, not as a string literal, and so python does not 'cook' it either. Running tem.bat from a command line (which echoes line from .bat), so I see the output, I get (Win7) C:\Programs\Python33>python -c "print(1)\nif 1: print(2)" File "", line 1 print(1)\nif 1: print(2) ^ SyntaxError: unexpected character after line continuation character One gets the same response interactively from >>> print('hi')\nif 1: print('hi') or >>> exec("print('hi')\\nif 1: print('hi')") The fix is to quote and pass the exact code that worked above in the python shell, keeping in mind that the outer quotes must be the double quote characters recognized by windows. C:\Programs\Python33>python -c "exec('print(1)\nif 1: print(2)')" 1 2 I did check that windows % interpolation of .bat args works within '' quoted strings. Change tem.bat to python -c "exec('print(%1)\nif 1: print(2)')" and calling 'tem 3' prints 3 2 That said, if you have many multiline statements, putting them in a separate file or files may be a good idea. -- Terry Jan Reedy From d at davea.name Wed Sep 19 14:22:39 2012 From: d at davea.name (Dave Angel) Date: Wed, 19 Sep 2012 14:22:39 -0400 Subject: using text file to get ip address from hostname In-Reply-To: <1ac7b836-abfb-401b-b6ac-3ae4ad6c1ce7@googlegroups.com> References: <3359a0e7-f7bb-4b1f-b586-e83f337566b7@googlegroups.com> <1ac7b836-abfb-401b-b6ac-3ae4ad6c1ce7@googlegroups.com> Message-ID: <505A0D6F.7060909@davea.name> On 09/19/2012 08:28 AM, Dan Katorza wrote: > ?????? ??? ?????, 19 ??????? 2012 12:11:04 UTC+3, ??? Dan Katorza: >> >> hi, ll like >> found a solution, >> it's not quite like Chris advised but it works. Not at all like Chris advised. But it also doesn't help you understand programming. Two concepts you're going to have to get a lot more comfortable with, in Python, or in some other language. One is loops, and the other is functions. >> #!/usr/bin/env python >> #Get the IP Address >> >> import sys, socket, os >> >> def restart_program(): >> python = sys.executable >> os.execl(python, python, * sys.argv) >> >> print ("\n\n#########################################################") >> print ("# Get IP from Host v 1.0 #") >> print ("#########################################################") >> print ("# Choose from the options below #") >> print ("# 1- url , 2-File(Text file only.txt) #") >> print ("#########################################################\n") >> >> mchoice = int(raw_input("Please enter your choice> ")) >> while mchoice !=1 and mchoice !=2: >> print("{0} is not a menu option.".format(mchoice)) >> mchoice = int(raw_input("Please try again> ")) >> >> >> while mchoice == 2: >> filename = raw_input("Please enter file name here> ") >> if filename.endswith(".txt"): >> >> try: >> infile = open(filename) >> except EnvironmentError as e: >> print(e) >> sys.exit(1) >> >> print("\nFile {0} exists!".format(filename)) >> print("\nGetting IP addresses for hosts") >> print("\n") >> else: >> print("{0} is not a Text file.".format(filename)) >> sys.exit(1) >> for line in infile: >> hostname = line.strip() >> try: >> ip_address = socket.gethostbyname(hostname) >> except EnvironmentError as e: >> print("Couldn't find IP address for {0}: {1}".format(hostname, e)) >> continue >> print("IP address for {0} is {1}.".format(hostname, ip_address)) >> else: >> print ("\nFinished the operation") >> print ("A=another search, M=main menu, E=exit") >> >> waction=raw_input("Please choose your action > ") >> >> while waction !='A' and waction !='M' and waction !='E': >> print("{0} is not a valid action.".format(waction)) >> waction=raw_input("Please try again> ") >> if waction =='E': >> sys.exit(1) >> if waction =='A': >> continue >> if waction =='M': >> print ("#########################################################") >> print ("# Choose from the options below #") >> print ("# 1- url , 2-File(Text file only.txt) #") >> print ("#########################################################\n") >> >> mchoice = int(raw_input("Please enter your choice> ")) >> while mchoice !=1 and mchoice !=2: >> print("{0} is not a menu option.".format(mchoice)) >> mchoice = int(raw_input("Please try again> ")) >> >> >> while mchoice == 1: >> murl = raw_input("Enter URL here> ") >> try: >> print("Checking URL...") >> ip_address = socket.gethostbyname(murl) >> except EnvironmentError as d: >> print(d) >> sys.exit(1) >> print("Valid URL") >> print("\nIP address for {0} is {1}.".format(murl, ip_address)) >> print ("\nFinished the operation") >> print ("A=another search, M=main menu, E=exit") >> >> waction=raw_input("Please choose your action > ") >> >> while waction !='A' and waction !='M' and waction !='E': >> print("{0} is not a valid action.".format(waction)) >> waction=raw_input("Please try again> ") >> if waction =='E': >> sys.exit(1) >> if waction =='A': >> continue >> if waction =='M': >> restart_program() >> >> >> >> This is one enormous top-level code, and when you needed to enclose it in a loop, your answer is to start a new process! You also duplicate quite a few lines, rather than making a function for them, and calling it from two places. -- DaveA From hansmu at xs4all.nl Wed Sep 19 14:23:07 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 19 Sep 2012 20:23:07 +0200 Subject: 'indent'ing Python in windows bat In-Reply-To: References: <5057C990.8080809@invtools.com> Message-ID: <505a0d8c$0$6852$e4fe514c@news2.news.xs4all.nl> On 19/09/12 19:51:44, Albert Hopkins wrote: > On Tue, 2012-09-18 at 22:12 -0600, Jason Friedman wrote: >>> I'm converting windows bat files little by little to Python 3 as I find time >>> and learn Python. >>> The most efficient method for some lines is to call Python like: >>> python -c "import sys; sys.exit(3)" >>> >>> How do I "indent" if I have something like: >>> if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else >>> sys.exit(3) >> >> Some months ago I posted what I think is a similar question in the >> Unix world: I wanted to call a small portion of Python from within a >> Bash script. >> >> Someone on this list answered (for Bash): >> >> #!/bin/bash >> command1 >> command2 >> python -c "if True: >> import module >> if condition: >> do_this >> else: >> do_that >> " >> command4 >> # end code > > A better way (in *nix) would be, e.g.: > > #!/bin/sh > > read -p 'Enter a number ' count > > python << EOF > print 'Odd numbers between 0 and ${count}' > for i in range(${count}): > if i % 2: > print i > EOF > > Horribly bad example, but you get the idea. If you do it like that, you have to remember to not use certain punctuation characters in your Python code, because they are meaningful to the shell, even inside a < References: Message-ID: On Wed, Sep 19, 2012 at 9:37 AM, Steve Howell wrote: > Sequences are iterables, so I'd say the docs are technically correct, > but maybe I'm misunderstanding what you would be trying to clarify. The doc string suggests that the argument to sum() must be a sequence, when in fact any iterable will do. The restriction in the docs should be relaxed to match the reality. From showell30 at yahoo.com Wed Sep 19 14:43:30 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 19 Sep 2012 11:43:30 -0700 (PDT) Subject: sum works in sequences (Python 3) References: Message-ID: <22cf6162-f969-46db-832a-b472489245a6@m3g2000vby.googlegroups.com> On Sep 19, 11:34?am, Ian Kelly wrote: > On Wed, Sep 19, 2012 at 9:37 AM, Steve Howell wrote: > > Sequences are iterables, so I'd say the docs are technically correct, > > but maybe I'm misunderstanding what you would be trying to clarify. > > The doc string suggests that the argument to sum() must be a sequence, > when in fact any iterable will do. ?The restriction in the docs should > be relaxed to match the reality. Ah. The docstring looks to be fixed in 3.1.3, but not in Python 2. Python 3.1.3 (r313:86834, Mar 13 2011, 00:40:38) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> sum.__doc__ "sum(iterable[, start]) -> value\n\nReturns the sum of an iterable of numbers (NOT strings) plus the value\nof parameter 'start' (which defaults to 0). When the iterable is\nempty, returns start." Python 2.6.6 (r266:84292, Mar 13 2011, 00:35:19) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> sum.__doc__ "sum(sequence[, start]) -> value\n\nReturns the sum of a sequence of numbers (NOT strings) plus the value\nof parameter 'start' (which defaults to 0). When the sequence is\nempty, returns start." >>> From tjreedy at udel.edu Wed Sep 19 14:49:45 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 19 Sep 2012 14:49:45 -0400 Subject: sum works in sequences (Python 3) In-Reply-To: References: Message-ID: On 9/19/2012 11:07 AM, Alister wrote: > Summation is a mathematical function that works on numbers > Concatenation is the process of appending 1 string to another > > although they are not related to each other they do share the same > operator(+) which is the cause of confusion. If one represents counts in unary, as a sequence or tally of 1s (or other markers indicating 'successor' or 'increment'), then count addition is sequence concatenation. I think Guido got it right. It happens that when the members of all sequences are identical, there is a much more compact exponential place value notation that enables more efficient addition and other operations. When not, other tricks are needed to avoid so much copying that an inherently O(N) operation balloons into an O(N*N) operation. -- Terry Jan Reedy From ashish.makani at gmail.com Wed Sep 19 15:12:37 2012 From: ashish.makani at gmail.com (ashish) Date: Wed, 19 Sep 2012 12:12:37 -0700 (PDT) Subject: How to send email programmatically from a gmail email a/c when port 587(smtp) is blocked In-Reply-To: References: <0f6686fd-7363-43d6-a5fa-0bd4f12586b5@googlegroups.com> Message-ID: <30853fb3-ef5a-4304-9123-15c84a2f9c89@googlegroups.com> Folks, I asked the same query on the python tutor mailing list. The responses i received are here : http://thread.gmane.org/gmane.comp.python.tutor/77601 Mark, There is nothing wrong in asking a query on multiple forums. Poeple on the tutor list, may not be part of comp.lang.python & subscribers to comp.lang.python On Wednesday, September 12, 2012 4:18:05 AM UTC+5:30, Mark Lawrence wrote: > On 11/09/2012 22:51, ashish makani wrote: > > > Hi c.l.p peeps > > > > > > I am stuck with an issue, so am coming to the Pythonista deltaforce who rescue me everytime :) > > > > > > > [big snip] > > > > I say old chap, it's simply not cricket to ask a question like this some > > 32 minutes after asking the same question on the tutor mailing list. > > > > -- > > Cheers. > > > > Mark Lawrence. From ashish.makani at gmail.com Wed Sep 19 15:12:37 2012 From: ashish.makani at gmail.com (ashish) Date: Wed, 19 Sep 2012 12:12:37 -0700 (PDT) Subject: How to send email programmatically from a gmail email a/c when port 587(smtp) is blocked In-Reply-To: References: <0f6686fd-7363-43d6-a5fa-0bd4f12586b5@googlegroups.com> Message-ID: <30853fb3-ef5a-4304-9123-15c84a2f9c89@googlegroups.com> Folks, I asked the same query on the python tutor mailing list. The responses i received are here : http://thread.gmane.org/gmane.comp.python.tutor/77601 Mark, There is nothing wrong in asking a query on multiple forums. Poeple on the tutor list, may not be part of comp.lang.python & subscribers to comp.lang.python On Wednesday, September 12, 2012 4:18:05 AM UTC+5:30, Mark Lawrence wrote: > On 11/09/2012 22:51, ashish makani wrote: > > > Hi c.l.p peeps > > > > > > I am stuck with an issue, so am coming to the Pythonista deltaforce who rescue me everytime :) > > > > > > > [big snip] > > > > I say old chap, it's simply not cricket to ask a question like this some > > 32 minutes after asking the same question on the tutor mailing list. > > > > -- > > Cheers. > > > > Mark Lawrence. From dihedral88888 at googlemail.com Wed Sep 19 15:43:57 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 19 Sep 2012 12:43:57 -0700 (PDT) Subject: Python presentations In-Reply-To: References: <20120919022003.GB61866@snakebite.org> Message-ID: <2ea7c371-ae27-4d6c-9828-c97a86cec349@googlegroups.com> andrea crotti? 2012?9?20????UTC+8??12?42?50???? > 2012/9/19 Trent Nelson : > > > > > > FWIW, I gave a presentation on decorators to the New York Python > > > User Group back in 2008. Relevant blog post: > > > > > > http://blogs.onresolve.com/?p=48 > > > > > > There's a link to the PowerPoint presentation I used in the first > > > paragraph. It's in .pptx format; let me know if you'd like it in > > > some other form. > > > > > > Regards, > > > > > > Trent. > > > > > > Ok thanks a lot, how long did it take for you to present that material? > > > > Interesting the part about the learning process, I had a similar > > experience, but probably skip this since I only have 30 minutes. > > > > Another thing which I would skip or only explain how it works are > > parametrized decorators, in the triple-def form they just look to ugly > > to be worth the effort (but at least should be understood). I think the decorator part is reasonable in testing and prototyping. Every layor of some decorator just adds more overheads, therefore, the syntax sugar of the symbol @ just reminds the programmer the fact. Acctually writing better wrappers for non-trivial enhancements to objects or functions should be practiced by professionals. It is easy to import objects written by others in python. It is also user responsible to test and enhance the objects from others by decorators, the unittest module, or whatever suitable. I love to play with functions with a varable representing the time in writing computer games that emulate hundreds to thousands of animated obects. From dihedral88888 at googlemail.com Wed Sep 19 15:43:57 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 19 Sep 2012 12:43:57 -0700 (PDT) Subject: Python presentations In-Reply-To: References: <20120919022003.GB61866@snakebite.org> Message-ID: <2ea7c371-ae27-4d6c-9828-c97a86cec349@googlegroups.com> andrea crotti? 2012?9?20????UTC+8??12?42?50???? > 2012/9/19 Trent Nelson : > > > > > > FWIW, I gave a presentation on decorators to the New York Python > > > User Group back in 2008. Relevant blog post: > > > > > > http://blogs.onresolve.com/?p=48 > > > > > > There's a link to the PowerPoint presentation I used in the first > > > paragraph. It's in .pptx format; let me know if you'd like it in > > > some other form. > > > > > > Regards, > > > > > > Trent. > > > > > > Ok thanks a lot, how long did it take for you to present that material? > > > > Interesting the part about the learning process, I had a similar > > experience, but probably skip this since I only have 30 minutes. > > > > Another thing which I would skip or only explain how it works are > > parametrized decorators, in the triple-def form they just look to ugly > > to be worth the effort (but at least should be understood). I think the decorator part is reasonable in testing and prototyping. Every layor of some decorator just adds more overheads, therefore, the syntax sugar of the symbol @ just reminds the programmer the fact. Acctually writing better wrappers for non-trivial enhancements to objects or functions should be practiced by professionals. It is easy to import objects written by others in python. It is also user responsible to test and enhance the objects from others by decorators, the unittest module, or whatever suitable. I love to play with functions with a varable representing the time in writing computer games that emulate hundreds to thousands of animated obects. From ashish.makani at gmail.com Wed Sep 19 15:46:33 2012 From: ashish.makani at gmail.com (ashish) Date: Wed, 19 Sep 2012 12:46:33 -0700 (PDT) Subject: Passing arguments to & executing, a python script on a remote machine from a python script on local machine Message-ID: <5a8a09f8-db4c-4f1d-ae8e-a5c848903c68@googlegroups.com> Hi PyTutor Folks Here is my situation 1. I have two machines. Lets call them local & remote. Both run ubuntu & both have python installed 2. I have a python script, local.py, running on local which needs to pass arguments ( 3/4 string arguments, containing whitespaces like spaces, etc ) to a python script, remote.py running on remote (the remote machine). I have the following questions: 1. What's the best way to accomplish my task ? I have researched quite a bit & so far found really conflicting & complex workarounds. I googled & found people using several libraries to accomplish ssh to remote machine & execute a command on remote machine. paramiko ( now forked into the ssh moduke), fabric, pushy ,etc People who have used any of these libraries, which one would you recommend, as the most apt (simple & easy to use, lightweight, best performance, etc) for my situation ? 2. I would prefer a solution, which does NOT require the installation of extra libraries on the local & remote machines. If installing external librar 3. Has anybody been able to do this using os.system ? I tried this >>> import os >>> os.system ("ssh remoteuser at remote python remote.py arg1 arg2 arg3") This worked, but if the arguments i tried to pass, had spaces, i was not able to 'escape' the spaces. Any & all explanations/links/code snippets/thoughts/ideas/suggestions/feedback/comments/ of the Python tutor community would be greatly appreciated. Thanks a ton cheers ashish email : ashish.makani domain:gmail.com ?The only way to do great work is to love what you do. If you haven?t found it yet, keep looking. Don?t settle. As with all matters of the heart, you?ll know when you find it.? - Steve Jobs (1955 - 2011) From ashish.makani at gmail.com Wed Sep 19 15:50:56 2012 From: ashish.makani at gmail.com (ashish) Date: Wed, 19 Sep 2012 12:50:56 -0700 (PDT) Subject: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?) Message-ID: <10db83e4-80eb-4265-b11c-062269fea1b0@googlegroups.com> Hi c.l.p folks Here is my situation 1. I have two machines. Lets call them 'local' & 'remote'. Both run ubuntu & both have python installed 2. I have a python script, local.py, running on 'local' which needs to pass arguments ( 3/4 string arguments, containing whitespaces like spaces, etc ) to a python script, remote.py running on 'remote' (the remote machine). I have the following questions: 1. What's the best way to accomplish my task ? I have researched quite a bit & pretty much everybody is using ssh. After googling a bunch, most people are using very complex workarounds to do this sort of thing. I googled & found people using several libraries to accomplish ssh to remote machine & execute a command on remote machine. paramiko ( now forked into the ssh moduke), fabric, pushy ,etc People who have used any of these libraries, which one would you recommend, as the most apt (simple & easy to use, lightweight, best performance, etc) for my situation ? 2. I would prefer a solution, which does NOT require the installation of extra libraries on the local & remote machines. If installing external librar 3. Has anybody been able to do this using os.system ? I tried this >>> import os >>> os.system ("ssh remoteuser at remote python remote.py arg1 arg2 arg3") This worked, but if the arguments i tried to pass, had spaces, i was not able to 'escape' the spaces. Any & all explanations/links/code snippets/thoughts/ideas/suggestions/feedback/comments/ of the Python tutor community would be greatly appreciated. Thanks a ton cheers ashish email : ashish.makani domain:gmail.com ?The only way to do great work is to love what you do. If you haven?t found it yet, keep looking. Don?t settle. As with all matters of the heart, you?ll know when you find it.? - Steve Jobs (1955 - 2011) From davids at invtools.com Wed Sep 19 16:09:50 2012 From: davids at invtools.com (David Smith) Date: Wed, 19 Sep 2012 16:09:50 -0400 Subject: 'indent'ing Python in windows bat In-Reply-To: References: <5057C990.8080809@invtools.com> <505803A9.4000409@davea.name> <5059BA28.2090803@invtools.com> Message-ID: <505A268E.2030502@invtools.com> On 2012-09-19 14:18, Terry Reedy wrote: > stating correctly that it works for exec(). My mistake. I fancied you were talking shell, not python. I now see that Python 3 has exec() as a built-in. python -c "exec('print(\"hi\")\nif 0:\n print(\"hi\")\nelif 1:\n print(\"hi2\")')" worked right off the *.bat. Shades of sed! Note I used a one space indentation. A tab works fine, too. > python -c "exec('print(%1)\nif 1: print(2)')" > and calling 'tem 3' prints > 3 > 2 Thanks for the exhaustive study. :-) I'll keep it in mind. I hope I don't have to do this, though. > That said, if you have many multiline statements, putting them in a > separate file or files may be a good idea. ASAP I'm hoping to have each bat swallowed completely by python. My current "bathon" or "pytch" file closes an old session then opens the session I select just like the bat mom used to bake. Thank you again, Terry, and thanks to all -- even the *nix'ers. Might come in handy if I get back into that again. From sulfurfff at gmail.com Wed Sep 19 16:29:15 2012 From: sulfurfff at gmail.com (=?UTF-8?Q?Ismael_Farf=C3=A1n?=) Date: Wed, 19 Sep 2012 15:29:15 -0500 Subject: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?) In-Reply-To: <10db83e4-80eb-4265-b11c-062269fea1b0@googlegroups.com> References: <10db83e4-80eb-4265-b11c-062269fea1b0@googlegroups.com> Message-ID: 2012/9/19 ashish : > Hi c.l.p folks > > Here is my situation > > 1. I have two machines. Lets call them 'local' & 'remote'. > Both run ubuntu & both have python installed > > 2. I have a python script, local.py, running on 'local' which needs to pass arguments ( 3/4 string arguments, containing whitespaces like spaces, etc ) to a python script, remote.py running on 'remote' (the remote machine). > > I have the following questions: > > 1. What's the best way to accomplish my task ? > I have researched quite a bit & pretty much everybody is using ssh. > After googling a bunch, most people are using very complex workarounds to do this sort of thing. > > I googled & found people using several libraries to accomplish ssh to remote machine & execute a command on remote machine. > paramiko ( now forked into the ssh moduke), fabric, pushy ,etc > > People who have used any of these libraries, which one would you recommend, as the most apt (simple & easy to use, lightweight, best performance, etc) for my situation ? > > 2. I would prefer a solution, which does NOT require the installation of extra libraries on the local & remote machines. > If installing external librar > > 3. Has anybody been able to do this using os.system ? > > I tried this >>>> import os >>>> os.system ("ssh remoteuser at remote python remote.py arg1 arg2 arg3") > > This worked, but if the arguments i tried to pass, had spaces, i was not able to 'escape' the spaces. How about something like this: os.system ( 'ssh remoteuser at remote python remote.py "arg 1" "arg 2" "arg 3"' ) Cheers Ismael > > Any & all explanations/links/code snippets/thoughts/ideas/suggestions/feedback/comments/ of the Python tutor community would be greatly appreciated. > > Thanks a ton > > cheers > ashish > > email : > ashish.makani > domain:gmail.com > > ?The only way to do great work is to love what you do. If you haven?t found it yet, keep looking. Don?t settle. As with all matters of the heart, you?ll know when you find it.? - Steve Jobs (1955 - 2011) > -- > http://mail.python.org/mailman/listinfo/python-list -- Do not let me induce you to satisfy my curiosity, from an expectation, that I shall gratify yours. What I may judge proper to conceal, does not concern myself alone. From sulfurfff at gmail.com Wed Sep 19 16:36:02 2012 From: sulfurfff at gmail.com (=?UTF-8?Q?Ismael_Farf=C3=A1n?=) Date: Wed, 19 Sep 2012 15:36:02 -0500 Subject: How to get the list of all my open file(descriptor)s and locks? In-Reply-To: References: Message-ID: 2012/9/19 Ismael Farf?n : > Hello list > > From man 2 EXECVE > "By default, file descriptors remain open across an execve()" > > And from man 2 FCNTL > "Record locks are... preserved across an execve(2)." > > So the question: > * If I execve a python script (from C), how can I retrieve the list of > files, and optionally the list of locks, from within the execve(d) > python process so that I can use them? > > > Some more info: > I'm working with exotic stuff like AIX and Solaris 10 (Windows and > linux too :) and my lowest common denominator is python 2.3. > > From a standalone test within the interpreter I'd expect to get (at > least) std(in/out/err). > > If more information is needed in order to help me, please let me know. > > Cheers > Ismael > > > -- > Do not let me induce you to satisfy my curiosity, from an expectation, > that I shall gratify yours. What I may judge proper to conceal, does > not concern myself alone. It seems like I can use os.fstat to find out if a fd exists and also get it's type and mode (I'm getting some pipes too : ) I hope it's portable across platforms, if someone knows a better solution please let me know. Ismael -- Do not let me induce you to satisfy my curiosity, from an expectation, that I shall gratify yours. What I may judge proper to conceal, does not concern myself alone. From ian.g.kelly at gmail.com Wed Sep 19 17:09:47 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 19 Sep 2012 15:09:47 -0600 Subject: How to get the list of all my open file(descriptor)s and locks? In-Reply-To: References: Message-ID: On Wed, Sep 19, 2012 at 11:34 AM, Ismael Farf?n wrote: > So the question: > * If I execve a python script (from C), how can I retrieve the list of > files, and optionally the list of locks, from within the execve(d) > python process so that I can use them? > > > Some more info: > I'm working with exotic stuff like AIX and Solaris 10 (Windows and > linux too :) and my lowest common denominator is python 2.3. You could do: os.listdir("/proc/%d/fd" % os.getpid()) This should work on Linux, AIX, and Solaris, but obviously not on Windows. From ian.g.kelly at gmail.com Wed Sep 19 17:40:11 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 19 Sep 2012 15:40:11 -0600 Subject: How to get the list of all my open file(descriptor)s and locks? In-Reply-To: References: Message-ID: On Wed, Sep 19, 2012 at 2:36 PM, Ismael Farf?n wrote: > It seems like I can use os.fstat to find out if a fd exists and also > get it's type and mode (I'm getting some pipes too : ) Sure, because files and pipes both use the file descriptor abstraction. If your process does any networking, you'll find sockets in there as well. From sulfurfff at gmail.com Wed Sep 19 17:58:56 2012 From: sulfurfff at gmail.com (=?UTF-8?Q?Ismael_Farf=C3=A1n?=) Date: Wed, 19 Sep 2012 16:58:56 -0500 Subject: How to get the list of all my open file(descriptor)s and locks? In-Reply-To: References: Message-ID: 2012/9/19 Ian Kelly : > On Wed, Sep 19, 2012 at 2:36 PM, Ismael Farf?n wrote: >> It seems like I can use os.fstat to find out if a fd exists and also >> get it's type and mode (I'm getting some pipes too : ) > > Sure, because files and pipes both use the file descriptor > abstraction. If your process does any networking, you'll find sockets > in there as well. > -- > http://mail.python.org/mailman/listinfo/python-list Seems like things will get interesting :D Ismael -- Do not let me induce you to satisfy my curiosity, from an expectation, that I shall gratify yours. What I may judge proper to conceal, does not concern myself alone. From hansmu at xs4all.nl Wed Sep 19 18:25:40 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Thu, 20 Sep 2012 00:25:40 +0200 Subject: sum works in sequences (Python 3) In-Reply-To: References: Message-ID: <505a4664$0$6961$e4fe514c@news2.news.xs4all.nl> On 19/09/12 17:07:04, Alister wrote: > On Wed, 19 Sep 2012 16:41:20 +0200, Franck Ditter wrote: > >> Hello, >> I wonder why sum does not work on the string sequence in Python 3 : >> >>>>> sum((8,5,9,3)) >> 25 >>>>> sum([5,8,3,9,2]) >> 27 >>>>> sum('rtarze') >> TypeError: unsupported operand type(s) for +: 'int' and 'str' >> >> I naively thought that sum('abc') would expand to 'a'+'b'+'c' >> And the error message is somewhat cryptic... >> >> franck > > Summation is a mathematical function that works on numbers > Concatenation is the process of appending 1 string to another Actually, the 'sum' builtin function is quite capable of concatenatig objects, for example lists: >>> sum(([2,3], [5,8], [13,21]), []) [2, 3, 5, 8, 13, 21] But if you pass a string as a starting value, you get an error: >>> sum([], '') Traceback (most recent call last): File "", line 1, in TypeError: sum() can't sum strings [use ''.join(seq) instead] In fact, you can bamboozle 'sum' into concatenating string by by tricking it with a non-string starting value: >>> class not_a_string(object): ... def __add__(self, other): ... return other ... >>> sum("rtarze", not_a_string()) 'rtarze' >>> sum(["Monty ", "Python", "'s Fly", "ing Ci", "rcus"], ... not_a_string()) "Monty Python's Flying Circus" >>> Hope this helps, -- HansM From oscar.j.benjamin at gmail.com Wed Sep 19 19:04:26 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 19 Sep 2012 23:04:26 +0000 (UTC) Subject: Using dict as object References: <345da32c-a22b-4025-bb50-794d684885b1@googlegroups.com> <5059B062.8020108@davea.name> Message-ID: On 2012-09-19, Pierre Tardy wrote: > --===============1362296571== > Content-Type: multipart/alternative; boundary=bcaec554d3229e814204ca105e50 > > --bcaec554d3229e814204ca105e50 > Content-Type: text/plain; charset=ISO-8859-1 > >> >> This has been proposed and discussed and even implemented many >> times on this list and others. >> > I can find this question on SO > http://stackoverflow.com/questions/4984647/accessing-dict-keys-like-an-attribute-in-python > which is basically answered with this solution > > class AttributeDict(dict): > __getattr__ = dict.__getitem__ > __setattr__ = dict.__setitem__ > > > but this does not allow recursive access, you would need to first convert > all nested dictionaries to AttributeDict. > a.b.c.d = 2 # fail > a.b = dict(c=3) > a.b.c=4 # fail There is no way to control "recursive access" in Python. The statement a.b.c = 2 is equivalent to the statements o = a.b # o = a.__getattr__('b') o.c = 2 # o.__setattr__('c', 2) The way that the o.c assignment is handled is determined by the type of o regardless of the type of a. If you're looking for a way to change only the type of a and make a custom __(set|get)attr__ work for all dicts that are indirectly referred to then there is no solution to your problem. Oscar From christian at python.org Wed Sep 19 20:39:42 2012 From: christian at python.org (Christian Heimes) Date: Thu, 20 Sep 2012 02:39:42 +0200 Subject: How to get the list of all my open file(descriptor)s and locks? In-Reply-To: References: Message-ID: Am 19.09.2012 19:34, schrieb Ismael Farf?n: > Hello list > > From man 2 EXECVE > "By default, file descriptors remain open across an execve()" > > And from man 2 FCNTL > "Record locks are... preserved across an execve(2)." > > So the question: > * If I execve a python script (from C), how can I retrieve the list of > files, and optionally the list of locks, from within the execve(d) > python process so that I can use them? Have a look at psutil: http://code.google.com/p/psutil/#Process_management Christian From jdildy85 at gmail.com Wed Sep 19 21:32:40 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Wed, 19 Sep 2012 18:32:40 -0700 (PDT) Subject: Installing Pip onto a mac os x system Message-ID: <08f09236-a4d4-4b92-b212-f152be0d9449@googlegroups.com> Does anyone know how to install Pip onto a mac os x ver 10.7.4? Ive tried easy_instal pip but it brings up this message (but it doesn't help with my problem): error: can't create or remove files in install directory The following error occurred while trying to add or remove files in the installation directory: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-1820.write-test' The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was: /Library/Python/2.7/site-packages/ Perhaps your account does not have write access to this directory? If the installation directory is a system-owned directory, you may need to sign in as the administrator or "root" account. If you do not have administrative access to this machine, you may wish to choose a different installation directory, preferably one that is listed in your PYTHONPATH environment variable. For information on other options, you may wish to consult the documentation at: http://peak.telecommunity.com/EasyInstall.html Please make the appropriate changes for your system and try again. Thing is I am the Administrator of the computer and can use all of the folders on the mac computer. Thank you in advance if you guys can help me with the problem, John Dildy From benjamin.kaplan at case.edu Wed Sep 19 21:46:31 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 19 Sep 2012 18:46:31 -0700 Subject: Installing Pip onto a mac os x system In-Reply-To: <08f09236-a4d4-4b92-b212-f152be0d9449@googlegroups.com> References: <08f09236-a4d4-4b92-b212-f152be0d9449@googlegroups.com> Message-ID: On Sep 19, 2012 6:37 PM, "John Mordecai Dildy" wrote: > > Does anyone know how to install Pip onto a mac os x ver 10.7.4? > > Ive tried easy_instal pip but it brings up this message (but it doesn't help with my problem): > > error: can't create or remove files in install directory > > The following error occurred while trying to add or remove files in the > installation directory: > > [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-1820.write-test' > > The installation directory you specified (via --install-dir, --prefix, or > the distutils default setting) was: > > /Library/Python/2.7/site-packages/ > > Perhaps your account does not have write access to this directory? If the > installation directory is a system-owned directory, you may need to sign in > as the administrator or "root" account. If you do not have administrative > access to this machine, you may wish to choose a different installation > directory, preferably one that is listed in your PYTHONPATH environment > variable. > > For information on other options, you may wish to consult the > documentation at: > > http://peak.telecommunity.com/EasyInstall.html > > Please make the appropriate changes for your system and try again. > > Thing is I am the Administrator of the computer and can use all of the folders on the mac computer. > No you can't. You can ask permission to use skill the folders (and then grant yourself that permission), but the user that you're currently running as does not have full access to the computer. You know how every time you install a program, a prompt comes up asking for your password? That's you giving the process permission to run as "root", the only account with full access to everything. On the command line, you run things as root by using the "sudo" command (being an administrator means your account is able to run that) sudo easy_install pip should work -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Sep 19 23:11:11 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 20 Sep 2012 13:11:11 +1000 Subject: How to get the list of all my open file(descriptor)s and locks? In-Reply-To: References: Message-ID: On Thu, Sep 20, 2012 at 7:09 AM, Ian Kelly wrote: > You could do: > > os.listdir("/proc/%d/fd" % os.getpid()) > > This should work on Linux, AIX, and Solaris, but obviously not on Windows. I'm not sure how cross-platform it is, but at least on Linux, you can use /proc/self as an alias for "/proc/"+os.getpid() - worth a try, might make your code a bit easier to read. It's documented as useful when you don't know the PID yet (eg telling a process to read the file /proc/self/fd/0 to force it to use stdin). So I'm confident enough to recommend testing it. :) ChrisA From jason at powerpull.net Wed Sep 19 23:41:29 2012 From: jason at powerpull.net (Jason Friedman) Date: Wed, 19 Sep 2012 21:41:29 -0600 Subject: Programming Issues In-Reply-To: References: Message-ID: > Ask the user for the amount of change expressed in cents. Your program must > compute and display the number of half-dollars, quarters, dimes, nickels, > and pennies to be returned. > Return as many half-dollars as possible, then quarters, dimes, nickels, and > pennies, in that order. > Your program must allow the user to continue entering different amounts of > change until they enter 0 to indicate they are finished. If the user enters > a negative number, inform them of their mistake and ask them to enter a > correct value. Perhaps you can start with pseudo-code (http://en.wikipedia.org/wiki/Pseudo_code) and ask for help writing that in Python. I'll get you started. Ask for a number. If number = 0, stop. If number < 0, ask again. With values 50, 25, 10, 5 and 1: if number > value: coincount = integer portion of number divided by value print coincount, value remaining number = ... I've broken the pseudo-code into two parts because they are, in some sense, different programs. You might try to write one, then the other. In other words, starting by writing this in Python: Ask for a number. If number = 0, stop. If number < 0, ask again. If number > 0, print number and quit. From timr at probo.com Wed Sep 19 23:51:07 2012 From: timr at probo.com (Tim Roberts) Date: Wed, 19 Sep 2012 20:51:07 -0700 Subject: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?) References: <10db83e4-80eb-4265-b11c-062269fea1b0@googlegroups.com> Message-ID: <6j4l58dci13pe3jkc96l33atd0tppo6pg2@4ax.com> ashish wrote: > >Here is my situation > >1. I have two machines. Lets call them 'local' & 'remote'. >Both run ubuntu & both have python installed > >2. I have a python script, local.py, running on 'local' which needs to pass >arguments ( 3/4 string arguments, containing whitespaces like spaces, etc ) >to a python script, remote.py running on 'remote' (the remote machine). You haven't provided very many details, so it's possible ssh is the low-impact solution, but don't discard the possibility of using a TCP socket for this. It's easy in Python. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From sulfurfff at gmail.com Thu Sep 20 00:21:25 2012 From: sulfurfff at gmail.com (=?UTF-8?Q?Ismael_Farf=C3=A1n?=) Date: Wed, 19 Sep 2012 23:21:25 -0500 Subject: How to get the list of all my open file(descriptor)s and locks? In-Reply-To: References: Message-ID: 2012/9/19 Christian Heimes : >> So the question: >> * If I execve a python script (from C), how can I retrieve the list of >> files, and optionally the list of locks, from within the execve(d) >> python process so that I can use them? > > Have a look at psutil: > > http://code.google.com/p/psutil/#Process_management > > Christian > > -- > http://mail.python.org/mailman/listinfo/python-list Unfortunately I'm not allowed to install 3rd party SW unless it's absolutely necessary, but thanks for sharing, I'll have a look at the arch dependent code : ) Ismael -- Do not let me induce you to satisfy my curiosity, from an expectation, that I shall gratify yours. What I may judge proper to conceal, does not concern myself alone. From steve+comp.lang.python at pearwood.info Thu Sep 20 00:27:14 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Sep 2012 04:27:14 GMT Subject: Passing arguments to & executing, a python script on a remote machine from a python script on local machine References: <5a8a09f8-db4c-4f1d-ae8e-a5c848903c68@googlegroups.com> Message-ID: <505a9b22$0$29890$c3e8da3$5496439d@news.astraweb.com> On Wed, 19 Sep 2012 12:46:33 -0700, ashish wrote: > Hi PyTutor Folks > > Here is my situation > > 1. I have two machines. Lets call them local & remote. Both run ubuntu & > both have python installed > > 2. I have a python script, local.py, running on local which needs to > pass arguments ( 3/4 string arguments, containing whitespaces like > spaces, etc ) to a python script, remote.py running on remote (the > remote machine). If 3/4 of the arguments are strings, what sort of objects are the other 1/4? > I have the following questions: > > 1. What's the best way to accomplish my task ? Use a dedicated remote procedure call library. Do not try to invent your own. The wheel has already been invented, you are just wasting your time. I've used both Pyro and Rpyc, either of them seem perfectly reasonable. There are many others, but frankly I don't think there is a "best of breed" that stands far ahead of the rest. -- Steven From rosuav at gmail.com Thu Sep 20 01:09:18 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 20 Sep 2012 15:09:18 +1000 Subject: Passing arguments to & executing, a python script on a remote machine from a python script on local machine In-Reply-To: <505a9b22$0$29890$c3e8da3$5496439d@news.astraweb.com> References: <5a8a09f8-db4c-4f1d-ae8e-a5c848903c68@googlegroups.com> <505a9b22$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 20, 2012 at 2:27 PM, Steven D'Aprano wrote: > On Wed, 19 Sep 2012 12:46:33 -0700, ashish wrote: > >> 2. I have a python script, local.py, running on local which needs to >> pass arguments ( 3/4 string arguments, containing whitespaces like >> spaces, etc ) to a python script, remote.py running on remote (the >> remote machine). > > If 3/4 of the arguments are strings, what sort of objects are the other > 1/4? I understand the OP as meaning "three or four string arguments". ChrisA From dkatorza at gmail.com Thu Sep 20 01:13:29 2012 From: dkatorza at gmail.com (Dan Katorza) Date: Wed, 19 Sep 2012 22:13:29 -0700 (PDT) Subject: using text file to get ip address from hostname In-Reply-To: References: <3359a0e7-f7bb-4b1f-b586-e83f337566b7@googlegroups.com> Message-ID: <2c5997bd-e458-4e83-af44-fcbfe3d95a8b@googlegroups.com> ?????? ??? ?????, 19 ??????? 2012 15:28:23 UTC+3, ??? Dan Katorza: > ?????? ??? ?????, 19 ??????? 2012 12:11:04 UTC+3, ??? Dan Katorza: > > > ?????? ??? ?????, 19 ??????? 2012 11:50:56 UTC+3, ??? Dan Katorza: > > > > > > > ?????? ??? ?????, 19 ??????? 2012 11:14:29 UTC+3, ??? Chris Angelico: > > > > > > > > > > > > > > > On Wed, Sep 19, 2012 at 5:41 PM, Dan Katorza wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Hello again, > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > I have another question and i hope you will understand me.. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Is there any option where you can set the program to go back to lets say the top of the code? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > I mean if the program finished the operation and i want to stay in the program and go back ro the start. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > after any operation i want the option to do it again , go back to the main menu or full exit from the program, and i want it every time. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > i hope i'm clear :) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Yep! Look up the docs and tutorial on "control flow" and "looping > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > constructs". Sounds like what you want here is a 'while' loop. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ChrisA > > > > > > > > > > > > > > > > > > > > > > > > > > > > Hi Chris, > > > > > > > > > > > > > > this is my code: > > > > > > > > > > > > > > > > > > > > > > > > > > > > #!/usr/bin/env python > > > > > > > > > > > > > > #Get the IP Address > > > > > > > > > > > > > > > > > > > > > > > > > > > > import sys, socket > > > > > > > > > > > > > > > > > > > > > > > > > > > > print ("\n\n#########################################################") > > > > > > > > > > > > > > print ("# Get IP from Host v 1.0 #") > > > > > > > > > > > > > > print ("#########################################################") > > > > > > > > > > > > > > print ("# Choose from the options below #") > > > > > > > > > > > > > > print ("# 1- url , 2-File(Text file only.txt) #") > > > > > > > > > > > > > > print ("#########################################################\n") > > > > > > > > > > > > > > > > > > > > > > > > > > > > mchoice = int(raw_input("Please enter your choice> ")) > > > > > > > > > > > > > > while mchoice !=1 and mchoice !=2: > > > > > > > > > > > > > > print("{0} is not a menu option.".format(mchoice)) > > > > > > > > > > > > > > mchoice = int(raw_input("Please try again> ")) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > if mchoice == 2: > > > > > > > > > > > > > > filename = raw_input("Hello, please enter file name here> ") > > > > > > > > > > > > > > if filename.endswith(".txt"): > > > > > > > > > > > > > > > > > > > > > > > > > > > > try: > > > > > > > > > > > > > > infile = open(filename) > > > > > > > > > > > > > > except EnvironmentError as e: > > > > > > > > > > > > > > print(e) > > > > > > > > > > > > > > sys.exit(1) > > > > > > > > > > > > > > > > > > > > > > > > > > > > print("\nFile {0} exists!".format(filename)) > > > > > > > > > > > > > > print("\nGetting IP addresses for hosts") > > > > > > > > > > > > > > print("\n") > > > > > > > > > > > > > > else: > > > > > > > > > > > > > > print("{0} is not a Text file.".format(filename)) > > > > > > > > > > > > > > sys.exit(1) > > > > > > > > > > > > > > for line in infile: > > > > > > > > > > > > > > hostname = line.strip() > > > > > > > > > > > > > > try: > > > > > > > > > > > > > > ip_address = socket.gethostbyname(hostname) > > > > > > > > > > > > > > except EnvironmentError as e: > > > > > > > > > > > > > > print("Couldn't find IP address for {0}: {1}".format(hostname, e)) > > > > > > > > > > > > > > continue > > > > > > > > > > > > > > print("IP address for {0} is {1}.".format(hostname, ip_address)) > > > > > > > > > > > > > > else: > > > > > > > > > > > > > > print ("\nFinished the operation") > > > > > > > > > > > > > > > > > > > > > > > > > > > > if mchoice == 1: > > > > > > > > > > > > > > murl = raw_input("Enter URL here> ") > > > > > > > > > > > > > > try: > > > > > > > > > > > > > > print("Checking URL...") > > > > > > > > > > > > > > ip_address = socket.gethostbyname(murl) > > > > > > > > > > > > > > except EnvironmentError as d: > > > > > > > > > > > > > > print(d) > > > > > > > > > > > > > > sys.exit(1) > > > > > > > > > > > > > > print("Valid URL") > > > > > > > > > > > > > > print("\nIP address for {0} is {1}.".format(murl, ip_address)) > > > > > > > > > > > > > > print ("\nFinished the operation") > > > > > > > > > > > > > > ===================================================================== > > > > > > > > > > > > > > > > > > > > > > > > > > > > now where it says Finsihed the operation i want it to show (another search /main menu/exit program) > > > > > > > > > > > > > > > > > > > > > > > > > > > > i know about the while loop , but forgive me i just don't have a clue how to use it for this situation. > > > > > > > > > > > > > > > > > > > > > > > > > > > > i don't want you to give me the code:) just the idea. > > > > > > > > > > > > > > i did read the section about the while loop but still i do not know how to use it in this situation. > > > > > > > > > > > > > > thanks. > > > > > > > > > > > > o.k a giant while loop :) > > > > > > thanks. > > > > hi, > > found a solution, > > it's not quite like Chris advised but it works. > > > > #!/usr/bin/env python > > #Get the IP Address > > > > import sys, socket, os > > > > def restart_program(): > > python = sys.executable > > os.execl(python, python, * sys.argv) > > > > print ("\n\n#########################################################") > > print ("# Get IP from Host v 1.0 #") > > print ("#########################################################") > > print ("# Choose from the options below #") > > print ("# 1- url , 2-File(Text file only.txt) #") > > print ("#########################################################\n") > > > > mchoice = int(raw_input("Please enter your choice> ")) > > while mchoice !=1 and mchoice !=2: > > print("{0} is not a menu option.".format(mchoice)) > > mchoice = int(raw_input("Please try again> ")) > > > > > > while mchoice == 2: > > filename = raw_input("Please enter file name here> ") > > if filename.endswith(".txt"): > > > > try: > > infile = open(filename) > > except EnvironmentError as e: > > print(e) > > sys.exit(1) > > > > print("\nFile {0} exists!".format(filename)) > > print("\nGetting IP addresses for hosts") > > print("\n") > > else: > > print("{0} is not a Text file.".format(filename)) > > sys.exit(1) > > for line in infile: > > hostname = line.strip() > > try: > > ip_address = socket.gethostbyname(hostname) > > except EnvironmentError as e: > > print("Couldn't find IP address for {0}: {1}".format(hostname, e)) > > continue > > print("IP address for {0} is {1}.".format(hostname, ip_address)) > > else: > > print ("\nFinished the operation") > > print ("A=another search, M=main menu, E=exit") > > > > waction=raw_input("Please choose your action > ") > > > > while waction !='A' and waction !='M' and waction !='E': > > print("{0} is not a valid action.".format(waction)) > > waction=raw_input("Please try again> ") > > if waction =='E': > > sys.exit(1) > > if waction =='A': > > continue > > if waction =='M': > > print ("#########################################################") > > print ("# Choose from the options below #") > > print ("# 1- url , 2-File(Text file only.txt) #") > > print ("#########################################################\n") > > > > mchoice = int(raw_input("Please enter your choice> ")) > > while mchoice !=1 and mchoice !=2: > > print("{0} is not a menu option.".format(mchoice)) > > mchoice = int(raw_input("Please try again> ")) > > > > > > while mchoice == 1: > > murl = raw_input("Enter URL here> ") > > try: > > print("Checking URL...") > > ip_address = socket.gethostbyname(murl) > > except EnvironmentError as d: > > print(d) > > sys.exit(1) > > print("Valid URL") > > print("\nIP address for {0} is {1}.".format(murl, ip_address)) > > print ("\nFinished the operation") > > print ("A=another search, M=main menu, E=exit") > > > > waction=raw_input("Please choose your action > ") > > > > while waction !='A' and waction !='M' and waction !='E': > > print("{0} is not a valid action.".format(waction)) > > waction=raw_input("Please try again> ") > > if waction =='E': > > sys.exit(1) > > if waction =='A': > > continue > > if waction =='M': > > restart_program() Hi Dave, thanks for your comment. please note this is only my 6th day of programing in any language ever and i'm tutoring my self. I know this code is too long and lousy for a simple task, but i guess this is part of my learning process. 3 days ago i already figured out that is too long and probably there is better solution, but I decided to try and work it out anyway just for learning and dealing with a bad code. anyway what i realized is before i want to write a program/task , i need to write what i want before and plan it ahead. anyway thanks everyone. From dkatorza at gmail.com Thu Sep 20 01:13:29 2012 From: dkatorza at gmail.com (Dan Katorza) Date: Wed, 19 Sep 2012 22:13:29 -0700 (PDT) Subject: using text file to get ip address from hostname In-Reply-To: References: <3359a0e7-f7bb-4b1f-b586-e83f337566b7@googlegroups.com> Message-ID: <2c5997bd-e458-4e83-af44-fcbfe3d95a8b@googlegroups.com> ?????? ??? ?????, 19 ??????? 2012 15:28:23 UTC+3, ??? Dan Katorza: > ?????? ??? ?????, 19 ??????? 2012 12:11:04 UTC+3, ??? Dan Katorza: > > > ?????? ??? ?????, 19 ??????? 2012 11:50:56 UTC+3, ??? Dan Katorza: > > > > > > > ?????? ??? ?????, 19 ??????? 2012 11:14:29 UTC+3, ??? Chris Angelico: > > > > > > > > > > > > > > > On Wed, Sep 19, 2012 at 5:41 PM, Dan Katorza wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Hello again, > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > I have another question and i hope you will understand me.. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Is there any option where you can set the program to go back to lets say the top of the code? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > I mean if the program finished the operation and i want to stay in the program and go back ro the start. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > after any operation i want the option to do it again , go back to the main menu or full exit from the program, and i want it every time. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > i hope i'm clear :) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Yep! Look up the docs and tutorial on "control flow" and "looping > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > constructs". Sounds like what you want here is a 'while' loop. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ChrisA > > > > > > > > > > > > > > > > > > > > > > > > > > > > Hi Chris, > > > > > > > > > > > > > > this is my code: > > > > > > > > > > > > > > > > > > > > > > > > > > > > #!/usr/bin/env python > > > > > > > > > > > > > > #Get the IP Address > > > > > > > > > > > > > > > > > > > > > > > > > > > > import sys, socket > > > > > > > > > > > > > > > > > > > > > > > > > > > > print ("\n\n#########################################################") > > > > > > > > > > > > > > print ("# Get IP from Host v 1.0 #") > > > > > > > > > > > > > > print ("#########################################################") > > > > > > > > > > > > > > print ("# Choose from the options below #") > > > > > > > > > > > > > > print ("# 1- url , 2-File(Text file only.txt) #") > > > > > > > > > > > > > > print ("#########################################################\n") > > > > > > > > > > > > > > > > > > > > > > > > > > > > mchoice = int(raw_input("Please enter your choice> ")) > > > > > > > > > > > > > > while mchoice !=1 and mchoice !=2: > > > > > > > > > > > > > > print("{0} is not a menu option.".format(mchoice)) > > > > > > > > > > > > > > mchoice = int(raw_input("Please try again> ")) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > if mchoice == 2: > > > > > > > > > > > > > > filename = raw_input("Hello, please enter file name here> ") > > > > > > > > > > > > > > if filename.endswith(".txt"): > > > > > > > > > > > > > > > > > > > > > > > > > > > > try: > > > > > > > > > > > > > > infile = open(filename) > > > > > > > > > > > > > > except EnvironmentError as e: > > > > > > > > > > > > > > print(e) > > > > > > > > > > > > > > sys.exit(1) > > > > > > > > > > > > > > > > > > > > > > > > > > > > print("\nFile {0} exists!".format(filename)) > > > > > > > > > > > > > > print("\nGetting IP addresses for hosts") > > > > > > > > > > > > > > print("\n") > > > > > > > > > > > > > > else: > > > > > > > > > > > > > > print("{0} is not a Text file.".format(filename)) > > > > > > > > > > > > > > sys.exit(1) > > > > > > > > > > > > > > for line in infile: > > > > > > > > > > > > > > hostname = line.strip() > > > > > > > > > > > > > > try: > > > > > > > > > > > > > > ip_address = socket.gethostbyname(hostname) > > > > > > > > > > > > > > except EnvironmentError as e: > > > > > > > > > > > > > > print("Couldn't find IP address for {0}: {1}".format(hostname, e)) > > > > > > > > > > > > > > continue > > > > > > > > > > > > > > print("IP address for {0} is {1}.".format(hostname, ip_address)) > > > > > > > > > > > > > > else: > > > > > > > > > > > > > > print ("\nFinished the operation") > > > > > > > > > > > > > > > > > > > > > > > > > > > > if mchoice == 1: > > > > > > > > > > > > > > murl = raw_input("Enter URL here> ") > > > > > > > > > > > > > > try: > > > > > > > > > > > > > > print("Checking URL...") > > > > > > > > > > > > > > ip_address = socket.gethostbyname(murl) > > > > > > > > > > > > > > except EnvironmentError as d: > > > > > > > > > > > > > > print(d) > > > > > > > > > > > > > > sys.exit(1) > > > > > > > > > > > > > > print("Valid URL") > > > > > > > > > > > > > > print("\nIP address for {0} is {1}.".format(murl, ip_address)) > > > > > > > > > > > > > > print ("\nFinished the operation") > > > > > > > > > > > > > > ===================================================================== > > > > > > > > > > > > > > > > > > > > > > > > > > > > now where it says Finsihed the operation i want it to show (another search /main menu/exit program) > > > > > > > > > > > > > > > > > > > > > > > > > > > > i know about the while loop , but forgive me i just don't have a clue how to use it for this situation. > > > > > > > > > > > > > > > > > > > > > > > > > > > > i don't want you to give me the code:) just the idea. > > > > > > > > > > > > > > i did read the section about the while loop but still i do not know how to use it in this situation. > > > > > > > > > > > > > > thanks. > > > > > > > > > > > > o.k a giant while loop :) > > > > > > thanks. > > > > hi, > > found a solution, > > it's not quite like Chris advised but it works. > > > > #!/usr/bin/env python > > #Get the IP Address > > > > import sys, socket, os > > > > def restart_program(): > > python = sys.executable > > os.execl(python, python, * sys.argv) > > > > print ("\n\n#########################################################") > > print ("# Get IP from Host v 1.0 #") > > print ("#########################################################") > > print ("# Choose from the options below #") > > print ("# 1- url , 2-File(Text file only.txt) #") > > print ("#########################################################\n") > > > > mchoice = int(raw_input("Please enter your choice> ")) > > while mchoice !=1 and mchoice !=2: > > print("{0} is not a menu option.".format(mchoice)) > > mchoice = int(raw_input("Please try again> ")) > > > > > > while mchoice == 2: > > filename = raw_input("Please enter file name here> ") > > if filename.endswith(".txt"): > > > > try: > > infile = open(filename) > > except EnvironmentError as e: > > print(e) > > sys.exit(1) > > > > print("\nFile {0} exists!".format(filename)) > > print("\nGetting IP addresses for hosts") > > print("\n") > > else: > > print("{0} is not a Text file.".format(filename)) > > sys.exit(1) > > for line in infile: > > hostname = line.strip() > > try: > > ip_address = socket.gethostbyname(hostname) > > except EnvironmentError as e: > > print("Couldn't find IP address for {0}: {1}".format(hostname, e)) > > continue > > print("IP address for {0} is {1}.".format(hostname, ip_address)) > > else: > > print ("\nFinished the operation") > > print ("A=another search, M=main menu, E=exit") > > > > waction=raw_input("Please choose your action > ") > > > > while waction !='A' and waction !='M' and waction !='E': > > print("{0} is not a valid action.".format(waction)) > > waction=raw_input("Please try again> ") > > if waction =='E': > > sys.exit(1) > > if waction =='A': > > continue > > if waction =='M': > > print ("#########################################################") > > print ("# Choose from the options below #") > > print ("# 1- url , 2-File(Text file only.txt) #") > > print ("#########################################################\n") > > > > mchoice = int(raw_input("Please enter your choice> ")) > > while mchoice !=1 and mchoice !=2: > > print("{0} is not a menu option.".format(mchoice)) > > mchoice = int(raw_input("Please try again> ")) > > > > > > while mchoice == 1: > > murl = raw_input("Enter URL here> ") > > try: > > print("Checking URL...") > > ip_address = socket.gethostbyname(murl) > > except EnvironmentError as d: > > print(d) > > sys.exit(1) > > print("Valid URL") > > print("\nIP address for {0} is {1}.".format(murl, ip_address)) > > print ("\nFinished the operation") > > print ("A=another search, M=main menu, E=exit") > > > > waction=raw_input("Please choose your action > ") > > > > while waction !='A' and waction !='M' and waction !='E': > > print("{0} is not a valid action.".format(waction)) > > waction=raw_input("Please try again> ") > > if waction =='E': > > sys.exit(1) > > if waction =='A': > > continue > > if waction =='M': > > restart_program() Hi Dave, thanks for your comment. please note this is only my 6th day of programing in any language ever and i'm tutoring my self. I know this code is too long and lousy for a simple task, but i guess this is part of my learning process. 3 days ago i already figured out that is too long and probably there is better solution, but I decided to try and work it out anyway just for learning and dealing with a bad code. anyway what i realized is before i want to write a program/task , i need to write what i want before and plan it ahead. anyway thanks everyone. From ashish.makani at gmail.com Thu Sep 20 03:28:26 2012 From: ashish.makani at gmail.com (ashish) Date: Thu, 20 Sep 2012 00:28:26 -0700 (PDT) Subject: Passing arguments to & executing, a python script on a remote machine from a python script on local machine In-Reply-To: References: <5a8a09f8-db4c-4f1d-ae8e-a5c848903c68@googlegroups.com> <505a9b22$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6f04ab26-8e8e-4531-85a9-622bc9603686@googlegroups.com> On Thursday, September 20, 2012 10:39:28 AM UTC+5:30, Chris Angelico wrote: > On Thu, Sep 20, 2012 at 2:27 PM, Steven D'Aprano > > wrote: > > > On Wed, 19 Sep 2012 12:46:33 -0700, ashish wrote: > > > > > >> 2. I have a python script, local.py, running on local which needs to > > >> pass arguments ( 3/4 string arguments, containing whitespaces like > > >> spaces, etc ) to a python script, remote.py running on remote (the > > >> remote machine). > > > > > > If 3/4 of the arguments are strings, what sort of objects are the other > > > 1/4? Sorry for the confusion Steven. There are 3 or 4 arguments, all of which are strings. > > > > I understand the OP as meaning "three or four string arguments". Yup, that's what i meant. > > > > ChrisA From ashish.makani at gmail.com Thu Sep 20 03:28:26 2012 From: ashish.makani at gmail.com (ashish) Date: Thu, 20 Sep 2012 00:28:26 -0700 (PDT) Subject: Passing arguments to & executing, a python script on a remote machine from a python script on local machine In-Reply-To: References: <5a8a09f8-db4c-4f1d-ae8e-a5c848903c68@googlegroups.com> <505a9b22$0$29890$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6f04ab26-8e8e-4531-85a9-622bc9603686@googlegroups.com> On Thursday, September 20, 2012 10:39:28 AM UTC+5:30, Chris Angelico wrote: > On Thu, Sep 20, 2012 at 2:27 PM, Steven D'Aprano > > wrote: > > > On Wed, 19 Sep 2012 12:46:33 -0700, ashish wrote: > > > > > >> 2. I have a python script, local.py, running on local which needs to > > >> pass arguments ( 3/4 string arguments, containing whitespaces like > > >> spaces, etc ) to a python script, remote.py running on remote (the > > >> remote machine). > > > > > > If 3/4 of the arguments are strings, what sort of objects are the other > > > 1/4? Sorry for the confusion Steven. There are 3 or 4 arguments, all of which are strings. > > > > I understand the OP as meaning "three or four string arguments". Yup, that's what i meant. > > > > ChrisA From breamoreboy at yahoo.co.uk Thu Sep 20 03:56:38 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 20 Sep 2012 08:56:38 +0100 Subject: How to send email programmatically from a gmail email a/c when port 587(smtp) is blocked In-Reply-To: <30853fb3-ef5a-4304-9123-15c84a2f9c89@googlegroups.com> References: <0f6686fd-7363-43d6-a5fa-0bd4f12586b5@googlegroups.com> <30853fb3-ef5a-4304-9123-15c84a2f9c89@googlegroups.com> Message-ID: On 19/09/2012 20:12, ashish wrote: > Folks, > > I asked the same query on the python tutor mailing list. > The responses i received are here : > http://thread.gmane.org/gmane.comp.python.tutor/77601 > > > Mark, > > There is nothing wrong in asking a query on multiple forums. > > Poeple on the tutor list, may not be part of comp.lang.python & subscribers to comp.lang.python > And you've done exactly the same thing with another question. So there are two sets of answers on two mls/ngs that are completely unconnected except that I amongst others know that they exist. If you had to ask on both, why not post to both in one hit? -- Cheers. Mark Lawrence. From hansmu at xs4all.nl Thu Sep 20 04:21:37 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Thu, 20 Sep 2012 10:21:37 +0200 Subject: Installing Pip onto a mac os x system In-Reply-To: <08f09236-a4d4-4b92-b212-f152be0d9449@googlegroups.com> References: <08f09236-a4d4-4b92-b212-f152be0d9449@googlegroups.com> Message-ID: <505ad212$0$6943$e4fe514c@news2.news.xs4all.nl> On 20/09/12 03:32:40, John Mordecai Dildy wrote: > Does anyone know how to install Pip onto a mac os x ver 10.7.4? > > Ive tried easy_instal pip but it brings up this message (but it doesn't help with my problem): > > error: can't create or remove files in install directory > > The following error occurred while trying to add or remove files in the > installation directory: > > [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-1820.write-test' > > The installation directory you specified (via --install-dir, --prefix, or > the distutils default setting) was: > > /Library/Python/2.7/site-packages/ > > Perhaps your account does not have write access to this directory? If the > installation directory is a system-owned directory, you may need to sign in > as the administrator or "root" account. If you do not have administrative > access to this machine, you may wish to choose a different installation > directory, preferably one that is listed in your PYTHONPATH environment > variable. > > For information on other options, you may wish to consult the > documentation at: > > http://peak.telecommunity.com/EasyInstall.html > > Please make the appropriate changes for your system and try again. > > Thing is I am the Administrator of the computer In that case, you should be able to do sudo easy_instal pip This will ask your login password, and then run "easy_instal pip" with so-called "root" privileges. > and can use all of the folders on the mac computer. You may be able to view them, but I doubt that you can add new files to folders like, say, /Library/Python . Hope this helps, -- HansM From hansmu at xs4all.nl Thu Sep 20 04:30:30 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Thu, 20 Sep 2012 10:30:30 +0200 Subject: How to get the list of all my open file(descriptor)s and locks? In-Reply-To: References: Message-ID: <505ad426$0$6877$e4fe514c@news2.news.xs4all.nl> On 20/09/12 05:11:11, Chris Angelico wrote: > On Thu, Sep 20, 2012 at 7:09 AM, Ian Kelly wrote: >> You could do: >> >> os.listdir("/proc/%d/fd" % os.getpid()) >> >> This should work on Linux, AIX, and Solaris, but obviously not on Windows. On MacOS X, you can use os.listdir("/dev/fd") This might work on other OSes. > I'm not sure how cross-platform it is, but at least on Linux, you can > use /proc/self as an alias for "/proc/"+os.getpid() - worth a try, > might make your code a bit easier to read. > > It's documented as useful when you don't know the PID yet (eg telling > a process to read the file /proc/self/fd/0 to force it to use stdin). At least on Linux, Solaris and MacOS X, you shouldd use /dev/stdin, which is a symlink to whatever the official name is. "/dev/stdin" is more readable and more portable than the official name. > So I'm confident enough to recommend testing it. :) Testing such things is the best way to learn. Hope this helps, -- HansM From kwa at kuwata-lab.com Thu Sep 20 07:27:37 2012 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Thu, 20 Sep 2012 20:27:37 +0900 Subject: [Q] How to exec code object with local variables specified? Message-ID: Hi, Is it possible to run code object with local variables specified? I'm trying the following code but not work: def fn(): x = 1 y = 2 localvars = {'x': 0} exec(fn.func_code, globals(), localvars) print(localvars) ## what I expected is: {'x': 1, 'y': 2} ## but actual is: {'x': 0} Python: 2.7.3 OS: MacOS X -- regards, makoto kuwata From d at davea.name Thu Sep 20 07:34:34 2012 From: d at davea.name (Dave Angel) Date: Thu, 20 Sep 2012 07:34:34 -0400 Subject: Programming Issues In-Reply-To: References: <50591DEC.6040904@davea.name> Message-ID: <505AFF4A.4060902@davea.name> On 09/19/2012 07:01 PM, Nathan Spicer wrote: > Dave, > You sent this response privately, which isn't the way the mailing list works. Private responses are good for thank-yous and for personal remarks of no interest to others. But you're short-circuiting the helping process if you don't let everyone else see what you're saying here. I'll forward my response to the list, so others can jump in. You also top-posted, rather than putting your remarks after what you're quoting. > I'm running Python 3.2. I think doing raw input is what the instructor is > looking for. What version of Python does the instructor think you're using? raw_input is not in Python 3.2, being renamed to input(). The 2.x logic of input() is fortunately gone, as it was quite unsafe. > I know a need to do a loop, but the problem is i don't know ho > to do this. An open-ended loop can be done with the while statement. What I mean by open-ended is that you have no way of predicting how many times it will loop, because it depends on data you don't have ahead of time. The other type of loop is the for loop, where the loop will normally progress till it processes all items in a sequence. A while loop might look something like: def ask_user(): amount = get_amount() while amount != 0: do_some_stuff(amount) amount = get_amount() print "done with program" # And your top-level code might look something like: if __name__ == "__main__": ask_user() If that makes sense to you, then write the functions that this one calls. If you don't understand this loop, then ask us to elaborate. And if you don't understand what this while statement itself does, ask your professor. > There is no code, because i'm not sure how or what to write. So > far we've done simple inputs. Are you aware of any examples similar to my > problem, that i could look at and possibly base my program accordingly? > > Thanks, > Nathan > -- DaveA From __peter__ at web.de Thu Sep 20 09:15:24 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 20 Sep 2012 15:15:24 +0200 Subject: [Q] How to exec code object with local variables specified? References: Message-ID: Makoto Kuwata wrote: > Is it possible to run code object with local variables specified? > I'm trying the following code but not work: > > def fn(): > x = 1 > y = 2 > localvars = {'x': 0} > exec(fn.func_code, globals(), localvars) > print(localvars) > ## what I expected is: {'x': 1, 'y': 2} > ## but actual is: {'x': 0} > > Python: 2.7.3 >>> loc = {} >>> exec("x = 1; y = 2", globals(), loc) >>> loc {'y': 2, 'x': 1} However, this won't work with the code object taken from a function which uses a different a bytecode (STORE_FAST instead of STORE_NAME): >>> import dis >>> def f(): x = 1 ... >>> dis.dis(f) 1 0 LOAD_CONST 1 (1) 3 STORE_FAST 0 (x) 6 LOAD_CONST 0 (None) 9 RETURN_VALUE >>> dis.dis(compile("x=1", "", "exec")) 1 0 LOAD_CONST 0 (1) 3 STORE_NAME 0 (x) 6 LOAD_CONST 1 (None) 9 RETURN_VALUE From duncan.booth at invalid.invalid Thu Sep 20 09:35:35 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Sep 2012 13:35:35 GMT Subject: 'indent'ing Python in windows bat References: <5057C990.8080809@invtools.com> Message-ID: Jason Friedman wrote: >> I'm converting windows bat files little by little to Python 3 as I >> find time and learn Python. >> The most efficient method for some lines is to call Python like: >> python -c "import sys; sys.exit(3)" >> >> How do I "indent" if I have something like: >> if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else >> sys.exit(3) > > Some months ago I posted what I think is a similar question in the > Unix world: I wanted to call a small portion of Python from within a > Bash script. > > Someone on this list answered (for Bash): > > #!/bin/bash > command1 > command2 > python -c "if True: > import module > if condition: > do_this > else: > do_that > " > command4 > # end code > > Perhaps something similar would work for a .bat file. > Provided there's only one Python block in the .bat or .cmd file then there's no real problem; you just have to hide each language from the other: goto :start """ :start @echo off echo This is a CMD script python -x %~f0 "%1" echo Back in the CMD script goto :eof """ import sys print("Welcome to Python") print("Arguments were {}".format(sys.argv)) print("Bye!") You can put the Python code either before or after the triple-quote string containing the CMD commands, just begin the file with a goto to skip into the batch commands and end them by jumping to eof. -- Duncan Booth http://kupuguy.blogspot.com From jure.erznoznik at gmail.com Thu Sep 20 09:52:07 2012 From: jure.erznoznik at gmail.com (=?UTF-8?Q?Jure_Erzno=C5=BEnik?=) Date: Thu, 20 Sep 2012 06:52:07 -0700 (PDT) Subject: Fool Python class with imaginary members (serious guru stuff inside) Message-ID: <89b80b56-d1f2-477e-b28a-4410f2cf9de6@googlegroups.com> I'm trying to create a class that would lie to the user that a member is in some cases a simple variable and in other cases a class. The nature of the member would depend on call syntax like so: 1. x = obj.member #x becomes the "simple" value contained in member 2. x = obj.member.another_member #x becomes the "simple" value contained in first member's another_member. So the first method "detects" that we only need a simple value and returns that. The second method "sees" that we need "member" as a class and returns that. Note that "simple type" could mean anything, from int to bitmap image. I have determined that this is possible if I sacrifice the final member reference to the __call__ override using function-call syntax: 1. x = obj.member(). The call syntax returns the simple value and the other returns the class. It is also possible if I override the __xxxitem__ methods to simulate a dictionary. However, I would like to use the "true member" access syntax if possible. So, is it possible? From emile at fenx.com Thu Sep 20 10:50:51 2012 From: emile at fenx.com (Emile van Sebille) Date: Thu, 20 Sep 2012 07:50:51 -0700 Subject: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?) In-Reply-To: <10db83e4-80eb-4265-b11c-062269fea1b0@googlegroups.com> References: <10db83e4-80eb-4265-b11c-062269fea1b0@googlegroups.com> Message-ID: On 9/19/2012 12:50 PM ashish said... > Hi c.l.p folks > > Here is my situation > > 1. I have two machines. Lets call them 'local' & 'remote'. > Both run ubuntu & both have python installed > > 2. I have a python script, local.py, running on 'local' which needs to pass arguments ( 3/4 string arguments, containing whitespaces like spaces, etc ) to a python script, remote.py running on 'remote' (the remote machine). > > I have the following questions: > > 1. What's the best way to accomplish my task ? Check out http://rpyc.sourceforge.net/ -- It's reasonably lightweight and has been working well for our similar situation. Emile From rolando.caner at cnic.edu.cu Thu Sep 20 11:12:44 2012 From: rolando.caner at cnic.edu.cu (=?ISO-8859-1?Q?Rolando_Ca=F1er_Roblejo?=) Date: Thu, 20 Sep 2012 11:12:44 -0400 Subject: How to limit CPU usage in Python Message-ID: <505B326C.1060503@cnic.edu.cu> Hi all, Is it possible for me to put a limit in the amount of processor usage (% CPU) that my current python script is using? Is there any module useful for this task? I saw Resource module but I think it is not the module I am looking for. Some people recommend to use nice and cpulimit unix tools, but those are external to python and I prefer a python solution. I am working with Linux (Ubuntu 10.04). Best regards. From kwa at kuwata-lab.com Thu Sep 20 11:40:15 2012 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Fri, 21 Sep 2012 00:40:15 +0900 Subject: [Q] How to exec code object with local variables specified? In-Reply-To: References: Message-ID: On Thu, Sep 20, 2012 at 10:15 PM, Peter Otten <__peter__ at web.de> wrote: > >>>> loc = {} >>>> exec("x = 1; y = 2", globals(), loc) >>>> loc > {'y': 2, 'x': 1} > > However, this won't work with the code object taken from a function which > uses a different a bytecode (STORE_FAST instead of STORE_NAME): > Is there any way to use STORE_FAST instead of STORE_NAME? exec("string", ...) is not a solution for me. # What is different between fn.func_code and compile("string")? -- regards, makoto kuwata From tjreedy at udel.edu Thu Sep 20 12:18:00 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 20 Sep 2012 12:18:00 -0400 Subject: [Q] How to exec code object with local variables specified? In-Reply-To: References: Message-ID: On 9/20/2012 7:27 AM, Makoto Kuwata wrote: > Is it possible to run code object with local variables specified? In the way you mean that, no. > I'm trying the following code but not work: > > def fn(): > x = 1 > y = 2 > localvars = {'x': 0} > exec(fn.func_code, globals(), localvars) The globals and locals you pass to exec are the globals and locals for the context in which the code object runs. They have nothing to do with the code objects local namespace. Running exec with separate globals and locals is like running the code within a class definition context. If you ran def fn(): x = 1 class dummy: fn() dummy.x would not be defined and I presume you would not expect it to. -- Terry Jan Reedy From clp2 at rebertia.com Thu Sep 20 12:19:12 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 20 Sep 2012 09:19:12 -0700 Subject: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?) In-Reply-To: <10db83e4-80eb-4265-b11c-062269fea1b0@googlegroups.com> References: <10db83e4-80eb-4265-b11c-062269fea1b0@googlegroups.com> Message-ID: On Wed, Sep 19, 2012 at 12:50 PM, ashish wrote: > 2. I have a python script, local.py, running on 'local' which needs to pass arguments ( 3/4 string arguments, containing whitespaces like spaces, etc ) to a python script, remote.py running on 'remote' (the remote machine). > 3. Has anybody been able to do this using os.system ? > > I tried this >>>> import os >>>> os.system ("ssh remoteuser at remote python remote.py arg1 arg2 arg3") > > This worked, but if the arguments i tried to pass, had spaces, i was not able to 'escape' the spaces. Use the `subprocess` module instead (with shell=False). You then won't need to worry about escaping. http://docs.python.org/library/subprocess.html Cheers, Chris From toby at tobiah.org Thu Sep 20 12:28:58 2012 From: toby at tobiah.org (Tobiah) Date: Thu, 20 Sep 2012 09:28:58 -0700 Subject: A little morning puzzle In-Reply-To: References: Message-ID: >> Here is my solution: >> ** Incredibly convoluted and maximally less concise solution >> than other offerings. ** >> Might be better ones though. > > Unlikely. Zing! From tjreedy at udel.edu Thu Sep 20 12:46:33 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 20 Sep 2012 12:46:33 -0400 Subject: How to limit CPU usage in Python In-Reply-To: <505B326C.1060503@cnic.edu.cu> References: <505B326C.1060503@cnic.edu.cu> Message-ID: On 9/20/2012 11:12 AM, Rolando Ca?er Roblejo wrote: > Hi all, > > Is it possible for me to put a limit in the amount of processor usage (% > CPU) that my current python script is using? Is there any module useful > for this task? I saw Resource module but I think it is not the module I > am looking for. Some people recommend to use nice and cpulimit unix > tools, but those are external to python and I prefer a python solution. > I am working with Linux (Ubuntu 10.04). Call the external tools with subprocess.open. -- Terry Jan Reedy From tjreedy at udel.edu Thu Sep 20 12:53:41 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 20 Sep 2012 12:53:41 -0400 Subject: How to limit CPU usage in Python In-Reply-To: References: <505B326C.1060503@cnic.edu.cu> Message-ID: On 9/20/2012 12:46 PM, Terry Reedy wrote: > On 9/20/2012 11:12 AM, Rolando Ca?er Roblejo wrote: >> Hi all, >> >> Is it possible for me to put a limit in the amount of processor usage (% >> CPU) that my current python script is using? Is there any module useful >> for this task? I saw Resource module but I think it is not the module I >> am looking for. Some people recommend to use nice and cpulimit unix >> tools, but those are external to python and I prefer a python solution. >> I am working with Linux (Ubuntu 10.04). > > Call the external tools with subprocess.open. I meant to end that with ? as I don't know how easy it is to get the external id of the calling process that is to be limited. I presume that can be done by first calling ps (with subprocess) and searching the piped-back output. -- Terry Jan Reedy From tjreedy at udel.edu Thu Sep 20 13:04:31 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 20 Sep 2012 13:04:31 -0400 Subject: Fool Python class with imaginary members (serious guru stuff inside) In-Reply-To: <89b80b56-d1f2-477e-b28a-4410f2cf9de6@googlegroups.com> References: <89b80b56-d1f2-477e-b28a-4410f2cf9de6@googlegroups.com> Message-ID: On 9/20/2012 9:52 AM, Jure Erzno?nik wrote: > I'm trying to create a class that would lie to the user that a member is in some cases a simple variable and in other cases a class. The nature of the member would depend on call syntax like so: > 1. x = obj.member #x becomes the "simple" value contained in member > 2. x = obj.member.another_member #x becomes the "simple" value contained in first member's another_member. x.y.z is parsed and executed as (x.y).z, so you are asking if the attribute-getter can know what will be done with the object it returns. Assuming CPython, you would have to write something that searches the Python code before compilation, the ast during compilation, or the bytecode after compilation. Much easier would be to define a union class that is a simple type with attributes and return that in the first lookup. class AttrInt(int): def __getattr__(self, name): return 'attribute' y = AttrInt(3) print(y, y.a) ### 3 attribute If x.y returns an AttrInt, it will act like an int for most purposes, while x.y.z will return whatever AttrInt.__getattr__ does and the temporary AttrInt y disappears. -- Terry Jan Reedy From malaclypse2 at gmail.com Thu Sep 20 13:08:57 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Thu, 20 Sep 2012 13:08:57 -0400 Subject: How to limit CPU usage in Python In-Reply-To: <505B326C.1060503@cnic.edu.cu> References: <505B326C.1060503@cnic.edu.cu> Message-ID: On Thu, Sep 20, 2012 at 11:12 AM, Rolando Ca?er Roblejo wrote: > Hi all, > > Is it possible for me to put a limit in the amount of processor usage (% > CPU) that my current python script is using? Is there any module useful for > this task? I saw Resource module but I think it is not the module I am > looking for. Some people recommend to use nice and cpulimit unix tools, but > those are external to python and I prefer a python solution. I am working > with Linux (Ubuntu 10.04). Maximum percentage of CPU used isn't normally something you control. The only way I know of to do it involves having another process monitor the thing you want to control and sending signals to stop and start it (e.g., http://cpulimit.sourceforge.net/). Typically, you instead want to control the priority (so that higher priority apps can easily take more CPU time). That's what nice is for (http://docs.python.org/library/os.html#os.nice). If you want to limit a process in the same way that ulimit does, then the resources module is what you want (http://docs.python.org/library/resource.html#resource.setrlimit). Is there a particular reason that you'd rather have your CPU sitting idle, rather than continuing with whatever code is waiting to be run? I'm having a hard time understanding what problem you might be having that some combination of setting the nice level and imposing resource limits won't handle. -- Jerry From piet at vanoostrum.org Thu Sep 20 13:30:49 2012 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 20 Sep 2012 19:30:49 +0200 Subject: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?) References: <10db83e4-80eb-4265-b11c-062269fea1b0@googlegroups.com> Message-ID: Ismael Farf?n writes: > How about something like this: > os.system ( 'ssh remoteuser at remote python remote.py "arg 1" "arg 2" "arg 3"' ) That won't work. You need an additional level of quoting because ssh is also a shell so it adds another level of interpretation. The following works: os.system('''ssh remoteuser at remote "python remote.py 'arg 1' 'arg 2' 'arg 3'"''') -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From piet at vanoostrum.org Thu Sep 20 13:45:31 2012 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 20 Sep 2012 19:45:31 +0200 Subject: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?) References: <10db83e4-80eb-4265-b11c-062269fea1b0@googlegroups.com> Message-ID: Chris Rebert writes: > Use the `subprocess` module instead (with shell=False). You then won't > need to worry about escaping. > http://docs.python.org/library/subprocess.html You will still need to worry about escaping because on the remote end you invoke ssh which is a shell. The obvious call: subprocess.call(["ssh", "remoteuser at remote", "python", "remote.py", "arg 1", "arg 2", "arg 3"]) won't work because ssh will break up the "arg n" strings. You need to use "'arg n'" or put the whole python command in a string like: "python TEST/testargs.py 'arg 1' 'arg 2' 'arg 3'" -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From giuseppe.amatulli at gmail.com Thu Sep 20 14:31:43 2012 From: giuseppe.amatulli at gmail.com (giuseppe.amatulli at gmail.com) Date: Thu, 20 Sep 2012 11:31:43 -0700 (PDT) Subject: looping in array vs looping in a dic Message-ID: <007b2d71-3355-4085-b84f-204834b2c8d0@googlegroups.com> Hi, I have this script in python that i need to apply for very large arrays (arrays coming from satellite images). The script works grate but i would like to speed up the process. The larger computational time is in the for loop process. Is there is a way to improve that part? Should be better to use dic() instead of np.ndarray for saving the results? and if yes how i can make the sum in dic()(like in the correspondent matrix[row_c,1] = matrix[row_c,1] + valuesRaster[row,col] )? If the dic() is the solution way is faster? Thanks Giuseppe import numpy as np import sys from time import clock, time # create the arrays start = time() valuesRaster = np.random.random_integers(0, 100, 100).reshape(10, 10) valuesCategory = np.random.random_integers(1, 10, 100).reshape(10, 10) elapsed = (time() - start) print(elapsed , "create the data") start = time() categories = np.unique(valuesCategory) matrix = np.c_[ categories , np.zeros(len(categories))] elapsed = (time() - start) print(elapsed , "create the matrix and append a colum zero ") rows = 10 cols = 10 start = time() for col in range(0,cols): for row in range(0,rows): for row_c in range(0,len(matrix)) : if valuesCategory[row,col] == matrix[row_c,0] : matrix[row_c,1] = matrix[row_c,1] + valuesRaster[row,col] break elapsed = (time() - start) print(elapsed , "loop in the data ") print (matrix) From henryalphabet at hotmail.com Thu Sep 20 15:02:26 2012 From: henryalphabet at hotmail.com (py_lrnr) Date: Thu, 20 Sep 2012 12:02:26 -0700 (PDT) Subject: "Development mode" Message-ID: <3142822a-9e66-413c-ac21-4363ba882bc3@googlegroups.com> I am new to python and I have come across the following command and its description: >Now to be able to run the project you will need to install it and its >dependencies. >python setup.py develop I looked up what the 'develop' argument does and found: >Extra commands: > develop install package in 'development mode' I searched for a description of 'development mode' but could not find a good description. Can anyone (very briefly) explain to me, in a sentence or two: what 'development mode' is? how 'development mode' differs from other 'modes'? why/when I would use 'development mode'? what 'development mode' does or does not allow me to do? Many thanks in advance. From python at mrabarnett.plus.com Thu Sep 20 15:09:52 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 20 Sep 2012 20:09:52 +0100 Subject: looping in array vs looping in a dic In-Reply-To: <007b2d71-3355-4085-b84f-204834b2c8d0@googlegroups.com> References: <007b2d71-3355-4085-b84f-204834b2c8d0@googlegroups.com> Message-ID: <505B6A00.10308@mrabarnett.plus.com> On 2012-09-20 19:31, giuseppe.amatulli at gmail.com wrote: > Hi, > I have this script in python that i need to apply for very large arrays (arrays coming from satellite images). > The script works grate but i would like to speed up the process. > The larger computational time is in the for loop process. > Is there is a way to improve that part? > Should be better to use dic() instead of np.ndarray for saving the results? > and if yes how i can make the sum in dic()(like in the correspondent matrix[row_c,1] = matrix[row_c,1] + valuesRaster[row,col] )? > If the dic() is the solution way is faster? > > Thanks > Giuseppe > > import numpy as np > import sys > from time import clock, time > > # create the arrays > > start = time() > valuesRaster = np.random.random_integers(0, 100, 100).reshape(10, 10) > valuesCategory = np.random.random_integers(1, 10, 100).reshape(10, 10) > > elapsed = (time() - start) > print(elapsed , "create the data") > > start = time() > > categories = np.unique(valuesCategory) > matrix = np.c_[ categories , np.zeros(len(categories))] > > elapsed = (time() - start) > print(elapsed , "create the matrix and append a colum zero ") > > rows = 10 > cols = 10 > > start = time() > > for col in range(0,cols): > for row in range(0,rows): > for row_c in range(0,len(matrix)) : > if valuesCategory[row,col] == matrix[row_c,0] : > matrix[row_c,1] = matrix[row_c,1] + valuesRaster[row,col] > break > elapsed = (time() - start) > print(elapsed , "loop in the data ") > > print (matrix) > If I understand the code correctly, 'matrix' contains the categories in column 0 and the totals in column 1. What you're doing is performing a linear search through the categories and then adding to the corresponding total. Linear searches are slow because on average you have to search through half of the list. Using a dict would be much faster (although you should of course measure it!). Try something like this: import numpy as np from time import time # Create the arrays. start = time() valuesRaster = np.random.random_integers(0, 100, 100).reshape(10, 10) valuesCategory = np.random.random_integers(1, 10, 100).reshape(10, 10) elapsed = time() - start print(elapsed, "Create the data.") start = time() categories = np.unique(valuesCategory) totals = dict.fromkeys(categories, 0) elapsed = time() - start print(elapsed, "Create the totals dict.") rows = 100 cols = 10 start = time() for col in range(cols): for row in range(rows): cat = valuesCategory[row, col] ras = valuesRaster[row, col] totals[cat] += ras elapsed = time() - start print(elapsed, "Loop in the data.") print(totals) From steve+comp.lang.python at pearwood.info Thu Sep 20 15:15:06 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Sep 2012 19:15:06 GMT Subject: Fool Python class with imaginary members (serious guru stuff inside) References: <89b80b56-d1f2-477e-b28a-4410f2cf9de6@googlegroups.com> Message-ID: <505b6b3a$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 20 Sep 2012 06:52:07 -0700, Jure Erzno?nik wrote: > I'm trying to create a class that would lie to the user that a member is > in some cases a simple variable and in other cases a class. The nature > of the member would depend on call syntax like so: > 1. x = obj.member #x becomes the "simple" value contained in member > 2. x = obj.member.another_member #x becomes the "simple" value > contained in first member's another_member. Why do you hate your users so much that you want to cause them enormous difficulty with perfectly reasonable code like this? tmp = obj.member x = tmp.another_member > So the first method "detects" that we only need a simple value and > returns that. Fortunately that is impossible without nasty bytecode or AST hacks. Thank the stars that Python doesn't allow anything as badly designed as this! -- Steven From ian.g.kelly at gmail.com Thu Sep 20 15:28:12 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 20 Sep 2012 13:28:12 -0600 Subject: looping in array vs looping in a dic In-Reply-To: <505B6A00.10308@mrabarnett.plus.com> References: <007b2d71-3355-4085-b84f-204834b2c8d0@googlegroups.com> <505B6A00.10308@mrabarnett.plus.com> Message-ID: On Thu, Sep 20, 2012 at 1:09 PM, MRAB wrote: > for col in range(cols): > for row in range(rows): > cat = valuesCategory[row, col] > ras = valuesRaster[row, col] > totals[cat] += ras Expanding on what MRAB wrote, since you probably have far fewer categories than pixels, you may be able to take better advantage of numpy's vectorized operations (which are pretty much the whole point of using numpy in the first place) by looping over the categories instead: for cat in categories: totals[cat] += np.sum(valuesCategory * (valuesRaster == cat)) From christian at python.org Thu Sep 20 15:28:34 2012 From: christian at python.org (Christian Heimes) Date: Thu, 20 Sep 2012 21:28:34 +0200 Subject: How to limit CPU usage in Python In-Reply-To: <505B326C.1060503@cnic.edu.cu> References: <505B326C.1060503@cnic.edu.cu> Message-ID: Am 20.09.2012 17:12, schrieb Rolando Ca?er Roblejo: > Hi all, > > Is it possible for me to put a limit in the amount of processor usage (% > CPU) that my current python script is using? Is there any module useful > for this task? I saw Resource module but I think it is not the module I > am looking for. Some people recommend to use nice and cpulimit unix > tools, but those are external to python and I prefer a python solution. > I am working with Linux (Ubuntu 10.04). Hello, you have two options here. You can either limit the total amount of CPU seconds with the resource module or reduce the priority and scheduling priority of the process. The resource module is a wrapper around the setrlimit and getrlimit feature as described in http://linux.die.net/man/2/setrlimit . The scheduling priority can be altered with nice, get/setpriority or io priority. The psutil package http://code.google.com/p/psutil/ wraps all functions in a nice Python API. Regards Christian From ian.g.kelly at gmail.com Thu Sep 20 15:29:23 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 20 Sep 2012 13:29:23 -0600 Subject: looping in array vs looping in a dic In-Reply-To: References: <007b2d71-3355-4085-b84f-204834b2c8d0@googlegroups.com> <505B6A00.10308@mrabarnett.plus.com> Message-ID: On Thu, Sep 20, 2012 at 1:28 PM, Ian Kelly wrote: > Expanding on what MRAB wrote, since you probably have far fewer > categories than pixels, you may be able to take better advantage of > numpy's vectorized operations (which are pretty much the whole point > of using numpy in the first place) by looping over the categories > instead: > > for cat in categories: > totals[cat] += np.sum(valuesCategory * (valuesRaster == cat)) Of course, that should have read: for cat in categories: totals[cat] += np.sum(valuesRaster * (valuesCategory == cat)) From henryalphabet at hotmail.com Thu Sep 20 15:38:54 2012 From: henryalphabet at hotmail.com (py_lrnr) Date: Thu, 20 Sep 2012 12:38:54 -0700 (PDT) Subject: When should I use "development mode"? Message-ID: <67ebd881-f038-4a98-8eea-98fea0fbdff0@googlegroups.com> I am new to python and I have come across the following command and its description: >Now to be able to run the project you will need to install it and its >dependencies. >python setup.py develop I looked up what the 'develop' argument does and found: >Extra commands: > develop install package in 'development mode' I searched for a description of 'development mode' but could not find a good description. Can anyone (very briefly) explain to me, in a sentence or two: what 'development mode' is? how 'development mode' differs from other 'modes'? why/when I would use 'development mode'? what 'development mode' does or does not allow me to do? Many thanks in advance. From ian.g.kelly at gmail.com Thu Sep 20 15:58:15 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 20 Sep 2012 13:58:15 -0600 Subject: When should I use "development mode"? In-Reply-To: <67ebd881-f038-4a98-8eea-98fea0fbdff0@googlegroups.com> References: <67ebd881-f038-4a98-8eea-98fea0fbdff0@googlegroups.com> Message-ID: On Thu, Sep 20, 2012 at 1:38 PM, py_lrnr wrote: > Can anyone (very briefly) explain to me, in a sentence or two: > > what 'development mode' is? > how 'development mode' differs from other 'modes'? > why/when I would use 'development mode'? > what 'development mode' does or does not allow me to do? Instead of installing the package into your site-packages, it installs a link back to the source folder. This lets you make changes to the code in the source folder which are immediately visible to Python without having to install the package again. From jdildy85 at gmail.com Thu Sep 20 16:33:34 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Thu, 20 Sep 2012 13:33:34 -0700 (PDT) Subject: Installing Pip onto a mac os x system In-Reply-To: <08f09236-a4d4-4b92-b212-f152be0d9449@googlegroups.com> References: <08f09236-a4d4-4b92-b212-f152be0d9449@googlegroups.com> Message-ID: Thank you Hans M. for some input. Now it shows the error of: sudo: easy_instal: command not found From gordon at panix.com Thu Sep 20 16:37:35 2012 From: gordon at panix.com (John Gordon) Date: Thu, 20 Sep 2012 20:37:35 +0000 (UTC) Subject: Installing Pip onto a mac os x system References: <08f09236-a4d4-4b92-b212-f152be0d9449@googlegroups.com> Message-ID: In John Mordecai Dildy writes: > Now it shows the error of: > sudo: easy_instal: command not found Try 'easy_install' instead of 'easy_instal'. -- 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 jdildy85 at gmail.com Thu Sep 20 16:39:08 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Thu, 20 Sep 2012 13:39:08 -0700 (PDT) Subject: Installing Pip onto a mac os x system In-Reply-To: References: <08f09236-a4d4-4b92-b212-f152be0d9449@googlegroups.com> Message-ID: On Thursday, September 20, 2012 4:37:36 PM UTC-4, John Gordon wrote: > In John Mordecai Dildy writes: > > > > > Now it shows the error of: > > > > > sudo: easy_instal: command not found > > > > Try 'easy_install' instead of 'easy_instal'. > > > > -- > > 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" Thanks John G. From gelonida at gmail.com Thu Sep 20 17:06:46 2012 From: gelonida at gmail.com (Gelonida N) Date: Thu, 20 Sep 2012 23:06:46 +0200 Subject: portable way of locating an executable (like which) Message-ID: I'd like to implement the equivalent functionality of the unix command /usr/bin/which The function should work under Linux and under windows. Did anybody already implement such a function. If not, is there a portable way of splitting the environment variable PATH? Thanks for any sugestions From breamoreboy at yahoo.co.uk Thu Sep 20 17:47:11 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 20 Sep 2012 22:47:11 +0100 Subject: portable way of locating an executable (like which) In-Reply-To: References: Message-ID: On 20/09/2012 22:06, Gelonida N wrote: > I'd like to implement the equivalent functionality of the unix command > /usr/bin/which > > The function should work under Linux and under windows. > > Did anybody already implement such a function. Searching found nothing obvious to me :( > If not, is there a portable way of splitting the environment variable PATH? With os.sep ? > > Thanks for any sugestions > > -- Cheers. Mark Lawrence. From jason.swails at gmail.com Thu Sep 20 18:04:41 2012 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 20 Sep 2012 18:04:41 -0400 Subject: portable way of locating an executable (like which) In-Reply-To: References: Message-ID: On Thu, Sep 20, 2012 at 5:06 PM, Gelonida N wrote: > I'd like to implement the equivalent functionality of the unix command > /usr/bin/which > > The function should work under Linux and under windows. > > Did anybody already implement such a function. > If not, is there a portable way of splitting the environment variable PATH? > I've used the following in programs I write: def which(program): def is_exe(fpath): return os.path.exists(fpath) and os.access(fpath, os.X_OK) fpath, fname = os.path.split(program) if fpath: if is_exe(program): return program else: for path in os.getenv("PATH").split(os.pathsep): exe_file = os.path.join(path, program) if is_exe(exe_file): return exe_file return None IIRC, I adapted it from StackOverflow. I know it works on Linux and Mac OS X, but not sure about windows (since I don't know if PATH works the same way there). HTH, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Sep 20 18:21:27 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Sep 2012 08:21:27 +1000 Subject: portable way of locating an executable (like which) In-Reply-To: References: Message-ID: On Fri, Sep 21, 2012 at 7:47 AM, Mark Lawrence wrote: > On 20/09/2012 22:06, Gelonida N wrote: >> >> I'd like to implement the equivalent functionality of the unix command >> /usr/bin/which >> >> The function should work under Linux and under windows. >> >> Did anybody already implement such a function. > > Searching found nothing obvious to me :( > >> If not, is there a portable way of splitting the environment variable >> PATH? > With os.sep ? os.sep is the directory separator, but os.pathsep may be what you want. Between that and os.getenv('path') you can at least get the directories. Then on Windows, you also need to check out os.getenv('pathext') and split _that_ on the semicolon, and try each of those as a file extension. I'm not sure whether or not Windows will add extensions from pathext if one is given on the command line - for instance, if typing "foo.exe" will search for "foo.exe.bat" - but the basics are there. Alternatively, there may be a Win32 API funct5ion that does this. Would be worth a look. ChrisA From ian.g.kelly at gmail.com Thu Sep 20 18:32:42 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 20 Sep 2012 16:32:42 -0600 Subject: portable way of locating an executable (like which) In-Reply-To: References: Message-ID: On Thu, Sep 20, 2012 at 4:21 PM, Chris Angelico wrote: > os.sep is the directory separator, but os.pathsep may be what you > want. Between that and os.getenv('path') you can at least get the > directories. Then on Windows, you also need to check out > os.getenv('pathext') and split _that_ on the semicolon, and try each > of those as a file extension. I'm not sure whether or not Windows will > add extensions from pathext if one is given on the command line - for > instance, if typing "foo.exe" will search for "foo.exe.bat" - but the > basics are there. Easy enough to test: C:\>echo echo hello! > foo.exe.bat C:\>foo.exe hello! Yup, it does. It looks like it tries it without the extension first, though: C:\>copy c:\windows\notepad.exe foo.exe 1 file(s) copied. C:\>foo.exe [starts notepad] From thorsopia at lavabit.com Thu Sep 20 18:58:21 2012 From: thorsopia at lavabit.com (thorsopia at lavabit.com) Date: Thu, 20 Sep 2012 18:58:21 -0400 (EDT) Subject: Functional way to compare things inside a list Message-ID: <63673.77.105.185.196.1348181901.squirrel@lavabit.com> Hi, list = [{'1': []}, {'2': []}, {'3': ['4', '5']}] I want to check for a value (e.g. '4'), and get the key of the dictionary that contains that value. (Yep, this is bizarre.) some_magic(list, '4') => '3' What's the functional way to do it? Is it possible to do it with a one-liner? From rosuav at gmail.com Thu Sep 20 19:04:06 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Sep 2012 09:04:06 +1000 Subject: portable way of locating an executable (like which) In-Reply-To: References: Message-ID: On Fri, Sep 21, 2012 at 8:32 AM, Ian Kelly wrote: > On Thu, Sep 20, 2012 at 4:21 PM, Chris Angelico wrote: >> os.sep is the directory separator, but os.pathsep may be what you >> want. Between that and os.getenv('path') you can at least get the >> directories. Then on Windows, you also need to check out >> os.getenv('pathext') and split _that_ on the semicolon, and try each >> of those as a file extension. I'm not sure whether or not Windows will >> add extensions from pathext if one is given on the command line - for >> instance, if typing "foo.exe" will search for "foo.exe.bat" - but the >> basics are there. > > Easy enough to test: > > C:\>echo echo hello! > foo.exe.bat > > C:\>foo.exe > hello! > > Yup, it does. It looks like it tries it without the extension first, though: > > C:\>copy c:\windows\notepad.exe foo.exe > 1 file(s) copied. > > C:\>foo.exe > [starts notepad] Well, at least it's consistent. Makes your PATH extremely sensitive, though, easy for anyone to inject executables into it. But then, you can already do that by putting them in the current directory, so that's not really any different. Jason's solution looks fine apart from the PATHEXT requirement, so if you know you have the full filename and you don't care if the actual command interpreter will do exactly the same, that'll do you fine. Is this something that might want to be a function in the os module? Particularly so if, as I suspect there might be, there's a Win32 API function that precisely replicates the behaviour of executable invocation. A while since I've done much Windows programming but I think there's a SearchPath function? ChrisA From gelonida at gmail.com Thu Sep 20 19:07:08 2012 From: gelonida at gmail.com (Gelonida N) Date: Fri, 21 Sep 2012 01:07:08 +0200 Subject: portable way of locating an executable (like which) In-Reply-To: References: Message-ID: On 09/21/2012 12:21 AM, Chris Angelico wrote: > On Fri, Sep 21, 2012 at 7:47 AM, Mark Lawrence wrote: >> On 20/09/2012 22:06, Gelonida N wrote: >>> >>> I'd like to implement the equivalent functionality of the unix command >>> /usr/bin/which >>> >>> The function should work under Linux and under windows. >>> >>> Did anybody already implement such a function. >> >> Searching found nothing obvious to me :( I was afraid so, but wanted to be sure >> >>> If not, is there a portable way of splitting the environment variable >>> PATH? >> With os.sep ? > > os.sep is the directory separator, but os.pathsep may be what you > want. Thanks, os.pathsep was the missing piece for portably splitting the searchpath > Between that and os.getenv('path') you can at least get the > directories. Then on Windows, you also need to check out > os.getenv('pathext') and split _that_ on the semicolon, and try each > of those as a file extension. I'm not sure whether or not Windows will > add extensions from pathext if one is given on the command line - for > instance, if typing "foo.exe" will search for "foo.exe.bat" - but the > basics are there. > For what I am doing I can even skip trying the pathexts, the ext is already given, but good to know :-) > Alternatively, there may be a Win32 API funct5ion that does this. > Would be worth a look. Yeah true, but ideally I'd like to avoid platform detection and just have a generic function. From gelonida at gmail.com Thu Sep 20 19:15:02 2012 From: gelonida at gmail.com (Gelonida N) Date: Fri, 21 Sep 2012 01:15:02 +0200 Subject: portable way of locating an executable (like which) In-Reply-To: References: Message-ID: On 09/21/2012 12:04 AM, Jason Swails wrote: > Thanks a lot Jason, > I've used the following in programs I write: > > def which(program): > def is_exe(fpath): > return os.path.exists(fpath) and os.access(fpath, os.X_OK) > > fpath, fname = os.path.split(program) > if fpath: > if is_exe(program): > return program > else: > for path in os.getenv("PATH").split(os.pathsep): > exe_file = os.path.join(path, program) > if is_exe(exe_file): > return exe_file > return None > > IIRC, I adapted it from StackOverflow. I know it works on Linux and Mac > OS X, but not sure about windows (since I don't know if PATH works the > same way there). I'll try it, the script looks reasonably portable (using os.pathsep) to really replicate which I had probably to add os.getenv('pathext') as Chris mentioned. However for my current use case this is not necessarily required. > > HTH, > Jason > > > From giuseppe.amatulli at gmail.com Thu Sep 20 19:35:15 2012 From: giuseppe.amatulli at gmail.com (giuseppe.amatulli at gmail.com) Date: Thu, 20 Sep 2012 16:35:15 -0700 (PDT) Subject: looping in array vs looping in a dic In-Reply-To: References: <007b2d71-3355-4085-b84f-204834b2c8d0@googlegroups.com> <505B6A00.10308@mrabarnett.plus.com> Message-ID: Hi Ian and MRAB thanks to you input i have improve the speed of my code. Definitely reading in dic() is faster. I have one more question. In the dic() I calculate the sum of the values, but i want count also the number of observation, in order to calculate the average in the end. Should i create a new dic() or is possible to do in the same dic(). Here in the final code. Thanks Giuseppe rows = dsCategory.RasterYSize cols = dsCategory.RasterXSize print("Generating output file %s" %(dst_file)) start = time() unique=dict() for irows in xrange(rows): valuesRaster=dsRaster.GetRasterBand(1).ReadAsArray(0,irows,cols,1) valuesCategory=dsCategory.GetRasterBand(1).ReadAsArray(0,irows,cols,1) for icols in xrange(cols): if ( valuesRaster[0,icols] != no_data_Raster ) and ( valuesCategory[0,icols] != no_data_Category ) : row = valuesCategory[0, icols],valuesRaster[0, icols] if row[0] in unique : unique[row[0]] += row[1] else: unique[row[0]] = 0+row[1] # this 0 was add if not the first observation was considered = 0 From giuseppe.amatulli at gmail.com Thu Sep 20 19:35:15 2012 From: giuseppe.amatulli at gmail.com (giuseppe.amatulli at gmail.com) Date: Thu, 20 Sep 2012 16:35:15 -0700 (PDT) Subject: looping in array vs looping in a dic In-Reply-To: References: <007b2d71-3355-4085-b84f-204834b2c8d0@googlegroups.com> <505B6A00.10308@mrabarnett.plus.com> Message-ID: Hi Ian and MRAB thanks to you input i have improve the speed of my code. Definitely reading in dic() is faster. I have one more question. In the dic() I calculate the sum of the values, but i want count also the number of observation, in order to calculate the average in the end. Should i create a new dic() or is possible to do in the same dic(). Here in the final code. Thanks Giuseppe rows = dsCategory.RasterYSize cols = dsCategory.RasterXSize print("Generating output file %s" %(dst_file)) start = time() unique=dict() for irows in xrange(rows): valuesRaster=dsRaster.GetRasterBand(1).ReadAsArray(0,irows,cols,1) valuesCategory=dsCategory.GetRasterBand(1).ReadAsArray(0,irows,cols,1) for icols in xrange(cols): if ( valuesRaster[0,icols] != no_data_Raster ) and ( valuesCategory[0,icols] != no_data_Category ) : row = valuesCategory[0, icols],valuesRaster[0, icols] if row[0] in unique : unique[row[0]] += row[1] else: unique[row[0]] = 0+row[1] # this 0 was add if not the first observation was considered = 0 From breamoreboy at yahoo.co.uk Thu Sep 20 19:46:48 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 21 Sep 2012 00:46:48 +0100 Subject: portable way of locating an executable (like which) In-Reply-To: References: Message-ID: On 21/09/2012 00:15, Gelonida N wrote: > On 09/21/2012 12:04 AM, Jason Swails wrote: >> > Thanks a lot Jason, > > >> I've used the following in programs I write: >> >> def which(program): >> def is_exe(fpath): >> return os.path.exists(fpath) and os.access(fpath, os.X_OK) >> >> fpath, fname = os.path.split(program) >> if fpath: >> if is_exe(program): >> return program >> else: >> for path in os.getenv("PATH").split(os.pathsep): >> exe_file = os.path.join(path, program) >> if is_exe(exe_file): >> return exe_file >> return None >> >> IIRC, I adapted it from StackOverflow. I know it works on Linux and Mac >> OS X, but not sure about windows (since I don't know if PATH works the >> same way there). > > I'll try it, the script looks reasonably portable (using os.pathsep) > to really replicate which I had probably to add os.getenv('pathext') > as Chris mentioned. > However for my current use case this is not necessarily required. >> >> HTH, >> Jason >> >> >> > > http://nedbatchelder.com/code/utilities/wh_py.html -- Cheers. Mark Lawrence. From python at mrabarnett.plus.com Thu Sep 20 19:58:03 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 21 Sep 2012 00:58:03 +0100 Subject: looping in array vs looping in a dic In-Reply-To: References: <007b2d71-3355-4085-b84f-204834b2c8d0@googlegroups.com> <505B6A00.10308@mrabarnett.plus.com> Message-ID: <505BAD8B.5040104@mrabarnett.plus.com> On 2012-09-21 00:35, giuseppe.amatulli at gmail.com wrote: > Hi Ian and MRAB > thanks to you input i have improve the speed of my code. Definitely reading in dic() is faster. I have one more question. > In the dic() I calculate the sum of the values, but i want count also the number of observation, in order to calculate the average in the end. > Should i create a new dic() or is possible to do in the same dic(). > Here in the final code. > Thanks Giuseppe > Keep it simple. Use 2 dicts. > > > rows = dsCategory.RasterYSize > cols = dsCategory.RasterXSize > > print("Generating output file %s" %(dst_file)) > > start = time() > > unique=dict() > > for irows in xrange(rows): > valuesRaster=dsRaster.GetRasterBand(1).ReadAsArray(0,irows,cols,1) > valuesCategory=dsCategory.GetRasterBand(1).ReadAsArray(0,irows,cols,1) > for icols in xrange(cols): > if ( valuesRaster[0,icols] != no_data_Raster ) and ( valuesCategory[0,icols] != no_data_Category ) : > row = valuesCategory[0, icols],valuesRaster[0, icols] > if row[0] in unique : > unique[row[0]] += row[1] > else: > unique[row[0]] = 0+row[1] # this 0 was add if not the first observation was considered = 0 > You could use defaultdict instead: from collections import defaultdict unique = defaultdict(int) ... category, raster = valuesCategory[0, icols], valuesRaster[0, icols] unique[category] += raster From nobody at nowhere.com Thu Sep 20 19:59:53 2012 From: nobody at nowhere.com (Nobody) Date: Fri, 21 Sep 2012 00:59:53 +0100 Subject: portable way of locating an executable (like which) References: Message-ID: On Thu, 20 Sep 2012 23:06:46 +0200, Gelonida N wrote: > I'd like to implement the equivalent functionality of the unix command > /usr/bin/which > > The function should work under Linux and under windows. Note that "which" attempts to emulate the behaviour of execvp() etc. The exec(3) manpage will explain the precise algorithm used (e.g. they skip files for which the process lacks execute permission). Also, note that the shell has built-in commands, functions, and aliases in addition to programs. The "type" built-in command performs a similar function to "which" but using the shell's semantics. On some systems, the default configuration may alias "which" to "type". On Windows, there's a host of different "execute program" interface, all with subtly different semantics: which extensions they will run, which extensions can be omitted, which paths are used (e.g. %PATH%, paths from the registry, current directory). From d at davea.name Thu Sep 20 22:31:17 2012 From: d at davea.name (Dave Angel) Date: Thu, 20 Sep 2012 22:31:17 -0400 Subject: portable way of locating an executable (like which) In-Reply-To: References: Message-ID: <505BD175.408@davea.name> On 09/20/2012 06:04 PM, Jason Swails wrote: > On Thu, Sep 20, 2012 at 5:06 PM, Gelonida N wrote: > >> I'd like to implement the equivalent functionality of the unix command >> /usr/bin/which >> >> The function should work under Linux and under windows. >> >> Did anybody already implement such a function. >> If not, is there a portable way of splitting the environment variable PATH? >> > I've used the following in programs I write: > > def which(program): > def is_exe(fpath): > return os.path.exists(fpath) and os.access(fpath, os.X_OK) > > fpath, fname = os.path.split(program) > if fpath: > if is_exe(program): > return program > else: > for path in os.getenv("PATH").split(os.pathsep): > exe_file = os.path.join(path, program) > if is_exe(exe_file): > return exe_file > return None > > IIRC, I adapted it from StackOverflow. I know it works on Linux and Mac OS > X, but not sure about windows (since I don't know if PATH works the same > way there). > I don't have a Windows machine set up right now, but I believe there are two more directories to search, besides the ones described in the PATH variable. One is the current directory, and the other is the Windows directory (maybe also the xxx/system32 or something). They don't have analogues in Linux or Mac, as far as I know. -- DaveA From bahamutzero8825 at gmail.com Thu Sep 20 22:57:14 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 20 Sep 2012 21:57:14 -0500 Subject: portable way of locating an executable (like which) In-Reply-To: <505BD175.408@davea.name> References: <505BD175.408@davea.name> Message-ID: <505BD78A.9040002@gmail.com> On 2012.09.20 21:31, Dave Angel wrote: > I don't have a Windows machine set up right now, but I believe there are > two more directories to search, besides the ones described in the PATH > variable. > > One is the current directory, and the other is the Windows directory > (maybe also the xxx/system32 or something). Those system directories are in the path by default. -- CPython 3.3.0rc2 | Windows NT 6.1.7601.17835 From robertmiles at teranews.com Fri Sep 21 01:22:05 2012 From: robertmiles at teranews.com (Robert Miles) Date: Fri, 21 Sep 2012 00:22:05 -0500 Subject: Obnoxious postings from Google Groups In-Reply-To: <87wqzum7h6.fsf_-_@benfinney.id.au> References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> Message-ID: On 9/16/2012 8:18 AM, Ben Finney wrote: > ???????? ?????? writes: > >> Iam sorry i didnt do that on purpose and i dont know how this is done. >> >> Iam positng via google groups using chrome, thats all i know. > > It is becoming quite clear that some change has happened recently to > Google Groups that makes posts coming from there rather more obnoxious > than before. And there doesn't seem to be much its users can do except > use something else. > > Using Google Groups for posting to Usenet has been a bad idea for a long > time, but now it just seems to be a sure recipe for annoying the rest of > us. Again, not something you have much control over, except to stop > using Google Groups. Could this mean that Google wants all the spam posted through Google Groups to look obnoxious to the rest of Usenet that the spammers will go elsewhere? Robert Miles From vineet.deodhar at gmail.com Fri Sep 21 01:34:48 2012 From: vineet.deodhar at gmail.com (Vineet) Date: Thu, 20 Sep 2012 22:34:48 -0700 (PDT) Subject: python idioms : some are confusing Message-ID: <3ab545f9-6077-4a29-a0f6-0ada35ab6bd9@googlegroups.com> Amongst the python idioms, how the below-mentioned make sense? ## There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. --- In programming, there can be a number of ways, equally efficient, to do certain thing. ## Although never is often better than *right* now. --- How come "never" is better that "right now" ? Any thoughts?... From wuwei23 at gmail.com Fri Sep 21 01:52:45 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 20 Sep 2012 22:52:45 -0700 (PDT) Subject: python idioms : some are confusing References: <3ab545f9-6077-4a29-a0f6-0ada35ab6bd9@googlegroups.com> Message-ID: <684fdcdc-405a-42da-b112-7ffd2fc77580@t2g2000pbt.googlegroups.com> On Sep 21, 3:34?pm, Vineet wrote: > Amongst the python idioms, how the below-mentioned make sense? > ## There should be one-- and preferably only one --obvious way to do it. > --- In programming, there can be a number of ways, equally efficient, to do certain ?thing. This isn't talking about your Python code as much as about Python itself. For example, in Python 2.x you can use either `open` or `file` to open a file, with `file` being a factory function for creating file objects, and `open` using it internally. In Python 3.x, `file` is no longer a built-in, as it produced a point of confusion as to which was the one obvious way to open a file. > ## Although never is often better than *right* now. > --- How come "never" is better that "right now" ? It's better to not add a language feature than it is to add it poorly, especially when you endeavour to provide backwards compatibility as much as possible within major versions. From clp2 at rebertia.com Fri Sep 21 02:04:11 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 20 Sep 2012 23:04:11 -0700 Subject: python idioms : some are confusing In-Reply-To: <3ab545f9-6077-4a29-a0f6-0ada35ab6bd9@googlegroups.com> References: <3ab545f9-6077-4a29-a0f6-0ada35ab6bd9@googlegroups.com> Message-ID: On Thu, Sep 20, 2012 at 10:34 PM, Vineet wrote: > Amongst the python idioms, how the below-mentioned make sense? These aren't idioms (that term has a specific technical meaning in programming); they're *way* too abstract to be idioms. "Design principles" or "design guidelines" would be a better description. > ## There should be one-- and preferably only one --obvious way to do it. > Although that way may not be obvious at first unless you're Dutch. > > --- In programming, there can be a number of ways, equally efficient, to do certain thing. Yes, but that brings with it the cost of having to understand/learn them all, because you'll encounter them when reading/maintaining/modifying others' code. And you'll have to evaluate them all to choose which one you should use (which might even vary from moment to moment depending on the circumstances). And you'll have to watch out for subtle variants that actually do something significantly different. Better to keep things simple in the X% of cases where the differences don't matter enough, and save those brain cycles for other, more important things. See also: the so-called "paradox of choice". Further reading: the criticisms on http://c2.com/cgi/wiki?ThereIsMoreThanOneWayToDoIt > ## Although never is often better than *right* now. > > --- How come "never" is better that "right now" ? Because "right now" is so quick that it was likely hastily hacked together and thus of poor (or at least lesser) quality. Cheers, Chris From vineet.deodhar at gmail.com Fri Sep 21 02:05:31 2012 From: vineet.deodhar at gmail.com (Vineet) Date: Thu, 20 Sep 2012 23:05:31 -0700 (PDT) Subject: python idioms : some are confusing In-Reply-To: <684fdcdc-405a-42da-b112-7ffd2fc77580@t2g2000pbt.googlegroups.com> References: <3ab545f9-6077-4a29-a0f6-0ada35ab6bd9@googlegroups.com> <684fdcdc-405a-42da-b112-7ffd2fc77580@t2g2000pbt.googlegroups.com> Message-ID: <65781ceb-8b2c-45b6-945f-7f7c697e9892@googlegroups.com> Oh I see ! On these lines mentioned by you, I can now sense the sense. Thanks. On Friday, 21 September 2012 11:22:45 UTC+5:30, alex23 wrote: > On Sep 21, 3:34?pm, Vineet wrote: > > > Amongst the python idioms, how the below-mentioned make sense? > > > ## There should be one-- and preferably only one --obvious way to do it. > > > --- In programming, there can be a number of ways, equally efficient, to do certain ?thing. > > > > This isn't talking about your Python code as much as about Python > > itself. For example, in Python 2.x you can use either `open` or `file` > > to open a file, with `file` being a factory function for creating file > > objects, and `open` using it internally. In Python 3.x, `file` is no > > longer a built-in, as it produced a point of confusion as to which was > > the one obvious way to open a file. > > > > > ## Although never is often better than *right* now. > > > --- How come "never" is better that "right now" ? > > > > It's better to not add a language feature than it is to add it poorly, > > especially when you endeavour to provide backwards compatibility as > > much as possible within major versions. From rosuav at gmail.com Fri Sep 21 02:07:13 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Sep 2012 16:07:13 +1000 Subject: python idioms : some are confusing In-Reply-To: <684fdcdc-405a-42da-b112-7ffd2fc77580@t2g2000pbt.googlegroups.com> References: <3ab545f9-6077-4a29-a0f6-0ada35ab6bd9@googlegroups.com> <684fdcdc-405a-42da-b112-7ffd2fc77580@t2g2000pbt.googlegroups.com> Message-ID: I'm responding to the OP here, not to Alex, but I'm quoting his text to expand on it. :) On Fri, Sep 21, 2012 at 3:52 PM, alex23 wrote: > On Sep 21, 3:34 pm, Vineet wrote: >> Amongst the python idioms, how the below-mentioned make sense? >> ## There should be one-- and preferably only one --obvious way to do it. >> --- In programming, there can be a number of ways, equally efficient, to do certain thing. > > This isn't talking about your Python code as much as about Python > itself. The "it" in the zen there refers to some programming task. For instance, there's only one obvious way to increment an integer: spam += 1 Python's philosophy is to have just that, and to not trouble itself with "spam++" and "++spam" and the distinction between them. As a C programmer, I'm quite accustomed to them, and know what they mean, but not everyone does. And don't get me started on "&&" vs "and" in PHP... Python is a simpler and cleaner language for not having superfluous operators. >> ## Although never is often better than *right* now. >> --- How come "never" is better that "right now" ? > > It's better to not add a language feature than it is to add it poorly, > especially when you endeavour to provide backwards compatibility as > much as possible within major versions. The compatibility issue is the thing here. It's better to get something good now rather than dither for another fifty years, because the longer you dally, the more code will be written using third party libraries. But it's better to not put it into the standard library at all than to put in a messy API that now can't be changed because code's using it. The Zen of Python is a whole lot of tradeoffs and ideas. Several of them balance each other directly. Some, while not contradicted in the Zen itself, are still violated at times in the language and/or stdlib. They're principles, not laws, and need to be read with the understanding that people who write code are intelligent, thinking beings (though a quick look at TheDailyWTF.com proves that this is not universal). ChrisA From cosmius at gmail.com Fri Sep 21 02:22:07 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Thu, 20 Sep 2012 23:22:07 -0700 (PDT) Subject: Is there a public API equvalent for urllib2.parse_http_list? Message-ID: I'm porting my code to python3, and found there is no parse_http_list in any module of urllib of python3. So, is there a public API equvalent for urllib2.parse_http_list? Thanks. -------- Cosmia Luna From steve+comp.lang.python at pearwood.info Fri Sep 21 02:23:57 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Sep 2012 06:23:57 GMT Subject: python idioms : some are confusing References: <3ab545f9-6077-4a29-a0f6-0ada35ab6bd9@googlegroups.com> Message-ID: <505c07fc$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 20 Sep 2012 22:34:48 -0700, Vineet wrote: > Amongst the python idioms, how the below-mentioned make sense? They're not Python idioms. Idioms are common pieces of code, like looping: for item in sequence: do_something What you have quoted are parts of the Zen of Python, which is deliberately named. Zen koans are notorious for being contradictory and impossible to understand. As Terry Pratchett wrote: In the second scroll of Wen the Eternally Surprised a story is written concerning one day when the apprentice Clodpool, in a rebellious mood, approached Wen and spake thusly: "Master, what is the difference between a humanistic, monastic system of belief in which wisdom is sought by means of an apparently nonsensical system of questions and answers, and a lot of mystic gibberish made up on the spur of the moment?" Wen considered this for some time, and at last said: "A fish!" And Clodpool went away, satisfied. -- (Terry Pratchett, Thief of Time) So be careful about over-interpreting the Zen of Python. Half of it is meant to followed seriously, half is meant as a joke, and half is meant as a guideline only. > ## There should be one-- and preferably only one --obvious way to do it. > Although that way may not be obvious at first unless you're Dutch. This tells us that for any task you might want to do in Python, there should be some way to do it which is obvious. It is not enough that there is some (hard to find, convoluted) way to do it, it should be obvious. And while it isn't forbidden to be two or more obvious ways, it is better if there is only one. The joke is that even this single sentence goes against its own advice. There are at least three obvious ways to put a parenthetical aside in a sentence: There should be one--and preferably only one--obvious way to do it. There should be one -- and preferably only one -- obvious way to do it. There should be one (and preferably only one) obvious way to do it. The author of the Zen deliberately choose a fourth, non-obvious way. Finally, the second line warns that although Python has many obvious ways to solve things, they may only be obvious to the creator of Python, Guido van Rossum, who is Dutch. > --- In programming, there can be a number of ways, equally efficient, to > do certain thing. The Zen refers to the philosophy that Python the language should provide an obvious way to solve a problem. The emphasis is on the *obvious* part, not the *one* part. > ## Although never is often better than *right* now. > > --- How come "never" is better that "right now" ? Solving a problem in the language -- adding a new language feature such as a keyword, new syntax, a library, etc. -- should only be done when that new feature brings more benefit than problems. But sometimes a new feature might bring more problems than benefits. In this case, it is better to *never* solve that problem *in the language* than to add a feature that solves the problem badly and causes more problems than it solves. E.g. multi-line lambdas. The problem is that once you add a feature to the language, it becomes almost impossible to remove it. You are stuck with it nearly forever, or at least for many years. So better to not add it than to be stuck with a bad feature. -- Steven From cosmius at gmail.com Fri Sep 21 02:26:39 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Thu, 20 Sep 2012 23:26:39 -0700 (PDT) Subject: Is there a public API equvalent for urllib2.parse_http_list? In-Reply-To: References: Message-ID: <49d7f9ab-0d0f-4abc-ae68-e01c803fd0b1@googlegroups.com> On Friday, September 21, 2012 2:22:08 PM UTC+8, Cosmia Luna wrote: > I'm porting my code to python3, and found there is no parse_http_list in any module of urllib of python3. > > > > So, is there a public API equvalent for urllib2.parse_http_list? > > > > Thanks. > > > > -------- > > Cosmia Luna I'm sorry, but I found it at urllib.request.parse_http_list. But I still want to know where is a DOCUMENTED equivalent of this function, or the python team forgot to document it? Thanks. -------- Cosmia Luna From santhosh.sweetmemory at gmail.com Fri Sep 21 02:27:05 2012 From: santhosh.sweetmemory at gmail.com (santhosh.sweetmemory at gmail.com) Date: Thu, 20 Sep 2012 23:27:05 -0700 (PDT) Subject: Storing of folder structure in SQL DB In-Reply-To: <1175854371.476464.125540@d57g2000hsg.googlegroups.com> References: <1175774302.652656.285260@d57g2000hsg.googlegroups.com> <1175854371.476464.125540@d57g2000hsg.googlegroups.com> Message-ID: <75a8d5b3-9ffc-4427-b725-86922e80d41f@googlegroups.com> folderid name parentid 1 cricket 0 2 india 1 3 sachin 2 4 tennis 0 5 saniamirza 4 i need coding for this table..folder id 'll automatically populate.. From steve+comp.lang.python at pearwood.info Fri Sep 21 02:29:10 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Sep 2012 06:29:10 GMT Subject: python idioms : some are confusing References: <3ab545f9-6077-4a29-a0f6-0ada35ab6bd9@googlegroups.com> <684fdcdc-405a-42da-b112-7ffd2fc77580@t2g2000pbt.googlegroups.com> Message-ID: <505c0935$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 20 Sep 2012 22:52:45 -0700, alex23 wrote: > On Sep 21, 3:34?pm, Vineet wrote: >> Amongst the python idioms, how the below-mentioned make sense? ## There >> should be one-- and preferably only one --obvious way to do it. --- In >> programming, there can be a number of ways, equally efficient, to do >> certain ?thing. > > This isn't talking about your Python code as much as about Python > itself. For example, in Python 2.x you can use either `open` or `file` > to open a file, with `file` being a factory function for creating file > objects, and `open` using it internally. In Python 3.x, `file` is no > longer a built-in, as it produced a point of confusion as to which was > the one obvious way to open a file. I don't think that's the reason. I think the reason is that moving the built-in file into the _io library gives the developers a lot more flexibility in how they handle text and binary files. E.g.: py> open('junk', 'w') <_io.TextIOWrapper name='junk' mode='w' encoding='UTF-8'> py> open('junk', 'wb') <_io.BufferedWriter name='junk'> py> open('junk', 'wb', buffering=0) <_io.FileIO name='junk' mode='wb'> The open() function now can return three (or more?) types instead of having a single built-in type handle all cases. -- Steven From santhosh.sweetmemory at gmail.com Fri Sep 21 02:43:22 2012 From: santhosh.sweetmemory at gmail.com (santhosh.sweetmemory at gmail.com) Date: Thu, 20 Sep 2012 23:43:22 -0700 (PDT) Subject: Storing of folder structure in SQL DB In-Reply-To: <75a8d5b3-9ffc-4427-b725-86922e80d41f@googlegroups.com> References: <1175774302.652656.285260@d57g2000hsg.googlegroups.com> <1175854371.476464.125540@d57g2000hsg.googlegroups.com> <75a8d5b3-9ffc-4427-b725-86922e80d41f@googlegroups.com> Message-ID: <5b5602e1-ee4e-4ada-9b22-bab6f8bf534b@googlegroups.com> On Friday, September 21, 2012 11:57:05 AM UTC+5:30, santhosh.s... at gmail.com wrote: > folderid name parentid > > > > 1 cricket 0 > > 2 india 1 > > 3 sachin 2 > > 4 tennis 0 > > 5 saniamirza 4 > > > > i need coding for this table..folder id 'll automatically populate.. in asp.net or sql From __peter__ at web.de Fri Sep 21 03:42:32 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 21 Sep 2012 09:42:32 +0200 Subject: [Q] How to exec code object with local variables specified? References: Message-ID: Makoto Kuwata wrote: > On Thu, Sep 20, 2012 at 10:15 PM, Peter Otten <__peter__ at web.de> wrote: >> >>>>> loc = {} >>>>> exec("x = 1; y = 2", globals(), loc) >>>>> loc >> {'y': 2, 'x': 1} >> >> However, this won't work with the code object taken from a function which >> uses a different a bytecode (STORE_FAST instead of STORE_NAME): >> > > Is there any way to use STORE_FAST instead of STORE_NAME? > > exec("string", ...) is not a solution for me. Can you describe your use-case? Perhaps we can suggest an alternative approach. > # What is different between fn.func_code and compile("string")? func_code has faster bytecode at the expense of flexibility. From tarek at ziade.org Fri Sep 21 04:12:29 2012 From: tarek at ziade.org (=?ISO-8859-1?Q?Tarek_Ziad=E9?=) Date: Fri, 21 Sep 2012 10:12:29 +0200 Subject: portable way of locating an executable (like which) In-Reply-To: References: Message-ID: <505C216D.7070807@ziade.org> On 9/21/12 1:59 AM, Nobody wrote: > On Thu, 20 Sep 2012 23:06:46 +0200, Gelonida N wrote: > >> I'd like to implement the equivalent functionality of the unix command >> /usr/bin/which >> >> The function should work under Linux and under windows. > Note that "which" attempts to emulate the behaviour of execvp() etc. The > exec(3) manpage will explain the precise algorithm used (e.g. they skip > files for which the process lacks execute permission). > > Also, note that the shell has built-in commands, functions, and aliases in > addition to programs. The "type" built-in command performs a similar > function to "which" but using the shell's semantics. On some systems, > the default configuration may alias "which" to "type". > > On Windows, there's a host of different "execute program" interface, all > with subtly different semantics: which extensions they will run, which > extensions can be omitted, which paths are used (e.g. %PATH%, paths > from the registry, current directory). > You can also look at shutil.which http://hg.python.org/cpython/file/aa153b827d17/Lib/shutil.py#l974 Mmmm I wonder why it's removed in the last revs.. From rosuav at gmail.com Fri Sep 21 04:23:34 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Sep 2012 18:23:34 +1000 Subject: Functional way to compare things inside a list In-Reply-To: <63673.77.105.185.196.1348181901.squirrel@lavabit.com> References: <63673.77.105.185.196.1348181901.squirrel@lavabit.com> Message-ID: On Fri, Sep 21, 2012 at 8:58 AM, wrote: > Hi, > > list = [{'1': []}, {'2': []}, {'3': ['4', '5']}] > > I want to check for a value (e.g. '4'), and get the key of the dictionary > that contains that value. > (Yep, this is bizarre.) > > some_magic(list, '4') > => '3' > > What's the functional way to do it? > Is it possible to do it with a one-liner? I'm thinking here of a list comprehension, filter(), and next() to grab the first element. Let's see... By the way, I wouldn't use 'list' as a variable name; you shadow the built-in type. lst = [{'1': []}, {'2': []}, {'3': ['4', '5']}] def find_n(n,dic): for key,searchme in dic.items(): if n in searchme: return key next(filter(None,[find_n('4',x) for x in lst])) That gets the result, but probably not in the cleanest way. I'm not sure off-hand if Python has a convenient way to curry a function, but if so, you could make the filter call rather simpler. Note that this is written for Python 3, where filter() returns an iterator, thus the algorithm is lazy and thus efficient (a very Australian way to do things). ChrisA Proudly Australian, proudly lazy! From ivan.cvetkovic at pakel.hr Fri Sep 21 04:24:40 2012 From: ivan.cvetkovic at pakel.hr (Ivan@work) Date: Fri, 21 Sep 2012 10:24:40 +0200 Subject: Functional way to compare things inside a list In-Reply-To: References: Message-ID: On 21.09.2012 00:58, thorsopia at lavabit.com wrote: > Hi, > > list = [{'1': []}, {'2': []}, {'3': ['4', '5']}] > > I want to check for a value (e.g. '4'), and get the key of the dictionary > that contains that value. > (Yep, this is bizarre.) > > some_magic(list, '4') > => '3' > > What's the functional way to do it? > Is it possible to do it with a one-liner? > > Yes: [key for d in list for key in d if '4' in d[key]] From clp2 at rebertia.com Fri Sep 21 04:28:41 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 21 Sep 2012 01:28:41 -0700 Subject: Functional way to compare things inside a list In-Reply-To: References: <63673.77.105.185.196.1348181901.squirrel@lavabit.com> Message-ID: On Fri, Sep 21, 2012 at 1:23 AM, Chris Angelico wrote: > On Fri, Sep 21, 2012 at 8:58 AM, wrote: > That gets the result, but probably not in the cleanest way. I'm not > sure off-hand if Python has a convenient way to curry a function, http://docs.python.org/library/functools.html#functools.partial Cheers, Chris of the Northern Hemisphere From rosuav at gmail.com Fri Sep 21 04:31:04 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Sep 2012 18:31:04 +1000 Subject: Functional way to compare things inside a list In-Reply-To: References: <63673.77.105.185.196.1348181901.squirrel@lavabit.com> Message-ID: On Fri, Sep 21, 2012 at 6:28 PM, Chris Rebert wrote: > On Fri, Sep 21, 2012 at 1:23 AM, Chris Angelico wrote: >> On Fri, Sep 21, 2012 at 8:58 AM, wrote: > >> That gets the result, but probably not in the cleanest way. I'm not >> sure off-hand if Python has a convenient way to curry a function, > > http://docs.python.org/library/functools.html#functools.partial Thanks, that'd be it; didn't come up in a quick search for 'curry' (for obvious reason). So it would probably be possible to do it as a one-liner with a honking big lambda, but if code clarity is what you want, I'd go with the externally-defined function. > Cheers, > Chris of the Northern Hemisphere :) ChrisA From news at blinne.net Fri Sep 21 04:31:40 2012 From: news at blinne.net (Alexander Blinne) Date: Fri, 21 Sep 2012 10:31:40 +0200 Subject: Functional way to compare things inside a list In-Reply-To: References: Message-ID: <505c25ed$0$6581$9b4e6d93@newsspool3.arcor-online.net> On 21.09.2012 00:58, thorsopia at lavabit.com wrote: > Hi, > > list = [{'1': []}, {'2': []}, {'3': ['4', '5']}] > > I want to check for a value (e.g. '4'), and get the key of the dictionary > that contains that value. > (Yep, this is bizarre.) > > some_magic(list, '4') > => '3' > > What's the functional way to do it? > Is it possible to do it with a one-liner? simple, but possibly slow solution: import itertools def some_magic(list, search): return (key for key, val in itertools.chain(*(d.iteritems() for d in list)) if search in val).next() one-liner, yeah... From clp2 at rebertia.com Fri Sep 21 04:33:38 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 21 Sep 2012 01:33:38 -0700 Subject: Functional way to compare things inside a list In-Reply-To: <63673.77.105.185.196.1348181901.squirrel@lavabit.com> References: <63673.77.105.185.196.1348181901.squirrel@lavabit.com> Message-ID: On Thu, Sep 20, 2012 at 3:58 PM, wrote: > Hi, > > list = [{'1': []}, {'2': []}, {'3': ['4', '5']}] Are the dictionaries each guaranteed to only contain a single key-value pair? (Or is your example just simplistic?) > I want to check for a value (e.g. '4'), and get the key of the dictionary > that contains that value. And what if there is no such dictionary? Or what if there are multiple such dictionaries? > (Yep, this is bizarre.) > > some_magic(list, '4') > => '3' > > What's the functional way to do it? Why do you care about the paradigm used? > Is it possible to do it with a one-liner? Who cares? It's possible to implement more complicated things in one line of APL, but most people probably wouldn't recommend it. Regards, Chris R. From tarek at ziade.org Fri Sep 21 04:48:45 2012 From: tarek at ziade.org (=?ISO-8859-1?Q?Tarek_Ziad=E9?=) Date: Fri, 21 Sep 2012 10:48:45 +0200 Subject: "Development mode" In-Reply-To: <3142822a-9e66-413c-ac21-4363ba882bc3@googlegroups.com> References: <3142822a-9e66-413c-ac21-4363ba882bc3@googlegroups.com> Message-ID: <505C29ED.20207@ziade.org> On 9/20/12 9:02 PM, py_lrnr wrote: > I am new to python and I have come across the following command and its description: > >> Now to be able to run the project you will need to install it and its >dependencies. >> python setup.py develop > I looked up what the 'develop' argument does and found: > >> Extra commands: >> develop install package in 'development mode' > I searched for a description of 'development mode' but could not find a good description. > > Can anyone (very briefly) explain to me, in a sentence or two: > > what 'development mode' is? > how 'development mode' differs from other 'modes'? > why/when I would use 'development mode'? > what 'development mode' does or does not allow me to do? > > Many thanks in advance. This a setuptools / distribute feature that allows you to add a project to your Python environment without installing it - so you can continue its "development" In other words, when you call "python setup.py develop", setuptools will compile the metadata and hook your project into Python's site-package, but the packages and modules that will be used are the one in the directory where you've run that command. This is useful to continue working on your code and testing it without having to run "python setup.py install" on every run see http://packages.python.org/distribute/setuptools.html#develop-deploy-the-project-source-in-development-mode From ulrich.eckhardt at dominolaser.com Fri Sep 21 04:52:31 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 21 Sep 2012 10:52:31 +0200 Subject: Functional way to compare things inside a list In-Reply-To: References: Message-ID: Am 21.09.2012 00:58, schrieb thorsopia at lavabit.com: > list = [{'1': []}, {'2': []}, {'3': ['4', '5']}] > > I want to check for a value (e.g. '4'), and get the key of the dictionary > that contains that value. Note: 1. list is a built-in type, who's name is rebound above 2. The list above contains dictionaries that all only contain a single key? 3. You have strings containing decimal representations of numbers? > (Yep, this is bizarre.) The data are really stored in a strange way and you might be able to make things clearer by reorganizing them a bit. > some_magic(list, '4') > => '3' > > What's the functional way to do it? Functional as in functional programming and an emphasis on lazy evaluation? In that case I'd write a generator that emits the keys where the values contain the requested string. > Is it possible to do it with a one-liner? Yep, filter(), lambda and the 'in' operator. Question remains if this is readable. Note that you can use a local function, too, if you just want to reduce the scope/visibility. Good luck! Uli From mayuresh at kathe.in Fri Sep 21 04:56:04 2012 From: mayuresh at kathe.in (Mayuresh Kathe) Date: Fri, 21 Sep 2012 14:26:04 +0530 Subject: Algorithms using Python? Message-ID: Is there a good book on foundational as well as advanced algorithms using Python? Thanks. From nameDOTsurname at gmail.com Fri Sep 21 05:10:07 2012 From: nameDOTsurname at gmail.com (Marco) Date: Fri, 21 Sep 2012 11:10:07 +0200 Subject: Python 3.3 and .pyo files Message-ID: I was trying to import a pyo module in Python 3.3, but Python does not find it: $ echo "print(__file__)" > foo.py $ python3.3 -O -m foo /home/marco/temp/foo.py $ ls foo.py __pycache__ $ rm foo.py $ mv __pycache__/foo.cpython-33.pyo foo.pyo $ rm __pycache__ -r $ ls foo.pyo # The following works in Python3.2, but not in 3.3 $ python3.3 -O -m foo /usr/local/bin/python3.3: No module named foo How come? Thanks in advance, Marco -- Marco From janis.judvaitis at gmail.com Fri Sep 21 05:13:28 2012 From: janis.judvaitis at gmail.com (janis.judvaitis at gmail.com) Date: Fri, 21 Sep 2012 02:13:28 -0700 (PDT) Subject: Seome kind of unblocking input Message-ID: <0be9b4c2-b661-4709-ba8f-40a6f78ad634@googlegroups.com> Hello! I'm building small console like program for embedded system control over serial port. Naturally I need to be able to recieve commands from user and print reply's from embedded device. Since I'm using threads and pipes everything works ok, except that when i call input() there is no way that I could print something, is there any workaround for this?? Note: I don't need to catch any key's before enter or smtng, just be able to print while input() is waiting. I'm thinking that maybe there is a way for two threads to share one stdout, which should resolve this, but I can't make it work, since U can't pickle file like object(stdout) to pass it to other thread. Note 2: I've readed about ways to make nonblocking input by reading single char etc. but that's is all messy and very platform dependent, I would love to have platform independent solution. Thanks in advance! --JJ From tymoteusz.jankowski at gmail.com Fri Sep 21 06:07:56 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Fri, 21 Sep 2012 03:07:56 -0700 (PDT) Subject: Does python have built command for package skeleton creation? Message-ID: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> Like the topic.. . I found this: http://learnpythonthehardway.org/book/ex46.html it seems fine, but shouldn't be an interactive (with CLI API) script creating that? It's a lot of effort for common work. I can contribute but i have to know that i'm not reinvent a wheel. From hansmu at xs4all.nl Fri Sep 21 06:13:48 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 21 Sep 2012 12:13:48 +0200 Subject: portable way of locating an executable (like which) In-Reply-To: References: Message-ID: <505c3ddd$0$6883$e4fe514c@news2.news.xs4all.nl> On 21/09/12 04:31:17, Dave Angel wrote: > On 09/20/2012 06:04 PM, Jason Swails wrote: >> On Thu, Sep 20, 2012 at 5:06 PM, Gelonida N wrote: >> >>> I'd like to implement the equivalent functionality of the unix command >>> /usr/bin/which >>> >>> The function should work under Linux and under windows. >>> >>> Did anybody already implement such a function. >>> If not, is there a portable way of splitting the environment variable PATH? >>> >> I've used the following in programs I write: >> >> def which(program): >> def is_exe(fpath): >> return os.path.exists(fpath) and os.access(fpath, os.X_OK) >> >> fpath, fname = os.path.split(program) >> if fpath: >> if is_exe(program): >> return program >> else: >> for path in os.getenv("PATH").split(os.pathsep): On Posix systems, you need to insert at this point: if not path: path = "." >> exe_file = os.path.join(path, program) >> if is_exe(exe_file): >> return exe_file >> return None >> >> IIRC, I adapted it from StackOverflow. I know it works on Linux and Mac OS >> X, but not sure about windows (since I don't know if PATH works the same >> way there). > > I don't have a Windows machine set up right now, but I believe there are > two more directories to search, besides the ones described in the PATH > variable. > > One is the current directory, and the other is the Windows directory > (maybe also the xxx/system32 or something). > > They don't have analogues in Linux or Mac, as far as I know. On Posix system (inlcuding Linux and Mac OS X), the current directory is not searched by default. If there's an empty string in os.getenv("PATH").split(os.pathsep), then the current directory will be searched at that point in the part. Hope this helps, -- HansM From nospam at nospam.com Fri Sep 21 06:49:18 2012 From: nospam at nospam.com (Gilles) Date: Fri, 21 Sep 2012 12:49:18 +0200 Subject: [WSGI] FCGID + Flup vs. mod_wsgi? Message-ID: <3lgo58lfns3lc7njhkv28ee1k2q83p0u7d@4ax.com> Hello The shared host I intend to use to run a small Python web app only supports mod_fcgid on its Apache server. If I understood what I read on the Net, the ideal solution would be to have mod_wsgi installed and have it run either as a module within Apache or a stand-alone process to talk to the Python app, but it's N.A. so that's out. As for FCGID, am I correct in understanding that this is the way things work: Apache <-> mod_fcgid <-> Flup (or some other wrapper) <-> WSGI application? www.stackoverflow.com/questions/1747266/is-there-a-speed-difference-between-wsgi-and-fcgi Would I miss a lot by using the mod_fcgid+Flup solution instead of mod_wsgi? Thank you. From tarek at ziade.org Fri Sep 21 07:08:49 2012 From: tarek at ziade.org (=?ISO-8859-1?Q?Tarek_Ziad=E9?=) Date: Fri, 21 Sep 2012 13:08:49 +0200 Subject: Does python have built command for package skeleton creation? In-Reply-To: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> Message-ID: <505C4AC1.6010508@ziade.org> On 9/21/12 12:07 PM, xliiv wrote: > Like the topic.. . I found this: > > http://learnpythonthehardway.org/book/ex46.html > > it seems fine, but shouldn't be an interactive (with CLI API) script creating that? It's a lot of effort for common work. > > I can contribute but i have to know that i'm not reinvent a wheel. > > Python Paste is probably what you are looking for - see http://lucasmanual.com/mywiki/PythonPaste for example From tymoteusz.jankowski at gmail.com Fri Sep 21 08:14:36 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Fri, 21 Sep 2012 05:14:36 -0700 (PDT) Subject: Does python have built command for package skeleton creation? In-Reply-To: References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> Message-ID: <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> On Friday, September 21, 2012 1:08:23 PM UTC+2, Tarek Ziad? wrote: > On 9/21/12 12:07 PM, xliiv wrote: > > > Like the topic.. . I found this: > > > > > > http://learnpythonthehardway.org/book/ex46.html > > > > > > it seems fine, but shouldn't be an interactive (with CLI API) script creating that? It's a lot of effort for common work. > > > > > > I can contribute but i have to know that i'm not reinvent a wheel. > > > > > > > > Python Paste is probably what you are looking for - see > > http://lucasmanual.com/mywiki/PythonPaste for example It's a nice beast but: - it's not built in. Should it be? I think it should. - about readme and manifest.in: "You could add to your template a file called readme.rst . Inside of it you can add the following code that will generate this:" i dont want to add, i want it already added :).. readme is something typical, it's not rare habit for some geeks how wants to customize it all!! the same with manifest.in.. what do you think? iteractive creation is big plus.. From tymoteusz.jankowski at gmail.com Fri Sep 21 08:14:36 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Fri, 21 Sep 2012 05:14:36 -0700 (PDT) Subject: Does python have built command for package skeleton creation? In-Reply-To: References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> Message-ID: <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> On Friday, September 21, 2012 1:08:23 PM UTC+2, Tarek Ziad? wrote: > On 9/21/12 12:07 PM, xliiv wrote: > > > Like the topic.. . I found this: > > > > > > http://learnpythonthehardway.org/book/ex46.html > > > > > > it seems fine, but shouldn't be an interactive (with CLI API) script creating that? It's a lot of effort for common work. > > > > > > I can contribute but i have to know that i'm not reinvent a wheel. > > > > > > > > Python Paste is probably what you are looking for - see > > http://lucasmanual.com/mywiki/PythonPaste for example It's a nice beast but: - it's not built in. Should it be? I think it should. - about readme and manifest.in: "You could add to your template a file called readme.rst . Inside of it you can add the following code that will generate this:" i dont want to add, i want it already added :).. readme is something typical, it's not rare habit for some geeks how wants to customize it all!! the same with manifest.in.. what do you think? iteractive creation is big plus.. From steve+comp.lang.python at pearwood.info Fri Sep 21 08:55:17 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Sep 2012 12:55:17 GMT Subject: Python 3.3 and .pyo files References: Message-ID: <505c63b4$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 21 Sep 2012 11:10:07 +0200, Marco wrote: > I was trying to import a pyo module in Python 3.3, but Python does not > find it: > > $ echo "print(__file__)" > foo.py > $ python3.3 -O -m foo > /home/marco/temp/foo.py > $ ls > foo.py __pycache__ > $ rm foo.py > $ mv __pycache__/foo.cpython-33.pyo foo.pyo I cannot duplicate the creation of the foo.cpython-33.pyo file using just the -m option. I believe that you created the foo*.pyo file some other way. Nevertheless, moving along: > $ rm __pycache__ -r > $ ls > foo.pyo > # The following works in Python3.2, but not in 3.3 > $ python3.3 -O -m foo > /usr/local/bin/python3.3: No module named foo I can confirm that (1) it works using Python 3.2; (2) it doesn't work using Python 3.3; and (3) it does work in Python 3.3 if you don't use the -O option. I believe that is a bug. (Tested using Python 3.2.2 and Python 3.3.0a1) -- Steven From overhaalsgang_24_bob at me.com Fri Sep 21 08:57:57 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Fri, 21 Sep 2012 05:57:57 -0700 (PDT) Subject: How to apply the user's HTML environment in a Python programme? Message-ID: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> I'd like to write a programme that will be offered as a web service (Django), in which the user will point to a specific URL and the programme will be used to read the text of that URL. This text can be behind a username/password, but for several reasons, I don't want to know those. So I would like to set up a situation where the user logs in (if/when appropriate), points out the URL to my programme and my programme would then be able to read that particular text. I'm aware this may sound fishy. It should not be: I want the user to be fully aware and in control of this process. Any thoughts on how to approach this? Best regards, Bob From tarek at ziade.org Fri Sep 21 09:04:30 2012 From: tarek at ziade.org (=?ISO-8859-1?Q?Tarek_Ziad=E9?=) Date: Fri, 21 Sep 2012 15:04:30 +0200 Subject: Does python have built command for package skeleton creation? In-Reply-To: <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> Message-ID: <505C65DE.1040604@ziade.org> On 9/21/12 2:14 PM, xliiv wrote: > > Python Paste is probably what you are looking for - see > > http://lucasmanual.com/mywiki/PythonPaste for example > It's a nice beast but: > - it's not built in. Should it be? I think it should. You can suggest this to python-ideas but I really doubt you will get any traction. The sdtlib don't get new features these days because it's a burden to maintain high level tool on a 2 years release cycle > - about readme and manifest.in: > "You could add to your template a file called readme.rst . Inside of it you can add the following code that will generate this:" > > i dont want to add, i want it already added :).. readme is something typical, it's not rare habit for some geeks how wants to customize it all!! the same with manifest.in.. > > what do you think? iteractive creation is big plus.. I am not sure I get your remark on this. I pointed to this page to show a typical use case of building Paster Templates, so you can bootstrap your projects boiler-plate code So IOW everyone's free to create any kind of template :) Cheers Tarek From tymoteusz.jankowski at gmail.com Fri Sep 21 09:13:35 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Fri, 21 Sep 2012 06:13:35 -0700 (PDT) Subject: Does python have built command for package skeleton creation? In-Reply-To: References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> Message-ID: On Friday, September 21, 2012 3:04:02 PM UTC+2, Tarek Ziad? wrote: > On 9/21/12 2:14 PM, xliiv wrote: > > > > > > Python Paste is probably what you are looking for - see > > > > > > http://lucasmanual.com/mywiki/PythonPaste for example > > > It's a nice beast but: > > > - it's not built in. Should it be? I think it should. > > You can suggest this to python-ideas but I really doubt you will get any > > traction. The sdtlib don't get new features these days because it's a burden > > to maintain high level tool on a 2 years release cycle Why is this '2 years release cycle'? From tymoteusz.jankowski at gmail.com Fri Sep 21 09:13:35 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Fri, 21 Sep 2012 06:13:35 -0700 (PDT) Subject: Does python have built command for package skeleton creation? In-Reply-To: References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> Message-ID: On Friday, September 21, 2012 3:04:02 PM UTC+2, Tarek Ziad? wrote: > On 9/21/12 2:14 PM, xliiv wrote: > > > > > > Python Paste is probably what you are looking for - see > > > > > > http://lucasmanual.com/mywiki/PythonPaste for example > > > It's a nice beast but: > > > - it's not built in. Should it be? I think it should. > > You can suggest this to python-ideas but I really doubt you will get any > > traction. The sdtlib don't get new features these days because it's a burden > > to maintain high level tool on a 2 years release cycle Why is this '2 years release cycle'? From joel.goldstick at gmail.com Fri Sep 21 09:22:42 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 21 Sep 2012 09:22:42 -0400 Subject: How to apply the user's HTML environment in a Python programme? In-Reply-To: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> Message-ID: On Fri, Sep 21, 2012 at 8:57 AM, BobAalsma wrote: > I'd like to write a programme that will be offered as a web service (Django), in which the user will point to a specific URL and the programme will be used to read the text of that URL. > > This text can be behind a username/password, but for several reasons, I don't want to know those. > > So I would like to set up a situation where the user logs in (if/when appropriate), points out the URL to my programme and my programme would then be able to read that particular text. > > I'm aware this may sound fishy. It should not be: I want the user to be fully aware and in control of this process. > > Any thoughts on how to approach this? There are several python modules to get web pages. urllib, urllib2 and another called requests. (http://kennethreitz.com/requests-python-http-module.html) Check those out > > Best regards, > Bob > -- > http://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick From overhaalsgang_24_bob at me.com Fri Sep 21 09:31:37 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Fri, 21 Sep 2012 06:31:37 -0700 (PDT) Subject: How to apply the user's HTML environment in a Python programme? In-Reply-To: References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> Message-ID: Op vrijdag 21 september 2012 15:23:14 UTC+2 schreef Joel Goldstick het volgende: > On Fri, Sep 21, 2012 at 8:57 AM, BobAalsma wrote: > > > I'd like to write a programme that will be offered as a web service (Django), in which the user will point to a specific URL and the programme will be used to read the text of that URL. > > > > > > This text can be behind a username/password, but for several reasons, I don't want to know those. > > > > > > So I would like to set up a situation where the user logs in (if/when appropriate), points out the URL to my programme and my programme would then be able to read that particular text. > > > > > > I'm aware this may sound fishy. It should not be: I want the user to be fully aware and in control of this process. > > > > > > Any thoughts on how to approach this? > > > > There are several python modules to get web pages. urllib, urllib2 > > and another called requests. > > (http://kennethreitz.com/requests-python-http-module.html) Check > > those out > > > > > > Best regards, > > > Bob > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > > Joel Goldstick Thanks, Joel, yes, but as far as I'm aware these would all require the Python programme to have the user's username and password (or "credentials"), which I wanted to avoid. From overhaalsgang_24_bob at me.com Fri Sep 21 09:31:37 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Fri, 21 Sep 2012 06:31:37 -0700 (PDT) Subject: How to apply the user's HTML environment in a Python programme? In-Reply-To: References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> Message-ID: Op vrijdag 21 september 2012 15:23:14 UTC+2 schreef Joel Goldstick het volgende: > On Fri, Sep 21, 2012 at 8:57 AM, BobAalsma wrote: > > > I'd like to write a programme that will be offered as a web service (Django), in which the user will point to a specific URL and the programme will be used to read the text of that URL. > > > > > > This text can be behind a username/password, but for several reasons, I don't want to know those. > > > > > > So I would like to set up a situation where the user logs in (if/when appropriate), points out the URL to my programme and my programme would then be able to read that particular text. > > > > > > I'm aware this may sound fishy. It should not be: I want the user to be fully aware and in control of this process. > > > > > > Any thoughts on how to approach this? > > > > There are several python modules to get web pages. urllib, urllib2 > > and another called requests. > > (http://kennethreitz.com/requests-python-http-module.html) Check > > those out > > > > > > Best regards, > > > Bob > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > > Joel Goldstick Thanks, Joel, yes, but as far as I'm aware these would all require the Python programme to have the user's username and password (or "credentials"), which I wanted to avoid. From malaclypse2 at gmail.com Fri Sep 21 09:36:08 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Fri, 21 Sep 2012 09:36:08 -0400 Subject: How to apply the user's HTML environment in a Python programme? In-Reply-To: References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> Message-ID: On Fri, Sep 21, 2012 at 9:31 AM, BobAalsma wrote: > Thanks, Joel, yes, but as far as I'm aware these would all require the Python programme to have the user's username and password (or "credentials"), which I wanted to avoid. No matter what you do, your web service is going to have to authenticate with the remote web site. The details of that authentication are going to vary with each remote web site you want to connect to. -- Jerry From echo.hping at gmail.com Fri Sep 21 09:36:58 2012 From: echo.hping at gmail.com (echo.hping at gmail.com) Date: Fri, 21 Sep 2012 06:36:58 -0700 (PDT) Subject: how to do draw pattern with python? Message-ID: may i know how to shift the bits using only looping and branching?? x....x .x..x. ..xx.. ..xx.. .x..x. x....x xx.... ..x..x ...xx. ...xx. ..x..x xx.... .xx... x..x.. ....xx ....xx x..x.. .xx... etc.. From breamoreboy at yahoo.co.uk Fri Sep 21 09:50:36 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 21 Sep 2012 14:50:36 +0100 Subject: Does python have built command for package skeleton creation? In-Reply-To: References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> Message-ID: On 21/09/2012 14:13, xliiv wrote: > On Friday, September 21, 2012 3:04:02 PM UTC+2, Tarek Ziad? wrote: >> On 9/21/12 2:14 PM, xliiv wrote: >> >>> >> >>> Python Paste is probably what you are looking for - see >> >>> >> >>> http://lucasmanual.com/mywiki/PythonPaste for example >> >>> It's a nice beast but: >> >>> - it's not built in. Should it be? I think it should. >> >> You can suggest this to python-ideas but I really doubt you will get any >> >> traction. The sdtlib don't get new features these days because it's a burden >> >> to maintain high level tool on a 2 years release cycle > > Why is this '2 years release cycle'? > Because there aren't enough volunteers to get it done any faster? -- Cheers. Mark Lawrence. From gandalf at shopzeus.com Fri Sep 21 09:54:29 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 21 Sep 2012 15:54:29 +0200 Subject: how to do draw pattern with python? In-Reply-To: References: Message-ID: <505C7195.4080705@shopzeus.com> On 2012-09-21 15:36, echo.hping at gmail.com wrote: > may i know how to shift the bits using only looping and branching?? > > x....x > .x..x. > ..xx.. > ..xx.. > .x..x. > x....x What kinds of bits? What are these points and x-es anyway? Are they strings? Or binary data? I recommend this for reading: http://www.catb.org/esr/faqs/smart-questions.html From breamoreboy at yahoo.co.uk Fri Sep 21 09:55:30 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 21 Sep 2012 14:55:30 +0100 Subject: how to do draw pattern with python? In-Reply-To: References: Message-ID: On 21/09/2012 14:36, echo.hping at gmail.com wrote: > may i know how to shift the bits using only looping and branching?? > > x....x > .x..x. > ..xx.. > ..xx.. > .x..x. > x....x > > xx.... > ..x..x > ...xx. > ...xx. > ..x..x > xx.... > > .xx... > x..x.. > ....xx > ....xx > x..x.. > .xx... > > etc.. > You write some code and test it. If it doesn't work you cut and paste the smallest sample of code that can reproduce the problem, together with the full traceback if applicable, and you're likely to get plenty of answers. -- Cheers. Mark Lawrence. From overhaalsgang_24_bob at me.com Fri Sep 21 09:58:42 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Fri, 21 Sep 2012 06:58:42 -0700 (PDT) Subject: How to apply the user's HTML environment in a Python programme? In-Reply-To: References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> Message-ID: <3de0aac0-d7f2-4990-9428-54c89b143b9a@googlegroups.com> Op vrijdag 21 september 2012 15:36:11 UTC+2 schreef Jerry Hill het volgende: > On Fri, Sep 21, 2012 at 9:31 AM, BobAalsma wrote: > > > Thanks, Joel, yes, but as far as I'm aware these would all require the Python programme to have the user's username and password (or "credentials"), which I wanted to avoid. > > > > No matter what you do, your web service is going to have to > > authenticate with the remote web site. The details of that > > authentication are going to vary with each remote web site you want to > > connect to. > > > > -- > > Jerry Hmm, from the previous posts I get the impression that I could best solve this by asking the user for the specific combination of username, password and URL + promising not to keep any of that... OK, that does sound doable - thank you all Bob From overhaalsgang_24_bob at me.com Fri Sep 21 09:58:42 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Fri, 21 Sep 2012 06:58:42 -0700 (PDT) Subject: How to apply the user's HTML environment in a Python programme? In-Reply-To: References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> Message-ID: <3de0aac0-d7f2-4990-9428-54c89b143b9a@googlegroups.com> Op vrijdag 21 september 2012 15:36:11 UTC+2 schreef Jerry Hill het volgende: > On Fri, Sep 21, 2012 at 9:31 AM, BobAalsma wrote: > > > Thanks, Joel, yes, but as far as I'm aware these would all require the Python programme to have the user's username and password (or "credentials"), which I wanted to avoid. > > > > No matter what you do, your web service is going to have to > > authenticate with the remote web site. The details of that > > authentication are going to vary with each remote web site you want to > > connect to. > > > > -- > > Jerry Hmm, from the previous posts I get the impression that I could best solve this by asking the user for the specific combination of username, password and URL + promising not to keep any of that... OK, that does sound doable - thank you all Bob From d at davea.name Fri Sep 21 10:00:33 2012 From: d at davea.name (Dave Angel) Date: Fri, 21 Sep 2012 10:00:33 -0400 Subject: how to do draw pattern with python? In-Reply-To: References: Message-ID: <505C7301.90706@davea.name> On 09/21/2012 09:36 AM, echo.hping at gmail.com wrote: > may i know how to shift the bits using only looping and branching?? Yes, show us your code, and what isn't working, and we'll try to help you complete the assignment. It'd probably also be good to specify the rest of the homework, like what version of what language it has to be implemented in. I don't see any bits, only strings of characters. And it seems to me that using slices is the most obvious mechanism for rotating fixed-length strings. > x....x > .x..x. > ..xx.. > ..xx.. > .x..x. > x....x > > xx.... > ..x..x > ...xx. > ...xx. > ..x..x > xx.... > > .xx... > x..x.. > ....xx > ....xx > x..x.. > .xx... > > etc.. -- DaveA From michele.cecere at gmail.com Fri Sep 21 10:04:48 2012 From: michele.cecere at gmail.com (mikcec82) Date: Fri, 21 Sep 2012 07:04:48 -0700 (PDT) Subject: Blue Screen Python Message-ID: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> Hallo to all, I'm using Python 2.7.3 with Windows 7 @ 64 bit and an Intel Core i3 -2350M CPU @2.30GHz 2.3GHz. Sometimes, when I'm programming in Python on my screen compare this blue screen: http://imageshack.us/a/img228/8352/48579647436249494527021.jpg Can you help on what is the issue, and how I can solve it? If you need more info I'm available. Thank you so much, Michele From joel.goldstick at gmail.com Fri Sep 21 10:15:26 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 21 Sep 2012 10:15:26 -0400 Subject: How to apply the user's HTML environment in a Python programme? In-Reply-To: <3de0aac0-d7f2-4990-9428-54c89b143b9a@googlegroups.com> References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> <3de0aac0-d7f2-4990-9428-54c89b143b9a@googlegroups.com> Message-ID: On Fri, Sep 21, 2012 at 9:58 AM, BobAalsma wrote: > Op vrijdag 21 september 2012 15:36:11 UTC+2 schreef Jerry Hill het volgende: >> On Fri, Sep 21, 2012 at 9:31 AM, BobAalsma wrote: >> >> > Thanks, Joel, yes, but as far as I'm aware these would all require the Python programme to have the user's username and password (or "credentials"), which I wanted to avoid. >> >> >> >> No matter what you do, your web service is going to have to >> >> authenticate with the remote web site. The details of that >> >> authentication are going to vary with each remote web site you want to >> >> connect to. >> >> >> >> -- >> >> Jerry > > Hmm, from the previous posts I get the impression that I could best solve this by asking the user for the specific combination of username, password and URL + promising not to keep any of that... > > OK, that does sound doable - thank you all I recommend that you write your program to read pages that are not protected. Once you get that working, you can go back and figure out how you want to get the username/password from your 'friends' and add that in. Also look up Beautiful Soup (version 4) for a great library to parse the pages that you retrieve > > Bob > -- > http://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick From rosuav at gmail.com Fri Sep 21 10:29:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Sep 2012 00:29:14 +1000 Subject: Blue Screen Python In-Reply-To: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> References: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> Message-ID: On Sat, Sep 22, 2012 at 12:04 AM, mikcec82 wrote: > Hallo to all, > > I'm using Python 2.7.3 with Windows 7 @ 64 bit > and an Intel Core i3 -2350M CPU @2.30GHz 2.3GHz. > > Sometimes, when I'm programming in Python on my screen compare this blue screen: > http://imageshack.us/a/img228/8352/48579647436249494527021.jpg > > Can you help on what is the issue, and how I can solve it? > > If you need more info I'm available. Ouch, that's not fun. I've never actually seen Python bsod by itself. My first guesses are: 1) It's a buggy library that you're using with Python. Do you know what modules your code calls on? Mainly ones that aren't part of the standard library. 2) It's unrelated, but maybe triggered somehow. For instance, your Python program might be consuming a lot of RAM, which causes a problem when you make use of a faulty bit of memory somewhere in the higher addresses. Have you run a RAM test on that machine? This is a well-respected one: http://www.memtest.org/ Alternatively, can you narrow the problem down to a particular script that will repeatedly cause the BSOD? ChrisA From __peter__ at web.de Fri Sep 21 10:29:31 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 21 Sep 2012 16:29:31 +0200 Subject: how to do draw pattern with python? References: Message-ID: echo.hping at gmail.com wrote: > may i know how to shift the bits using only looping and branching?? import time data = """\ x....x .x..x. ..xx.. ..xx.. .x..x. x....x """.splitlines() data = [line * 12 for line in data] # optional while True: print "\x1b[2J\x1b[0;0H" # optional for i, line in enumerate(data): print line data[i] = line[1:] + line[:1] time.sleep(.1) Doing your homework since 2001 ;) From franck at ditter.org Fri Sep 21 10:29:55 2012 From: franck at ditter.org (Franck Ditter) Date: Fri, 21 Sep 2012 16:29:55 +0200 Subject: Reading a file in IDLE 3 on Mac-Lion Message-ID: Hello, I create a text file utf-8 encoded in Python 3 with IDLE (Mac Lion). It runs fine and creates the disk file, visible with TextWrangler or another. But I can't open it with IDLE (its name is greyed). IDLE is supposed to read utf-8 files, no ? This works on Windows-7. Thanks for the tip, franck From __peter__ at web.de Fri Sep 21 10:33:32 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 21 Sep 2012 16:33:32 +0200 Subject: How to apply the user's HTML environment in a Python programme? References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> <3de0aac0-d7f2-4990-9428-54c89b143b9a@googlegroups.com> Message-ID: BobAalsma wrote: > Hmm, from the previous posts I get the impression that I could best solve > this by asking the user for the specific combination of username, password > and URL + promising not to keep any of that... > > OK, that does sound doable - thank you all Hmm, promising seems doable, but keeping? From joel.goldstick at gmail.com Fri Sep 21 10:41:31 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 21 Sep 2012 10:41:31 -0400 Subject: Algorithms using Python? In-Reply-To: References: Message-ID: On Fri, Sep 21, 2012 at 4:56 AM, Mayuresh Kathe wrote: > Is there a good book on foundational as well as advanced algorithms using > Python? > > Thanks. > > -- > http://mail.python.org/mailman/listinfo/python-list There is one on Apress that I've seen http://www.amazon.com/Python-Algorithms-Mastering-Language-Experts/dp/1430232374 -- Joel Goldstick From invalid at invalid.invalid Fri Sep 21 11:07:09 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 21 Sep 2012 15:07:09 +0000 (UTC) Subject: Obnoxious postings from Google Groups (was: datetime issue) References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> Message-ID: On 2012-09-16, Ben Finney wrote: > ???????????????? ???????????? writes: > >> Iam sorry i didnt do that on purpose and i dont know how this is done. >> >> Iam positng via google groups using chrome, thats all i know. > > It is becoming quite clear that some change has happened recently to > Google Groups that makes posts coming from there rather more obnoxious > than before. Well, that's certainly something of an accomplishment. I've become somewhat suspicious that Google Groups is Google's deliberate attempt to kill off Usenet and non-Google-controlled mailing lists. Nothing can be that bad by accident. Except perhaps certain Microsoft products.... make that most Microsoft products. > And there doesn't seem to be much its users can do except > use something else. > > Using Google Groups for posting to Usenet has been a bad idea for a long > time, but now it just seems to be a sure recipe for annoying the rest of > us. Again, not something you have much control over, except to stop > using Google Groups. I told my news client years ago to filter out anything posted from Google Groups -- and I know I'm not alone. If one wants the best chance of getting a question answered, using something other than Google Groups is indeed a good idea. -- Grant Edwards grant.b.edwards Yow! The PILLSBURY DOUGHBOY at is CRYING for an END to gmail.com BURT REYNOLDS movies!! From invalid at invalid.invalid Fri Sep 21 11:14:53 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 21 Sep 2012 15:14:53 +0000 (UTC) Subject: Blue Screen Python References: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> Message-ID: On 2012-09-21, mikcec82 wrote: > Hallo to all, > > I'm using Python 2.7.3 with Windows 7 @ 64 bit and an Intel Core i3 > -2350M CPU @2.30GHz 2.3GHz. > > Sometimes, when I'm programming in Python on my screen compare this > blue screen: > http://imageshack.us/a/img228/8352/48579647436249494527021.jpg > > Can you help on what is the issue, and how I can solve it? IMO, the easiest waht to avoid those is by not running Windows. ;) Python is a user-space application. User-space applications can't cause blue-screens unless they manage to trigger a bug in hardware, OS kernel, or device driver. The solution is usually to fix the hardware, OS, or device driver. -- Grant Edwards grant.b.edwards Yow! I'm having an at emotional outburst!! gmail.com From nameDOTsurname at gmail.com Fri Sep 21 11:27:49 2012 From: nameDOTsurname at gmail.com (Marco) Date: Fri, 21 Sep 2012 17:27:49 +0200 Subject: Python 3.3 and .pyo files References: <505c63b4$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 09/21/2012 02:55 PM, Steven D'Aprano wrote: >> $ ls >> >foo.pyo >> ># The following works in Python3.2, but not in 3.3 >> >$ python3.3 -O -m foo >> >/usr/local/bin/python3.3: No module named foo > > I can confirm that (1) it works using Python 3.2; (2) it doesn't work > using Python 3.3; and (3) it does work in Python 3.3 if you don't use the > -O option. It doesn't work with Python 3.3.0rc2 too. -- Marco From davids at invtools.com Fri Sep 21 11:28:07 2012 From: davids at invtools.com (David Smith) Date: Fri, 21 Sep 2012 11:28:07 -0400 Subject: How to apply the user's HTML environment in a Python programme? In-Reply-To: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> Message-ID: <505C8787.6060807@invtools.com> On 2012-09-21 08:57, BobAalsma wrote: > This text can be behind a username/password, but for several reasons, I don't want to know those. > > So I would like to set up a situation where the user logs in (if/when appropriate), points out the URL to my programme and my programme would then be able to read that particular text. I do this from a bat file that I will later translate to Python. I tell my work wiki which file I want. I use chrome, so for every new session I'm asked for my credentials. However, that is all transparent to my bat file. For that matter, when I download a new build from part of another bat file, I use Firefox and never see the credential exchange. I wouldn't expect any different behavior using Python. From steve+comp.lang.python at pearwood.info Fri Sep 21 11:54:41 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Sep 2012 15:54:41 GMT Subject: Does python have built command for package skeleton creation? References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> Message-ID: <505c8dc1$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 21 Sep 2012 14:50:36 +0100, Mark Lawrence wrote: > On 21/09/2012 14:13, xliiv wrote: >> Why is this '2 years release cycle'? >> >> > Because there aren't enough volunteers to get it done any faster? Because if it were any faster, it would piss off a lot of people. Python's release cycle is actually closer to 18 months for minor releases (3.2 -> 3.3, for example), and 10 years for major releases (2.x -> 3.x). But consider, C and C++ don't have minor releases *at all*. The last versions of those two languages are C99 and C+98 -- that's FOURTEEN YEARS since the last version of C++. And Java hasn't had a major feature update since 2006. For a programming language with a lot of corporate use, Python already seems like it changes at the drop of a hat. -- Steven From alister.ware at ntlworld.com Fri Sep 21 12:01:16 2012 From: alister.ware at ntlworld.com (Alister) Date: Fri, 21 Sep 2012 16:01:16 GMT Subject: Blue Screen Python References: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> Message-ID: On Fri, 21 Sep 2012 15:14:53 +0000, Grant Edwards wrote: > On 2012-09-21, mikcec82 wrote: >> Hallo to all, >> >> I'm using Python 2.7.3 with Windows 7 @ 64 bit and an Intel Core i3 >> -2350M CPU @2.30GHz 2.3GHz. >> >> Sometimes, when I'm programming in Python on my screen compare this > Python is a user-space application. User-space applications can't cause > blue-screens unless they manage to trigger a bug in hardware, OS kernel, > or device driver. But Windows does not have any true concept of user-space (although it does make an almost convincing pretence) it has been hacked up from an operating system that's original security model was "Lock the door when you leave the office" -- Watch all-night Donna Reed reruns until your mind resembles oatmeal. From alister.ware at ntlworld.com Fri Sep 21 12:02:44 2012 From: alister.ware at ntlworld.com (Alister) Date: Fri, 21 Sep 2012 16:02:44 GMT Subject: Blue Screen Python References: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> Message-ID: On Fri, 21 Sep 2012 16:01:16 +0000, Alister wrote: > On Fri, 21 Sep 2012 15:14:53 +0000, Grant Edwards wrote: > >> On 2012-09-21, mikcec82 wrote: >>> Hallo to all, >>> >>> I'm using Python 2.7.3 with Windows 7 @ 64 bit and an Intel Core i3 >>> -2350M CPU @2.30GHz 2.3GHz. >>> >>> Sometimes, when I'm programming in Python on my screen compare this >> Python is a user-space application. User-space applications can't >> cause blue-screens unless they manage to trigger a bug in hardware, OS >> kernel, >> or device driver. > > But Windows does not have any true concept of user-space (although it > does make an almost convincing pretence) it has been hacked up from an > operating system that's original security model was "Lock the door when > you leave the office" on a slightly more helpful front try adding break points to your code to see what part is actually causing the crash -- Whenever I feel like exercise, I lie down until the feeling passes. From sulfurfff at gmail.com Fri Sep 21 12:50:35 2012 From: sulfurfff at gmail.com (=?UTF-8?Q?Ismael_Farf=C3=A1n?=) Date: Fri, 21 Sep 2012 11:50:35 -0500 Subject: how to do draw pattern with python? In-Reply-To: References: Message-ID: 2012/9/21 Peter Otten <__peter__ at web.de>: > echo.hping at gmail.com wrote: > > print "\x1b[2J\x1b[0;0H" # optional Nice code : ) Could you dissect that weird string for us? It isn't returning the cursor to (0,0), it's just like executing clear(1), and looks like those line coloring scape sequences for bash. Ismael -- Do not let me induce you to satisfy my curiosity, from an expectation, that I shall gratify yours. What I may judge proper to conceal, does not concern myself alone. From d at davea.name Fri Sep 21 13:26:32 2012 From: d at davea.name (Dave Angel) Date: Fri, 21 Sep 2012 13:26:32 -0400 Subject: Does python have built command for package skeleton creation? In-Reply-To: <505c8dc1$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> <505c8dc1$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <505CA348.7070008@davea.name> On 09/21/2012 11:54 AM, Steven D'Aprano wrote: > On Fri, 21 Sep 2012 14:50:36 +0100, Mark Lawrence wrote: > >> On 21/09/2012 14:13, xliiv wrote: >>> Why is this '2 years release cycle'? >>> >>> >> Because there aren't enough volunteers to get it done any faster? > Because if it were any faster, it would piss off a lot of people. > > Python's release cycle is actually closer to 18 months for minor releases > (3.2 -> 3.3, for example), and 10 years for major releases (2.x -> 3.x). > But consider, C and C++ don't have minor releases *at all*. The last > versions of those two languages are C99 and C+98 -- that's FOURTEEN YEARS > since the last version of C++. And Java hasn't had a major feature update > since 2006. "C++0x was the working name of a new ISO C++ standard, which was then released in 2011 as C++11 ..." according to http://gcc.gnu.org/projects/cxx0x.html And it replaced C++03, released in 2003. > For a programming language with a lot of corporate use, Python already > seems like it changes at the drop of a hat. > > Correct. -- DaveA From __peter__ at web.de Fri Sep 21 13:29:02 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 21 Sep 2012 19:29:02 +0200 Subject: how to do draw pattern with python? References: Message-ID: Ismael Farf?n wrote: > 2012/9/21 Peter Otten <__peter__ at web.de>: >> echo.hping at gmail.com wrote: >> >> print "\x1b[2J\x1b[0;0H" # optional > > Nice code : ) > > Could you dissect that weird string for us? > > It isn't returning the cursor to (0,0), it's just like executing > clear(1), and looks like those line coloring scape sequences for bash. "\x1b[2J" or ESC [2J should clear the screen and "\x1b[1;1H" or ESC [1;1H should move the cursor to the origin (I got that wrong in the previous post) There may be other problems -- I stopped reading http://en.wikipedia.org/wiki/ANSI_escape_code as soon as I got the desired effect (scrolling) in konsole. From steve+comp.lang.python at pearwood.info Fri Sep 21 13:29:13 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Sep 2012 17:29:13 GMT Subject: Exact integer-valued floats Message-ID: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> Python floats can represent exact integer values (e.g. 42.0), but above a certain value (see below), not all integers can be represented. For example: py> 1e16 == 1e16 + 1 # no such float as 10000000000000001.0 True py> 1e16 + 3 == 1e16 + 4 # or 10000000000000003.0 True So some integers are missing from the floats. For large enough values, the gap between floats is rather large, and many numbers are missing: py> 1e200 + 1e10 == 1e200 True The same applies for large enough negative values. The question is, what is the largest integer number N such that every whole number between -N and N inclusive can be represented as a float? If my tests are correct, that value is 9007199254740992.0 = 2**53. Have I got this right? Is there a way to work out the gap between one float and the next? (I haven't tried to exhaustively check every float because, even at one nanosecond per number, it will take over 200 days.) -- Steven From steve+comp.lang.python at pearwood.info Fri Sep 21 13:31:05 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Sep 2012 17:31:05 GMT Subject: Does python have built command for package skeleton creation? References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> <505c8dc1$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <505ca459$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 21 Sep 2012 13:26:32 -0400, Dave Angel wrote: > On 09/21/2012 11:54 AM, Steven D'Aprano wrote: >> Python's release cycle is actually closer to 18 months for minor >> releases (3.2 -> 3.3, for example), and 10 years for major releases >> (2.x -> 3.x). But consider, C and C++ don't have minor releases *at >> all*. The last versions of those two languages are C99 and C+98 -- >> that's FOURTEEN YEARS since the last version of C++. And Java hasn't >> had a major feature update since 2006. > > "C++0x was the working name of a new ISO C++ standard, which was then > released in 2011 as C++11 ..." > according to http://gcc.gnu.org/projects/cxx0x.html > > And it replaced C++03, released in 2003. I stand corrected, thank you. -- Steven From rosuav at gmail.com Fri Sep 21 13:31:54 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Sep 2012 03:31:54 +1000 Subject: how to do draw pattern with python? In-Reply-To: References: Message-ID: On Sat, Sep 22, 2012 at 2:50 AM, Ismael Farf?n wrote: > 2012/9/21 Peter Otten <__peter__ at web.de>: >> echo.hping at gmail.com wrote: >> >> print "\x1b[2J\x1b[0;0H" # optional > > Nice code : ) > > Could you dissect that weird string for us? > > It isn't returning the cursor to (0,0), it's just like executing > clear(1), and looks like those line coloring scape sequences for bash. It's an ANSI escape sequence, or rather two of them. The first one clears the screen, the second returns you to 0,0. (Isn't that implicit in the 2J code? Maybe I'm misremembering.) But it depends on the terminal responding to them, and not all terminals do. For instance, most MUD clients parse only a very small subset of ANSI codes, eg color codes only. ChrisA From ian.g.kelly at gmail.com Fri Sep 21 13:32:20 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 21 Sep 2012 11:32:20 -0600 Subject: how to do draw pattern with python? In-Reply-To: References: Message-ID: On Fri, Sep 21, 2012 at 10:50 AM, Ismael Farf?n wrote: > 2012/9/21 Peter Otten <__peter__ at web.de>: >> echo.hping at gmail.com wrote: >> >> print "\x1b[2J\x1b[0;0H" # optional > > Nice code : ) > > Could you dissect that weird string for us? > > It isn't returning the cursor to (0,0), it's just like executing > clear(1), and looks like those line coloring scape sequences for bash. They're called "ANSI escape codes". :-) CSI 2J clears the screen. CSI 0;0H means "move the cursor to row 0, column 0". However, I don't think that's valid ANSI, as the coordinates are 1-based. Probably it should have been "\x1b[2J\x1b[1;1H". From rosuav at gmail.com Fri Sep 21 13:35:24 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Sep 2012 03:35:24 +1000 Subject: how to do draw pattern with python? In-Reply-To: References: Message-ID: On Sat, Sep 22, 2012 at 3:31 AM, Chris Angelico wrote: > It's an ANSI escape sequence, or rather two of them. The first one > clears the screen, the second returns you to 0,0. (Isn't that implicit > in the 2J code? Maybe I'm misremembering.) Ah. From Wikipedia: "If n is two, clear entire screen (and moves cursor to upper left on MS-DOS ANSI.SYS)." So adding \e[H is necessary. ChrisA From rosuav at gmail.com Fri Sep 21 13:44:55 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Sep 2012 03:44:55 +1000 Subject: Does python have built command for package skeleton creation? In-Reply-To: <505c8dc1$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> <505c8dc1$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 22, 2012 at 1:54 AM, Steven D'Aprano wrote: > But consider, C and C++ don't have minor releases *at all*. The last > versions of those two languages are C99 and C+98 -- that's FOURTEEN YEARS > since the last version of C++. And Java hasn't had a major feature update > since 2006. > > For a programming language with a lot of corporate use, Python already > seems like it changes at the drop of a hat. Hang on, you're conflating the language and its implementation. C and C++ don't have minor releases, because you're looking only at the language. On the other hand, gcc has major.minor.revision releases, because it's possible for the compiler to have trivial bugs that merit a small bugfix, or minor changes that perhaps enhance the stdlib. The way I see it, a Python minor release shouldn't normally be a problem to an active developer, but is too big a change to push quietly to active scripts. That's a lot smaller than a release of a new C/C++ spec; more akin to the next version of Microsoft Visual C++, which comes out every couple of years ish. And as DaveA (no relation to me, but I love the coincidence of surname AND signature style) pointed out, there have been C++ spec updates since 98. Python's release schedule is plenty fast enough. It's already outstripping the packagers in Debian and Red Hat. Fortunately it's pretty easy to whip up your own Python straight from source and 'make altinstall' to keep things happily parallel. You want faster releases? You got 'em. ChrisA From ian.g.kelly at gmail.com Fri Sep 21 14:13:09 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 21 Sep 2012 12:13:09 -0600 Subject: Exact integer-valued floats In-Reply-To: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 21, 2012 at 11:29 AM, Steven D'Aprano wrote: > The question is, what is the largest integer number N such that every > whole number between -N and N inclusive can be represented as a float? > > If my tests are correct, that value is 9007199254740992.0 = 2**53. > > Have I got this right? Is there a way to work out the gap between one > float and the next? That looks mathematically correct. The "gap" between floats is the equivalent of a difference of 1 bit in the significand. For a floating point number represented as (sign * c * 2 ** q), where c is an integer, the gap between floats is equal to 2 ** q. There are 53 bits of precision in a double-precision float (technically an implicit 1 followed by 52 bits), so q becomes greater than 0 at 2 ** 53. Cheers, Ian From nikos.gr33k at gmail.com Fri Sep 21 14:45:14 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rx5eXq?=) Date: Fri, 21 Sep 2012 11:45:14 -0700 (PDT) Subject: One of my joomla webpages has been hacked. Please help. Message-ID: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> Hello, One webpage of mine, http://www.varsa.gr/ has been *hacked* 15 mins ago. I logged into CPanel but the joomla files seem ok. but when i view page code with chrome i get the source code, i dont knwo of which file thaty contains javascript inside. Please visit my web page varsa.gr and view the source code and maybe you can tell me what has happened. I would be gratefull for any help you provide me. I know this is not a python question but you guyshave high knowledge of web sites programming and i though you wouldnt mind helping me out. Thank you very much. From jpiitula at ling.helsinki.fi Fri Sep 21 15:47:07 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 21 Sep 2012 22:47:07 +0300 Subject: Exact integer-valued floats References: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > Python floats can represent exact integer values (e.g. 42.0), but above a > certain value (see below), not all integers can be represented. For > example: > > py> 1e16 == 1e16 + 1 # no such float as 10000000000000001.0 > True > py> 1e16 + 3 == 1e16 + 4 # or 10000000000000003.0 > True > > So some integers are missing from the floats. For large enough values, > the gap between floats is rather large, and many numbers are missing: > > py> 1e200 + 1e10 == 1e200 > True > > The same applies for large enough negative values. > > The question is, what is the largest integer number N such that every > whole number between -N and N inclusive can be represented as a float? > > If my tests are correct, that value is 9007199254740992.0 = 2**53. > > Have I got this right? Is there a way to work out the gap between one > float and the next? There is a way to find the distance between two IEEE floats in "ulps", or "units in the last position", computable from the bit pattern using integer arithmetic. I think it's then also possible to find the next float by adding one. I don't have a link at hand, I'm too tired to search at the moment, and I'm no expert on floats, but you might find an answer by looking for ulps. > (I haven't tried to exhaustively check every float because, even at one > nanosecond per number, it will take over 200 days.) Come to think of it, the difference between adjacent floats is exactly one ulp. Just use the right unit :) From dihedral88888 at googlemail.com Fri Sep 21 15:54:14 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 21 Sep 2012 12:54:14 -0700 (PDT) Subject: Functional way to compare things inside a list In-Reply-To: References: Message-ID: <48191878-3a0e-4733-a426-55b6981c471d@googlegroups.com> Ulrich Eckhardt? 2012?9?21????UTC+8??5?15?03???? > Am 21.09.2012 00:58, schrieb thorsopia at lavabit.com: > > > list = [{'1': []}, {'2': []}, {'3': ['4', '5']}] > > > > > > I want to check for a value (e.g. '4'), and get the key of the dictionary > > > that contains that value. > > > > Note: > > 1. list is a built-in type, who's name is rebound above > > 2. The list above contains dictionaries that all only contain a single key? > > 3. You have strings containing decimal representations of numbers? > > > > > (Yep, this is bizarre.) > > > > The data are really stored in a strange way and you might be able to > > make things clearer by reorganizing them a bit. > > > > > > > some_magic(list, '4') > > > => '3' > > > > > > What's the functional way to do it? > > > > Functional as in functional programming and an emphasis on lazy > > evaluation? In that case I'd write a generator that emits the keys where > > the values contain the requested string. > > > > > > > Is it possible to do it with a one-liner? > > > > Yep, filter(), lambda and the 'in' operator. Question remains if this is > > readable. Note that you can use a local function, too, if you just want > > to reduce the scope/visibility. > > > > > > Good luck! > > > > > > Uli I don't think functional aspects are only marked as lazy programming. It just means when one is experimenting something the efficient execution in speed is not on focus yet. From breamoreboy at yahoo.co.uk Fri Sep 21 15:55:02 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 21 Sep 2012 20:55:02 +0100 Subject: how to do draw pattern with python? In-Reply-To: References: Message-ID: On 21/09/2012 15:29, Peter Otten wrote: > echo.hping at gmail.com wrote: > >> may i know how to shift the bits using only looping and branching?? > > import time > > data = """\ > x....x > .x..x. > ..xx.. > ..xx.. > .x..x. > x....x > > """.splitlines() > > data = [line * 12 for line in data] # optional > > while True: > print "\x1b[2J\x1b[0;0H" # optional > for i, line in enumerate(data): > print line > data[i] = line[1:] + line[:1] > time.sleep(.1) > > Doing your homework since 2001 ;) > I tried running your code but got this:- c:\Users\Mark>pattern.py File "C:\Users\Mark\pattern.py", line 22 Doing your homework since 2001 ^ SyntaxError: invalid syntax What am I doing wrong? -- Cheers. Mark Lawrence. From nobody at nowhere.com Fri Sep 21 15:59:16 2012 From: nobody at nowhere.com (Nobody) Date: Fri, 21 Sep 2012 20:59:16 +0100 Subject: Exact integer-valued floats References: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 21 Sep 2012 17:29:13 +0000, Steven D'Aprano wrote: > The question is, what is the largest integer number N such that every > whole number between -N and N inclusive can be represented as a float? > > If my tests are correct, that value is 9007199254740992.0 = 2**53. > > Have I got this right? Is there a way to work out the gap between one > float and the next? CPython's "float" type uses C's "double". For a system where C's "double" is IEEE-754 double precision, N=2**53 is the correct answer. An IEEE-754 double precision value consists of a 53-bit integer whose first bit is a "1", multiplied or divided by a power of two. http://en.wikipedia.org/wiki/IEEE_754-1985 The largest 53-bit integer is 2**53-1. 2**53 can be represented as 2**52 * 2**1. 2**53+1 cannot be represented in this form. 2**53+2 can be represented as (2**52+1) * 2**1. For values x where 2**52 <= x < 2**53, the the interval between representable values (aka Unit in the Last Place or ULP) is 1.0. For 2**51 <= x < 2**52, the ULP is 0.5. For 2**53 <= x < 2**54, the ULP is 2.0. And so on. From ian.g.kelly at gmail.com Fri Sep 21 16:07:01 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 21 Sep 2012 14:07:01 -0600 Subject: Algorithms using Python? In-Reply-To: References: Message-ID: On Fri, Sep 21, 2012 at 1:45 PM, Dennis Lee Bieber wrote: > You can probably implement them, but they're not going to be very > efficient. (And never "remove" an element from the linked-list > implementation because Python would shift all the other elements, hence > your "links" become invalid). I'm not sure what you mean by that last comment. class Node(object): def __init__(self, data, next): self.data = data self.next = next class LinkedList(object): def __init__(self): self._head = None def __iter__(self): node = self._head while node: yield node.data node = node.next def insert_front(self, value): self._head = Node(value, self._head) def remove(self, value): prior, node = None, self._head while node: if node.data == value: if prior: prior.next = node.next else: self._head = node.next break prior, node = node, node.next else: raise ValueError("value not found") >>> li = LinkedList() >>> for char in 'edcba': ... li.insert_front(char) ... >>> print ''.join(li) abcde >>> li.remove('c') >>> print ''.join(li) abde It seems to work fine to me. From gengyangcai at gmail.com Fri Sep 21 16:20:09 2012 From: gengyangcai at gmail.com (gengyangcai at gmail.com) Date: Fri, 21 Sep 2012 13:20:09 -0700 (PDT) Subject: Print Function Message-ID: Hello , I am currently using Python 3.2.3 . WHen I use the print function by typing print "Game Over" , it mentions " SyntaxError : invalid syntax ". Any ideas on what the problem is and how to resolve it ? Thanks a lot . GengYang From dihedral88888 at googlemail.com Fri Sep 21 16:20:31 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 21 Sep 2012 13:20:31 -0700 (PDT) Subject: [Q] How to exec code object with local variables specified? In-Reply-To: References: Message-ID: Makoto Kuwata? 2012?9?20????UTC+8??7?27?40???? > Hi, > > > > Is it possible to run code object with local variables specified? > > I'm trying the following code but not work: > > > > def fn(): > > x = 1 > > y = 2 > > localvars = {'x': 0} > > exec(fn.func_code, globals(), localvars) > > print(localvars) > > ## what I expected is: {'x': 1, 'y': 2} > > ## but actual is: {'x': 0} > > > > Python: 2.7.3 > > OS: MacOS X > > > > -- > > regards, > > makoto kuwata Do you plan to write an IDE for python scrits ? I have seen a lot abusiosns of spawns or pipes of mutlti-processes, and now the exec part again. I think the sources of Doctor Python and IDLE were available years ago for showing off python's capabilities in developing an IDE. From dihedral88888 at googlemail.com Fri Sep 21 16:20:31 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 21 Sep 2012 13:20:31 -0700 (PDT) Subject: [Q] How to exec code object with local variables specified? In-Reply-To: References: Message-ID: Makoto Kuwata? 2012?9?20????UTC+8??7?27?40???? > Hi, > > > > Is it possible to run code object with local variables specified? > > I'm trying the following code but not work: > > > > def fn(): > > x = 1 > > y = 2 > > localvars = {'x': 0} > > exec(fn.func_code, globals(), localvars) > > print(localvars) > > ## what I expected is: {'x': 1, 'y': 2} > > ## but actual is: {'x': 0} > > > > Python: 2.7.3 > > OS: MacOS X > > > > -- > > regards, > > makoto kuwata Do you plan to write an IDE for python scrits ? I have seen a lot abusiosns of spawns or pipes of mutlti-processes, and now the exec part again. I think the sources of Doctor Python and IDLE were available years ago for showing off python's capabilities in developing an IDE. From hansmu at xs4all.nl Fri Sep 21 16:27:49 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 21 Sep 2012 22:27:49 +0200 Subject: Reading a file in IDLE 3 on Mac-Lion In-Reply-To: References: Message-ID: <505ccdc5$0$6919$e4fe514c@news2.news.xs4all.nl> On 21/09/12 16:29:55, Franck Ditter wrote: > I create a text file utf-8 encoded in Python 3 with IDLE (Mac Lion). > It runs fine and creates the disk file, visible with > TextWrangler or another. > But I can't open it with IDLE (its name is greyed). > IDLE is supposed to read utf-8 files, no ? > This works on Windows-7. There's a little pop-menu below the list of files. It allows you to choose which kind of files you want to open. By default, it is set to "Python files", which greys out all files, except those with a '.py' or '.pyw' extension. Setting it to "Text files" should help, or else try "All files". Hope this helps -- HansM From rodrick.brown at gmail.com Fri Sep 21 16:28:19 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Fri, 21 Sep 2012 16:28:19 -0400 Subject: Print Function In-Reply-To: References: Message-ID: <7383089012385283931@unknownmsgid> Go away troll! Sent from my iPhone On Sep 21, 2012, at 4:27 PM, "gengyangcai at gmail.com" wrote: > Hello , > > > I am currently using Python 3.2.3 . WHen I use the print function by typing print "Game Over" , it mentions " SyntaxError : invalid syntax ". Any ideas on what the problem is and how to resolve it ? Thanks a lot . > > > GengYang > -- > http://mail.python.org/mailman/listinfo/python-list From tarek at ziade.org Fri Sep 21 16:29:55 2012 From: tarek at ziade.org (=?ISO-8859-1?Q?Tarek_Ziad=E9?=) Date: Fri, 21 Sep 2012 22:29:55 +0200 Subject: Print Function In-Reply-To: References: Message-ID: <505CCE43.8060502@ziade.org> On 9/21/12 10:20 PM, gengyangcai at gmail.com wrote: > Hello , > > > I am currently using Python 3.2.3 . WHen I use the print function by typing print "Game Over" , it mentions " SyntaxError : invalid syntax ". Any ideas on what the problem is and how to resolve it ? Thanks a lot . print was a statement in python 2.x, it is now a function so you need parenthesis: >>> print("Game Over") Game Over > > > GengYang From driscoll at cs.wisc.edu Fri Sep 21 16:43:53 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Fri, 21 Sep 2012 15:43:53 -0500 Subject: Algorithms using Python? In-Reply-To: References: Message-ID: <505CD189.9060604@cs.wisc.edu> On 09/21/2012 02:45 PM, Dennis Lee Bieber wrote: > On Fri, 21 Sep 2012 14:26:04 +0530, Mayuresh Kathe > declaimed the following in gmane.comp.python.general: > >> Is there a good book on foundational as well as advanced algorithms >> using Python? >> > Depends on what you mean by "foundational"... > > Since Python has dynamic lists and dictionaries, I suspect you won't > find any textbook focusing on linked-list or hashed lookup algorithms > using Python. I wouldn't be so sure; C++ and Java both have standard libraries with dictionaries (and thus are mostly lacking a literal syntax). But it's easy to find books talking about the simple stuff. I'd suggest looking at the books used in MIT's intro classes: 6.000 (Intro to CS and programming): http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc-introduction-to-computer-science-and-programming-spring-2011/Syllabus/ Zelle, John M. Python Programming: An Introduction to Computer Science Budd, Timothy. Exploring Python Shaw, Zed A. Learn Python the Hard Way [online] Swaroop, CH. A Byte of Python 6.006 (Intro to algorithms): http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-spring-2008/syllabus/ Miller and Ranum. Problem Solving with Algorithms and Data Structures Using Python. [CLRS isn't Python] and see if they have anything to offer. (I didn't actually look.) > You can probably implement them, but they're not going to be very > efficient. (And never "remove" an element from the linked-list > implementation because Python would shift all the other elements, hence > your "links" become invalid). Huh? Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 554 bytes Desc: OpenPGP digital signature URL: From ian.g.kelly at gmail.com Fri Sep 21 16:49:55 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 21 Sep 2012 14:49:55 -0600 Subject: Functional way to compare things inside a list In-Reply-To: <48191878-3a0e-4733-a426-55b6981c471d@googlegroups.com> References: <48191878-3a0e-4733-a426-55b6981c471d@googlegroups.com> Message-ID: On Fri, Sep 21, 2012 at 1:54 PM, 88888 Dihedral wrote: > I don't think functional aspects are only marked as lazy > programming. He wrote "lazy evaluation", not "lazy programming". Two entirely different things. > It just means when one is experimenting something > the efficient execution in speed is not on focus > yet. No, what you're describing is a "prototype". It has nothing to do with functional programming at all. From ian.g.kelly at gmail.com Fri Sep 21 16:54:14 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 21 Sep 2012 14:54:14 -0600 Subject: Print Function In-Reply-To: <7383089012385283931@unknownmsgid> References: <7383089012385283931@unknownmsgid> Message-ID: On Fri, Sep 21, 2012 at 2:28 PM, Rodrick Brown wrote: > Go away troll! Troll? It looked like a sincere question to me. From hansmu at xs4all.nl Fri Sep 21 17:04:14 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 21 Sep 2012 23:04:14 +0200 Subject: Exact integer-valued floats In-Reply-To: References: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <505cd64e$0$6958$e4fe514c@news2.news.xs4all.nl> On 21/09/12 22:26:26, Dennis Lee Bieber wrote: > On 21 Sep 2012 17:29:13 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > >> >> The question is, what is the largest integer number N such that every >> whole number between -N and N inclusive can be represented as a float? >> > Single precision commonly has 7 significant (decimal) digits. Double > precision runs somewhere between 13 and 15 (decimal) significant digits > >> If my tests are correct, that value is 9007199254740992.0 = 2**53. The expression 2 / sys.float_info.epsilon produces exactly that number. That's probably not a coincidence. > For an encoding of a double precision using one sign bit and an > 8-bit exponent, you have 53 bits available for the mantissa. If your floats have 64 bits, and you use 1 bit for the sign and 8 for the exponent, you'll have 55 bits available for the mantissa. > This > ignores the possibility of an implied msb in the mantissa (encodings > which normalize to put the leading 1-bit at the msb can on some machines > remove that 1-bit and shift the mantissa one more place; effectively > giving a 54-bit mantissa). My machine has 64-bits floats, using 1 bit for the sign, 11 for the exponent, leaving 52 for the mantissa. The mantissa has an implied leading 1, so it's nominally 53 bits. You can find this number in sys.float_info.mant_dig > Something like an old XDS Sigma-6 used > non-binary exponents (exponent was in power of 16 <> 2^4) and used > "non-normalized" mantissa -- the mantissa could have up to three leading > 0-bits); this affected the decimal significance... Your Sigma-6 must have sys.float_info.radix == 16 then. Hope this helps, -- HansM From alister.ware at ntlworld.com Fri Sep 21 17:11:29 2012 From: alister.ware at ntlworld.com (Alister) Date: Fri, 21 Sep 2012 21:11:29 GMT Subject: Print Function References: <7383089012385283931@unknownmsgid> Message-ID: <5K47s.294147$Up5.154909@fx06.am4> On Fri, 21 Sep 2012 14:54:14 -0600, Ian Kelly wrote: > On Fri, Sep 21, 2012 at 2:28 PM, Rodrick Brown > wrote: >> Go away troll! > > Troll? It looked like a sincere question to me. but one that page 1 of the documentation would answer. -- Waste not, get your budget cut next year. From alister.ware at ntlworld.com Fri Sep 21 17:14:29 2012 From: alister.ware at ntlworld.com (Alister) Date: Fri, 21 Sep 2012 21:14:29 GMT Subject: Exact integer-valued floats References: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 21 Sep 2012 17:29:13 +0000, Steven D'Aprano wrote: > Python floats can represent exact integer values (e.g. 42.0), but above > a certain value (see below), not all integers can be represented. For > example: > > py> 1e16 == 1e16 + 1 # no such float as 10000000000000001.0 True py> > 1e16 + 3 == 1e16 + 4 # or 10000000000000003.0 True > > So some integers are missing from the floats. For large enough values, > the gap between floats is rather large, and many numbers are missing: > > py> 1e200 + 1e10 == 1e200 True > > The same applies for large enough negative values. > > The question is, what is the largest integer number N such that every > whole number between -N and N inclusive can be represented as a float? > > If my tests are correct, that value is 9007199254740992.0 = 2**53. > > Have I got this right? Is there a way to work out the gap between one > float and the next? > > (I haven't tried to exhaustively check every float because, even at one > nanosecond per number, it will take over 200 days.) technically this would be implementation dependant, although the other responses are probably accurate for most (if not all) current implementations :-) -- Well, I'm a classic ANAL RETENTIVE!! And I'm looking for a way to VICARIOUSLY experience some reason to LIVE!! From gordon at panix.com Fri Sep 21 17:17:45 2012 From: gordon at panix.com (John Gordon) Date: Fri, 21 Sep 2012 21:17:45 +0000 (UTC) Subject: Print Function References: Message-ID: In gengyangcai at gmail.com writes: > I am currently using Python 3.2.3 . WHen I use the print function by > typing print "Game Over" , it mentions " SyntaxError : invalid syntax ". > Any ideas on what the problem is and how to resolve it ? Thanks a lot . In python version 3, print was changed into a function. Use this and it will work: print("Game Over") -- 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 joshua.landau.ws at gmail.com Fri Sep 21 17:45:13 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Fri, 21 Sep 2012 22:45:13 +0100 Subject: Functional way to compare things inside a list In-Reply-To: References: <48191878-3a0e-4733-a426-55b6981c471d@googlegroups.com> Message-ID: On 21 September 2012 21:49, Ian Kelly wrote: > On Fri, Sep 21, 2012 at 1:54 PM, 88888 Dihedral > wrote: > > I don't think functional aspects are only marked as lazy > > programming. > > He wrote "lazy evaluation", not "lazy programming". Two entirely > different things. > > > It just means when one is experimenting something > > the efficient execution in speed is not on focus > > yet. > > No, what you're describing is a "prototype". It has nothing to do > with functional programming at all. > -- > http://mail.python.org/mailman/listinfo/python-list > I am pretty sure dihedral88888 is a bot. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dihedral88888 at googlemail.com Fri Sep 21 17:45:15 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 21 Sep 2012 14:45:15 -0700 (PDT) Subject: Functional way to compare things inside a list In-Reply-To: References: <48191878-3a0e-4733-a426-55b6981c471d@googlegroups.com> Message-ID: <709c4ffe-27ad-47d8-8536-1ab394092da5@googlegroups.com> A Ian? 2012?9?22????UTC+8??4?50?49???? > On Fri, Sep 21, 2012 at 1:54 PM, 88888 Dihedral > > wrote: > > > I don't think functional aspects are only marked as lazy > > > programming. > > > > He wrote "lazy evaluation", not "lazy programming". Two entirely > > different things. > > > > > It just means when one is experimenting something > > > the efficient execution in speed is not on focus > > > yet. > > > > No, what you're describing is a "prototype". It has nothing to do > > with functional programming at all. A function with varaible arguments can be stored as a variable to functions called decorators in python to return enhanced functions. A function mapps a decorator to another decorator can be called a decorator map or a decorator maker in python. The closure level is guaranteed for decorators to be mapped by multi-levels of decorator mappers trivially in python. What do you want else for functional prgramming in python? From dihedral88888 at googlemail.com Fri Sep 21 17:45:15 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 21 Sep 2012 14:45:15 -0700 (PDT) Subject: Functional way to compare things inside a list In-Reply-To: References: <48191878-3a0e-4733-a426-55b6981c471d@googlegroups.com> Message-ID: <709c4ffe-27ad-47d8-8536-1ab394092da5@googlegroups.com> A Ian? 2012?9?22????UTC+8??4?50?49???? > On Fri, Sep 21, 2012 at 1:54 PM, 88888 Dihedral > > wrote: > > > I don't think functional aspects are only marked as lazy > > > programming. > > > > He wrote "lazy evaluation", not "lazy programming". Two entirely > > different things. > > > > > It just means when one is experimenting something > > > the efficient execution in speed is not on focus > > > yet. > > > > No, what you're describing is a "prototype". It has nothing to do > > with functional programming at all. A function with varaible arguments can be stored as a variable to functions called decorators in python to return enhanced functions. A function mapps a decorator to another decorator can be called a decorator map or a decorator maker in python. The closure level is guaranteed for decorators to be mapped by multi-levels of decorator mappers trivially in python. What do you want else for functional prgramming in python? From ethan at stoneleaf.us Fri Sep 21 17:59:47 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 21 Sep 2012 14:59:47 -0700 Subject: technologies synergistic with Python Message-ID: <505CE353.9090907@stoneleaf.us> Greetings! What is the consensus... okay, okay -- what are some wide ranging opinions on technologies that I should know if my dream job is one that consists mostly of Python, and might allow telecommuting? (Please don't say Java, please don't say Java, please don't say... ;) ~Ethan~ From walterhurry at lavabit.com Fri Sep 21 18:11:55 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Fri, 21 Sep 2012 22:11:55 +0000 (UTC) Subject: Obnoxious postings from Google Groups (was: datetime issue) References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> Message-ID: On Fri, 21 Sep 2012 15:07:09 +0000, Grant Edwards wrote: > I told my news client years ago to filter out anything posted from > Google Groups -- and I know I'm not alone. If one wants the best chance > of getting a question answered, using something other than Google Groups > is indeed a good idea. +1 From no.email at nospam.invalid Fri Sep 21 18:23:41 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 21 Sep 2012 15:23:41 -0700 Subject: Exact integer-valued floats References: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xzk4j6mmq.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Have I got this right? Is there a way to work out the gap between one > float and the next? Yes, 53-bit mantissa as people have mentioned. That tells you what ints can be exactly represented. But, arithmetic in some situations can have a 1-ulp error. So I wonder if it's possible that if n is large enough, you might have something like n+1==n even if the integers n and n+1 have distinct floating point representations. From rodrick.brown at gmail.com Fri Sep 21 18:33:53 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Fri, 21 Sep 2012 18:33:53 -0400 Subject: technologies synergistic with Python In-Reply-To: <505CE353.9090907@stoneleaf.us> References: <505CE353.9090907@stoneleaf.us> Message-ID: <0305585E-5130-4ABE-9ACB-282F489A02E1@gmail.com> On Sep 21, 2012, at 5:59 PM, Ethan Furman wrote: > Greetings! > > What is the consensus... okay, okay -- what are some wide ranging opinions on technologies that I should know if my dream job is one that consists mostly of Python, and might allow telecommuting? > > (Please don't say Java, please don't say Java, please don't say... ;) Django, JavaScript, HTML 5, JQuery, , SQL, Redis, Twisted > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list From ramdevtech.netinc at gmail.com Fri Sep 21 18:39:55 2012 From: ramdevtech.netinc at gmail.com (ram dev) Date: Fri, 21 Sep 2012 15:39:55 -0700 (PDT) Subject: Client Needs---QA Manual Tester at Sacramento, CA Message-ID: Good Day, We have an urgent Contract Openings in Folsom, CA Looking forward to submit your resume for below mentioned Requirement? If you are interested, Please forward your latest resume along with location and pay rate details to ram at tech-netinc.com Job Title: QA Engineer(Strong Web services Experience Needed) Location: Sacramento, CA Duration: 2 Years Required: ? Strong knowledge of SDLC ? Manual testing experience should be 6+ years ? Web services exp must be more than 4+ years ? Solid background of software testing methods, processes, tools ? Strong in XML,UNIX and SQL ? Advance level knowledge and hands-on experience with Test Planning, Test Development, Test Data Setup, Test Execution and Test Reporting. ? Knowledge of variety of testing methods and direct experience in test development and execution of functionality, integration, security, transaction, error handling, performance of web applications. ? Expertise in testing web services API using Parasoft SOA Test or SOAP UI. ? Hands-on experience with Quality Center/ALM 11. ? Experience working in Windows and Unix (Linux) environments. ? Team player with good mentoring and presentation skills Desired: ? ISO or Electricity Industry experience ? GUI and API test automation using HP Quick Test Pro ? Load/performance test automation using HP Load Runner ? Experience in integrating QTP, SOA Test, Load Runner or other test automation tools with HP Quality Center ? Advance level experience in using and administering Quality Center, developing workflows to customize QC using VB Script. ? Strong programming/scripting background in Java and Python. Able to code review and develop unit test if needed. Environment: JBoss, Groovy and Grails, Oracle 11g, SQL, XNL, Actuate, Reporting Services, SharePoint, Quality Center, Quick Test Pro, Load Runner, SOA Test, Windows, Linux. Thanks, ============================ Ram Dev Recruiter Tech-Net Inc. Tel: 916-458-4390 Ext 102 Email: ram at tech-netinc.com URL: www.tech-netinc.com From ian.g.kelly at gmail.com Fri Sep 21 18:43:05 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 21 Sep 2012 16:43:05 -0600 Subject: Print Function In-Reply-To: <5K47s.294147$Up5.154909@fx06.am4> References: <7383089012385283931@unknownmsgid> <5K47s.294147$Up5.154909@fx06.am4> Message-ID: On Fri, Sep 21, 2012 at 3:11 PM, Alister wrote: > On Fri, 21 Sep 2012 14:54:14 -0600, Ian Kelly wrote: > >> On Fri, Sep 21, 2012 at 2:28 PM, Rodrick Brown >> wrote: >>> Go away troll! >> >> Troll? It looked like a sincere question to me. > > but one that page 1 of the documentation would answer. So point the asker to the documentation, don't just dismiss them as a troll. This newsgroup has a reputation for being friendly. Let's keep it that way. From d at davea.name Fri Sep 21 18:47:57 2012 From: d at davea.name (Dave Angel) Date: Fri, 21 Sep 2012 18:47:57 -0400 Subject: Blue Screen Python In-Reply-To: References: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> Message-ID: <505CEE9D.7020609@davea.name> On 09/21/2012 12:01 PM, Alister wrote: > On Fri, 21 Sep 2012 15:14:53 +0000, Grant Edwards wrote: > >> On 2012-09-21, mikcec82 wrote: >>> Hallo to all, >>> >>> I'm using Python 2.7.3 with Windows 7 @ 64 bit and an Intel Core i3 >>> -2350M CPU @2.30GHz 2.3GHz. >>> >>> Sometimes, when I'm programming in Python on my screen compare this >> Python is a user-space application. User-space applications can't cause >> blue-screens unless they manage to trigger a bug in hardware, OS kernel, >> or device driver. True. Too bad there are so many of those bugs. > But Windows does not have any true concept of user-space (although it > does make an almost convincing pretence) it has been hacked up from an > operating system that's original security model was "Lock the door when > you leave the office" > That's not true at all. You're thinking of Windows 3, Windows 95, 98, and ME, which were hacked on top of MSDOS. But Windows NT3.5, 4, 2000, XP, Vista and Windows 7 have an entirely different bloodline. NT 3.51 was actually very robust, but in 4.0 to gain better performance, they apparently did some compromising in the video driver's isolation. And who knows what's happened since then. -- DaveA From python.list at tim.thechases.com Fri Sep 21 19:00:51 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 21 Sep 2012 18:00:51 -0500 Subject: technologies synergistic with Python In-Reply-To: <0305585E-5130-4ABE-9ACB-282F489A02E1@gmail.com> References: <505CE353.9090907@stoneleaf.us> <0305585E-5130-4ABE-9ACB-282F489A02E1@gmail.com> Message-ID: <505CF1A3.7040003@tim.thechases.com> On 09/21/12 17:33, Rodrick Brown wrote: >> What is the consensus... okay, okay -- what are some wide >> ranging opinions on technologies that I should know if my dream >> job is one that consists mostly of Python, and might allow >> telecommuting? > > Django, JavaScript, HTML 5, JQuery, , SQL, Redis, Twisted The only thing I might tweak in Rodrick's list is to broaden entries like "Django" to "a web framework such as Django, Pyramid, web.py, or ..." and "Redis" to "a NoSQL database such as Redis, CouchDB, ..." The others are pretty solid, even if I dislike JavaScript/ECMAScript as a language, jQuery makes it tolerable, it's the lingua-franca of the web. -tkc From dihedral88888 at googlemail.com Fri Sep 21 19:13:09 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 21 Sep 2012 16:13:09 -0700 (PDT) Subject: technologies synergistic with Python In-Reply-To: References: <505CE353.9090907@stoneleaf.us> Message-ID: i Rodrick Brown? 2012?9?22????UTC+8??6?33?59???? > On Sep 21, 2012, at 5:59 PM, Ethan Furman wrote: > > > > > Greetings! > > > > > > What is the consensus... okay, okay -- what are some wide ranging opinions on technologies that I should know if my dream job is one that consists mostly of Python, and might allow telecommuting? > > > > > > (Please don't say Java, please don't say Java, please don't say... ;) > > > > Django, JavaScript, HTML 5, JQuery, , SQL, Redis, Twisted > > > > > > > > ~Ethan~ > > > -- > > > http://mail.python.org/mailman/listinfo/python-list I always prefer a computer language with a lot examples in the sources for all kinds of nontrivial applications. I am not interested in those trivial batches or shell programming scripts for novices. From dihedral88888 at googlemail.com Fri Sep 21 19:13:09 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 21 Sep 2012 16:13:09 -0700 (PDT) Subject: technologies synergistic with Python In-Reply-To: References: <505CE353.9090907@stoneleaf.us> Message-ID: i Rodrick Brown? 2012?9?22????UTC+8??6?33?59???? > On Sep 21, 2012, at 5:59 PM, Ethan Furman wrote: > > > > > Greetings! > > > > > > What is the consensus... okay, okay -- what are some wide ranging opinions on technologies that I should know if my dream job is one that consists mostly of Python, and might allow telecommuting? > > > > > > (Please don't say Java, please don't say Java, please don't say... ;) > > > > Django, JavaScript, HTML 5, JQuery, , SQL, Redis, Twisted > > > > > > > > ~Ethan~ > > > -- > > > http://mail.python.org/mailman/listinfo/python-list I always prefer a computer language with a lot examples in the sources for all kinds of nontrivial applications. I am not interested in those trivial batches or shell programming scripts for novices. From cs at zip.com.au Fri Sep 21 19:44:04 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 22 Sep 2012 09:44:04 +1000 Subject: How to limit CPU usage in Python In-Reply-To: References: Message-ID: <20120921234404.GA8384@cskk.homeip.net> On 20Sep2012 12:53, Terry Reedy wrote: | On 9/20/2012 12:46 PM, Terry Reedy wrote: | > On 9/20/2012 11:12 AM, Rolando Ca?er Roblejo wrote: | >> Is it possible for me to put a limit in the amount of processor usage (% | >> CPU) that my current python script is using? Is there any module useful | >> for this task? I saw Resource module but I think it is not the module I | >> am looking for. Some people recommend to use nice and cpulimit unix | >> tools, but those are external to python and I prefer a python solution. | >> I am working with Linux (Ubuntu 10.04). | > | > Call the external tools with subprocess.open. | | I meant to end that with ? as I don't know how easy it is to get the | external id of the calling process that is to be limited. I presume that | can be done by first calling ps (with subprocess) and searching the | piped-back output. If you're limiting yourself, os.getpid(). -- Cameron Simpson From hank.gay+eternal.september at gmail.com Fri Sep 21 20:51:27 2012 From: hank.gay+eternal.september at gmail.com (Hank Gay) Date: Fri, 21 Sep 2012 20:51:27 -0400 Subject: Obnoxious postings from Google Groups (was: datetime issue) References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> Message-ID: On 2012-09-21 15:07:09 +0000, Grant Edwards said: > > I told my news client years ago to filter out anything posted from > Google Groups -- and I know I'm not alone. If one wants the best > chance of getting a question answered, using something other than > Google Groups is indeed a good idea. What's that filter look like? --Hank From steve+comp.lang.python at pearwood.info Fri Sep 21 21:25:35 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Sep 2012 01:25:35 GMT Subject: Functional way to compare things inside a list References: <48191878-3a0e-4733-a426-55b6981c471d@googlegroups.com> Message-ID: <505d138e$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 21 Sep 2012 14:49:55 -0600, Ian Kelly wrote: > On Fri, Sep 21, 2012 at 1:54 PM, 88888 Dihedral > wrote: >> I don't think functional aspects are only marked as lazy programming. > > He wrote "lazy evaluation", not "lazy programming". Two entirely > different things. For the record, the consensus here is that 88888 Dihedral is probably a bot. It appears to be a pretty good bot, I haven't spotted it making any egregious or obvious grammatical mistakes, but the semantics of its posts don't seem quite human. 88888 Dihedral, if you're not a bot, you can go a long way towards proving that by telling us what colour a purple elephant is. -- Steven From steve+comp.lang.python at pearwood.info Fri Sep 21 21:26:43 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Sep 2012 01:26:43 GMT Subject: Print Function References: Message-ID: <505d13d3$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 21 Sep 2012 13:20:09 -0700, gengyangcai wrote: > I am currently using Python 3.2.3 . WHen I use the print function by > typing print "Game Over" , it mentions " SyntaxError : invalid syntax > ". Any ideas on what the problem is and how to resolve it ? No, none what so ever. Perhaps you are the first person in the world to have come across this error. If you ever solve it, please write up the solution and put it on a blog or a website somewhere so that if it ever happens again, googling for "python print SyntaxError" will return a useful result. Tongue-firmly-in-cheek-ly y'rs, -- Steven From steve+comp.lang.python at pearwood.info Fri Sep 21 21:28:04 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Sep 2012 01:28:04 GMT Subject: Algorithms using Python? References: Message-ID: <505d1424$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 21 Sep 2012 17:14:14 -0400, Dennis Lee Bieber wrote: > On Fri, 21 Sep 2012 14:07:01 -0600, Ian Kelly > declaimed the following in gmane.comp.python.general: > > >> It seems to work fine to me. > > You are working with dynamically allocated memory for the nodes; Doesn't everybody? :) > I was envisioning the implementation of linked lists in what would have > been statically allocated arrays (or one large dynamic memory block with > all data tracking kept internally) (ie; a naive attempt using a Python > list where nodes are [nxtIndex, data], and accidently removing a node > from that list). Writing Fortran77 in Python! :) -- Steven From rosuav at gmail.com Fri Sep 21 21:34:40 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Sep 2012 11:34:40 +1000 Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> Message-ID: On Sat, Sep 22, 2012 at 4:45 AM, ????? ?????? wrote: > One webpage of mine, http://www.varsa.gr/ has been *hacked* 15 mins ago. > > I know this is not a python question but you guyshave high knowledge of web sites programming and i though you wouldnt mind helping me out. No, this is not a Python question. I would recommend looking for Joomla-specific help. And when you do, you'll find out that these sorts of web frameworks have vulnerabilities just like every other big program seems to, with Joomla looking like a happy member of the Windows family. ChrisA From steve+comp.lang.python at pearwood.info Fri Sep 21 21:36:59 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Sep 2012 01:36:59 GMT Subject: Exact integer-valued floats References: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> <7xzk4j6mmq.fsf@ruckus.brouhaha.com> Message-ID: <505d163b$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 21 Sep 2012 15:23:41 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> Have I got this right? Is there a way to work out the gap between one >> float and the next? > > Yes, 53-bit mantissa as people have mentioned. That tells you what ints > can be exactly represented. But, arithmetic in some situations can have > a 1-ulp error. So I wonder if it's possible that if n is large enough, > you might have something like n+1==n even if the integers n and n+1 have > distinct floating point representations. I don't think that is possible for IEEE 754 floats, where integer arithmetic is exact. But I'm not entirely sure, which is why I asked. For non IEEE 754 floating point systems, there is no telling how bad the implementation could be :( -- Steven From steve+comp.lang.python at pearwood.info Fri Sep 21 21:42:35 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Sep 2012 01:42:35 GMT Subject: One of my joomla webpages has been hacked. Please help. References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> Message-ID: <505d178a$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 21 Sep 2012 11:45:14 -0700, ????? ?????? wrote: > One webpage of mine, [url redacted] has been *hacked* 15 mins ago. [...] > I would be gratefull for any help you provide me. Yeah yeah, sure. Is this an attempt to get people to visit your web site so it can do a drive-by install of malware? > I know this is not a python question But you asked anyway. Why don't you ask your car mechanic to fix your plumbing, or go to the doctor to ask advice on how to cook pizza? -- Steven From steve+comp.lang.python at pearwood.info Fri Sep 21 21:43:05 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Sep 2012 01:43:05 GMT Subject: Does python have built command for package skeleton creation? References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> <505c8dc1$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <505d17a9$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 22 Sep 2012 03:44:55 +1000, Chris Angelico wrote: > On Sat, Sep 22, 2012 at 1:54 AM, Steven D'Aprano > wrote: >> But consider, C and C++ don't have minor releases *at all*. The last >> versions of those two languages are C99 and C+98 -- that's FOURTEEN >> YEARS since the last version of C++. And Java hasn't had a major >> feature update since 2006. >> >> For a programming language with a lot of corporate use, Python already >> seems like it changes at the drop of a hat. > > Hang on, you're conflating the language and its implementation. No I'm not. CPython is the reference implementation of Python the language. There is no ISO standard for Python (nor is there likely to be any time soon) so Python the language is more-or-less what CPython the implementation does. [...] > Python's release schedule is plenty fast enough. It's already > outstripping the packagers in Debian and Red Hat. And has for a long time, well back to Python 1.5 days if I remember correctly. > Fortunately it's > pretty easy to whip up your own Python straight from source and 'make > altinstall' to keep things happily parallel. You want faster releases? > You got 'em. But not faster than ?18 months between minor releases. Not unless you fork and do it yourself. -- Steven From steve+comp.lang.python at pearwood.info Fri Sep 21 21:48:27 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Sep 2012 01:48:27 GMT Subject: technologies synergistic with Python References: Message-ID: <505d18eb$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 21 Sep 2012 14:59:47 -0700, Ethan Furman wrote: > Greetings! > > What is the consensus... okay, okay -- what are some wide ranging > opinions on technologies that I should know if my dream job is one that > consists mostly of Python, and might allow telecommuting? That depends on what your dream job is using Python for. Web development? HTML, Javascript, Flash *spit*, JSON, XML, SQL, server-side system administration ("how do I restart the web server?"), whatever framework is being used. Linux system administration? Linux, bash (or some other shell), perl, gcc, Python. Numerical work? C, Fortran, numpy, scipy, mathematics. Integration with Java frameworks and applications? Java :-P > (Please don't say Java, please don't say Java, please don't say... ;) -- Steven From rosuav at gmail.com Fri Sep 21 21:48:57 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Sep 2012 11:48:57 +1000 Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: <505d178a$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505d178a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 22, 2012 at 11:42 AM, Steven D'Aprano wrote: > But you asked anyway. Why don't you ask your car mechanic to fix your > plumbing, or go to the doctor to ask advice on how to cook pizza? Or your plumber to rescue the princess who's in another castle... ChrisA From rosuav at gmail.com Fri Sep 21 22:00:15 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Sep 2012 12:00:15 +1000 Subject: Does python have built command for package skeleton creation? In-Reply-To: <505d17a9$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> <505c8dc1$0$29981$c3e8da3$5496439d@news.astraweb.com> <505d17a9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 22, 2012 at 11:43 AM, Steven D'Aprano wrote: > On Sat, 22 Sep 2012 03:44:55 +1000, Chris Angelico wrote: > >> On Sat, Sep 22, 2012 at 1:54 AM, Steven D'Aprano >> wrote: >>> For a programming language with a lot of corporate use, Python already >>> seems like it changes at the drop of a hat. >> >> Hang on, you're conflating the language and its implementation. > > No I'm not. CPython is the reference implementation of Python the > language. There is no ISO standard for Python (nor is there likely to be > any time soon) so Python the language is more-or-less what CPython the > implementation does. True, though not entirely; there are plenty of CPython behaviours that aren't strictly specified, and other Pythons don't have to comply. >> Fortunately it's >> pretty easy to whip up your own Python straight from source and 'make >> altinstall' to keep things happily parallel. You want faster releases? >> You got 'em. > > But not faster than ?18 months between minor releases. Not unless you > fork and do it yourself. Why wait for a release? Just build with whatever patches you want to build with. That's what I do with a lot of oddments of software. Well, actually, what I tend to do is simply build HEAD (or whatever hg calls it) as of when I want it, and update whenever I feel like it. :) ChrisA From rosuav at gmail.com Fri Sep 21 22:10:21 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Sep 2012 12:10:21 +1000 Subject: technologies synergistic with Python In-Reply-To: <505d18eb$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <505d18eb$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 22, 2012 at 11:48 AM, Steven D'Aprano wrote: > Integration with Java frameworks and applications? > > Java :-P I asked you not to tell me that! JavaScript/ECMAScript/etc-script isn't that bad a language. It's workable. And thanks to it, my boss now understands pass-by-object semantics, which is a Good Thing. But good or bad, you can't do much web programming without it. Of course, you can do a lot of Python without writing for the web. Expand out in any direction at all, really. Anything'll make you more employable. Systems administration and basic management, as Steven mentioned; I'd expand on that to general networking. Know how to diagnose basic issues with getting information off the web (interface down, routing problems, DNS issues, etc), because some day, you'll be on your own without any access to Google and have to solve the problem unassisted :) http://xkcd.com/903/ ChrisA From tjreedy at udel.edu Fri Sep 21 22:46:08 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 21 Sep 2012 22:46:08 -0400 Subject: Python 3.3 and .pyo files In-Reply-To: References: Message-ID: On 9/21/2012 5:10 AM, Marco wrote: > I was trying to import a pyo module in Python 3.3, but Python does not > find it: You appear to be trying to *run*, not *import* a .pyo module. > $ echo "print(__file__)" > foo.py > $ python3.3 -O -m foo Since foo.py is in the current directory, I am not sure why you use '-m foo' instead of 'foo.py'. -m is for running a module somewhere on sys.path. > /home/marco/temp/foo.py > $ ls > foo.py __pycache__ > $ rm foo.py > $ mv __pycache__/foo.cpython-33.pyo foo.pyo > $ rm __pycache__ -r > $ ls > foo.pyo > # The following works in Python3.2, but not in 3.3 > $ python3.3 -O -m foo I would try just 'foo.pyo' in case the -m part is the problem. Also, the -O is sort of redundant, or perhaps interfering, since its usual effect to to say 'get and put, from and to the cache, .pyo instead of .pyc'. > /usr/local/bin/python3.3: No module named foo > > How come? Thanks in advance, Marco You might read some of http://bugs.python.org/issue12982 in particular, from http://bugs.python.org/issue12982#msg162814 "Indeed, since I posted last night, the pydev discussion has moved to the question of whether -O, __debug__, and .pyo as now defined are worth the nuisance they cause or whether some or all should be deprecated. (Docstring stripping for saving space could then be a separate tool.) --- Python interpreters exist to run Python code. The existence, persistence, and other details of compilation caches are version-dependent implementation details. Being able to execute from such caches without source present is also an implementation detail, and for CPython, it gets secondary support at best. (This is a compromise between full support and no support.)" -- Terry Jan Reedy From maniandram01 at gmail.com Fri Sep 21 23:05:39 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 21 Sep 2012 20:05:39 -0700 (PDT) Subject: How to limit CPU usage in Python In-Reply-To: References: Message-ID: <302aaed2-4317-43e6-8a3a-574049931844@googlegroups.com> you On Saturday, 22 September 2012 05:14:15 UTC+5:30, Cameron Simpson wrote: > On 20Sep2012 12:53, Terry Reedy wrote: > > | On 9/20/2012 12:46 PM, Terry Reedy wrote: > > | > On 9/20/2012 11:12 AM, Rolando Ca?er Roblejo wrote: > > | >> Is it possible for me to put a limit in the amount of processor usage (% > > | >> CPU) that my current python script is using? Is there any module useful > > | >> for this task? I saw Resource module but I think it is not the module I > > | >> am looking for. Some people recommend to use nice and cpulimit unix > > | >> tools, but those are external to python and I prefer a python solution. > > | >> I am working with Linux (Ubuntu 10.04). > > | > > > | > Call the external tools with subprocess.open. > > | > > | I meant to end that with ? as I don't know how easy it is to get the > > | external id of the calling process that is to be limited. I presume that > > | can be done by first calling ps (with subprocess) and searching the > > | piped-back output. > > > > If you're limiting yourself, os.getpid(). > > -- > > Cameron Simpson You could use os.times to compute the CPU usage and then stop the process when that happens and then start it after some time using signals. From maniandram01 at gmail.com Fri Sep 21 23:05:39 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 21 Sep 2012 20:05:39 -0700 (PDT) Subject: How to limit CPU usage in Python In-Reply-To: References: Message-ID: <302aaed2-4317-43e6-8a3a-574049931844@googlegroups.com> you On Saturday, 22 September 2012 05:14:15 UTC+5:30, Cameron Simpson wrote: > On 20Sep2012 12:53, Terry Reedy wrote: > > | On 9/20/2012 12:46 PM, Terry Reedy wrote: > > | > On 9/20/2012 11:12 AM, Rolando Ca?er Roblejo wrote: > > | >> Is it possible for me to put a limit in the amount of processor usage (% > > | >> CPU) that my current python script is using? Is there any module useful > > | >> for this task? I saw Resource module but I think it is not the module I > > | >> am looking for. Some people recommend to use nice and cpulimit unix > > | >> tools, but those are external to python and I prefer a python solution. > > | >> I am working with Linux (Ubuntu 10.04). > > | > > > | > Call the external tools with subprocess.open. > > | > > | I meant to end that with ? as I don't know how easy it is to get the > > | external id of the calling process that is to be limited. I presume that > > | can be done by first calling ps (with subprocess) and searching the > > | piped-back output. > > > > If you're limiting yourself, os.getpid(). > > -- > > Cameron Simpson You could use os.times to compute the CPU usage and then stop the process when that happens and then start it after some time using signals. From rosuav at gmail.com Fri Sep 21 23:08:43 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Sep 2012 13:08:43 +1000 Subject: how to do draw pattern with python? In-Reply-To: References: Message-ID: On Sat, Sep 22, 2012 at 5:55 AM, Mark Lawrence wrote: > I tried running your code but got this:- > > c:\Users\Mark>pattern.py > File "C:\Users\Mark\pattern.py", line 22 > > Doing your homework since 2001 > ^ > SyntaxError: invalid syntax > > What am I doing wrong? The problem is the first non-blank line after "I tried running your code". Note the path designators and the way they appear ready to fall over backwards at a moment's notice, just like their host operating system. Switch to my new HomeworkOS, freely downloadable from my personal server running my own protocols and completely incompatible with TCP/IP, and this will work perfectly! *searches the Yellow Pages for cheek-tongue-removal services* ChrisA From ian.g.kelly at gmail.com Sat Sep 22 02:22:43 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 22 Sep 2012 00:22:43 -0600 Subject: Functional way to compare things inside a list In-Reply-To: <505d138e$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <48191878-3a0e-4733-a426-55b6981c471d@googlegroups.com> <505d138e$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 21, 2012 at 7:25 PM, Steven D'Aprano wrote: > On Fri, 21 Sep 2012 14:49:55 -0600, Ian Kelly wrote: > >> On Fri, Sep 21, 2012 at 1:54 PM, 88888 Dihedral >> wrote: >>> I don't think functional aspects are only marked as lazy programming. >> >> He wrote "lazy evaluation", not "lazy programming". Two entirely >> different things. > > > For the record, the consensus here is that 88888 Dihedral is probably a > bot. It appears to be a pretty good bot, I haven't spotted it making any > egregious or obvious grammatical mistakes, but the semantics of its posts > don't seem quite human. I'm aware of that, although sometimes the posts seem coherent enough that I think maybe it's not. Especially the ones where it posts almost-working code snippets, complete with obvious typos. Then it posts a complete non sequitur like the reply to my reply in this thread, and the illusion is shattered. From dihedral88888 at googlemail.com Sat Sep 22 02:50:28 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 21 Sep 2012 23:50:28 -0700 (PDT) Subject: Functional way to compare things inside a list In-Reply-To: References: <48191878-3a0e-4733-a426-55b6981c471d@googlegroups.com> <505d138e$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ian? 2012?9?22????UTC+8??2?23?43???? > On Fri, Sep 21, 2012 at 7:25 PM, Steven D'Aprano > > wrote: > > > On Fri, 21 Sep 2012 14:49:55 -0600, Ian Kelly wrote: > > > > > >> On Fri, Sep 21, 2012 at 1:54 PM, 88888 Dihedral > > >> wrote: > > >>> I don't think functional aspects are only marked as lazy programming. > > >> > > >> He wrote "lazy evaluation", not "lazy programming". Two entirely > > >> different things. > > > > > > > > > For the record, the consensus here is that 88888 Dihedral is probably a > > > bot. It appears to be a pretty good bot, I haven't spotted it making any > > > egregious or obvious grammatical mistakes, but the semantics of its posts > > > don't seem quite human. > > > > I'm aware of that, although sometimes the posts seem coherent enough > > that I think maybe it's not. Especially the ones where it posts > > almost-working code snippets, complete with obvious typos. > > > > Then it posts a complete non sequitur like the reply to my reply in > > this thread, and the illusion is shattered. Do you want to use the lisp way for implementing functional programming? From dihedral88888 at googlemail.com Sat Sep 22 02:50:28 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 21 Sep 2012 23:50:28 -0700 (PDT) Subject: Functional way to compare things inside a list In-Reply-To: References: <48191878-3a0e-4733-a426-55b6981c471d@googlegroups.com> <505d138e$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ian? 2012?9?22????UTC+8??2?23?43???? > On Fri, Sep 21, 2012 at 7:25 PM, Steven D'Aprano > > wrote: > > > On Fri, 21 Sep 2012 14:49:55 -0600, Ian Kelly wrote: > > > > > >> On Fri, Sep 21, 2012 at 1:54 PM, 88888 Dihedral > > >> wrote: > > >>> I don't think functional aspects are only marked as lazy programming. > > >> > > >> He wrote "lazy evaluation", not "lazy programming". Two entirely > > >> different things. > > > > > > > > > For the record, the consensus here is that 88888 Dihedral is probably a > > > bot. It appears to be a pretty good bot, I haven't spotted it making any > > > egregious or obvious grammatical mistakes, but the semantics of its posts > > > don't seem quite human. > > > > I'm aware of that, although sometimes the posts seem coherent enough > > that I think maybe it's not. Especially the ones where it posts > > almost-working code snippets, complete with obvious typos. > > > > Then it posts a complete non sequitur like the reply to my reply in > > this thread, and the illusion is shattered. Do you want to use the lisp way for implementing functional programming? From jamie at kode5.net Sat Sep 22 03:08:17 2012 From: jamie at kode5.net (Jamie Paul Griffin) Date: Sat, 22 Sep 2012 08:08:17 +0100 Subject: Functional way to compare things inside a list In-Reply-To: References: <48191878-3a0e-4733-a426-55b6981c471d@googlegroups.com> <505d138e$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120922070817.GA97500@osx.kode5.net> [ Ian Kelly wrote on Sat 22.Sep'12 at 0:22:43 -0600 ] > On Fri, Sep 21, 2012 at 7:25 PM, Steven D'Aprano > wrote: > > On Fri, 21 Sep 2012 14:49:55 -0600, Ian Kelly wrote: > > > >> On Fri, Sep 21, 2012 at 1:54 PM, 88888 Dihedral > >> wrote: > >>> I don't think functional aspects are only marked as lazy programming. > >> > >> He wrote "lazy evaluation", not "lazy programming". Two entirely > >> different things. > > > > > > For the record, the consensus here is that 88888 Dihedral is probably a > > bot. It appears to be a pretty good bot, I haven't spotted it making any > > egregious or obvious grammatical mistakes, but the semantics of its posts > > don't seem quite human. > > I'm aware of that, although sometimes the posts seem coherent enough > that I think maybe it's not. Especially the ones where it posts > almost-working code snippets, complete with obvious typos. > > Then it posts a complete non sequitur like the reply to my reply in > this thread, and the illusion is shattered. I find this intriguing, I had no idea bots existed to post to mailing lists in this way. What's the point of them? From nikos.gr33k at gmail.com Sat Sep 22 03:13:48 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rx5eXq?=) Date: Sat, 22 Sep 2012 00:13:48 -0700 (PDT) Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: <505d178a$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505d178a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: ?? ???????, 22 ??????????? 2012 4:42:35 ?.?. UTC+3, ? ??????? Steven D'Aprano ??????: > On Fri, 21 Sep 2012 11:45:14 -0700, ????? ?????? wrote: > > > > > One webpage of mine, [url redacted] has been *hacked* 15 mins ago. > > [...] > > > I would be gratefull for any help you provide me. > > > > Yeah yeah, sure. Is this an attempt to get people to visit your web site > > so it can do a drive-by install of malware? > > > > > > > I know this is not a python question > > > > But you asked anyway. Why don't you ask your car mechanic to fix your > > plumbing, or go to the doctor to ask advice on how to cook pizza? I was not into my intention to infect you with drive-by malware, it just my web site got defaced and i wanted info on how they did it. The web host company pulled a previous backup and now its all good. My apologies for the annoyance i have coused you all i wanted was some insight so to make sure this wont happen again( it already happened 2 times by now). From bahamutzero8825 at gmail.com Sat Sep 22 03:19:45 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 22 Sep 2012 02:19:45 -0500 Subject: Functional way to compare things inside a list In-Reply-To: <20120922070817.GA97500@osx.kode5.net> References: <48191878-3a0e-4733-a426-55b6981c471d@googlegroups.com> <505d138e$0$29981$c3e8da3$5496439d@news.astraweb.com> <20120922070817.GA97500@osx.kode5.net> Message-ID: <505D6691.6050605@gmail.com> On 2012.09.22 02:08, Jamie Paul Griffin wrote: > I find this intriguing, I had no idea bots existed to post to mailing > lists in this way. What's the point of them? To amuse their owners is my guess. -- CPython 3.3.0rc2 | Windows NT 6.1.7601.17835 From __peter__ at web.de Sat Sep 22 03:26:49 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 22 Sep 2012 09:26:49 +0200 Subject: One of my joomla webpages has been hacked. Please help. References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> Message-ID: ????? ?????? wrote: > One webpage of mine, http://www.varsa.gr/ has been *hacked* 15 mins ago. > Please visit my web page varsa.gr and view the source code and maybe you > can tell me what has happened. Do you use a password that was exposed in the other thread, http://mail.python.org/pipermail/python-list/2012-September/630779.html ? From breamoreboy at yahoo.co.uk Sat Sep 22 03:27:32 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 22 Sep 2012 08:27:32 +0100 Subject: Print Function In-Reply-To: <505d13d3$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <505d13d3$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 22/09/2012 02:26, Steven D'Aprano wrote: > On Fri, 21 Sep 2012 13:20:09 -0700, gengyangcai wrote: > >> I am currently using Python 3.2.3 . WHen I use the print function by >> typing print "Game Over" , it mentions " SyntaxError : invalid syntax >> ". Any ideas on what the problem is and how to resolve it ? > > No, none what so ever. Perhaps you are the first person in the world to > have come across this error. If you ever solve it, please write up the > solution and put it on a blog or a website somewhere so that if it ever > happens again, googling for "python print SyntaxError" will return a > useful result. > > Tongue-firmly-in-cheek-ly y'rs, > > + one trillion -- Cheers. Mark Lawrence. From franck at ditter.org Sat Sep 22 03:30:57 2012 From: franck at ditter.org (Franck Ditter) Date: Sat, 22 Sep 2012 09:30:57 +0200 Subject: Reading a file in IDLE 3 on Mac-Lion References: <505ccdc5$0$6919$e4fe514c@news2.news.xs4all.nl> Message-ID: In article <505ccdc5$0$6919$e4fe514c at news2.news.xs4all.nl>, Hans Mulder wrote: > On 21/09/12 16:29:55, Franck Ditter wrote: > > I create a text file utf-8 encoded in Python 3 with IDLE (Mac Lion). > > It runs fine and creates the disk file, visible with > > TextWrangler or another. > > But I can't open it with IDLE (its name is greyed). > > IDLE is supposed to read utf-8 files, no ? > > This works on Windows-7. > > There's a little pop-menu below the list of files. > > It allows you to choose which kind of files you want to open. > By default, it is set to "Python files", which greys out all > files, except those with a '.py' or '.pyw' extension. > Setting it to "Text files" should help, or else try "All files". > > Hope this helps > > -- HansM Alas this pop-up menu is for Windows only, I don't find it on MacOS-X. My files are xxx.dat files and not visible, even text only (numeric data). This can be filed as something to do ! Thanks, franck From nikos.gr33k at gmail.com Sat Sep 22 04:02:07 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rx5eXq?=) Date: Sat, 22 Sep 2012 01:02:07 -0700 (PDT) Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> Message-ID: ?? ???????, 22 ??????????? 2012 10:26:05 ?.?. UTC+3, ? ??????? Peter Otten ??????: > ????? ?????? wrote: > > > > > One webpage of mine, http://www.varsa.gr/ has been *hacked* 15 mins ago. > > > > > Please visit my web page varsa.gr and view the source code and maybe you > > > can tell me what has happened. > > > > Do you use a password that was exposed in the other thread, > > > > http://mail.python.org/pipermail/python-list/2012-September/630779.html > > > > ? No, that was for another web page of mine utilizing python mysql connection, this was joomla only website which remind me to also ask if i can embed somwhow python code to joomla cms. From nikos.gr33k at gmail.com Sat Sep 22 04:02:07 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rx5eXq?=) Date: Sat, 22 Sep 2012 01:02:07 -0700 (PDT) Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> Message-ID: ?? ???????, 22 ??????????? 2012 10:26:05 ?.?. UTC+3, ? ??????? Peter Otten ??????: > ????? ?????? wrote: > > > > > One webpage of mine, http://www.varsa.gr/ has been *hacked* 15 mins ago. > > > > > Please visit my web page varsa.gr and view the source code and maybe you > > > can tell me what has happened. > > > > Do you use a password that was exposed in the other thread, > > > > http://mail.python.org/pipermail/python-list/2012-September/630779.html > > > > ? No, that was for another web page of mine utilizing python mysql connection, this was joomla only website which remind me to also ask if i can embed somwhow python code to joomla cms. From rosuav at gmail.com Sat Sep 22 04:07:32 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Sep 2012 18:07:32 +1000 Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505d178a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 22, 2012 at 5:13 PM, ????? ?????? wrote: > The web host company pulled a previous backup and now its all good. > > My apologies for the annoyance i have coused you all i wanted was some insight so to make sure this wont happen again( it already happened 2 times by now). Just read those two sentences together, and figure out whether it really is "all good". What's happened twice can happen again. ChrisA From dwightdhutto at gmail.com Sat Sep 22 04:59:07 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sat, 22 Sep 2012 04:59:07 -0400 Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> Message-ID: On Fri, Sep 21, 2012 at 2:45 PM, ????? ?????? wrote: > Hello, > > One webpage of mine, http://www.varsa.gr/ has been *hacked* 15 mins ago. > The others are right, this is a joomla question, unless you're allowing execution of code by members and they utilize python. My questions: Only one? From my experience of joomla, you can allow your posters to execute code within their postings by utilizing certain plugins. It seems odd that only one page was hacked, or that they let you know, and didn't try db access. But it seems you're site had a hosting backup, but make sure to subscribe to the joomla update and security list, plus change the passwords. > I logged into CPanel but the joomla files seem ok. Did you have a backup of the file structure, and a zipped db backup, then check for new security flaws/change passwords/etc? > but when i view page code with chrome i get the source code, i dont knwo of which file thaty contains javascript inside. > > Please visit my web page varsa.gr and view the source code and maybe you can tell me what has happened. > > I would be gratefull for any help you provide me. > > I know this is not a python question but you guyshave high knowledge of web sites programming and i though you wouldnt mind helping me out. Yeah, programming, but joomla is html, php, css, and javascript, but I don't remember much python there. Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From kevin.p.dwyer at gmail.com Sat Sep 22 06:13:43 2012 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sat, 22 Sep 2012 11:13:43 +0100 Subject: One of my joomla webpages has been hacked. Please help. References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> Message-ID: ????? ?????? wrote: > ?? ???????, 22 ??????????? 2012 10:26:05 ?.?. UTC+3, ? ??????? Peter Otten > ??????: >> ????? ?????? wrote: >> >> >> >> > One webpage of mine, http://www.varsa.gr/ has been *hacked* 15 mins >> > ago. >> >> >> >> > Please visit my web page varsa.gr and view the source code and maybe >> > you >> >> > can tell me what has happened. >> >> >> >> Do you use a password that was exposed in the other thread, >> >> >> >> http://mail.python.org/pipermail/python-list/2012-September/630779.html >> >> >> >> ? > No, that was for another web page of mine utilizing python mysql > connection, this was joomla only website which remind me to also ask if i > can embed somwhow python code to joomla cms. This is only speculation, as I don't know exactly how your web page has been "hacked", but if your page somehow exposes a database connection, and the hack involves changing the contents of the database then you should read up on SQL injection attacks and how to prevent them. Cheers, Kev From nobody at nowhere.com Sat Sep 22 06:19:33 2012 From: nobody at nowhere.com (Nobody) Date: Sat, 22 Sep 2012 11:19:33 +0100 Subject: Exact integer-valued floats References: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> <7xzk4j6mmq.fsf@ruckus.brouhaha.com> Message-ID: On Fri, 21 Sep 2012 15:23:41 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> Have I got this right? Is there a way to work out the gap between one >> float and the next? > > Yes, 53-bit mantissa as people have mentioned. That tells you what ints > can be exactly represented. But, arithmetic in some situations can have a > 1-ulp error. So I wonder if it's possible that if n is large enough, you > might have something like n+1==n even if the integers n and n+1 have > distinct floating point representations. Not for IEEE-754. Or for any sane implementation, for that matter. OTOH, you can potentially get n != n due to the use of extended precision for intermediate results. For IEEE-754, addition, subtraction, multiplication, division, remainder and square root are "exact" in the sense that the result is as if the arithmetic had been performed with an infinite number of bits then rounded afterwards. For round-to-nearest, the result will be the closest representable value to the exact value. Transcendental functions suffer from the "table-maker's dilemma", and the result will be one of the two closest representable values to the exact value, but not necessarily *the* closest. From alister.ware at ntlworld.com Sat Sep 22 06:53:00 2012 From: alister.ware at ntlworld.com (Alister) Date: Sat, 22 Sep 2012 10:53:00 GMT Subject: Blue Screen Python References: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> Message-ID: On Fri, 21 Sep 2012 18:47:57 -0400, Dave Angel wrote: > On 09/21/2012 12:01 PM, Alister wrote: >> On Fri, 21 Sep 2012 15:14:53 +0000, Grant Edwards wrote: >> >>> On 2012-09-21, mikcec82 wrote: >>>> Hallo to all, >>>> >>>> I'm using Python 2.7.3 with Windows 7 @ 64 bit and an Intel Core i3 >>>> -2350M CPU @2.30GHz 2.3GHz. >>>> >>>> Sometimes, when I'm programming in Python on my screen compare this >>> Python is a user-space application. User-space applications can't >>> cause blue-screens unless they manage to trigger a bug in hardware, OS >>> kernel, >>> or device driver. > > True. Too bad there are so many of those bugs. > >> But Windows does not have any true concept of user-space (although it >> does make an almost convincing pretence) it has been hacked up from an >> operating system that's original security model was "Lock the door when >> you leave the office" >> >> > That's not true at all. You're thinking of Windows 3, Windows 95, 98, > and ME, which were hacked on top of MSDOS. But Windows NT3.5, 4, 2000, > XP, Vista and Windows 7 have an entirely different bloodline. > > NT 3.51 was actually very robust, but in 4.0 to gain better performance, > they apparently did some compromising in the video driver's isolation. > And who knows what's happened since then. Although NT upwards has tried to introduce user-space requirements the need to maintain backwards compatibility has compromised these efforts. it is not helped by the end user's (just look at what happened to Vista's attempt to make users authorise any changes to the system) -- VMS, n.: The world's foremost multi-user adventure game. From alister.ware at ntlworld.com Sat Sep 22 07:10:28 2012 From: alister.ware at ntlworld.com (Alister) Date: Sat, 22 Sep 2012 11:10:28 GMT Subject: One of my joomla webpages has been hacked. Please help. References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505d178a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 22 Sep 2012 18:07:32 +1000, Chris Angelico wrote: > On Sat, Sep 22, 2012 at 5:13 PM, ????? ?????? > wrote: >> The web host company pulled a previous backup and now its all good. >> >> My apologies for the annoyance i have coused you all i wanted was some >> insight so to make sure this wont happen again( it already happened 2 >> times by now). > > Just read those two sentences together, and figure out whether it really > is "all good". What's happened twice can happen again. > > ChrisA Indeed I would take this site down immediately until you can work out the insecurity in your application. without knowing too much I would suggest checking the following~: Rule 1) Use a strong password for the framework administration. Rule 2) Validate all inputs Rule 3) Do not give your application any more access privileges to you data bas that absolutely necessary. Rule 4)Ensure any data files containing passwords (hashed or otherwise) are stored outside the web-route. Rule 5) Validate ALL Inputs Rule 6) There is no rule 6 Rule 7) use prepared statements for database queries, do not construct them on the fly from user input ( Google SQL injection) Rule 8) VALIDATE ALL INPUTS! (Acknowledgement to 'The Bruces') -- My life is a patio of fun! From hansmu at xs4all.nl Sat Sep 22 07:11:00 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 22 Sep 2012 13:11:00 +0200 Subject: Reading a file in IDLE 3 on Mac-Lion In-Reply-To: References: <505ccdc5$0$6919$e4fe514c@news2.news.xs4all.nl> Message-ID: <505d9cc5$0$6846$e4fe514c@news2.news.xs4all.nl> On 22/09/12 09:30:57, Franck Ditter wrote: > In article <505ccdc5$0$6919$e4fe514c at news2.news.xs4all.nl>, > Hans Mulder wrote: > >> On 21/09/12 16:29:55, Franck Ditter wrote: >>> I create a text file utf-8 encoded in Python 3 with IDLE (Mac Lion). >>> It runs fine and creates the disk file, visible with >>> TextWrangler or another. >>> But I can't open it with IDLE (its name is greyed). >>> IDLE is supposed to read utf-8 files, no ? >>> This works on Windows-7. >> >> There's a little pop-menu below the list of files. >> >> It allows you to choose which kind of files you want to open. >> By default, it is set to "Python files", which greys out all >> files, except those with a '.py' or '.pyw' extension. >> Setting it to "Text files" should help, or else try "All files". >> >> Hope this helps >> >> -- HansM > > Alas this pop-up menu is for Windows only, I don't > find it on MacOS-X. It's there on my MacOS X 10.6.5 system. If your 10.7 system doesn't show it, that's definitely a bug. > My files are xxx.dat files and not visible, > even text only (numeric data). As a work-around, you could name the your file xxx.pyw. On Windows, there's a functional difference between .py and .pyw. On a Mac, there's no functional difference and Idle is willing to open both types of files, so you could use .py for code and .pyw for data. > This can be filed as something to do ! If you're feeling adventurous, you could try solving it yourself. Idle is written in pure Python; that makes this sort of thing a lot easier than if it were in C. And bug reports with a patch are far more likely to be picked up by the dev team. Hope this helps, -- HansM From overhaalsgang_24_bob at me.com Sat Sep 22 07:34:02 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Sat, 22 Sep 2012 04:34:02 -0700 (PDT) Subject: How to apply the user's HTML environment in a Python programme? In-Reply-To: References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> Message-ID: Op vrijdag 21 september 2012 17:28:02 UTC+2 schreef David Smith het volgende: > On 2012-09-21 08:57, BobAalsma wrote: > > > This text can be behind a username/password, but for several reasons, I don't want to know those. > > > > > > So I would like to set up a situation where the user logs in (if/when appropriate), points out the URL to my programme and my programme would then be able to read that particular text. > > I do this from a bat file that I will later translate to Python. > > I tell my work wiki which file I want. I use chrome, so for every new > > session I'm asked for my credentials. However, that is all transparent > > to my bat file. > > > > For that matter, when I download a new build from part of another bat > > file, I use Firefox and never see the credential exchange. > > > > I wouldn't expect any different behavior using Python. Umm, David, sorry, you've lost me but I think this could be a good solution - at least the division in client side/server side sounds like what I'm looking for. Could you please elaborate? Bob From overhaalsgang_24_bob at me.com Sat Sep 22 07:34:02 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Sat, 22 Sep 2012 04:34:02 -0700 (PDT) Subject: How to apply the user's HTML environment in a Python programme? In-Reply-To: References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> Message-ID: Op vrijdag 21 september 2012 17:28:02 UTC+2 schreef David Smith het volgende: > On 2012-09-21 08:57, BobAalsma wrote: > > > This text can be behind a username/password, but for several reasons, I don't want to know those. > > > > > > So I would like to set up a situation where the user logs in (if/when appropriate), points out the URL to my programme and my programme would then be able to read that particular text. > > I do this from a bat file that I will later translate to Python. > > I tell my work wiki which file I want. I use chrome, so for every new > > session I'm asked for my credentials. However, that is all transparent > > to my bat file. > > > > For that matter, when I download a new build from part of another bat > > file, I use Firefox and never see the credential exchange. > > > > I wouldn't expect any different behavior using Python. Umm, David, sorry, you've lost me but I think this could be a good solution - at least the division in client side/server side sounds like what I'm looking for. Could you please elaborate? Bob From overhaalsgang_24_bob at me.com Sat Sep 22 07:38:08 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Sat, 22 Sep 2012 04:38:08 -0700 (PDT) Subject: How to apply the user's HTML environment in a Python programme? In-Reply-To: References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> Message-ID: <6c7b7ada-1bc7-4eff-abba-301c6c3f2258@googlegroups.com> Op vrijdag 21 september 2012 22:10:04 UTC+2 schreef Dennis Lee Bieber het volgende: > On Fri, 21 Sep 2012 09:36:08 -0400, Jerry Hill > > declaimed the following in gmane.comp.python.general: > > > > > On Fri, Sep 21, 2012 at 9:31 AM, BobAalsma wrote: > > > > Thanks, Joel, yes, but as far as I'm aware these would all require the Python programme to have the user's username and password (or "credentials"), which I wanted to avoid. > > > > > > No matter what you do, your web service is going to have to > > > authenticate with the remote web site. The details of that > > > authentication are going to vary with each remote web site you want to > > > connect to. > > > > Hmmm, convoluted but presuming the "login" third party site uses > > cookies... Would it be possible to use Javascript on the client "copy" > > the HTML from the third-party and then transmit it to the application > > rather than having the application trying to do a direct fetch given > > just the URL? > > > > This should keep the authentication local to the client machine. > > > > > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ....com HTTP://wlfraed.home.netcom.com/ Wulfraed, yes, as with David's proposal: this sounds good, but I wouldn't know the first thing about Javascript... I'm also concerned that both solutions would seem to imply distributing software (or "software") to the clients systems. Hmm. Bob From overhaalsgang_24_bob at me.com Sat Sep 22 07:38:08 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Sat, 22 Sep 2012 04:38:08 -0700 (PDT) Subject: How to apply the user's HTML environment in a Python programme? In-Reply-To: References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> Message-ID: <6c7b7ada-1bc7-4eff-abba-301c6c3f2258@googlegroups.com> Op vrijdag 21 september 2012 22:10:04 UTC+2 schreef Dennis Lee Bieber het volgende: > On Fri, 21 Sep 2012 09:36:08 -0400, Jerry Hill > > declaimed the following in gmane.comp.python.general: > > > > > On Fri, Sep 21, 2012 at 9:31 AM, BobAalsma wrote: > > > > Thanks, Joel, yes, but as far as I'm aware these would all require the Python programme to have the user's username and password (or "credentials"), which I wanted to avoid. > > > > > > No matter what you do, your web service is going to have to > > > authenticate with the remote web site. The details of that > > > authentication are going to vary with each remote web site you want to > > > connect to. > > > > Hmmm, convoluted but presuming the "login" third party site uses > > cookies... Would it be possible to use Javascript on the client "copy" > > the HTML from the third-party and then transmit it to the application > > rather than having the application trying to do a direct fetch given > > just the URL? > > > > This should keep the authentication local to the client machine. > > > > > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ....com HTTP://wlfraed.home.netcom.com/ Wulfraed, yes, as with David's proposal: this sounds good, but I wouldn't know the first thing about Javascript... I'm also concerned that both solutions would seem to imply distributing software (or "software") to the clients systems. Hmm. Bob From d at davea.name Sat Sep 22 07:44:24 2012 From: d at davea.name (Dave Angel) Date: Sat, 22 Sep 2012 07:44:24 -0400 Subject: Blue Screen Python In-Reply-To: References: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> Message-ID: <505DA498.3070307@davea.name> On 09/22/2012 06:53 AM, Alister wrote: > On Fri, 21 Sep 2012 18:47:57 -0400, Dave Angel wrote: > >> >> >> That's not true at all. You'd re thinking of Windows 3, Windows 95, 98, >> and ME, which were hacked on top of MSDOS. But Windows NT3.5, 4, 2000, >> XP, Vista and Windows 7 have an entirely different bloodline. >> >> NT 3.51 was actually very robust, but in 4.0 to gain better performance, >> they apparently did some compromising in the video driver's isolation. >> And who knows what's happened since then. > Although NT upwards has tried to introduce Your wording seems to imply that you still think NT was built on some earlier MS product. It was written from scratch by a team recruited mostly from outside MS, including the leader, a guy who was I think experienced in VMS development. The names escape me right now. But there were a couple of books, by Helen someone, I think, which helped us outsiders understand some of the philosophies of the development. > user-space requirements the > need to maintain backwards compatibility has compromised these efforts. > it is not helped by the end user's (just look at what happened to Vista's > attempt to make users authorise any changes to the system) > > I don't see any connection between memory address space user models and user security models. -- DaveA From t at jollybox.de Sat Sep 22 08:01:29 2012 From: t at jollybox.de (Thomas Jollans) Date: Sat, 22 Sep 2012 14:01:29 +0200 Subject: How to apply the user's HTML environment in a Python programme? In-Reply-To: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> Message-ID: <505DA899.50802@jollybox.de> On 09/21/2012 02:57 PM, BobAalsma wrote: > I'd like to write a programme that will be offered as a web service (Django), in which the user will point to a specific URL and the programme will be used to read the text of that URL. > > This text can be behind a username/password, but for several reasons, I don't want to know those. > > So I would like to set up a situation where the user logs in (if/when appropriate), points out the URL to my programme and my programme would then be able to read that particular text. > > I'm aware this may sound fishy. It should not be: I want the user to be fully aware and in control of this process. > > Any thoughts on how to approach this? What services are you planning to interface with? Many services (twitter being a notable pioneer) have systems for external (web) applications to log in without being given a user's username & password. I think it's possible to load a page in an iframe and access it using JavaScript/DOM from the parent page. This is probably what you'll want to do. You say you don't know the first thing about JavaScript. Well, my friend, if you're developing for the web, learn JavaScript, or, depending on your situation, hire a front end developer who knows JavaScript. You can only do so much on the web without using JavaScript. I recently discovered this guide to learning JS; it sounds reasonable: http://javascriptissexy.com/how-to-learn-javascript-properly/ http://pyjs.org/ may be worth a look too. -- Thomas PS: Most of your messages appear to be both To: and Cc: this list. Please stop sending each message twice, it's rather distracting. From dihedral88888 at googlemail.com Sat Sep 22 08:19:25 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 22 Sep 2012 05:19:25 -0700 (PDT) Subject: Blue Screen Python In-Reply-To: References: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> Message-ID: Dave Angel? 2012?9?22????UTC+8??7?44?54???? > On 09/22/2012 06:53 AM, Alister wrote: > > > On Fri, 21 Sep 2012 18:47:57 -0400, Dave Angel wrote: > > > > > >> > > >> > > >> That's not true at all. You'd re thinking of Windows 3, Windows 95, 98, > > >> and ME, which were hacked on top of MSDOS. But Windows NT3.5, 4, 2000, > > >> XP, Vista and Windows 7 have an entirely different bloodline. > > >> > > >> NT 3.51 was actually very robust, but in 4.0 to gain better performance, > > >> they apparently did some compromising in the video driver's isolation. > > >> And who knows what's happened since then. > > > Although NT upwards has tried to introduce > > > > Your wording seems to imply that you still think NT was built on some > > earlier MS product. It was written from scratch by a team recruited > > mostly from outside MS, including the leader, a guy who was I think > > experienced in VMS development. The names escape me right now. But > > there were a couple of books, by Helen someone, I think, which helped us > > outsiders understand some of the philosophies of the development. > > > > > user-space requirements the > > > need to maintain backwards compatibility has compromised these efforts. > > > it is not helped by the end user's (just look at what happened to Vista's > > > attempt to make users authorise any changes to the system) > > > > > > > > I don't see any connection between memory address space user models and > > user security models. > > > > -- > > > > DaveA I tested MS NT in 1998-2002. I was pleased by the results to run real multi-tasking processes at that time. I ran some linux machines at that time, too. Anyway the heap walker problems in all the unix and linux systems were very obvious in those years. My conclusion at that time was people from DEC were really good in the OS. From dihedral88888 at googlemail.com Sat Sep 22 08:19:25 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 22 Sep 2012 05:19:25 -0700 (PDT) Subject: Blue Screen Python In-Reply-To: References: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> Message-ID: Dave Angel? 2012?9?22????UTC+8??7?44?54???? > On 09/22/2012 06:53 AM, Alister wrote: > > > On Fri, 21 Sep 2012 18:47:57 -0400, Dave Angel wrote: > > > > > >> > > >> > > >> That's not true at all. You'd re thinking of Windows 3, Windows 95, 98, > > >> and ME, which were hacked on top of MSDOS. But Windows NT3.5, 4, 2000, > > >> XP, Vista and Windows 7 have an entirely different bloodline. > > >> > > >> NT 3.51 was actually very robust, but in 4.0 to gain better performance, > > >> they apparently did some compromising in the video driver's isolation. > > >> And who knows what's happened since then. > > > Although NT upwards has tried to introduce > > > > Your wording seems to imply that you still think NT was built on some > > earlier MS product. It was written from scratch by a team recruited > > mostly from outside MS, including the leader, a guy who was I think > > experienced in VMS development. The names escape me right now. But > > there were a couple of books, by Helen someone, I think, which helped us > > outsiders understand some of the philosophies of the development. > > > > > user-space requirements the > > > need to maintain backwards compatibility has compromised these efforts. > > > it is not helped by the end user's (just look at what happened to Vista's > > > attempt to make users authorise any changes to the system) > > > > > > > > I don't see any connection between memory address space user models and > > user security models. > > > > -- > > > > DaveA I tested MS NT in 1998-2002. I was pleased by the results to run real multi-tasking processes at that time. I ran some linux machines at that time, too. Anyway the heap walker problems in all the unix and linux systems were very obvious in those years. My conclusion at that time was people from DEC were really good in the OS. From breamoreboy at yahoo.co.uk Sat Sep 22 08:53:49 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 22 Sep 2012 13:53:49 +0100 Subject: Blue Screen Python In-Reply-To: <505DA498.3070307@davea.name> References: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> <505DA498.3070307@davea.name> Message-ID: On 22/09/2012 12:44, Dave Angel wrote: > > Your wording seems to imply that you still think NT was built on some > earlier MS product. It was written from scratch by a team recruited > mostly from outside MS, including the leader, a guy who was I think > experienced in VMS development. The names escape me right now. But > there were a couple of books, by Helen someone, I think, which helped us > outsiders understand some of the philosophies of the development. > IIRC many of the people involved had VMS experience. Apparantly M$ decided they needed a team who knew something about designing and implementing operating systems :) -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Sat Sep 22 09:07:02 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Sep 2012 13:07:02 GMT Subject: Blue Screen Python References: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> Message-ID: <505db7f5$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 22 Sep 2012 07:44:24 -0400, Dave Angel wrote: [...] > Your wording seems to imply that you still think NT was built on some > earlier MS product. It was written from scratch by a team recruited > mostly from outside MS, including the leader, a guy who was I think > experienced in VMS development. I believe you are thinking of Dave Cutler, who wasn't just experienced in VMS development, he invented VMS. He also helped design the VAX, hated Unix with a passion, and killed off the RSTS operating system. He's now working on the Xbox. Windows NT was one of the reasons the IBM and Microsoft fell out. IBM and Microsoft partnered to build a new generation operating system, OS/2. Microsoft blew through a whole lot of IBM's money, produced something that they called version 1 but was more like version 0.1 (it only did text applications and had no GUI). They did eventually bring out a 1.1 version with a GUI, a year later. As per their partnership agreement, IBM took over development of OS/2 version 2 while Microsoft worked on developing version 3. OS/2 2.0 was significantly improved over the 1.x series. Then Microsoft reneged on the agreement to release OS/2 version 3, and instead re-badged it as Windows NT. One might say there was a little bit of bad blood over this, especially as IBM had good reason to think that Microsoft had been spending IBM's money on NT. -- Steven From steve+comp.lang.python at pearwood.info Sat Sep 22 09:09:36 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Sep 2012 13:09:36 GMT Subject: One of my joomla webpages has been hacked. Please help. References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> Message-ID: <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 22 Sep 2012 11:13:43 +0100, Kev Dwyer wrote: > This is only speculation, as I don't know exactly how your web page has > been "hacked", but if your page somehow exposes a database connection, > and the hack involves changing the contents of the database then you > should read up on SQL injection attacks and how to prevent them. This is joomla, that is, PHP. There are a bazillion ways to hack PHP. By the OP's own account, his website has been hacked twice before and he's done nothing to fix the vulnerability, just restored from backup. He'll be hacked again, and again, and again. Why are we discussing this? It has nothing to do with Python and is completely off-topic for this list. -- Steven From steve+comp.lang.python at pearwood.info Sat Sep 22 09:21:00 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Sep 2012 13:21:00 GMT Subject: Python 3.3 and .pyo files References: Message-ID: <505dbb3c$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 21 Sep 2012 22:46:08 -0400, Terry Reedy wrote: > On 9/21/2012 5:10 AM, Marco wrote: >> I was trying to import a pyo module in Python 3.3, but Python does not >> find it: > > You appear to be trying to *run*, not *import* a .pyo module. Marco is using the standard mechanism for finding, importing, and running a module. I don't believe his use of -m should be a problem. It works in 3.2, and it works with .pyc files in 3.3, I see nothing to suggest it shouldn't work with .pyo files in 3.3. >> $ echo "print(__file__)" > foo.py >> $ python3.3 -O -m foo > > Since foo.py is in the current directory, I am not sure why you use '-m > foo' instead of 'foo.py'. -m is for running a module somewhere on > sys.path. Yes, and the current directory is on sys.path. I would be astonished if python -m could not find a module that happened to be in the current directory. [...] > Also, the > -O is sort of redundant, or perhaps interfering, since its usual effect > to to say 'get and put, from and to the cache, .pyo instead of .pyc'. No it is not redundant. You link specifically to an bug tracker issue below where is is clearly decided that if you want to run a .pyo file you *must* use the -O switch. (I approve of this decision.) >> /usr/local/bin/python3.3: No module named foo >> >> How come? Thanks in advance, Marco > > You might read some of http://bugs.python.org/issue12982 > > in particular, from http://bugs.python.org/issue12982#msg162814 Whose words are these following? > Python interpreters exist to run Python code. The existence, > persistence, and other details of compilation caches are > version-dependent implementation details. Being able to execute from > such caches without source present is also an implementation detail, and > for CPython, it gets secondary support at best. (This is a compromise > between full support and no support.)" I'm not sure if these are your words, or if you are quoting some random commenter on the pydev list, or one of the lead developers who might actually know what he is talking about. As I recall, some time in the recent past Guido came down *hard* against the suggestion that support for running sourceless files (.pyc and .pyo) should be dropped. Even if I'm misremembering, it is the case that the Python 3.3 will find and run a .pyc file, but not a .pyo file. There's a new candidate release of 3.3 due out over the next couple of days. If it shows the same behaviour, it should be reported as a bug. -- Steven From alister.ware at ntlworld.com Sat Sep 22 09:29:13 2012 From: alister.ware at ntlworld.com (Alister) Date: Sat, 22 Sep 2012 13:29:13 GMT Subject: One of my joomla webpages has been hacked. Please help. References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 22 Sep 2012 13:09:36 +0000, Steven D'Aprano wrote: > On Sat, 22 Sep 2012 11:13:43 +0100, Kev Dwyer wrote: > >> This is only speculation, as I don't know exactly how your web page has >> been "hacked", but if your page somehow exposes a database connection, >> and the hack involves changing the contents of the database then you >> should read up on SQL injection attacks and how to prevent them. > > This is joomla, that is, PHP. There are a bazillion ways to hack PHP. By > the OP's own account, his website has been hacked twice before and he's > done nothing to fix the vulnerability, just restored from backup. He'll > be hacked again, and again, and again. > > Why are we discussing this? It has nothing to do with Python and is > completely off-topic for this list. the case may be off topic, but the principles and advise being given is well worth taking note of regardless of language. -- Kent's Heuristic: Look for it first where you'd most like to find it. From maniandram01 at gmail.com Sat Sep 22 10:01:49 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 22 Sep 2012 07:01:49 -0700 (PDT) Subject: Python 3.3 and .pyo files In-Reply-To: <505dbb3c$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <505dbb3c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2edbe283-8a2a-4562-a4cd-67e6dc018f00@googlegroups.com> On Saturday, 22 September 2012 18:51:01 UTC+5:30, Steven D'Aprano wrote: > On Fri, 21 Sep 2012 22:46:08 -0400, Terry Reedy wrote: > > > > > On 9/21/2012 5:10 AM, Marco wrote: > > >> I was trying to import a pyo module in Python 3.3, but Python does not > > >> find it: > > > > > > You appear to be trying to *run*, not *import* a .pyo module. > > > > Marco is using the standard mechanism for finding, importing, and running > > a module. I don't believe his use of -m should be a problem. It works in > > 3.2, and it works with .pyc files in 3.3, I see nothing to suggest it > > shouldn't work with .pyo files in 3.3. > > > > > > >> $ echo "print(__file__)" > foo.py > > >> $ python3.3 -O -m foo > > > > > > Since foo.py is in the current directory, I am not sure why you use '-m > > > foo' instead of 'foo.py'. -m is for running a module somewhere on > > > sys.path. > > > > Yes, and the current directory is on sys.path. > > > > I would be astonished if python -m could not find a module that happened > > to be in the current directory. > > > > > > [...] > > > Also, the > > > -O is sort of redundant, or perhaps interfering, since its usual effect > > > to to say 'get and put, from and to the cache, .pyo instead of .pyc'. > > > > No it is not redundant. You link specifically to an bug tracker issue > > below where is is clearly decided that if you want to run a .pyo file you > > *must* use the -O switch. (I approve of this decision.) > > > > > > >> /usr/local/bin/python3.3: No module named foo > > >> > > >> How come? Thanks in advance, Marco > > > > > > You might read some of http://bugs.python.org/issue12982 > > > > > > in particular, from http://bugs.python.org/issue12982#msg162814 > > > > Whose words are these following? > > > > > > > Python interpreters exist to run Python code. The existence, > > > persistence, and other details of compilation caches are > > > version-dependent implementation details. Being able to execute from > > > such caches without source present is also an implementation detail, and > > > for CPython, it gets secondary support at best. (This is a compromise > > > between full support and no support.)" > > > > I'm not sure if these are your words, or if you are quoting some random > > commenter on the pydev list, or one of the lead developers who might > > actually know what he is talking about. It is Terry J. Reedy's words - see end of http://bugs.python.org/issue12982#msg162814 > As I recall, some time in the recent past Guido came down *hard* against > > the suggestion that support for running sourceless files (.pyc and .pyo) > > should be dropped. Even if I'm misremembering, it is the case that the > > Python 3.3 will find and run a .pyc file, but not a .pyo file. There's a > > new candidate release of 3.3 due out over the next couple of days. If it > > shows the same behaviour, it should be reported as a bug. > > > > > > > > -- > > Steven From rosuav at gmail.com Sat Sep 22 10:10:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Sep 2012 00:10:09 +1000 Subject: Blue Screen Python In-Reply-To: <505db7f5$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> <505db7f5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 22, 2012 at 11:07 PM, Steven D'Aprano wrote: > As per their partnership agreement, IBM took over development of OS/2 > version 2 while Microsoft worked on developing version 3. OS/2 2.0 was > significantly improved over the 1.x series. > > Then Microsoft reneged on the agreement to release OS/2 version 3, and > instead re-badged it as Windows NT. One might say there was a little bit > of bad blood over this, especially as IBM had good reason to think that > Microsoft had been spending IBM's money on NT. And ever since then, Microsoft's been doing its best to kill OS/2 off. By the look of the database server sitting next to me, and the clients scattered throughout the building, it seems they have yet to succeed... OS/2 and Linux interoperate quite happily, too. Standards FTW. ChrisA From nikos.gr33k at gmail.com Sat Sep 22 10:44:36 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rx5eXq?=) Date: Sat, 22 Sep 2012 07:44:36 -0700 (PDT) Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: ?? ???????, 22 ??????????? 2012 4:09:37 ?.?. UTC+3, ? ??????? Steven D'Aprano ??????: > On Sat, 22 Sep 2012 11:13:43 +0100, Kev Dwyer wrote: > > > > > This is only speculation, as I don't know exactly how your web page has > > > been "hacked", but if your page somehow exposes a database connection, > > > and the hack involves changing the contents of the database then you > > > should read up on SQL injection attacks and how to prevent them. > > > > This is joomla, that is, PHP. There are a bazillion ways to hack PHP. By > > the OP's own account, his website has been hacked twice before and he's > > done nothing to fix the vulnerability, just restored from backup. He'll > > be hacked again, and again, and again. > > > > Why are we discussing this? It has nothing to do with Python and is > > completely off-topic for this list. > > > > > > -- > > Steven But how am i supposed to fix this vulnerability if i don't know which one is it? My guess is they used joomlas template to insert arbitrary code but thats just a guess. From rosuav at gmail.com Sat Sep 22 10:57:38 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Sep 2012 00:57:38 +1000 Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 23, 2012 at 12:44 AM, ????? ?????? wrote: > But how am i supposed to fix this vulnerability if i don't know which one is it? > > My guess is they used joomlas template to insert arbitrary code but thats just a guess. The answer to that is a thing called "research", and you'll usually find a lot of it at the other end of a web search. Also, you may want to look into what it means to be a web site administrator. It doesn't simply involve throwing down some code that someone else wrote and expecting it to work. If you want a web site without having to manage it yourself, consider a blog instead - someone else hosts it and worries about security, and you just post your content to it. It's a far FAR easier option, as long as what you want can be shoehorned into someone else's layout design. Neither of these options involves any Python coding, so if you want further assistance with them, I recommend looking for a forum dedicated to the technology you use. ChrisA From awilliam at whitemice.org Sat Sep 22 11:21:09 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sat, 22 Sep 2012 11:21:09 -0400 Subject: Looking for an IPC solution In-Reply-To: <50410AD6.7080003@shopzeus.com> References: <50410AD6.7080003@shopzeus.com> Message-ID: <1348327269.5145.11.camel@linux-nysu.site> On Fri, 2012-08-31 at 21:04 +0200, Laszlo Nagy wrote: > I have seen a stand alone cross platform IPC server before that could > serve "channels", and send/receive messages using these channels. But I > don't remember its name and now I cannot find it. Can somebody please help? I strongly recommend RabbitMQ - http://www.rabbitmq.com/ Just having a real and robust message broker is fabulous. It is tempting at first to want to avoid 'external' components; but development on top of a fully-featured message bus is extremely addictive. Working with Rabbit & AMQ is very pleasant and every time i have a uh-oh-i-need-to-deal-with... moment I discover that aha-rabbit-can-deal-with-that and back-to-my-application. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From ben+python at benfinney.id.au Sat Sep 22 11:21:20 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 23 Sep 2012 01:21:20 +1000 Subject: One of my joomla webpages has been hacked. Please help. References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7w392af5hr.fsf@benfinney.id.au> ????? ?????? writes: > ?? ???????, 22 ??????????? 2012 4:09:37 ?.?. UTC+3, ? ??????? Steven D'Aprano ??????: > > Why are we discussing this? It has nothing to do with Python and is > > completely off-topic for this list. > > But how am i supposed to fix this vulnerability if i don't know which > one is it? This is not the forum to discuss it. -- \ ?It is the fundamental duty of the citizen to resist and to | `\ restrain the violence of the state.? ?Noam Chomsky, 1971 | _o__) | Ben Finney From emile at fenx.com Sat Sep 22 13:58:38 2012 From: emile at fenx.com (Emile van Sebille) Date: Sat, 22 Sep 2012 10:58:38 -0700 Subject: technologies synergistic with Python In-Reply-To: <505CE353.9090907@stoneleaf.us> References: <505CE353.9090907@stoneleaf.us> Message-ID: <505DFC4E.5020206@fenx.com> On 9/21/2012 2:59 PM Ethan Furman said... > ...if my dream job is one that > consists mostly of Python, and might allow telecommuting? Hi Ethan, I have an open position in my two man office I've tried to fill a couple times without success that is predominately python and would allow for telecommuting. I'm looking for a third member of the team that will focus on back end development integrating various systems through to an open source python platform. Where are you located? I'm on the SF Peninsula. Emile From emile at fenx.com Sat Sep 22 13:58:38 2012 From: emile at fenx.com (Emile van Sebille) Date: Sat, 22 Sep 2012 10:58:38 -0700 Subject: technologies synergistic with Python In-Reply-To: <505CE353.9090907@stoneleaf.us> References: <505CE353.9090907@stoneleaf.us> Message-ID: <505DFC4E.5020206@fenx.com> On 9/21/2012 2:59 PM Ethan Furman said... > ...if my dream job is one that > consists mostly of Python, and might allow telecommuting? Hi Ethan, I have an open position in my two man office I've tried to fill a couple times without success that is predominately python and would allow for telecommuting. I'm looking for a third member of the team that will focus on back end development integrating various systems through to an open source python platform. Where are you located? I'm on the SF Peninsula. Emile From nikos.gr33k at gmail.com Sat Sep 22 14:13:49 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rx5eXq?=) Date: Sat, 22 Sep 2012 11:13:49 -0700 (PDT) Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> ?? ???????, 22 ??????????? 2012 5:57:41 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Sun, Sep 23, 2012 at 12:44 AM, ????? ?????? wrote: > > > But how am i supposed to fix this vulnerability if i don't know which one is it? > > > > > > My guess is they used joomlas template to insert arbitrary code but thats just a guess. > > > > The answer to that is a thing called "research", and you'll usually > > find a lot of it at the other end of a web search. Also, you may want > > to look into what it means to be a web site administrator. It doesn't > > simply involve throwing down some code that someone else wrote and > > expecting it to work. > > > > If you want a web site without having to manage it yourself, consider > > a blog instead - someone else hosts it and worries about security, and > > you just post your content to it. It's a far FAR easier option, as > > long as what you want can be shoehorned into someone else's layout > > design. > > > > Neither of these options involves any Python coding, so if you want > > further assistance with them, I recommend looking for a forum > > dedicated to the technology you use. > > > > ChrisA Okey i'll ask this to the officila joomla forum, one last thing though. Is there a way to somehow embed(or utilize) python code, for example my python counter code script you have seen last week inside my Joomla/WordPress cms sites? For example: http://superhost.gr/ is my main website utilizing python counter script. http://superhost.gr/html/?show=log is my own way(i prefer it over awstats - don't ask why) for viewing my visitors. in my other sites which are CMS sites, like http://varsa.gr and http://thessalonik.wordpress.com/ is there a possible way to embed(if thats the term) my python counter script there too? so i can keep track of visitors info for each page i have there? From nikos.gr33k at gmail.com Sat Sep 22 14:13:49 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rx5eXq?=) Date: Sat, 22 Sep 2012 11:13:49 -0700 (PDT) Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> ?? ???????, 22 ??????????? 2012 5:57:41 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Sun, Sep 23, 2012 at 12:44 AM, ????? ?????? wrote: > > > But how am i supposed to fix this vulnerability if i don't know which one is it? > > > > > > My guess is they used joomlas template to insert arbitrary code but thats just a guess. > > > > The answer to that is a thing called "research", and you'll usually > > find a lot of it at the other end of a web search. Also, you may want > > to look into what it means to be a web site administrator. It doesn't > > simply involve throwing down some code that someone else wrote and > > expecting it to work. > > > > If you want a web site without having to manage it yourself, consider > > a blog instead - someone else hosts it and worries about security, and > > you just post your content to it. It's a far FAR easier option, as > > long as what you want can be shoehorned into someone else's layout > > design. > > > > Neither of these options involves any Python coding, so if you want > > further assistance with them, I recommend looking for a forum > > dedicated to the technology you use. > > > > ChrisA Okey i'll ask this to the officila joomla forum, one last thing though. Is there a way to somehow embed(or utilize) python code, for example my python counter code script you have seen last week inside my Joomla/WordPress cms sites? For example: http://superhost.gr/ is my main website utilizing python counter script. http://superhost.gr/html/?show=log is my own way(i prefer it over awstats - don't ask why) for viewing my visitors. in my other sites which are CMS sites, like http://varsa.gr and http://thessalonik.wordpress.com/ is there a possible way to embed(if thats the term) my python counter script there too? so i can keep track of visitors info for each page i have there? From rosuav at gmail.com Sat Sep 22 14:17:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Sep 2012 04:17:20 +1000 Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> Message-ID: On Sun, Sep 23, 2012 at 4:13 AM, ????? ?????? wrote: > Is there a way to somehow embed(or utilize) python code, for example my python counter code script you have seen last week inside my Joomla/WordPress cms sites? You probably could. But I reiterate, you're going about things all backwards. Keep things way WAY simpler and just do some basic parsing of your web logs after the event. Life is so much easier that way. ChrisA From hansmu at xs4all.nl Sat Sep 22 15:34:58 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 22 Sep 2012 21:34:58 +0200 Subject: how to do draw pattern with python? In-Reply-To: References: Message-ID: <505e12e3$0$6903$e4fe514c@news2.news.xs4all.nl> On 21/09/12 19:32:20, Ian Kelly wrote: > On Fri, Sep 21, 2012 at 10:50 AM, Ismael Farf?n wrote: >> 2012/9/21 Peter Otten <__peter__ at web.de>: >>> echo.hping at gmail.com wrote: >>> >>> print "\x1b[2J\x1b[0;0H" # optional >> >> Nice code : ) >> >> Could you dissect that weird string for us? >> >> It isn't returning the cursor to (0,0), it's just like executing >> clear(1), and looks like those line coloring scape sequences for bash. > > They're called "ANSI escape codes". :-) > > CSI 2J clears the screen. > CSI 0;0H means "move the cursor to row 0, column 0". However, I don't > think that's valid ANSI, as the coordinates are 1-based. Probably it > should have been "\x1b[2J\x1b[1;1H". Yes, the coordinates are 1-base, so it should have been "\x1b[2J\x1b[1;1H". Or, since 1;1 is the default, "\x1b[2J\x1b[H". On my machine, clear(1) uses "\x1b[H\x1b[2J". Using clear(1) appears to be the most portable way to do it: import os, time data = """\ x....x .x..x. ..xx.. ..xx.. .x..x. x....x """.splitlines() data = [line * 12 for line in data] # optional try: while True: os.system("clear") # optional for i, line in enumerate(data): print line data[i] = line[1:] + line[:1] time.sleep(.1) except KeyboardInterrupt: pass Hope this helps, -- HansM From tyler at tysdomain.com Sat Sep 22 16:13:49 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sat, 22 Sep 2012 14:13:49 -0600 Subject: request for another code review Message-ID: <505E1BFD.8010801@tysdomain.com> Hello all: I've gotten a bit farther into my python mud, and wanted to request another code review for style and the like. Mainly I'm concerned about player.py, world.py and components and other ways to handle what I'm trying to do. I didn't run pychecker just yet, so there are probably a ton of syntax errors; my problem was that world was importing room, and room imported world for functionality and that made things a mess. Ideas and suggestions for code cleanup and cleaner ways to do things would be appreciated. git clone https://code.google.com/p/pymud/ Thanks, -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From timr at probo.com Sat Sep 22 16:55:38 2012 From: timr at probo.com (Tim Roberts) Date: Sat, 22 Sep 2012 13:55:38 -0700 Subject: How to limit CPU usage in Python References: Message-ID: Rolando Ca?er Roblejo wrote: > >Is it possible for me to put a limit in the amount of processor usage (% >CPU) that my current python script is using? Why? That's an odd request. It's natural to want to reduce your priority if you want other processes handled first, but an idle CPU is a wasted resource. You want it to be busy all of the time. >Some people recommend to use nice and cpulimit unix >tools, but those are external to python and I prefer a python solution. Scheduling and CPU priority are, by their very nature, operating system concepts. You will not find generic mechanisms wrapping them. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Sat Sep 22 17:05:18 2012 From: timr at probo.com (Tim Roberts) Date: Sat, 22 Sep 2012 14:05:18 -0700 Subject: Exact integer-valued floats References: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> <7xzk4j6mmq.fsf@ruckus.brouhaha.com> <505d163b$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Dennis Lee Bieber wrote: > >On 22 Sep 2012 01:36:59 GMT, Steven D'Aprano wrote: >> >> For non IEEE 754 floating point systems, there is no telling how bad the >> implementation could be :( > > Let's see what can be found... > > IBM 360: Same as Sigma-6 (no surprise; hearsay is the Sigma was >designed by renegade IBM folk; even down to using EBCDIC internally -- >but with a much different interrupt system [224 individual interrupt >vectors as I recall, vs the IBM's 7 vectors and polling to find what >device]). The Control Data 6000/Cyber series had sign bit and 11-bit exponent, with either a 48-bit mantissa or a 96-bit mantissa, packed into one or two 60-bit words. Values were not automatically normalized, so there was no assumed 1 bit, as in IEEE-754. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From ross.marsden at gmail.com Sat Sep 22 17:57:52 2012 From: ross.marsden at gmail.com (ross.marsden at gmail.com) Date: Sat, 22 Sep 2012 14:57:52 -0700 (PDT) Subject: Redirecting STDOUT to a Python Variable In-Reply-To: <4c206409$0$14147$c3e8da3@news.astraweb.com> References: <7e934b64-ec84-48c8-a4bb-a2272f1449a4@u26g2000yqu.googlegroups.com> <4c206409$0$14147$c3e8da3@news.astraweb.com> Message-ID: <8cabc9bb-5ae0-41fa-86b6-0a184192e601@googlegroups.com> To capture the traceback, so to put it in a log, I use this import traceback def get_traceback(): # obtain and return the traceback exc_type, exc_value, exc_traceback = sys.exc_info() return ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback)) Suppose I have a script run by the scheduler, this captures the traceback form any problems and emails them. if __name__ == '__main__': try: Runs_unattended() except: send_mail(send_from = yourEmailAddress, send_to = [ yourEmailAddress ], subject = 'Runs_unattended', text = '%s' % get_traceback(), files = [], server=yourLocalSMTP) From tjreedy at udel.edu Sat Sep 22 18:54:12 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 22 Sep 2012 18:54:12 -0400 Subject: Python 3.3 and .pyo files In-Reply-To: <505dbb3c$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <505dbb3c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/22/2012 9:21 AM, Steven D'Aprano wrote: > On Fri, 21 Sep 2012 22:46:08 -0400, Terry Reedy wrote: > >> On 9/21/2012 5:10 AM, Marco wrote: >>> I was trying to import a pyo module in Python 3.3, but Python does not >>> find it: >> >> You appear to be trying to *run*, not *import* a .pyo module. > > Marco is using the standard mechanism for finding, importing, and running > a module. I don't believe his use of -m should be a problem. It works in > 3.2, and it works with .pyc files in 3.3, I see nothing to suggest it > shouldn't work with .pyo files in 3.3. > > >>> $ echo "print(__file__)" > foo.py >>> $ python3.3 -O -m foo >> >> Since foo.py is in the current directory, I am not sure why you use '-m >> foo' instead of 'foo.py'. -m is for running a module somewhere on >> sys.path. > > Yes, and the current directory is on sys.path. > > I would be astonished if python -m could not find a module that happened > to be in the current directory. > > > [...] >> Also, the >> -O is sort of redundant, or perhaps interfering, since its usual effect >> to to say 'get and put, from and to the cache, .pyo instead of .pyc'. > > No it is not redundant. You link specifically to an bug tracker issue > below where is is clearly decided that if you want to run a .pyo file you > *must* use the -O switch. (I approve of this decision.) > > >>> /usr/local/bin/python3.3: No module named foo >>> >>> How come? Thanks in advance, Marco >> >> You might read some of http://bugs.python.org/issue12982 >> >> in particular, from http://bugs.python.org/issue12982#msg162814 > > Whose words are these following? > > >> Python interpreters exist to run Python code. The existence, >> persistence, and other details of compilation caches are >> version-dependent implementation details. Being able to execute from >> such caches without source present is also an implementation detail, and >> for CPython, it gets secondary support at best. (This is a compromise >> between full support and no support.)" > > I'm not sure if these are your words, or if you are quoting some random > commenter on the pydev list, or one of the lead developers who might > actually know what he is talking about. My words summarizing the discussion on pydev which included at least a few lead developers. My initial post was probably 6/12/2012 -- Terry Jan Reedy From no.email at nospam.invalid Sat Sep 22 19:05:49 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 22 Sep 2012 16:05:49 -0700 Subject: How to limit CPU usage in Python References: Message-ID: <7xpq5d7j5e.fsf@ruckus.brouhaha.com> Rolando Ca?er Roblejo writes: > Is it possible for me to put a limit in the amount of processor usage > (% CPU) that my current python script is using? Is there any module > useful for this task? One way is check your cpu usage once in a while, compare with elapsed time, and if your % usage is above what you want, sleep for a suitable interval before proceeding. Tim Roberts: reasons to want to do this might involve a shared host where excessive cpu usage affects other users; or a computer with limited power consumption, where prolonged high cpu activity causes thermal or other problems. From d at davea.name Sat Sep 22 19:06:08 2012 From: d at davea.name (Dave Angel) Date: Sat, 22 Sep 2012 19:06:08 -0400 Subject: Exact integer-valued floats In-Reply-To: References: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> <7xzk4j6mmq.fsf@ruckus.brouhaha.com> <505d163b$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <505E4460.5060301@davea.name> On 09/22/2012 05:05 PM, Tim Roberts wrote: > Dennis Lee Bieber wrote: >> On 22 Sep 2012 01:36:59 GMT, Steven D'Aprano wrote: >>> For non IEEE 754 floating point systems, there is no telling how bad the >>> implementation could be :( >> Let's see what can be found... >> >> IBM 360: Same as Sigma-6 (no surprise; hearsay is the Sigma was >> designed by renegade IBM folk; even down to using EBCDIC internally -- >> but with a much different interrupt system [224 individual interrupt >> vectors as I recall, vs the IBM's 7 vectors and polling to find what >> device]). > The Control Data 6000/Cyber series had sign bit and 11-bit exponent, with > either a 48-bit mantissa or a 96-bit mantissa, packed into one or two > 60-bit words. Values were not automatically normalized, so there was no > assumed 1 bit, as in IEEE-754. And it's been a long time (about 39 years), but as I recall the CDC 6400 (at least) had no integer multiply or divide. You had to convert to float first. The other oddity about the CDC series is it's the last machine I've encountered that used ones-complement for ints, with two values for zero. -- DaveA From walterhurry at lavabit.com Sat Sep 22 19:28:10 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Sat, 22 Sep 2012 23:28:10 +0000 (UTC) Subject: Print Function References: <505d13d3$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 22 Sep 2012 01:26:43 +0000, Steven D'Aprano wrote: > On Fri, 21 Sep 2012 13:20:09 -0700, gengyangcai wrote: > >> I am currently using Python 3.2.3 . WHen I use the print function by >> typing print "Game Over" , it mentions " SyntaxError : invalid syntax >> ". Any ideas on what the problem is and how to resolve it ? > > No, none what so ever. Perhaps you are the first person in the world to > have come across this error. If you ever solve it, please write up the > solution and put it on a blog or a website somewhere so that if it ever > happens again, googling for "python print SyntaxError" will return a > useful result. > > Tongue-firmly-in-cheek-ly y'rs, I think OP rather gave the game away with the subject line. From walterhurry at lavabit.com Sat Sep 22 19:35:35 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Sat, 22 Sep 2012 23:35:35 +0000 (UTC) Subject: technologies synergistic with Python References: <505CE353.9090907@stoneleaf.us> Message-ID: On Sat, 22 Sep 2012 10:58:38 -0700, Emile van Sebille wrote: > On 9/21/2012 2:59 PM Ethan Furman said... >> ...if my dream job is one that consists mostly of Python, and might >> allow telecommuting? > > Hi Ethan, > > I have an open position in my two man office I've tried to fill a couple > times without success that is predominately python and would allow for > telecommuting. I'm looking for a third member of the team that will > focus on back end development integrating various systems through to an > open source python platform. > > Where are you located? I'm on the SF Peninsula. > > Emile PMFJI. If he's going to telecommute, why does it matter where he is located? From ethan at stoneleaf.us Sat Sep 22 21:19:28 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 22 Sep 2012 18:19:28 -0700 Subject: technologies synergistic with Python In-Reply-To: References: <505CE353.9090907@stoneleaf.us> Message-ID: <505E63A0.7080500@stoneleaf.us> Walter Hurry wrote: > On Sat, 22 Sep 2012 10:58:38 -0700, Emile van Sebille wrote: > >> On 9/21/2012 2:59 PM Ethan Furman said... >>> ...if my dream job is one that consists mostly of Python, and might >>> allow telecommuting? >> Hi Ethan, >> >> I have an open position in my two man office I've tried to fill a couple >> times without success that is predominately python and would allow for >> telecommuting. I'm looking for a third member of the team that will >> focus on back end development integrating various systems through to an >> open source python platform. >> >> Where are you located? I'm on the SF Peninsula. >> >> Emile > > PMFJI. If he's going to telecommute, why does it matter where he is > located? I would think the biggest reason is compatible time-zones. After that, how costly face-to-face meetings would be. ~Ethan~ From nikos.gr33k at gmail.com Sat Sep 22 22:52:00 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rx5eXq?=) Date: Sat, 22 Sep 2012 19:52:00 -0700 (PDT) Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> Message-ID: ?? ???????, 22 ??????????? 2012 9:18:02 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Sun, Sep 23, 2012 at 4:13 AM, ????? ?????? wrote: > > > Is there a way to somehow embed(or utilize) python code, for example my python counter code script you have seen last week inside my Joomla/WordPress cms sites? > > > > You probably could. But I reiterate, you're going about things all > > backwards. Keep things way WAY simpler and just do some basic parsing > > of your web logs after the event. Life is so much easier that way. > > > > ChrisA Out of curiocity how would i used my python counter source code along with Joomla? From nikos.gr33k at gmail.com Sat Sep 22 22:52:00 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rx5eXq?=) Date: Sat, 22 Sep 2012 19:52:00 -0700 (PDT) Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> Message-ID: ?? ???????, 22 ??????????? 2012 9:18:02 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Sun, Sep 23, 2012 at 4:13 AM, ????? ?????? wrote: > > > Is there a way to somehow embed(or utilize) python code, for example my python counter code script you have seen last week inside my Joomla/WordPress cms sites? > > > > You probably could. But I reiterate, you're going about things all > > backwards. Keep things way WAY simpler and just do some basic parsing > > of your web logs after the event. Life is so much easier that way. > > > > ChrisA Out of curiocity how would i used my python counter source code along with Joomla? From rosuav at gmail.com Sat Sep 22 22:55:00 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Sep 2012 12:55:00 +1000 Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> Message-ID: On Sun, Sep 23, 2012 at 12:52 PM, ????? ?????? wrote: > ?? ???????, 22 ??????????? 2012 9:18:02 ?.?. UTC+3, ? ??????? Chris Angelico ??????: >> On Sun, Sep 23, 2012 at 4:13 AM, ????? ?????? wrote: >> >> > Is there a way to somehow embed(or utilize) python code, for example my python counter code script you have seen last week inside my Joomla/WordPress cms sites? >> >> You probably could. But I reiterate, you're going about things all >> backwards. Keep things way WAY simpler and just do some basic parsing >> of your web logs after the event. Life is so much easier that way. >> > > Out of curiocity how would i used my python counter source code along with Joomla? Easy. Look for what common sense would recommend, then turn 180 degrees. Let me know when you get there and we'll send the rest of the directions. -- paraphrasing what a stupid American tourist was told about directions in Australia ChrisA From dwightdhutto at gmail.com Sat Sep 22 23:04:39 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sat, 22 Sep 2012 23:04:39 -0400 Subject: How to limit CPU usage in Python In-Reply-To: <7xpq5d7j5e.fsf@ruckus.brouhaha.com> References: <7xpq5d7j5e.fsf@ruckus.brouhaha.com> Message-ID: rites: >> Is it possible for me to put a limit in the amount of processor usage >> (% CPU) that my current python script is using? Is there any module >> useful for this task? > > One way is check your cpu usage once in a while, compare with elapsed > time, and if your % usage is above what you want, sleep for a suitable > interval before proceeding. > The script in constant runtime, unless it's in relation to other processes, could be put on a % based sleep constant variable. If the script is constantly running the same processes, and the OP wants to limit it statistically, then at a critical portion in the script sleep for a constant, or maybe, dynamic variable. The only other is to create an app, disassemble it, and then refine the asm instructions being used at the assembly level, but I'm just scratching the surface of those enhancements. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From castironpi at gmail.com Sat Sep 22 23:07:13 2012 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 22 Sep 2012 20:07:13 -0700 (PDT) Subject: unit test strategy In-Reply-To: <50563006$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <505582d1$0$29890$c3e8da3$5496439d@news.astraweb.com> <50563006$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9d944fa5-9983-4f67-9c29-46ed36ca4069@googlegroups.com> On Sunday, September 16, 2012 3:01:11 PM UTC-5, Steven D'Aprano wrote: > On Sun, 16 Sep 2012 11:38:15 -0700, Aaron Brady wrote: > > Here is an example of some repetitive code. > > > > for view_meth in [ dict.items, dict.keys, dict.values ]: > > dict0= dict( ( k, None ) for k in range( 10 ) ) > > iter0= iter( view_meth( dict0 ) ) > > dict.__setitem__( dict0, 0, 1 ) > > next( iter0 ) > > dict.__setitem__( dict0, 10, 1 ) > > self.assertRaises( IterationError, next, iter0 ) > [...] > > First off, if you have any wish for this to be accepted into the standard > library, I suggest you stick to PEP 8. The code in the zip file on the other thread does conform to PEP 8. > Secondly, this is test code. A bit of repetition is not to be concerned > about, clarity is far more important than "Don't Repeat Yourself". The > aim isn't to write the fastest, or most compact code, but to have good > test coverage with tests which are *obviously* correct (rather than test > code which has no obvious bugs, which is very different). If a test > fails, you should be able to identify quickly what failed without running > a debugger to identify what part of the code failed. > > Thirdly, why are you writing dict.__setitem__( dict0, 0, 1 ) instead of > dict0[0] = 1 ? > > > [...] > > Specifically my questions are, is the code condensed beyond legibility? > > Yes. > > > > Should 'chain' execute the test directly, or act as a metaprogram and > > output the test code into a 2nd file, or both? > > None of the above. > > > > Should 'chain' create > > the iterators in a dictionary, or in the function local variables > > directly with 'exec'? > > Heavens to Murgatroyd, you can't be serious. > > > Here's my attempt at this. Note the features: > > - meaningful names (if a bit long, but that's a hazard of tests) > - distinct methods for each distinct test case > - comments explaining what the test code does > - use of subclassing > > > # Untested > class TestDictIteratorModificationDetection(unittest.TestCase): [snip] > def testIteratorFailsAfterSet(self): > self.iterator_fails_after_modification(dict.__setitem__, 1, 1) > > def testIteratorFailsAfterDel(self): > self.iterator_fails_after_modification(dict.__delitem__, 1) > > def testIteratorFailsAfterUpdate(self): > self.iterator_fails_after_modification(dict.update, {5: 1}) > > def testIteratorFailsAfterPop(self): > self.iterator_fails_after_modification(dict.pop, 4) [snip] > > I think I've got all the methods which can mutate a dictionary. If I > missed any, it's easy enough to add a new test method to the class. [snip] Well Mr. D'Aprano, I have some serious disagreements with the script you posted. You did test all the mutating methods; there are 7; but I don't think it's enough. You omitted the test case which revealed the bug originally or other pairs of operations; you didn't test on empty sets; you didn't test on "null" modifications; you didn't test on multiple iterators in any form; and you didn't test for memory leaks which is important with a dynamic structure. A thorough test suite should contain tens if not hundreds of tests for this application. Your script was very easy to understand. However in the volume I'm advocating, something more concise would easier to understand, and D-R-Y becomes applicable again. In a more concise form, the reader could browse what tests are executed, find a certain test or determine if it's omitted. The "best of both" solution is a metaprogram, which is extremely brief, but does not run tests, and outputs a full test catalog instead, which is then itself scrutinized and run as the real test. The test script would consequently be two files big, and be run in a specific order. Not all tests can be condensed in a metaprogram; the script would contain large sections of literal code or it would appear in yet a 3rd file. > Thirdly, why are you writing dict.__setitem__( dict0, 0, 1 ) instead of > dict0[0] = 1 ? '__setitem__' can be passed to secondary functions whereas square brackets cannot. The 2nd file, the output of the metaprogram, could contain either or both. We could pass 'operator.setitem' as an alternative. I realize I'm introducing yet a 3rd foreign concept with the patch. If not enough readers approve of it I will have to abandon it, which would be a shame. OTOH, I appreciate the fact you used my "for view in (dict.items, dict.keys, dict.values):" idea. Also, what is your argument that an unstarted iterator should be exempt from invalidation when the set/dict is modified? It is not obvious it should or shouldn't, similar to the behavior of modifying dict values but not keys, and I would side against the exemption. (Perhaps we should raise that issue on the other thread.) From dwightdhutto at gmail.com Sat Sep 22 23:24:55 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sat, 22 Sep 2012 23:24:55 -0400 Subject: How to limit CPU usage in Python In-Reply-To: References: Message-ID: Now also, just thinking theoretically with the knowledge I have, you could underclock(as opposed to overclocking, which is what gamers do), but have never seen that option in BIOS. And maybe there is an option in your OS, google search term 'limiting processes activity cpu usage': https://www.google.com/search?client=ubuntu&channel=fs&q=limiting+processes+activity+cpu+usage&ie=utf-8&oe=utf-8 This seemed good for what you want from a brief overview: http://www.cyberciti.biz/faq/cpu-usage-limiter-for-linux/ Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Sat Sep 22 23:44:25 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sat, 22 Sep 2012 23:44:25 -0400 Subject: A little morning puzzle In-Reply-To: References: Message-ID: On Thu, Sep 20, 2012 at 12:28 PM, Tobiah wrote: > >>> Here is my solution: > > >>> ** Incredibly convoluted and maximally less concise solution >>> than other offerings. ** > > >>> Might be better ones though. >> >> >> Unlikely. > > > Zing! > Why don't you all look at the code(python and C), and tell me how much code it took to write the functions the other's examples made use of to complete the task. Just because you can use a function, and make it look easier, doesn't mean the function you used had less code than mine, so if you look at the whole of what you used to make it simpler, mine was on point. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From maniandram01 at gmail.com Sat Sep 22 23:55:46 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 22 Sep 2012 20:55:46 -0700 (PDT) Subject: portable way of locating an executable (like which) In-Reply-To: References: Message-ID: <2a9605c0-7d6d-4518-b6ef-387a1daac418@googlegroups.com> On Friday, 21 September 2012 02:37:01 UTC+5:30, gelonida wrote: > I'd like to implement the equivalent functionality of the unix command > > /usr/bin/which > > > > The function should work under Linux and under windows. > > > > Did anybody already implement such a function. > > If not, is there a portable way of splitting the environment variable PATH? > > > > Thanks for any sugestions shutil.which does this in Python 3.3: http://docs.python.org/dev/library/shutil.html#shutil.which You can copy the code to support older Python versions. From maniandram01 at gmail.com Sat Sep 22 23:55:46 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 22 Sep 2012 20:55:46 -0700 (PDT) Subject: portable way of locating an executable (like which) In-Reply-To: References: Message-ID: <2a9605c0-7d6d-4518-b6ef-387a1daac418@googlegroups.com> On Friday, 21 September 2012 02:37:01 UTC+5:30, gelonida wrote: > I'd like to implement the equivalent functionality of the unix command > > /usr/bin/which > > > > The function should work under Linux and under windows. > > > > Did anybody already implement such a function. > > If not, is there a portable way of splitting the environment variable PATH? > > > > Thanks for any sugestions shutil.which does this in Python 3.3: http://docs.python.org/dev/library/shutil.html#shutil.which You can copy the code to support older Python versions. From steve+comp.lang.python at pearwood.info Sun Sep 23 00:06:50 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Sep 2012 04:06:50 GMT Subject: One of my joomla webpages has been hacked. Please help. References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> Message-ID: <505e8ada$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 22 Sep 2012 19:52:00 -0700, ????? ?????? wrote: > Out of curiocity how would i used my python counter source code along > with Joomla? This is not a Joomla forum. We do not know how to run code in Joomla. Regardless of whether the code is Python, or Perl, or Lisp, or Lua, or any of thousands of different languages, your question is about Joomla. Please ask it on a Joomla forum. And when you are there, don't ask them to fix your Python bugs. -- Steven From maniandram01 at gmail.com Sun Sep 23 00:09:59 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 22 Sep 2012 21:09:59 -0700 (PDT) Subject: Functional way to compare things inside a list In-Reply-To: References: <48191878-3a0e-4733-a426-55b6981c471d@googlegroups.com> <505d138e$0$29981$c3e8da3$5496439d@news.astraweb.com> <20120922070817.GA97500@osx.kode5.net> Message-ID: On Saturday, 22 September 2012 12:50:08 UTC+5:30, Andrew Berg wrote: > On 2012.09.22 02:08, Jamie Paul Griffin wrote: > > > I find this intriguing, I had no idea bots existed to post to mailing > > > lists in this way. What's the point of them? > > > > To amuse their owners is my guess. > > -- > > CPython 3.3.0rc2 | Windows NT 6.1.7601.17835 The bot could be used for automatic replies for duplicate posts (common questions are quite often repeated) From maniandram01 at gmail.com Sun Sep 23 00:09:59 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 22 Sep 2012 21:09:59 -0700 (PDT) Subject: Functional way to compare things inside a list In-Reply-To: References: <48191878-3a0e-4733-a426-55b6981c471d@googlegroups.com> <505d138e$0$29981$c3e8da3$5496439d@news.astraweb.com> <20120922070817.GA97500@osx.kode5.net> Message-ID: On Saturday, 22 September 2012 12:50:08 UTC+5:30, Andrew Berg wrote: > On 2012.09.22 02:08, Jamie Paul Griffin wrote: > > > I find this intriguing, I had no idea bots existed to post to mailing > > > lists in this way. What's the point of them? > > > > To amuse their owners is my guess. > > -- > > CPython 3.3.0rc2 | Windows NT 6.1.7601.17835 The bot could be used for automatic replies for duplicate posts (common questions are quite often repeated) From dwightdhutto at gmail.com Sun Sep 23 00:48:36 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sun, 23 Sep 2012 00:48:36 -0400 Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: <505e8ada$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> <505e8ada$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 23, 2012 at 12:06 AM, Steven D'Aprano wrote: > On Sat, 22 Sep 2012 19:52:00 -0700, ????? ?????? wrote: > >> Out of curiocity how would i used my python counter source code along >> with Joomla? > > > This is not a Joomla forum. We do not know how to run code in Joomla. PHP, CSS, HTML, JAVASCRIPT, templates, that is if you study CMS, and look at other languages. > Regardless of whether the code is Python, or Perl, or Lisp, or Lua, or > any of thousands of different languages, your question is about Joomla. No, joomla is a CMS framework of several languages. You're right, this is a Joomla question, but even python could be added into joomla as an API> > Please ask it on a Joomla forum. > D'Aprano > And when you are there, don't ask them to fix your Python bugs. If they know Joomla(PHP, CSS, HTML, JAVASCRIPT, templates), then they should know something about python, unlike Steven D'Aprano, who only knows Python, and in other posts, not that well to be a self proclaimed expert. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From rosuav at gmail.com Sun Sep 23 00:56:52 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Sep 2012 14:56:52 +1000 Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> <505e8ada$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 23, 2012 at 2:48 PM, Dwight Hutto wrote: > On Sun, Sep 23, 2012 at 12:06 AM, Steven D'Aprano > wrote: >> On Sat, 22 Sep 2012 19:52:00 -0700, ????? ?????? wrote: >> >>> Out of curiocity how would i used my python counter source code along >>> with Joomla? >> >> >> This is not a Joomla forum. We do not know how to run code in Joomla. > > If they know Joomla(PHP, CSS, HTML, JAVASCRIPT, templates), then they > should know something about python, unlike Steven D'Aprano, who only > knows Python, and in other posts, not that well to be a self > proclaimed expert. Steven's point is not that we, human beings (or parahuman beings, as the case may be), do not know how to run code in Joomla; I've worked with it, and know something about it, and my day job involves some PHP programming, so there's a reasonable chance that I could help him. (If I cared to. I don't have very much sympathy for security holes in old versions of big frameworks.) But this is not the forum for it. We, the collective intelligence of python-list and comp.lang.python, are not experts on PHP, Joomla, etc, etc, etc. The fact that, in theory, you could make Joomla use Python is insignificant. I could write a Python script that fetches content from a Joomla web site, but that doesn't make Joomla questions appropriate here. ChrisA From dwightdhutto at gmail.com Sun Sep 23 01:18:17 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sun, 23 Sep 2012 01:18:17 -0400 Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> <505e8ada$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 23, 2012 at 12:56 AM, Chris Angelico wrote: > On Sun, Sep 23, 2012 at 2:48 PM, Dwight Hutto wrote: >> On Sun, Sep 23, 2012 at 12:06 AM, Steven D'Aprano >> wrote: >>> On Sat, 22 Sep 2012 19:52:00 -0700, ????? ?????? wrote: >>> >>>> Out of curiocity how would i used my python counter source code along >>>> with Joomla? >>> >>> >>> This is not a Joomla forum. We do not know how to run code in Joomla. >> >> If they know Joomla(PHP, CSS, HTML, JAVASCRIPT, templates), then they >> should know something about python, unlike Steven D'Aprano, who only >> knows Python, and in other posts, not that well to be a self >> proclaimed expert. > > Steven's point is not that we, human beings (or parahuman beings, as > the case may be), do not know how to run code in Joomla; I've worked > with it, and know something about it, and my day job involves some PHP > programming, so there's a reasonable chance that I could help him. Then a referral, is what he needs, and what you need is to tell others you're a cross languaged programmer. (If > I cared to. I don't have very much sympathy for security holes in old SYmpathy, how about empathy, to show your designs can have bugs, which is why they have version. > versions of big frameworks.) Then refer him to the joomla security hole mailing list Or extend your skills, help him, then refer him > > But this is not the forum for it. We, the collective intelligence of > python-list and comp.lang.python, are not experts on PHP, Joomla, etc, We're the borg. We have google to help, or another mailing list with data. > etc, etc. The fact that, in theory, you could make Joomla use Python > is insignificant. I could write a Python script that fetches content > from a Joomla web site, but that doesn't make Joomla questions > appropriate here. > It does if the page he's using uses Python execution of code. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From nikos.gr33k at gmail.com Sun Sep 23 01:19:52 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rx5eXq?=) Date: Sat, 22 Sep 2012 22:19:52 -0700 (PDT) Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> <505e8ada$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7389ac67-45b4-43d4-b595-ab39be82d6b0@googlegroups.com> ?? ???????, 23 ??????????? 2012 7:48:40 ?.?. UTC+3, ? ??????? David Hutto ??????: > No, joomla is a CMS framework of several languages. You're right, this > > is a Joomla question, but even python could be added into joomla as an > > API> Thank you for pointing this out, looks very interesting, i already asked in forum.joomla.gr and i will post back if this is doable or not which as you claim it must be. It would be nice if out python scripts can be used along with Joomla CMS, Drupal or even Wordpress. From nikos.gr33k at gmail.com Sun Sep 23 01:19:52 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rx5eXq?=) Date: Sat, 22 Sep 2012 22:19:52 -0700 (PDT) Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> <505e8ada$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7389ac67-45b4-43d4-b595-ab39be82d6b0@googlegroups.com> ?? ???????, 23 ??????????? 2012 7:48:40 ?.?. UTC+3, ? ??????? David Hutto ??????: > No, joomla is a CMS framework of several languages. You're right, this > > is a Joomla question, but even python could be added into joomla as an > > API> Thank you for pointing this out, looks very interesting, i already asked in forum.joomla.gr and i will post back if this is doable or not which as you claim it must be. It would be nice if out python scripts can be used along with Joomla CMS, Drupal or even Wordpress. From timr at probo.com Sun Sep 23 01:27:25 2012 From: timr at probo.com (Tim Roberts) Date: Sat, 22 Sep 2012 22:27:25 -0700 Subject: Exact integer-valued floats Message-ID: True. Seymour wanted all of the integer instructions to be combinatorial logic, rather than iterative. Fortunately, since the floating point binary point was to the right, it was trivial to pack integers to float, do a floating computation, then unpack back to integer. Apologize in advance for top-posting. My Xoom makes bottom-posting awkward. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. Dave Angel wrote: On 09/22/2012 05:05 PM, Tim Roberts wrote: > Dennis Lee Bieber wrote: >> On 22 Sep 2012 01:36:59 GMT, Steven D'Aprano wrote: >>> For non IEEE 754 floating point systems, there is no telling how bad the >>> implementation could be :( >> Let's see what can be found... >> >> IBM 360: Same as Sigma-6 (no surprise; hearsay is the Sigma was >> designed by renegade IBM folk; even down to using EBCDIC internally -- >> but with a much different interrupt system [224 individual interrupt >> vectors as I recall, vs the IBM's 7 vectors and polling to find what >> device]). > The Control Data 6000/Cyber series had sign bit and 11-bit exponent, with > either a 48-bit mantissa or a 96-bit mantissa, packed into one or two > 60-bit words. Values were not automatically normalized, so there was no > assumed 1 bit, as in IEEE-754. And it's been a long time (about 39 years), but as I recall the CDC 6400 (at least) had no integer multiply or divide. You had to convert to float first. The other oddity about the CDC series is it's the last machine I've encountered that used ones-complement for ints, with two values for zero. -- DaveA From dwightdhutto at gmail.com Sun Sep 23 01:28:17 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sun, 23 Sep 2012 01:28:17 -0400 Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: <7389ac67-45b4-43d4-b595-ab39be82d6b0@googlegroups.com> References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> <505e8ada$0$29981$c3e8da3$5496439d@news.astraweb.com> <7389ac67-45b4-43d4-b595-ab39be82d6b0@googlegroups.com> Message-ID: > It would be nice if out python scripts can be used along with Joomla CMS, Drupal or even Wordpress. As long as the server side prerequisites has been met, then the code should execute as long as it is allowed in the plugins. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From rosuav at gmail.com Sun Sep 23 01:38:35 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Sep 2012 15:38:35 +1000 Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> <505e8ada$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 23, 2012 at 3:18 PM, Dwight Hutto wrote: > On Sun, Sep 23, 2012 at 12:56 AM, Chris Angelico wrote: >> Steven's point is not that we, human beings (or parahuman beings, as >> the case may be), do not know how to run code in Joomla; I've worked >> with it, and know something about it, and my day job involves some PHP >> programming, so there's a reasonable chance that I could help him. > > Then a referral, is what he needs, and what you need is to tell others > you're a cross languaged programmer. Okay. I hereby inform you all that I am polyglot. I know many languages. But really, who here _isn't_? Is there anyone on this list who has absolutely no skills outside of Python? I rather doubt it. >> (If I cared to. I don't have very much sympathy for security holes in old >> versions of big frameworks.) > > SYmpathy, how about empathy, to show your designs can have bugs, which > is why they have version. > > Then refer him to the joomla security hole mailing list How about: Google is your friend? I'm sure that a Joomla security hole mailing list can easily be found at the opposite end of a web search. > We're the borg. We have google to help, or another mailing list with data. He has Google to help, and he can access other mailing lists. Anyone who wants to admin a web site ought to be able to find appropriate places to ask questions. There's a reasonable level of courtesy and assistance offered, but eventually, it's time to just say "This is off topic" and not try to assist. ChrisA From ben+python at benfinney.id.au Sun Sep 23 02:03:26 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 23 Sep 2012 16:03:26 +1000 Subject: Right tool for the job (was: Exact integer-valued floats) References: Message-ID: <7wy5k1e0nl.fsf@benfinney.id.au> Tim Roberts writes: > Apologize in advance for top-posting. My Xoom makes bottom-posting > awkward. Surely the better solution, then, is to use a tool which does allow you to compose a message properly ? and abstain from posting until you get to such a tool. -- \ ?Those are my principles. If you don't like them I have | `\ others.? ?Groucho Marx | _o__) | Ben Finney From nikos.gr33k at gmail.com Sun Sep 23 02:54:55 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rx5eXq?=) Date: Sat, 22 Sep 2012 23:54:55 -0700 (PDT) Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> <505e8ada$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2c8e16fe-5c02-4288-a364-ca596c46b92e@googlegroups.com> ?? ???????, 23 ??????????? 2012 8:38:38 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Sun, Sep 23, 2012 at 3:18 PM, Dwight Hutto wrote: > > > On Sun, Sep 23, 2012 at 12:56 AM, Chris Angelico wrote: > > >> Steven's point is not that we, human beings (or parahuman beings, as > > >> the case may be), do not know how to run code in Joomla; I've worked > > >> with it, and know something about it, and my day job involves some PHP > > >> programming, so there's a reasonable chance that I could help him. > > > > > > Then a referral, is what he needs, and what you need is to tell others > > > you're a cross languaged programmer. > > > > Okay. I hereby inform you all that I am polyglot. I know many > > languages. But really, who here _isn't_? Is there anyone on this list > > who has absolutely no skills outside of Python? I rather doubt it. > > > > >> (If I cared to. I don't have very much sympathy for security holes in old > > >> versions of big frameworks.) > > > > > > SYmpathy, how about empathy, to show your designs can have bugs, which > > > is why they have version. > > > > > > Then refer him to the joomla security hole mailing list > > > > How about: Google is your friend? I'm sure that a Joomla security hole > > mailing list can easily be found at the opposite end of a web search. > > > > > We're the borg. We have google to help, or another mailing list with data. > > > > He has Google to help, and he can access other mailing lists. Anyone > > who wants to admin a web site ought to be able to find appropriate > > places to ask questions. There's a reasonable level of courtesy and > > assistance offered, but eventually, it's time to just say "This is off > > topic" and not try to assist. > > > > ChrisA I shouldn't have asked about Joomla here, or even about Python embedding within Joomla cms. I was under the impression that the latter was relevant to ask here but it seems it isnt. My bad, let's just close this thread so i don't waste anyone's time. From nikos.gr33k at gmail.com Sun Sep 23 02:54:55 2012 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rx5eXq?=) Date: Sat, 22 Sep 2012 23:54:55 -0700 (PDT) Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> <505e8ada$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2c8e16fe-5c02-4288-a364-ca596c46b92e@googlegroups.com> ?? ???????, 23 ??????????? 2012 8:38:38 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Sun, Sep 23, 2012 at 3:18 PM, Dwight Hutto wrote: > > > On Sun, Sep 23, 2012 at 12:56 AM, Chris Angelico wrote: > > >> Steven's point is not that we, human beings (or parahuman beings, as > > >> the case may be), do not know how to run code in Joomla; I've worked > > >> with it, and know something about it, and my day job involves some PHP > > >> programming, so there's a reasonable chance that I could help him. > > > > > > Then a referral, is what he needs, and what you need is to tell others > > > you're a cross languaged programmer. > > > > Okay. I hereby inform you all that I am polyglot. I know many > > languages. But really, who here _isn't_? Is there anyone on this list > > who has absolutely no skills outside of Python? I rather doubt it. > > > > >> (If I cared to. I don't have very much sympathy for security holes in old > > >> versions of big frameworks.) > > > > > > SYmpathy, how about empathy, to show your designs can have bugs, which > > > is why they have version. > > > > > > Then refer him to the joomla security hole mailing list > > > > How about: Google is your friend? I'm sure that a Joomla security hole > > mailing list can easily be found at the opposite end of a web search. > > > > > We're the borg. We have google to help, or another mailing list with data. > > > > He has Google to help, and he can access other mailing lists. Anyone > > who wants to admin a web site ought to be able to find appropriate > > places to ask questions. There's a reasonable level of courtesy and > > assistance offered, but eventually, it's time to just say "This is off > > topic" and not try to assist. > > > > ChrisA I shouldn't have asked about Joomla here, or even about Python embedding within Joomla cms. I was under the impression that the latter was relevant to ask here but it seems it isnt. My bad, let's just close this thread so i don't waste anyone's time. From nad at acm.org Sun Sep 23 03:33:16 2012 From: nad at acm.org (Ned Deily) Date: Sun, 23 Sep 2012 00:33:16 -0700 Subject: Reading a file in IDLE 3 on Mac-Lion References: <505ccdc5$0$6919$e4fe514c@news2.news.xs4all.nl> <505d9cc5$0$6846$e4fe514c@news2.news.xs4all.nl> Message-ID: In article <505d9cc5$0$6846$e4fe514c at news2.news.xs4all.nl>, Hans Mulder wrote: > On 22/09/12 09:30:57, Franck Ditter wrote: > > In article <505ccdc5$0$6919$e4fe514c at news2.news.xs4all.nl>, > > Hans Mulder wrote: > >> On 21/09/12 16:29:55, Franck Ditter wrote: > >>> I create a text file utf-8 encoded in Python 3 with IDLE (Mac Lion). > >>> It runs fine and creates the disk file, visible with > >>> TextWrangler or another. > >>> But I can't open it with IDLE (its name is greyed). > >>> IDLE is supposed to read utf-8 files, no ? > >>> This works on Windows-7. > >> > >> There's a little pop-menu below the list of files. > >> > >> It allows you to choose which kind of files you want to open. > >> By default, it is set to "Python files", which greys out all > >> files, except those with a '.py' or '.pyw' extension. > >> Setting it to "Text files" should help, or else try "All files". > > Alas this pop-up menu is for Windows only, I don't > > find it on MacOS-X. > > It's there on my MacOS X 10.6.5 system. > > If your 10.7 system doesn't show it, that's definitely a bug. This appears to a difference in behavior between Carbon Tk 8.4 and Cocoa Tk 8.5 on OS X. The python.org 32-bit-only installers are built to link with the former and, with 8.4, the Open file dialog box does have the file-type filter menu as Hans describes. The python.org 64-/32-bit installers link with the newer Cocoa Tk 8.5 and, with it, the Open file dialog box does not have the filter menu. I'm not sure there is anything that IDLE or Tkinter can do about that; any change may need to be by the Tcl/Tk folks. But it would be good if you would open an issue at bugs.python.org so we can follow up on it. -- Ned Deily, nad at acm.org From hansmu at xs4all.nl Sun Sep 23 03:38:13 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sun, 23 Sep 2012 09:38:13 +0200 Subject: Redirecting STDOUT to a Python Variable In-Reply-To: <8cabc9bb-5ae0-41fa-86b6-0a184192e601@googlegroups.com> References: <7e934b64-ec84-48c8-a4bb-a2272f1449a4@u26g2000yqu.googlegroups.com> <4c206409$0$14147$c3e8da3@news.astraweb.com> <8cabc9bb-5ae0-41fa-86b6-0a184192e601@googlegroups.com> Message-ID: <505ebc65$0$6891$e4fe514c@news2.news.xs4all.nl> On 22/09/12 23:57:52, ross.marsden at gmail.com wrote: > To capture the traceback, so to put it in a log, I use this > > import traceback > > def get_traceback(): # obtain and return the traceback > exc_type, exc_value, exc_traceback = sys.exc_info() > return ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback)) This could be coded more succinctly as import sys, traceback def get_traceback(): # obtain and return the traceback return ''.join(traceback.format_exception(*sys.exc_info())) > Suppose I have a script run by the scheduler, this captures the traceback form any problems and emails them. > > if __name__ == '__main__': > try: > Runs_unattended() > except: > send_mail(send_from = yourEmailAddress, > send_to = [ yourEmailAddress ], subject = 'Runs_unattended', > text = '%s' % get_traceback(), > files = [], server=yourLocalSMTP) Errhm, '%s' % get_traceback() is equiavalent to get_traceback() How about: if __name__ == '__main__': try: Runs_unattended() except: send_mail(send_from = yourEmailAddress, send_to = [ yourEmailAddress ], subject = 'Runs_unattended', text = get_traceback(), files = [], server=yourLocalSMTP) Hope this helps, -- HansM From hansmu at xs4all.nl Sun Sep 23 03:45:33 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sun, 23 Sep 2012 09:45:33 +0200 Subject: Exact integer-valued floats In-Reply-To: References: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> <7xzk4j6mmq.fsf@ruckus.brouhaha.com> <505d163b$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <505ebe1e$0$6844$e4fe514c@news2.news.xs4all.nl> On 23/09/12 01:06:08, Dave Angel wrote: > On 09/22/2012 05:05 PM, Tim Roberts wrote: >> Dennis Lee Bieber wrote: >>> On 22 Sep 2012 01:36:59 GMT, Steven D'Aprano wrote: >>>> For non IEEE 754 floating point systems, there is no telling how bad the >>>> implementation could be :( >>> Let's see what can be found... >>> >>> IBM 360: Same as Sigma-6 (no surprise; hearsay is the Sigma was >>> designed by renegade IBM folk; even down to using EBCDIC internally -- >>> but with a much different interrupt system [224 individual interrupt >>> vectors as I recall, vs the IBM's 7 vectors and polling to find what >>> device]). >> The Control Data 6000/Cyber series had sign bit and 11-bit exponent, with >> either a 48-bit mantissa or a 96-bit mantissa, packed into one or two >> 60-bit words. Values were not automatically normalized, so there was no >> assumed 1 bit, as in IEEE-754. > > And it's been a long time (about 39 years), but as I recall the CDC 6400 > (at least) had no integer multiply or divide. You had to convert to > float first. You didn't have to convert if your ints would fit in 48 bits. If that was the case, then using the float multiply and divide instructions would do the trick. > The other oddity about the CDC series is it's the last machine I've > encountered that used ones-complement for ints, with two values for zero. Floats still have 0.0 and -0.0, even in IEEE-754. Was Python ever ported to such unusual hardware? -- HansM From andriy.kornatskyy at live.com Sun Sep 23 05:19:16 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Sun, 23 Sep 2012 12:19:16 +0300 Subject: Fastest web framework Message-ID: I have run recently a benchmark of a trivial 'hello world' application for various python web frameworks (bottle,?django, flask, pyramid, web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find it interesting: http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html Comments or suggestions are welcome. Thanks. Andriy Kornatskyy From 7segment at live.com Sun Sep 23 05:23:40 2012 From: 7segment at live.com (7segment) Date: Sun, 23 Sep 2012 04:23:40 -0500 Subject: msmtp in python Message-ID: Hi. I have written a program to send email using python. However, I want to use msmtp for delegating the sending to my gmail account. So this part should be changed but I have no idea how! In theory the "sendmail" function should automatically call msmtp, but i don't know how to define "s" then. s = smtplib.SMTP('localhost') s.sendmail(me, family, msg.as_string()) s.quit() Any help would be appreciated! From andriy.kornatskyy at live.com Sun Sep 23 05:24:36 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Sun, 23 Sep 2012 12:24:36 +0300 Subject: Fastest template engine Message-ID: I have run recently a benchmark of a trivial 'big table' example for various python template engines (jinja2, mako, tenjin,?tornado and wheezy.template) run on cpython2.7 and pypy1.9...... you might find it interesting: http://mindref.blogspot.com/2012/07/python-fastest-template.html Comments or suggestions are welcome. Thanks. Andriy Kornatskyy From jiangwen365 at gmail.com Sun Sep 23 05:50:53 2012 From: jiangwen365 at gmail.com (=?GB2312?B?va3OxA==?=) Date: Sun, 23 Sep 2012 17:50:53 +0800 Subject: [ANN] PyPyODBC 0.8.6 released! Message-ID: PyPyODBC - A Pure Python ctypes ODBC module Features - Pure Python, compatible with IronPython and PyPy (tested on Win32) - Almost totally same usage as pyodbc - Simple and small - the whole module is implemented in a less than 2000 lines python script You can simply try pypyodbc in your existing pyodbc powered script with the following changes: #import pyodbc <-- The original pyodbc importing line import pypyodbc as pyodbc pyodbc.connect(...) # pypyodbc is now doing pyodbc's job History Version 0.8.6 Sep 23 2012 Added ODBC pooling feature Bit, GUID type support Other fixes and improvements Version 0.8.5 Sep 16 2012 Numeric type fix Long and integer differentiate Other pyodbc compatibility improvements; Version 0.8.4 Sep 9 2012 Improved compatibility with pyodbc; Many underlying bug fixes; Version 0.8.3 Sep 1 2012 sql_longvarchar handling fix; performance optimization; Version 0.8.2 Aug 27 2012 Differentiate sql_varchar and sql_longvarchar; Initial support for SQLAlchemy; Version 0.8.1 Aug 26 2012 Fixed the long type parameter issue; Added support for IronPython; Version 0.8 Aug 25 2012 Added getinfo method; Version 0.7 Jul 28 2012 Fixed nchar/ntext/nvarchar string truncat problem ; Version 0.6 Jul 4 2012 Added Cursor.commit() and Cursor.rollback(); Added readonly keyword to connect; Version 0.5 Jun 23 2012 Initial release; From andriy.kornatskyy at live.com Sun Sep 23 06:02:02 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Sun, 23 Sep 2012 13:02:02 +0300 Subject: wheezy.web presentation - build modern, efficient web Message-ID: Here are links to presentation held in Kyiv.Py (Ukraine) on September 22, 2012: "wheezy.web introduction a lightweight, high performance, high concurrency WSGI web framework with the key features to build modern, efficient web" Download from: https://bitbucket.org/akorn/wheezy.web/downloads/ Files: wheezy.web-introduction.pdf wheezy.web-examine.pdf Hope you find it interesting. Thanks. Andriy Kornatskyy From tinnews at isbd.co.uk Sun Sep 23 06:24:31 2012 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Sun, 23 Sep 2012 11:24:31 +0100 Subject: A dateutil error has appeared, due to updates? How to fix? Message-ID: I have a python script which uses the dateutil module with the following:- import sys import datetime import icalendar from dateutil.relativedelta import relativedelta The section of code which uses relativedelta is as follows:- # # # If the event is a repeating event with a start date in the # past then we add the repeat interval until we find the next # occurrence # if eventDate < datetime.date.today(): if event.has_key('RRULE'): freq = event.decoded('RRULE')['FREQ'][0] if event.decoded('RRULE').has_key('INTERVAL'): interval = event.decoded('RRULE')['INTERVAL'][0] else: interval = 1; if 'WEEKLY' == freq: delta = relativedelta(weeks=+interval) if 'MONTHLY' == freq: delta = relativedelta(months=+interval) if 'YEARLY' == freq: delta = relativedelta(years=+interval) while eventDate < datetime.date.today(): eventDate += delta else: continue # if it's a non-repeating event in the past It used to work and all I have done meanwhile is to update my xubuntu system as fixes are released. I'm now getting the error:- Traceback (most recent call last): File "/home/chris/bin/calics.py", line 62, in eventDate += delta File "/usr/lib/python2.7/dist-packages/dateutil/relativedelta.py", line 261, in __radd__ day = min(calendar.monthrange(year, month)[1], AttributeError: 'module' object has no attribute 'monthrange' Have I lost a module somewhere in the updates or has something in python changed such that my code no longer works as it used to? Can anyone help diagnose this please. -- Chris Green From dihedral88888 at googlemail.com Sun Sep 23 07:17:15 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 23 Sep 2012 04:17:15 -0700 (PDT) Subject: Blue Screen Python In-Reply-To: References: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> <505db7f5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico? 2012?9?22????UTC+8??10?10?12???? > On Sat, Sep 22, 2012 at 11:07 PM, Steven D'Aprano > > wrote: > > > As per their partnership agreement, IBM took over development of OS/2 > > > version 2 while Microsoft worked on developing version 3. OS/2 2.0 was > > > significantly improved over the 1.x series. > > > > > > Then Microsoft reneged on the agreement to release OS/2 version 3, and > > > instead re-badged it as Windows NT. One might say there was a little bit > > > of bad blood over this, especially as IBM had good reason to think that > > > Microsoft had been spending IBM's money on NT. > > > > And ever since then, Microsoft's been doing its best to kill OS/2 off. > > By the look of the database server sitting next to me, and the clients > > scattered throughout the building, it seems they have yet to > > succeed... > > > > OS/2 and Linux interoperate quite happily, too. Standards so . > > > > ChrisA This is off topic in this forum. But we are getting so far at the MMU part. A cpu with an L1 and an L2 caches of large sizes is better to be equipped with a VMS like OS in the thread and the heap managements. But if the situation is different, some other alternative approaches might be more appropriate. From dihedral88888 at googlemail.com Sun Sep 23 07:17:15 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 23 Sep 2012 04:17:15 -0700 (PDT) Subject: Blue Screen Python In-Reply-To: References: <7c8701cc-1bc5-46ee-a83a-3e9a038ceada@googlegroups.com> <505db7f5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico? 2012?9?22????UTC+8??10?10?12???? > On Sat, Sep 22, 2012 at 11:07 PM, Steven D'Aprano > > wrote: > > > As per their partnership agreement, IBM took over development of OS/2 > > > version 2 while Microsoft worked on developing version 3. OS/2 2.0 was > > > significantly improved over the 1.x series. > > > > > > Then Microsoft reneged on the agreement to release OS/2 version 3, and > > > instead re-badged it as Windows NT. One might say there was a little bit > > > of bad blood over this, especially as IBM had good reason to think that > > > Microsoft had been spending IBM's money on NT. > > > > And ever since then, Microsoft's been doing its best to kill OS/2 off. > > By the look of the database server sitting next to me, and the clients > > scattered throughout the building, it seems they have yet to > > succeed... > > > > OS/2 and Linux interoperate quite happily, too. Standards so . > > > > ChrisA This is off topic in this forum. But we are getting so far at the MMU part. A cpu with an L1 and an L2 caches of large sizes is better to be equipped with a VMS like OS in the thread and the heap managements. But if the situation is different, some other alternative approaches might be more appropriate. From __peter__ at web.de Sun Sep 23 07:38:15 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 23 Sep 2012 13:38:15 +0200 Subject: A dateutil error has appeared, due to updates? How to fix? References: Message-ID: tinnews at isbd.co.uk wrote: > I have a python script which uses the dateutil module with the > following:- > > import sys > import datetime > import icalendar > from dateutil.relativedelta import relativedelta > > The section of code which uses relativedelta is as follows:- > > # > # > # If the event is a repeating event with a start date in the > # past then we add the repeat interval until we find the next > # occurrence > # > if eventDate < datetime.date.today(): > if event.has_key('RRULE'): > freq = event.decoded('RRULE')['FREQ'][0] > if event.decoded('RRULE').has_key('INTERVAL'): > interval = event.decoded('RRULE')['INTERVAL'][0] > else: > interval = 1; > if 'WEEKLY' == freq: > delta = relativedelta(weeks=+interval) > if 'MONTHLY' == freq: > delta = relativedelta(months=+interval) > if 'YEARLY' == freq: > delta = relativedelta(years=+interval) > while eventDate < datetime.date.today(): > eventDate += delta > else: > continue # if it's a non-repeating event in the > past > > > It used to work and all I have done meanwhile is to update my xubuntu > system as fixes are released. I'm now getting the error:- > > Traceback (most recent call last): > File "/home/chris/bin/calics.py", line 62, in > eventDate += delta > File "/usr/lib/python2.7/dist-packages/dateutil/relativedelta.py", > line 261, in __radd__ > day = min(calendar.monthrange(year, month)[1], > AttributeError: 'module' object has no attribute 'monthrange' > > Have I lost a module somewhere in the updates or has something in > python changed such that my code no longer works as it used to? > > Can anyone help diagnose this please. You probably have a file named calendar.py in your working directory: $ python -c 'from dateutil.relativedelta import calendar; print calendar.__file__' /usr/lib/python2.7/calendar.pyc $ touch calendar.py $ python -c 'from dateutil.relativedelta import calendar; print calendar.__file__' calendar.py Rename calendar.py in your working directory (and don't forget to delete the corresponding calendar.pyc) -- and dateutil should work again. From james.kennedy at abingdon.org.uk Sun Sep 23 08:05:38 2012 From: james.kennedy at abingdon.org.uk (james.kennedy at abingdon.org.uk) Date: Sun, 23 Sep 2012 05:05:38 -0700 (PDT) Subject: cant install livewires Message-ID: i cant install livewires and their help about making a directory is useless to me as i dont know how btw im using windows 7 REALLY DESPERATE :) -- Disclaimer From rosuav at gmail.com Sun Sep 23 08:22:44 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Sep 2012 22:22:44 +1000 Subject: cant install livewires In-Reply-To: References: Message-ID: On Sun, Sep 23, 2012 at 10:05 PM, wrote: > i cant install livewires and their help about making a directory is useless to me as i dont know how > btw im using windows 7 > REALLY DESPERATE :) May I recommend searching the web for 'make directory windows 7'? That might help. ChrisA From kw at codebykevin.com Sun Sep 23 08:45:06 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 23 Sep 2012 08:45:06 -0400 Subject: Reading a file in IDLE 3 on Mac-Lion In-Reply-To: References: <505ccdc5$0$6919$e4fe514c@news2.news.xs4all.nl> <505d9cc5$0$6846$e4fe514c@news2.news.xs4all.nl> Message-ID: On 9/23/12 3:33 AM, Ned Deily wrote: > This appears to a difference in behavior between Carbon Tk 8.4 and Cocoa > Tk 8.5 on OS X. The python.org 32-bit-only installers are built to link > with the former and, with 8.4, the Open file dialog box does have the > file-type filter menu as Hans describes. The python.org 64-/32-bit > installers link with the newer Cocoa Tk 8.5 and, with it, the Open file > dialog box does not have the filter menu. I'm not sure there is > anything that IDLE or Tkinter can do about that; any change may need to > be by the Tcl/Tk folks. But it would be good if you would open an issue > at bugs.python.org so we can follow up on it. It's a function of NSOpenPanel, the underlying native dialog that supports the "open file" dialog on OS X. It doesn't have a "file filter" capability, and so it will only recognize hard-coded types that are passed to it, cf. py and txt files. "dat" isn't recognized, I tested it out. There's nothing to do here; it's an aspect of the native dialog. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From breamoreboy at yahoo.co.uk Sun Sep 23 09:21:07 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 23 Sep 2012 14:21:07 +0100 Subject: cant install livewires In-Reply-To: References: Message-ID: On 23/09/2012 13:05, james.kennedy at abingdon.org.uk wrote: > i cant install livewires and their help about making a directory is useless to me as i dont know how > btw im using windows 7 > REALLY DESPERATE :) > Please don't shout. And if my experience of the UK education system is anything to go by, nothing is ever desperate anyway. Apart from that what have you tried and where did it go wrong? "I can't install livewires" isn't much to go on. -- Cheers. Mark Lawrence. From roy at panix.com Sun Sep 23 10:02:28 2012 From: roy at panix.com (Roy Smith) Date: Sun, 23 Sep 2012 10:02:28 -0400 Subject: Fastest web framework References: Message-ID: In article , Andriy Kornatskyy wrote: > I have run recently a benchmark of a trivial 'hello world' application for > various python web frameworks (bottle,?django, flask, pyramid, web.py, > wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find > it interesting: > > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > > Comments or suggestions are welcome. That's a nice comparison, thanks for posting it. One thing that's worth pointing out, however, is that in a real world application, as long as you're using something halfway decent, the speed of the framework is probably not going to matter at all. It's much more likely that database throughput will be the dominating factor. From kw at codebykevin.com Sun Sep 23 10:40:19 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 23 Sep 2012 10:40:19 -0400 Subject: Reading a file in IDLE 3 on Mac-Lion In-Reply-To: References: <505ccdc5$0$6919$e4fe514c@news2.news.xs4all.nl> <505d9cc5$0$6846$e4fe514c@news2.news.xs4all.nl> Message-ID: On 9/23/12 8:45 AM, Kevin Walzer wrote: > There's nothing to do here; it's an aspect of the native dialog. To clarify: there's nothing to do at the C level, which is where the native dialog is invoked. IDLE can probably be patched to accept other file types, such as "dat." -- Kevin Walzer Code by Kevin http://www.codebykevin.com From tinnews at isbd.co.uk Sun Sep 23 11:26:27 2012 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Sun, 23 Sep 2012 16:26:27 +0100 Subject: A dateutil error has appeared, due to updates? How to fix? References: Message-ID: <3am3j9-cfc.ln1@chris.zbmc.eu> Peter Otten <__peter__ at web.de> wrote: > tinnews at isbd.co.uk wrote: > [snip description of problem] > > Have I lost a module somewhere in the updates or has something in > > python changed such that my code no longer works as it used to? > > > > Can anyone help diagnose this please. > > You probably have a file named calendar.py in your working directory: > > $ python -c 'from dateutil.relativedelta import calendar; print > calendar.__file__' > /usr/lib/python2.7/calendar.pyc > $ touch calendar.py > $ python -c 'from dateutil.relativedelta import calendar; print > calendar.__file__' > calendar.py > > Rename calendar.py in your working directory (and don't forget to delete the > corresponding calendar.pyc) -- and dateutil should work again. > Brilliant, you're absolutely right! Thank you! :-) I'd written calendar.py doing something else entirely. I must remember not to use such 'obvious' names for things! -- Chris Green From maniandram01 at gmail.com Sun Sep 23 11:47:39 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sun, 23 Sep 2012 08:47:39 -0700 (PDT) Subject: Client Needs---QA Manual Tester at Sacramento, CA In-Reply-To: References: Message-ID: <7e8ada1e-0a90-490e-84eb-85f3395b0d69@googlegroups.com> On Saturday, 22 September 2012 04:09:55 UTC+5:30, ram dev wrote: > Good Day, > > We have an urgent Contract Openings in Folsom, CA > > Looking forward to submit your resume for below mentioned Requirement? > > If you are interested, Please forward your latest resume along with location and pay rate details to ram at tech-netinc.com > > > > Job Title: QA Engineer(Strong Web services Experience Needed) > > Location: Sacramento, CA > > Duration: 2 Years > > Required: > > ? Strong knowledge of SDLC > > ? Manual testing experience should be 6+ years > > ? Web services exp must be more than 4+ years > > ? Solid background of software testing methods, processes, tools > > ? Strong in XML,UNIX and SQL > > ? Advance level knowledge and hands-on experience with Test Planning, Test Development, Test Data Setup, Test Execution and Test Reporting. > > ? Knowledge of variety of testing methods and direct experience in test development and execution of functionality, integration, security, transaction, error handling, performance of web applications. > > ? Expertise in testing web services API using Parasoft SOA Test or SOAP UI. > > ? Hands-on experience with Quality Center/ALM 11. > > ? Experience working in Windows and Unix (Linux) environments. > > ? Team player with good mentoring and presentation skills > > Desired: > > ? ISO or Electricity Industry experience > > ? GUI and API test automation using HP Quick Test Pro > > ? Load/performance test automation using HP Load Runner > > ? Experience in integrating QTP, SOA Test, Load Runner or other test automation tools with HP Quality Center > > ? Advance level experience in using and administering Quality Center, developing workflows to customize QC using VB Script. > > ? Strong programming/scripting background in Java and Python. Able to code review and develop unit test if needed. > > Environment: JBoss, Groovy and Grails, Oracle 11g, SQL, XNL, Actuate, Reporting Services, SharePoint, Quality Center, Quick Test Pro, Load Runner, SOA Test, Windows, Linux. > > > > > > > > Thanks, > > ============================ > > Ram Dev > > Recruiter > > Tech-Net Inc. > > Tel: 916-458-4390 Ext 102 > > Email: ram at tech-netinc.com > > URL: www.tech-netinc.com This is not related to Python; I have reported this in Google Groups. From joshua.landau.ws at gmail.com Sun Sep 23 11:48:38 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Sun, 23 Sep 2012 16:48:38 +0100 Subject: Capitalization for variable that holds a class Message-ID: Simple question: [myClass() for myClass in myClasses] vs [MyClass() for MyClass in myClasses] Fight. (When considering, substitute in a more real-world example like [Token() for Token in allTokens] or [token() for token in allTokens]) -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Sun Sep 23 11:49:44 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sun, 23 Sep 2012 08:49:44 -0700 (PDT) Subject: Seome kind of unblocking input In-Reply-To: References: <0be9b4c2-b661-4709-ba8f-40a6f78ad634@googlegroups.com> Message-ID: <593f9c45-9150-4d37-9c9c-e3cd66ed2d8e@googlegroups.com> On Saturday, 22 September 2012 01:24:46 UTC+5:30, Dennis Lee Bieber wrote: > On Fri, 21 Sep 2012 02:13:28 -0700 (PDT), janis.judvaitis at gmail.com > > declaimed the following in gmane.comp.python.general: > > > > > Since I'm using threads and pipes everything works ok, except that when i call input() there is no way that I could print something, is there any workaround for this?? > > > > > > Note: I don't need to catch any key's before enter or smtng, just be able to print while input() is waiting. I'm thinking that maybe there is a way for two threads to share one stdout, which should resolve this, but I can't make it work, since U can't pickle file like object(stdout) to pass it to other thread. > > > > > > > Confusion abounds... > > > > You don't have to "pickle file like object..." for it to be used by > > a Python THREAD... But your mention of pipes makes me think you are > > using subprocesses and/or multiprocessing modules. Threads run in a > > shared environment (you may need to put a lock around the file object so > > that only one thread at a time does the I/O on that object), but > > processes are independent memory spaces. > > > > However, you may also encounter OS specific behavior WRT > > stdout/stderr when they are connected to a console. The OS itself may > > block/buffer output when there is a pending input on the same console. > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ You can clear the buffer by calling file.flush() From maniandram01 at gmail.com Sun Sep 23 11:49:44 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sun, 23 Sep 2012 08:49:44 -0700 (PDT) Subject: Seome kind of unblocking input In-Reply-To: References: <0be9b4c2-b661-4709-ba8f-40a6f78ad634@googlegroups.com> Message-ID: <593f9c45-9150-4d37-9c9c-e3cd66ed2d8e@googlegroups.com> On Saturday, 22 September 2012 01:24:46 UTC+5:30, Dennis Lee Bieber wrote: > On Fri, 21 Sep 2012 02:13:28 -0700 (PDT), janis.judvaitis at gmail.com > > declaimed the following in gmane.comp.python.general: > > > > > Since I'm using threads and pipes everything works ok, except that when i call input() there is no way that I could print something, is there any workaround for this?? > > > > > > Note: I don't need to catch any key's before enter or smtng, just be able to print while input() is waiting. I'm thinking that maybe there is a way for two threads to share one stdout, which should resolve this, but I can't make it work, since U can't pickle file like object(stdout) to pass it to other thread. > > > > > > > Confusion abounds... > > > > You don't have to "pickle file like object..." for it to be used by > > a Python THREAD... But your mention of pipes makes me think you are > > using subprocesses and/or multiprocessing modules. Threads run in a > > shared environment (you may need to put a lock around the file object so > > that only one thread at a time does the I/O on that object), but > > processes are independent memory spaces. > > > > However, you may also encounter OS specific behavior WRT > > stdout/stderr when they are connected to a console. The OS itself may > > block/buffer output when there is a pending input on the same console. > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ You can clear the buffer by calling file.flush() From stefan_ml at behnel.de Sun Sep 23 11:50:20 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 23 Sep 2012 17:50:20 +0200 Subject: Fastest web framework In-Reply-To: References: Message-ID: Roy Smith, 23.09.2012 16:02: > Andriy Kornatskyy wrote: >> I have run recently a benchmark of a trivial 'hello world' application for >> various python web frameworks (bottle,?django, flask, pyramid, web.py, >> wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find >> it interesting: >> >> http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html >> >> Comments or suggestions are welcome. > > That's a nice comparison, thanks for posting it. > > One thing that's worth pointing out, however, is that in a real world > application, as long as you're using something halfway decent, the speed > of the framework is probably not going to matter at all. It's much more > likely that database throughput will be the dominating factor. Yes, that makes the comparison (which may or may not be biased towards his own engine) a bit less interesting. Worth keeping this in mind: http://www.codeirony.com/?p=9 Stefan From missive at hotmail.com Sun Sep 23 12:09:11 2012 From: missive at hotmail.com (Lee Harr) Date: Sun, 23 Sep 2012 20:39:11 +0430 Subject: QThread.terminate in Python 3 Message-ID: Hi; I have asked this on the PyQt list, but have not seen any response yet. Hoping someone will be able to test this on their system to see if they see the same problem. The problem I am seeing is that terminating a QThread running certain code will freeze the program, requiring it to be kill'd. Adding a sleep will allow the QThread to be terminated, but for my use I need to be able to terminate any arbitrary code. I understand that use of QThread.terminate is discouraged, but it has worked well previously and I would like to continue this use if possible. I see the problem on Python 3.2.3 with PyQt 4.9.1 on Ubuntu 12.4 With Python 2.7.3 with PyQt 4.9.1 there is no problem. I am hoping to find out if this is a bug, and if so, where I should report it (Python, PyQt, Qt, Linux, etc). Thanks for any pointers. Here is a program that shows the problem: # test_qthread.py #from __future__ import print_function import time from PyQt4 import QtCore class CmdThread(QtCore.QThread): ??? def run(self): ??????? while True: ??????????? #print 'test' ??????????? print('test') ??????????? #time.sleep(0.2) if __name__ == '__main__': ??? t = CmdThread() ??? print('thread set up') ??? t.start() ??? print('thread started') ??? time.sleep(1) ??? print('terminating thread') ??? t.terminate() ??? print('terminated') ??? time.sleep(1) ??? print('thread is running:', t.isRunning()) From rosuav at gmail.com Sun Sep 23 12:12:25 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Sep 2012 02:12:25 +1000 Subject: Capitalization for variable that holds a class In-Reply-To: References: Message-ID: On Mon, Sep 24, 2012 at 1:48 AM, Joshua Landau wrote: > Simple question: > > [myClass() for myClass in myClasses] > vs > [MyClass() for MyClass in myClasses] > > Fight. > > (When considering, substitute in a more real-world example like [Token() for > Token in allTokens] or [token() for token in allTokens]) An interesting point! I assume you're basing this on the PEP 8 recommendation: http://www.python.org/dev/peps/pep-0008/#class-names Since there's no difference between a "class" and a "variable containing a class" or a "pointer to a class" or any other such concept, it makes sense to capitalize MyClass in your example, if you are guaranteeing that they're all classes. And certainly a long-lived variable ought to be named in CapWords. However, all you're really doing is taking a bunch of callables, calling them, and making a list of the results. I'd therefore be inclined to _not_ capitalize it. YMMV though. ChrisA From jimmyli1528 at gmail.com Sun Sep 23 12:36:19 2012 From: jimmyli1528 at gmail.com (jimbo1qaz) Date: Sun, 23 Sep 2012 09:36:19 -0700 (PDT) Subject: For Counter Variable Message-ID: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation. From rodrick.brown at gmail.com Sun Sep 23 12:45:20 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Sun, 23 Sep 2012 12:45:20 -0400 Subject: For Counter Variable In-Reply-To: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> Message-ID: <3339104963216908111@unknownmsgid> On Sep 23, 2012, at 12:42 PM, jimbo1qaz wrote: > Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation. for idx in : print (idx) i.e.. for idx in range(10): print(idx) > -- > http://mail.python.org/mailman/listinfo/python-list From oscar.j.benjamin at gmail.com Sun Sep 23 12:50:20 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 23 Sep 2012 17:50:20 +0100 Subject: For Counter Variable In-Reply-To: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> Message-ID: On Sep 23, 2012 5:42 PM, "jimbo1qaz" wrote: > > Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation. Have you seen the enumerate function? Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Sep 23 12:52:43 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Sep 2012 02:52:43 +1000 Subject: For Counter Variable In-Reply-To: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> Message-ID: On Mon, Sep 24, 2012 at 2:36 AM, jimbo1qaz wrote: > Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation. You mean, if you want the indices as well as the values? Try the enumerate() function: my_list = ["foo", "bar", "quux"] for idx,val in enumerate(my_list): print("Element "+str(idx)+" is: "+val) ChrisA From breamoreboy at yahoo.co.uk Sun Sep 23 13:10:57 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 23 Sep 2012 18:10:57 +0100 Subject: Client Needs---QA Manual Tester at Sacramento, CA In-Reply-To: <7e8ada1e-0a90-490e-84eb-85f3395b0d69@googlegroups.com> References: <7e8ada1e-0a90-490e-84eb-85f3395b0d69@googlegroups.com> Message-ID: On 23/09/2012 16:47, Ramchandra Apte wrote: I've snipped all the crap that came from gmail. Could you please get yourself a decent email client. > > This is not related to Python; I have reported this in Google Groups. > Thanks for policing this, but how about reporting it on gmane and possibly other places while you're at it, or does the whole world now revolve around G$? -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Sun Sep 23 13:13:57 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 23 Sep 2012 18:13:57 +0100 Subject: Seome kind of unblocking input In-Reply-To: <593f9c45-9150-4d37-9c9c-e3cd66ed2d8e@googlegroups.com> References: <0be9b4c2-b661-4709-ba8f-40a6f78ad634@googlegroups.com> <593f9c45-9150-4d37-9c9c-e3cd66ed2d8e@googlegroups.com> Message-ID: On 23/09/2012 16:49, Ramchandra Apte wrote: > On Saturday, 22 September 2012 01:24:46 UTC+5:30, Dennis Lee Bieber wrote: >> On Fri, 21 Sep 2012 02:13:28 -0700 (PDT), janis.judvaitis at gmail.com >> >> declaimed the following in gmane.comp.python.general: >> >> >> >>> Since I'm using threads and pipes everything works ok, except that when i call input() there is no way that I could print something, is there any workaround for this?? >> >>> >> >>> Note: I don't need to catch any key's before enter or smtng, just be able to print while input() is waiting. I'm thinking that maybe there is a way for two threads to share one stdout, which should resolve this, but I can't make it work, since U can't pickle file like object(stdout) to pass it to other thread. >> >>> >> >> >> >> Confusion abounds... >> >> >> >> You don't have to "pickle file like object..." for it to be used by >> >> a Python THREAD... But your mention of pipes makes me think you are >> >> using subprocesses and/or multiprocessing modules. Threads run in a >> >> shared environment (you may need to put a lock around the file object so >> >> that only one thread at a time does the I/O on that object), but >> >> processes are independent memory spaces. >> >> >> >> However, you may also encounter OS specific behavior WRT >> >> stdout/stderr when they are connected to a console. The OS itself may >> >> block/buffer output when there is a pending input on the same console. >> >> -- >> >> Wulfraed Dennis Lee Bieber AF6VN >> >> wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > You can clear the buffer by calling file.flush() > Shock, horror, probe, well I never did. I'm sure that everyone is updating their Xmas and birthday card lists to ensure that you're not missed out having furnished a piece of information that doubtless not one other person on this group knew. -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Sun Sep 23 13:20:03 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 23 Sep 2012 18:20:03 +0100 Subject: Fastest web framework In-Reply-To: References: Message-ID: On 23/09/2012 16:50, Stefan Behnel wrote: > Roy Smith, 23.09.2012 16:02: >> Andriy Kornatskyy wrote: >>> I have run recently a benchmark of a trivial 'hello world' application for >>> various python web frameworks (bottle,?django, flask, pyramid, web.py, >>> wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find >>> it interesting: >>> >>> http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html >>> >>> Comments or suggestions are welcome. >> >> That's a nice comparison, thanks for posting it. >> >> One thing that's worth pointing out, however, is that in a real world >> application, as long as you're using something halfway decent, the speed >> of the framework is probably not going to matter at all. It's much more >> likely that database throughput will be the dominating factor. > > Yes, that makes the comparison (which may or may not be biased towards his > own engine) a bit less interesting. Worth keeping this in mind: > > http://www.codeirony.com/?p=9 > > Stefan > > I'd like to say thanks for the link but unfortunately for me, but good news for you (plural), is that I've bust a gut laughing out loud, so I won't :) Oh alright then thanks for the link. -- Cheers. Mark Lawrence. From andriy.kornatskyy at live.com Sun Sep 23 13:42:47 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Sun, 23 Sep 2012 20:42:47 +0300 Subject: Fastest web framework In-Reply-To: References: , Message-ID: If we take a look at web application we can split it into at least two parts, one that renders things out and the other one that does data extraction, e.g. from database (this is what you are pointing at). If you made a first call to database you get your list and can easily cache it. The next call IS without impact that database call may cause... but you still keep serving pages out... Thanks. Andriy ---------------------------------------- From: roy at panix.com Subject: Re: Fastest web framework Date: Sun, 23 Sep 2012 10:02:28 -0400 To: python-list at python.org In article , Andriy Kornatskyy wrote: > I have run recently a benchmark of a trivial 'hello world' application for > various python web frameworks (bottle, django, flask, pyramid, web.py, > wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find > it interesting: > > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > > Comments or suggestions are welcome. That's a nice comparison, thanks for posting it. One thing that's worth pointing out, however, is that in a real world application, as long as you're using something halfway decent, the speed of the framework is probably not going to matter at all. It's much more likely that database throughput will be the dominating factor. -- http://mail.python.org/mailman/listinfo/python-list From giuseppe.amatulli at gmail.com Sun Sep 23 13:44:30 2012 From: giuseppe.amatulli at gmail.com (giuseppe.amatulli at gmail.com) Date: Sun, 23 Sep 2012 10:44:30 -0700 (PDT) Subject: write to a file two dict() Message-ID: Hi Have two dict() of the same length and i want print them to a common file. a={1: 1, 2: 2, 3: 3} b={1: 11, 2: 22, 3: 33} in order to obtain 1 1 1 11 2 2 2 22 3 3 3 33 I tried output = open(dst_file, "w") for (a), b , (c) , d in a.items() , b.items() : output.write("%i %i %i %i\n" % (a,b,c,d)) output.close() but i get the error ValueError: need more than 3 values to unpack. do you have some suggestions?. Thanks Giuseppe From jimmyli1528 at gmail.com Sun Sep 23 13:45:53 2012 From: jimmyli1528 at gmail.com (jimbo1qaz) Date: Sun, 23 Sep 2012 10:45:53 -0700 (PDT) Subject: For Counter Variable In-Reply-To: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> Message-ID: On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: > Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation. Ya, they should really give a better way, but for now, enumerate works pretty well. From stefan_ml at behnel.de Sun Sep 23 13:48:12 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 23 Sep 2012 19:48:12 +0200 Subject: Fastest web framework In-Reply-To: References: , Message-ID: Andriy Kornatskyy, 23.09.2012 19:42: > If we take a look at web application we can split it into at least two > parts, one that renders things out and the other one that does data > extraction, e.g. from database (this is what you are pointing at). > > If you made a first call to database you get your list and can easily > cache it. The next call IS without impact that database call may > cause... but you still keep serving pages out... Well, if it was really that easy, you wouldn't be using a database in the first place but static pages, would you? Stefan From jdildy85 at gmail.com Sun Sep 23 13:48:52 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 23 Sep 2012 10:48:52 -0700 (PDT) Subject: Anyone able to help on installing packages? Message-ID: <377867f4-d508-4a1b-adba-076f99afbaad@googlegroups.com> Hello everyone out there. Ive been trying to install packages like distribute, nose, and virturalenv and believe me it is a hard process to do. I tried everything I could think of to install. I have done the following: pip install "package name" easy_install "package name" Would anyone help me at least to give directions for at least one of the package installation? Would it work along with any other package installation (for example if you helped it show nose will it work with distribute, etc)? Thank You all for your help From andriy.kornatskyy at live.com Sun Sep 23 13:57:55 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Sun, 23 Sep 2012 20:57:55 +0300 Subject: Fastest web framework In-Reply-To: References: , , Message-ID: Few facts that doesn't make it less interesting: (1) the test source code available (2) the test itself is pretty famous (3) you can re-run it (4) or even better supply own that in your believe is 100% relevant Not every project has problem with database performance. Some use caching... and pretty happy. In my case I have got 2x boost of web application performance just by switching to wheezy.template, that simple. Thanks. Andriy ---------------------------------------- > To: python-list at python.org > From: stefan_ml at behnel.de > Subject: Re: Fastest web framework > Date: Sun, 23 Sep 2012 17:50:20 +0200 > > Roy Smith, 23.09.2012 16:02: > > Andriy Kornatskyy wrote: > >> I have run recently a benchmark of a trivial 'hello world' application for > >> various python web frameworks (bottle,?django, flask, pyramid, web.py, > >> wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find > >> it interesting: > >> > >> http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > >> > >> Comments or suggestions are welcome. > > > > That's a nice comparison, thanks for posting it. > > > > One thing that's worth pointing out, however, is that in a real world > > application, as long as you're using something halfway decent, the speed > > of the framework is probably not going to matter at all. It's much more > > likely that database throughput will be the dominating factor. > > Yes, that makes the comparison (which may or may not be biased towards his > own engine) a bit less interesting. Worth keeping this in mind: > > http://www.codeirony.com/?p=9 > > Stefan > > > -- > http://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Sun Sep 23 14:00:33 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 23 Sep 2012 19:00:33 +0100 Subject: write to a file two dict() In-Reply-To: References: Message-ID: <505F4E41.1090300@mrabarnett.plus.com> On 2012-09-23 18:44, giuseppe.amatulli at gmail.com wrote: > Hi > Have two dict() of the same length and i want print them to a common file. > > > a={1: 1, 2: 2, 3: 3} > b={1: 11, 2: 22, 3: 33} > > in order to obtain > > 1 1 1 11 > 2 2 2 22 > 3 3 3 33 > > I tried > > output = open(dst_file, "w") > for (a), b , (c) , d in a.items() , b.items() : > output.write("%i %i %i %i\n" % (a,b,c,d)) > output.close() > > but i get the error ValueError: need more than 3 values to unpack. > > do you have some suggestions?. > If they are guaranteed to have the same keys: a = {1: 1, 2: 2, 3: 3} b = {1: 11, 2: 22, 3: 33} for k in a: output.write("%i %i %i %i\n" % (k, a[k], k, b[k])) If they don't have the same keys, but are merely the same length, then you'll first need to decide what it should do. From oscar.j.benjamin at gmail.com Sun Sep 23 14:04:38 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 23 Sep 2012 19:04:38 +0100 Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> Message-ID: On Sep 23, 2012 6:52 PM, "jimbo1qaz" wrote: > > On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: > > Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation. > > Ya, they should really give a better way, but for now, enumerate works pretty well. I can't tell who you're responding to here. It would make more sense if you quote from the post you're replying to. Also, maybe there is a better way. Unfortunately your post was quite vague so this is as good a response as you can hope for. Why don't you post a code snippet representing what your trying to do? Then someone can tell you a better way if there is one. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From andriy.kornatskyy at live.com Sun Sep 23 14:15:44 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Sun, 23 Sep 2012 21:15:44 +0300 Subject: Fastest web framework In-Reply-To: References: , , , Message-ID: Good to know you are in a good humor today. You will be surprised... far not all share your point of view.?;-) Few links for you to stop laughing that loud: http://packages.python.org/wheezy.http/userguide.html#content-cache http://packages.python.org/wheezy.caching/userguide.html#cachedependency Andriy ---------------------------------------- > To: python-list at python.org > From: breamoreboy at yahoo.co.uk > Subject: Re: Fastest web framework > Date: Sun, 23 Sep 2012 18:20:03 +0100 > > On 23/09/2012 16:50, Stefan Behnel wrote: > > Roy Smith, 23.09.2012 16:02: > >> Andriy Kornatskyy wrote: > >>> I have run recently a benchmark of a trivial 'hello world' application for > >>> various python web frameworks (bottle,?django, flask, pyramid, web.py, > >>> wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find > >>> it interesting: > >>> > >>> http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > >>> > >>> Comments or suggestions are welcome. > >> > >> That's a nice comparison, thanks for posting it. > >> > >> One thing that's worth pointing out, however, is that in a real world > >> application, as long as you're using something halfway decent, the speed > >> of the framework is probably not going to matter at all. It's much more > >> likely that database throughput will be the dominating factor. > > > > Yes, that makes the comparison (which may or may not be biased towards his > > own engine) a bit less interesting. Worth keeping this in mind: > > > > http://www.codeirony.com/?p=9 > > > > Stefan > > > > > > I'd like to say thanks for the link but unfortunately for me, but good > news for you (plural), is that I've bust a gut laughing out loud, so I > won't :) > > Oh alright then thanks for the link. > > -- > Cheers. > > Mark Lawrence. > > -- > http://mail.python.org/mailman/listinfo/python-list From andriy.kornatskyy at live.com Sun Sep 23 14:16:23 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Sun, 23 Sep 2012 21:16:23 +0300 Subject: Fastest web framework In-Reply-To: References: , , , Message-ID: Good to know you are in a good humor today. You will be surprised... far not all share your point of view. ;-) Few links for you to stop laughing that loud: http://packages.python.org/wheezy.http/userguide.html#content-cache http://packages.python.org/wheezy.caching/userguide.html#cachedependency Andriy ---------------------------------------- > To: python-list at python.org > From: breamoreboy at yahoo.co.uk > Subject: Re: Fastest web framework > Date: Sun, 23 Sep 2012 18:20:03 +0100 > > On 23/09/2012 16:50, Stefan Behnel wrote: > > Roy Smith, 23.09.2012 16:02: > >> Andriy Kornatskyy wrote: > >>> I have run recently a benchmark of a trivial 'hello world' application for > >>> various python web frameworks (bottle,?django, flask, pyramid, web.py, > >>> wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find > >>> it interesting: > >>> > >>> http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > >>> > >>> Comments or suggestions are welcome. > >> > >> That's a nice comparison, thanks for posting it. > >> > >> One thing that's worth pointing out, however, is that in a real world > >> application, as long as you're using something halfway decent, the speed > >> of the framework is probably not going to matter at all. It's much more > >> likely that database throughput will be the dominating factor. > > > > Yes, that makes the comparison (which may or may not be biased towards his > > own engine) a bit less interesting. Worth keeping this in mind: > > > > http://www.codeirony.com/?p=9 > > > > Stefan > > > > > > I'd like to say thanks for the link but unfortunately for me, but good > news for you (plural), is that I've bust a gut laughing out loud, so I > won't :) > > Oh alright then thanks for the link. > > -- > Cheers. > > Mark Lawrence. > > -- > http://mail.python.org/mailman/listinfo/python-list From andriy.kornatskyy at live.com Sun Sep 23 14:17:20 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Sun, 23 Sep 2012 21:17:20 +0300 Subject: Fastest web framework In-Reply-To: References: , , , Message-ID: Good to know you are in a good humor today. You will be surprised... far not all share your point of view. ;-) Few links for you to stop laughing that loud: http://packages.python.org/wheezy.http/userguide.html#content-cache http://packages.python.org/wheezy.caching/userguide.html#cachedependency Andriy ---------------------------------------- > To: python-list at python.org > From: breamoreboy at yahoo.co.uk > Subject: Re: Fastest web framework > Date: Sun, 23 Sep 2012 18:20:03 +0100 > > On 23/09/2012 16:50, Stefan Behnel wrote: > > Roy Smith, 23.09.2012 16:02: > >> Andriy Kornatskyy wrote: > >>> I have run recently a benchmark of a trivial 'hello world' application for > >>> various python web frameworks (bottle,?django, flask, pyramid, web.py, > >>> wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find > >>> it interesting: > >>> > >>> http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > >>> > >>> Comments or suggestions are welcome. > >> > >> That's a nice comparison, thanks for posting it. > >> > >> One thing that's worth pointing out, however, is that in a real world > >> application, as long as you're using something halfway decent, the speed > >> of the framework is probably not going to matter at all. It's much more > >> likely that database throughput will be the dominating factor. > > > > Yes, that makes the comparison (which may or may not be biased towards his > > own engine) a bit less interesting. Worth keeping this in mind: > > > > http://www.codeirony.com/?p=9 > > > > Stefan > > > > > > I'd like to say thanks for the link but unfortunately for me, but good > news for you (plural), is that I've bust a gut laughing out loud, so I > won't :) > > Oh alright then thanks for the link. > > -- > Cheers. > > Mark Lawrence. > > -- > http://mail.python.org/mailman/listinfo/python-list From jimmyli1528 at gmail.com Sun Sep 23 14:31:41 2012 From: jimmyli1528 at gmail.com (jimbo1qaz) Date: Sun, 23 Sep 2012 11:31:41 -0700 (PDT) Subject: 'str' object does not support item assignment Message-ID: spots[y][x]=mark fails with a "'str' object does not support item assignment" error,even though: >>> a=[["a"]] >>> a[0][0]="b" and: >>> a=[["a"]] >>> a[0][0]=1000000 both work. Spots is a nested list created as a copy of another list. From python.list at tim.thechases.com Sun Sep 23 14:36:17 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 23 Sep 2012 13:36:17 -0500 Subject: Capitalization for variable that holds a class In-Reply-To: References: Message-ID: <505F56A1.4060000@tim.thechases.com> On 09/23/12 11:12, Chris Angelico wrote: > On Mon, Sep 24, 2012 at 1:48 AM, Joshua Landau > wrote: >> Simple question: >> >> [myClass() for myClass in myClasses] >> vs >> [MyClass() for MyClass in myClasses] > > Since there's no difference between a "class" and a "variable > containing a class" or a "pointer to a class" or any other such > concept, it makes sense to capitalize MyClass in your example, if you > are guaranteeing that they're all classes. Having just written code very much like this in the last 24hr, my own code reads something like my_list_of_classes = [ MyClassA, MyClassB, MyClassC, ] instances = [my_cls(args) for my_cls in my_list_of_classes] I do come down on it being a variable (and thus lowercase-with-underscores, according to PEP-8) because, well, it's varying. A class *definition* is generally expected to be non-varying (or if it does, it's often a code smell) so it gets the CapCamelCase. So while ChrisA correctly claims that at the interpreter-level "there's no difference between a 'class' and a 'variable containing a class'", I'd say that at a programmer-level, there's a conceptual difference between "expect this to vary" and "expect this to be the same". And I try to write my code for other programmers first, and the interpreter second. -tkc From jimmyli1528 at gmail.com Sun Sep 23 14:36:36 2012 From: jimmyli1528 at gmail.com (jimbo1qaz) Date: Sun, 23 Sep 2012 11:36:36 -0700 (PDT) Subject: 'str' object does not support item assignment In-Reply-To: References: Message-ID: <0456eb94-237e-4376-9a49-ef8b0e93f82b@googlegroups.com> On Sunday, September 23, 2012 11:31:41 AM UTC-7, jimbo1qaz wrote: > spots[y][x]=mark fails with a "'str' object does not support item assignment" error,even though: > > >>> a=[["a"]] > > >>> a[0][0]="b" > > and: > > >>> a=[["a"]] > > >>> a[0][0]=1000000 > > both work. > > Spots is a nested list created as a copy of another list. Yeah, it's a recursive function. Like it makes a difference. From andriy.kornatskyy at live.com Sun Sep 23 14:41:10 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Sun, 23 Sep 2012 21:41:10 +0300 Subject: Fastest web framework In-Reply-To: References: , , , , Message-ID: The problem is that easy if?you have a complete control over what you are caching. Complete control over cache may look a?challenging task however with use of cache dependency you can lower it?significantly. Take a look here: http://packages.python.org/wheezy.caching/userguide.html#cachedependency If you have a willing to go even further consider take a look at content caching: http://packages.python.org/wheezy.http/userguide.html#content-cache Serving static page out of your data is not that impossible... there are still exceptions, of cause. Thanks. Andriy ---------------------------------------- > To: python-list at python.org > From: stefan_ml at behnel.de > Subject: Re: Fastest web framework > Date: Sun, Sep 2 :::::: +0<<< > > Andriy Kornatskyy, ......2 :::::: > > If we take a look at web application we can split it into at least two > > parts, one that renders things out and the other one that does data > > extraction, e.g. from database (this is what you are pointing at). > > > > If you made a first call to database you get your list and can easily > > cache it. The next call IS without impact that database call may > > cause... but you still keep serving pages out... > > Well, if it was really that easy, you wouldn't be using a database in the > first place but static pages, would you? > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list From ian.g.kelly at gmail.com Sun Sep 23 14:45:09 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 23 Sep 2012 12:45:09 -0600 Subject: 'str' object does not support item assignment In-Reply-To: References: Message-ID: On Sun, Sep 23, 2012 at 12:31 PM, jimbo1qaz wrote: > spots[y][x]=mark fails with a "'str' object does not support item assignment" error,even though: >>>> a=[["a"]] >>>> a[0][0]="b" > and: >>>> a=[["a"]] >>>> a[0][0]=1000000 > both work. > Spots is a nested list created as a copy of another list. There's not enough information to go on here to even speculate what might be causing the error, beyond "spots probably does not have the structure you think it does". Please post the code that you're actually running along with the full error traceback, and then maybe we can help you out. Also try printing the value of spots just before the assignment and see what it actually looks like. From oscar.j.benjamin at gmail.com Sun Sep 23 14:46:28 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 23 Sep 2012 19:46:28 +0100 Subject: Anyone able to help on installing packages? In-Reply-To: <377867f4-d508-4a1b-adba-076f99afbaad@googlegroups.com> References: <377867f4-d508-4a1b-adba-076f99afbaad@googlegroups.com> Message-ID: On Sep 23, 2012 6:56 PM, "John Mordecai Dildy" wrote: > > Hello everyone out there. Ive been trying to install packages like distribute, nose, and virturalenv and believe me it is a hard process to do. I tried everything I could think of to install. > > I have done the following: > > pip install "package name" > > easy_install "package name" What happened when you ran those commands? Was there an error message? If so can can you post the exact output? Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sun Sep 23 14:47:38 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 23 Sep 2012 19:47:38 +0100 Subject: 'str' object does not support item assignment In-Reply-To: References: Message-ID: <505F594A.60702@mrabarnett.plus.com> On 2012-09-23 19:31, jimbo1qaz wrote: > spots[y][x]=mark fails with a "'str' object does not support item assignment" error,even though: >>>> a=[["a"]] >>>> a[0][0]="b" > and: >>>> a=[["a"]] >>>> a[0][0]=1000000 > both work. > Spots is a nested list created as a copy of another list. > The error suggests that spots[y] is actually a string. Printing repr(spots) and repr(spots[y]) should tell you whether it is. From andrea.crotti.0 at gmail.com Sun Sep 23 14:48:49 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Sun, 23 Sep 2012 19:48:49 +0100 Subject: 'str' object does not support item assignment In-Reply-To: References: Message-ID: <505F5991.3090000@gmail.com> On 09/23/2012 07:31 PM, jimbo1qaz wrote: > spots[y][x]=mark fails with a "'str' object does not support item assignment" error,even though: >>>> a=[["a"]] >>>> a[0][0]="b" > and: >>>> a=[["a"]] >>>> a[0][0]=1000000 > both work. > Spots is a nested list created as a copy of another list. But a = "a" a[0] = 'c' fails for the same reason, which is that strings in Python are immutable.. From jimmyli1528 at gmail.com Sun Sep 23 14:55:09 2012 From: jimmyli1528 at gmail.com (jimbo1qaz) Date: Sun, 23 Sep 2012 11:55:09 -0700 (PDT) Subject: 'str' object does not support item assignment In-Reply-To: References: Message-ID: <76ce019e-6e3f-4732-a631-da5dabe20484@googlegroups.com> On Sunday, September 23, 2012 11:48:11 AM UTC-7, MRAB wrote: > On 2012-09-23 19:31, jimbo1qaz wrote: > > > spots[y][x]=mark fails with a "'str' object does not support item assignment" error,even though: > > >>>> a=[["a"]] > > >>>> a[0][0]="b" > > > and: > > >>>> a=[["a"]] > > >>>> a[0][0]=1000000 > > > both work. > > > Spots is a nested list created as a copy of another list. > > > > > The error suggests that spots[y] is actually a string. Printing > > repr(spots) and repr(spots[y]) should tell you whether it is. ya, I'm an idiot. I accidentally made a string instead of an array. From jimmyli1528 at gmail.com Sun Sep 23 14:55:09 2012 From: jimmyli1528 at gmail.com (jimbo1qaz) Date: Sun, 23 Sep 2012 11:55:09 -0700 (PDT) Subject: 'str' object does not support item assignment In-Reply-To: References: Message-ID: <76ce019e-6e3f-4732-a631-da5dabe20484@googlegroups.com> On Sunday, September 23, 2012 11:48:11 AM UTC-7, MRAB wrote: > On 2012-09-23 19:31, jimbo1qaz wrote: > > > spots[y][x]=mark fails with a "'str' object does not support item assignment" error,even though: > > >>>> a=[["a"]] > > >>>> a[0][0]="b" > > > and: > > >>>> a=[["a"]] > > >>>> a[0][0]=1000000 > > > both work. > > > Spots is a nested list created as a copy of another list. > > > > > The error suggests that spots[y] is actually a string. Printing > > repr(spots) and repr(spots[y]) should tell you whether it is. ya, I'm an idiot. I accidentally made a string instead of an array. From breamoreboy at yahoo.co.uk Sun Sep 23 15:11:05 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 23 Sep 2012 20:11:05 +0100 Subject: 'str' object does not support item assignment In-Reply-To: References: Message-ID: On 23/09/2012 19:31, jimbo1qaz wrote: > spots[y][x]=mark fails with a "'str' object does not support item assignment" error,even though: >>>> a=[["a"]] >>>> a[0][0]="b" > and: >>>> a=[["a"]] >>>> a[0][0]=1000000 > both work. > Spots is a nested list created as a copy of another list. > Looks to me as if there are three options. a) raise a bug report on the Python bug tracker at bugs.python.org. b) fix your code. As option b) is the likely route, the way forward is to put print statements in your code so you can see what data you have *AND* what type it is. -- Cheers. Mark Lawrence. From dwightdhutto at gmail.com Sun Sep 23 15:28:35 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sun, 23 Sep 2012 15:28:35 -0400 Subject: Fastest web framework In-Reply-To: References: Message-ID: On Sun, Sep 23, 2012 at 5:19 AM, Andriy Kornatskyy wrote: > > I have run recently a benchmark of a trivial 'hello world' application for various python web frameworks (bottle, django, flask, pyramid, web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9 There are other considerations that must be made when running a 'hello world'. -It is a basic string, but no numerical benchmarks. -You've overlooked the fact that different OS's have other processes at work, which need to be looked at -and a function which performed several tasks(a string, and numerical), and then returned the result on seveal operating systems, with non-essential processes turned off -etc -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From andriy.kornatskyy at live.com Sun Sep 23 15:48:38 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Sun, 23 Sep 2012 22:48:38 +0300 Subject: Fastest web framework In-Reply-To: References: , Message-ID: > On Sun, Sep 23, 2012 at 5:19 AM, Andriy Kornatskyy > wrote: > > > > I have run recently a benchmark of a trivial 'hello world' application for various python web frameworks (bottle, django, flask, pyramid, web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9 > > There are other considerations that must be made when running a 'hello world'. > > -It is a basic string, but no numerical benchmarks. The basic string in return was chosen to benchmark framework code in processing a simple thing and measure the overhead related. In other words how effective the framework is inside. > -You've overlooked the fact that different OS's have other processes > at work, which need to be looked at > -and a function which performed several tasks(a string, and > numerical), and then returned the result on seveal operating systems, > with non-essential processes turned off There were minimal processes running on both client and server, and even if some have had CPU/network activity it was not so important to the workload both client and server?experienced due to test performed.? Hope I understood you correctly. Thanks. Andriy From dwightdhutto at gmail.com Sun Sep 23 16:16:15 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sun, 23 Sep 2012 16:16:15 -0400 Subject: Fastest web framework In-Reply-To: References: Message-ID: > Hope I understood you correctly. > Well, lets break down timing something in a more scientific method approach through questioning. What's your processor speed? What is the constant temperature of the internals of your system? What OS, and version? What other processes are running? There's a scientific method to what you're benchmarking. There have to be constants, and variables to benchmark with. These will of course vary with other methods of approach with the same code. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dihedral88888 at googlemail.com Sun Sep 23 16:34:09 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 23 Sep 2012 13:34:09 -0700 (PDT) Subject: write to a file two dict() In-Reply-To: References: Message-ID: giuseppe... at gmail.com? 2012?9?24????UTC+8??1?44?30???? > Hi > > Have two dict() of the same length and i want print them to a common file. > > > > > > a={1: 1, 2: 2, 3: 3} > > b={1: 11, 2: 22, 3: 33} > > > > in order to obtain > > > > 1 1 1 11 > > 2 2 2 22 > > 3 3 3 33 > > > > I tried > > > > output = open(dst_file, "w") > > for (a), b , (c) , d in a.items() , b.items() : > > output.write("%i %i %i %i\n" % (a,b,c,d)) > > output.close() > > > > but i get the error ValueError: need more than 3 values to unpack. > > > > do you have some suggestions?. > > Thanks > > Giuseppe You can pickle the object directly in python. From oscar.j.benjamin at gmail.com Sun Sep 23 16:51:45 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 23 Sep 2012 21:51:45 +0100 Subject: Anyone able to help on installing packages? In-Reply-To: References: <377867f4-d508-4a1b-adba-076f99afbaad@googlegroups.com> Message-ID: Please send your reply to the mailing list (python-list at python.org) rather than privately to me. On 23 September 2012 20:57, John Dildy wrote: > When I give input at the start of terminal using the command pip install > virtualenv: > > Downloading/unpacking virtualenv > Running setup.py egg_info for package virtualenv > > warning: no previously-included files matching '*' found under > directory 'docs/_templates' > warning: no previously-included files matching '*' found under > directory 'docs/_build' > Installing collected packages: virtualenv > Running setup.py install for virtualenv > error: /Library/Python/2.7/site-packages/virtualenv.py: Permission > denied > Complete output from command /usr/bin/python -c "import > setuptools;__file__='/var/folders/4r/jxvj6v_j5571vbjxkx_jbdy80000gp/T/pip-build/virtualenv/setup.py';exec(compile(open(__file__).read().replace('\r\n', > '\n'), __file__, 'exec'))" install --record > /var/folders/4r/jxvj6v_j5571vbjxkx_jbdy80000gp/T/pip-S9mDRc-record/install-record.txt > --single-version-externally-managed: > running install > > running build > > running build_py > > running install_lib > > copying build/lib/virtualenv.py -> /Library/Python/2.7/site-packages > > error: /Library/Python/2.7/site-packages/virtualenv.py: Permission denied > Your user account does not have permission to install the package in the place where you want to install it. > > ---------------------------------------- > Command /usr/bin/python -c "import > setuptools;__file__='/var/folders/4r/jxvj6v_j5571vbjxkx_jbdy80000gp/T/pip-build/virtualenv/setup.py';exec(compile(open(__file__).read().replace('\r\n', > '\n'), __file__, 'exec'))" install --record > /var/folders/4r/jxvj6v_j5571vbjxkx_jbdy80000gp/T/pip-S9mDRc-record/install-record.txt > --single-version-externally-managed failed with error code 1 in > /var/folders/4r/jxvj6v_j5571vbjxkx_jbdy80000gp/T/pip-build/virtualenv > Storing complete log in /Users/jd3/Library/Logs/pip.log > > When I give the input of easy_install virtualenv: > > error: can't create or remove files in install directory > > The following error occurred while trying to add or remove files in the > installation directory: > > [Errno 13] Permission denied: > '/Library/Python/2.7/site-packages/test-easy-install-6258.write-test' > This problem is exactly the same. It doesn't matter whether you use pip or easy_install, you need to be an administrator to install the package in that location. See the rest of the message: > The installation directory you specified (via --install-dir, --prefix, or > the distutils default setting) was: > > /Library/Python/2.7/site-packages/ > > Perhaps your account does not have write access to this directory? If the > installation directory is a system-owned directory, you may need to sign in > as the administrator or "root" account. If you do not have administrative > access to this machine, you may wish to choose a different installation > directory, preferably one that is listed in your PYTHONPATH environment > variable. > There are two ways around this: 1) Run those commands as root. I don't use OSX but I believe the command is: $ sudo pip install virtualenv 2) Install into your user directory. I don't know if there's anything that needs to be done to make this work on OSX but I can do this with: $ sudo pip install --user virtualenv Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From jdildy85 at gmail.com Sun Sep 23 17:08:30 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 23 Sep 2012 14:08:30 -0700 (PDT) Subject: Anyone able to help on installing packages? In-Reply-To: <377867f4-d508-4a1b-adba-076f99afbaad@googlegroups.com> References: <377867f4-d508-4a1b-adba-076f99afbaad@googlegroups.com> Message-ID: <2f6f75c5-d96a-48f1-96b3-a8eccbb3d2ef@googlegroups.com> On Sunday, September 23, 2012 1:48:52 PM UTC-4, John Mordecai Dildy wrote: > Hello everyone out there. Ive been trying to install packages like distribute, nose, and virturalenv and believe me it is a hard process to do. I tried everything I could think of to install. > > > > I have done the following: > > > > pip install "package name" > > > > easy_install "package name" > > > > Would anyone help me at least to give directions for at least one of the package installation? > > > > Would it work along with any other package installation (for example if you helped it show nose will it work with distribute, etc)? > > > > Thank You all for your help I have just gotten help to have virtualenv installed now. It was On OS X to do: sudo pip install virtualenv Now I have nose and distribute to have installed in python From aclark at aclark.net Sun Sep 23 17:25:20 2012 From: aclark at aclark.net (Alex Clark) Date: Sun, 23 Sep 2012 17:25:20 -0400 Subject: Fastest web framework References: Message-ID: On 2012-09-23 09:19:16 +0000, Andriy Kornatskyy said: > > I have run recently a benchmark of a trivial 'hello world' application > for various python web frameworks (bottle,?django, flask, pyramid, > web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... > you might find it interesting: > > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > > Comments or suggestions are welcome. Are you on Python Planet? If not, you might want to syndicate your blog there to reach more of the Python web framework crowd. > > Thanks. > > Andriy Kornatskyy > -- Alex Clark ? http://pythonpackages.com From jimmyli1528 at gmail.com Sun Sep 23 17:31:48 2012 From: jimmyli1528 at gmail.com (jimbo1qaz) Date: Sun, 23 Sep 2012 14:31:48 -0700 (PDT) Subject: List Problem Message-ID: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> I have a nested list. Whenever I make a copy of the list, changes in one affect the other, even when I use list(orig) or even copy the sublists one by one. I have to manually copy each cell over for it to work. Link to broken code: http://jimbopy.pastebay.net/1090401 From steve+comp.lang.python at pearwood.info Sun Sep 23 17:42:23 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Sep 2012 21:42:23 GMT Subject: Capitalization for variable that holds a class References: Message-ID: <505f823f$0$1612$c3e8da3$76491128@news.astraweb.com> On Mon, 24 Sep 2012 02:12:25 +1000, Chris Angelico wrote: > On Mon, Sep 24, 2012 at 1:48 AM, Joshua Landau > wrote: >> Simple question: >> >> [myClass() for myClass in myClasses] >> vs >> [MyClass() for MyClass in myClasses] >> >> Fight. >> >> (When considering, substitute in a more real-world example like >> [Token() for Token in allTokens] or [token() for token in allTokens]) > > An interesting point! I assume you're basing this on the PEP 8 > recommendation: http://www.python.org/dev/peps/pep-0008/#class-names > > Since there's no difference between a "class" and a "variable containing > a class" or a "pointer to a class" or any other such concept, it makes > sense to capitalize MyClass in your example, if you are guaranteeing > that they're all classes. And certainly a long-lived variable ought to > be named in CapWords. However, all you're really doing is taking a bunch > of callables, calling them, and making a list of the results. I'd > therefore be inclined to _not_ capitalize it. YMMV though. The difference is in the programmer's intention. I would go with: [aclass() for aclass in MyClasses] to emphasise that aclass is intended as a temporary loop variable and not a long-lasting class definition. So I guess I'm agreeing with Chris. -- Steven From jimmyli1528 at gmail.com Sun Sep 23 17:44:13 2012 From: jimmyli1528 at gmail.com (jimbo1qaz) Date: Sun, 23 Sep 2012 14:44:13 -0700 (PDT) Subject: List Problem In-Reply-To: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> References: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> Message-ID: On Sunday, September 23, 2012 2:31:48 PM UTC-7, jimbo1qaz wrote: > I have a nested list. Whenever I make a copy of the list, changes in one affect the other, even when I use list(orig) or even copy the sublists one by one. I have to manually copy each cell over for it to work. > > Link to broken code: http://jimbopy.pastebay.net/1090401 No, actually that's the OK code. http://jimbopy.pastebay.net/1090494 is the broken one. From oscar.j.benjamin at gmail.com Sun Sep 23 17:50:05 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 23 Sep 2012 22:50:05 +0100 Subject: List Problem In-Reply-To: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> References: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> Message-ID: On 23 September 2012 22:31, jimbo1qaz wrote: > I have a nested list. Whenever I make a copy of the list, changes in one > affect the other, even when I use list(orig) or even copy the sublists one > by one. I have to manually copy each cell over for it to work. > Link to broken code: http://jimbopy.pastebay.net/1090401 There are many things wrong with that code but I can't tell what you're referring to. Can you paste the code into your post (rather than just a link to it)? Can you also explain what you want it to do and at what point it does the wrong thing? Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Sep 23 17:57:26 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Sep 2012 07:57:26 +1000 Subject: List Problem In-Reply-To: References: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> Message-ID: On Mon, Sep 24, 2012 at 7:44 AM, jimbo1qaz wrote: > On Sunday, September 23, 2012 2:31:48 PM UTC-7, jimbo1qaz wrote: >> I have a nested list. Whenever I make a copy of the list, changes in one affect the other, even when I use list(orig) or even copy the sublists one by one. I have to manually copy each cell over for it to work. >> >> Link to broken code: http://jimbopy.pastebay.net/1090401 > > No, actually that's the OK code. http://jimbopy.pastebay.net/1090494 is the broken one. The first thing I'd change about that code is the whole thing of using try/exec/except to suppress IndexError. Definitely not good code. I'm not wholly certain, but I think you might run into weird issues with negative OOBounds indices (since Python treats a negative list index as counting from the far end). This is nothing to do with your originally requested issue, which I can't see the cause of in your script there. But when you assign a list, you just get another reference to the same list. ChrisA From d at davea.name Sun Sep 23 18:03:32 2012 From: d at davea.name (Dave Angel) Date: Sun, 23 Sep 2012 18:03:32 -0400 Subject: List Problem In-Reply-To: References: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> Message-ID: <505F8734.2020908@davea.name> On 09/23/2012 05:44 PM, jimbo1qaz wrote: > On Sunday, September 23, 2012 2:31:48 PM UTC-7, jimbo1qaz wrote: >> I have a nested list. Whenever I make a copy of the list, changes in one affect the other, even when I use list(orig) or even copy the sublists one by one. I have to manually copy each cell over for it to work. >> >> Link to broken code: http://jimbopy.pastebay.net/1090401 > No, actually that's the OK code. http://jimbopy.pastebay.net/1090494 is the broken one. I also would prefer an inline posting of the code, but if it's too big to post here, it's probably too big for me to debug here. The usual reason for such a symptom is a nested list, where you have multiple references to the same inner list inside the outer. When you change one of those, you change all of them. alist = [1, 2, 3] blist = [alist, alist, alist] # or blist = alist * 3 print blist alist.append(49) print blist davea at think:~/temppython$ python jimbo.py [[1, 2, 3], [1, 2, 3], [1, 2, 3]] [[1, 2, 3, 49], [1, 2, 3, 49], [1, 2, 3, 49]] Solution to this is to make sure that only copies of alist get into blist. One way is blist = [alist[:], alist[:], alist[:]] More generally, you can get into this type of trouble whenever you have non-immutable objects inside the list. Understand, this is NOT a flaw in the language. It's perfectly reasonable to be able to do so, in fact essential in many cases, when you want it to be the SAME item. -- DaveA From steve+comp.lang.python at pearwood.info Sun Sep 23 18:07:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Sep 2012 22:07:22 GMT Subject: List Problem References: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> Message-ID: <505f8819$0$1612$c3e8da3$76491128@news.astraweb.com> On Sun, 23 Sep 2012 14:31:48 -0700, jimbo1qaz wrote: > I have a nested list. Whenever I make a copy of the list, changes in one > affect the other, Then you aren't making a copy. py> first_list = [1, 2, 3] py> second_list = first_list # THIS IS NOT A COPY py> second_list.append(9999) py> print first_list [1, 2, 3, 9999] > even when I use list(orig) Nonsense. Either you are confused, or there is something you aren't telling us. Calling list *does* make a copy: py> first_list = [1, 2, 3] py> second_list = list(first_list) py> second_list.append(9999) py> print first_list [1, 2, 3] What aren't you telling us? My guess is that there are TWO lists involved, and you're only copying ONE: py> a = [1, 2, 3] py> a.append(["ham", "spam", "cheese"]) py> print a [1, 2, 3, ['ham', 'spam', 'cheese']] py> b = list(a) # make a copy of a, but not the contents of a py> b.append(99) # change b py> b[-1].append("tomato") py> print a [1, 2, 3, ['ham', 'spam', 'cheese', 'tomato']] Notice that b is a copy of a: changing b does not change a. But the embedded list within a is *not* copied, so whether you append to that list via a or b is irrelevant, both see the same change because there is only one inner list in two places. It might be more obvious if you give the shared sublist a name: c = ['ham', 'spam', 'tomato'] a = [1, 2, 3, c] b = [1, 2, 3, c] # a copy of a, but not a copy of c Now it should be obvious that any changes to c will show up in both a and b, regardless of how you change it. All three of these will have the exact same effect: a[-1].append('eggs') b[-1].append('eggs') c.append('eggs') The way to copy lists, and all their sublists, and their sublists, and so on all the way down, is with the copy module: import copy b = copy.deepcopy(a) but if you are doing this a lot, (1) your code will be slow, and (2) you can probably redesign your code to avoid so many copies. By the way, instead of dumping lots of irrelevant code on us, please take the time to narrow your problem down to the smallest possible piece of code. We're volunteers here, and you are not paying us to wade through your code trying to determine where your problem lies. That is up to you: you narrow down to the actual problem, then ask for help. Please read http://sscce.org/ for more details of how, and why, you should do this. Thank you. -- Steven From joshua.landau.ws at gmail.com Sun Sep 23 18:24:46 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Sun, 23 Sep 2012 23:24:46 +0100 Subject: Invalid identifier claimed to be valid by docs (methinks) Message-ID: The docs describe identifiers to have this grammar: *identifier * ::= xid_start xid_continue **id_start * ::= *id_continue * ::= , plus characters in the categories Mn, Mc, Nd, Pc and others with the Other_ID_Continue property>*xid_start * ::= whose NFKC normalization is in "id_start xid_continue*">*xid_continue* ::= whose NFKC normalization is in "id_continue*"> So I would assume that exec("a{} = None".format(char)) would be valid if unicodedata.normalize("NFKC", char) == "1" as exec("a1 = None") is valid. BUT "a? = None" is not valid*. *a, accessible through +1 if your keyboard's set up to do that stuff. Thank you for your times. -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Sun Sep 23 18:25:22 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 23 Sep 2012 22:25:22 +0000 (UTC) Subject: Obnoxious postings from Google Groups (was: datetime issue) References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> <5055a1a6$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f9d9a0b-539a-4b6a-af3e-b02d1f4006ee@googlegroups.com> <87wqzum7h6.fsf_-_@benfinney.id.au> Message-ID: On 2012-09-22, Hank Gay wrote: > On 2012-09-21 15:07:09 +0000, Grant Edwards said: >> >> I told my news client years ago to filter out anything posted from >> Google Groups -- and I know I'm not alone. If one wants the best >> chance of getting a question answered, using something other than >> Google Groups is indeed a good idea. > > What's that filter look like? Score:: =-9999 Message-ID: .*googlegroups.com -- Grant From rosuav at gmail.com Sun Sep 23 18:27:28 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Sep 2012 08:27:28 +1000 Subject: List Problem In-Reply-To: <505F8734.2020908@davea.name> References: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> <505F8734.2020908@davea.name> Message-ID: On Mon, Sep 24, 2012 at 8:03 AM, Dave Angel wrote: > blist = [alist, alist, alist] # or blist = alist * 3 (Minor point: I think you mean this.) # or blist = [alist] * 3 > Understand, this is NOT a flaw in the language. It's perfectly > reasonable to be able to do so, in fact essential in many cases, when > you want it to be the SAME item. And this is the real part. There's no other way to handle complex objects that makes as much sense. PHP's system of references and copy-on-write assignment doesn't truly cover all cases, and it can make operations unexpectedly run vastly faster or slower depending on external circumstances, which gets annoying (the first write to an assigned array has to copy the array). C simply doesn't let you move arrays around, only pointers to them, so semantics are actually pretty similar to high level languages, only in a completely different way. These sorts of issues only ever seem to crop up with nested arrays, which strengthens this next point: Deep copying is a really REALLY hairy concept. It seems so simple at first: a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] b = deepcopy(a) # b is a new list with three new sublists But then it gets messy. a = [[1, 2, 3]]*2 + [[7, 8, 9]] It's much better to make copying a very explicit thing; it's so expensive that you really should make it very clear in your code when this happens. ChrisA From rosuav at gmail.com Sun Sep 23 18:30:33 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Sep 2012 08:30:33 +1000 Subject: List Problem In-Reply-To: References: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> <505F8734.2020908@davea.name> Message-ID: On Mon, Sep 24, 2012 at 8:27 AM, Chris Angelico wrote: > a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] > b = deepcopy(a) # b is a new list with three new sublists > Oops, this should be: b = copy.deepcopy(a) as in Steven's post. And in case I wasn't clear about it, the deepcopy() function does deal with the issue I mention, but that's part of why it's an expensive operation. ChrisA From steve+comp.lang.python at pearwood.info Sun Sep 23 18:37:19 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Sep 2012 22:37:19 GMT Subject: List Problem References: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> <505F8734.2020908@davea.name> Message-ID: <505f8f1e$0$1612$c3e8da3$76491128@news.astraweb.com> On Mon, 24 Sep 2012 08:27:28 +1000, Chris Angelico wrote: > C simply doesn't let you move > arrays around, only pointers to them, so semantics are actually pretty > similar to high level languages, only in a completely different way. I once dated a girl who looked exactly like Scarlett Johannsen only completely different. Pascal let's you pass arrays around either by value (which copies them, and may be expensive) or by reference (which doesn't), neither of which is what Python (or Java, Ruby, etc.) do. Passing pointers by value is not the same as Python object semantics. -- Steven From jimmyli1528 at gmail.com Sun Sep 23 18:44:06 2012 From: jimmyli1528 at gmail.com (jimbo1qaz) Date: Sun, 23 Sep 2012 15:44:06 -0700 (PDT) Subject: List Problem In-Reply-To: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> References: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> Message-ID: <4797cf1b-d18b-4c7d-bb89-dcb7b6ff4d45@googlegroups.com> On Sunday, September 23, 2012 2:31:48 PM UTC-7, jimbo1qaz wrote: > I have a nested list. Whenever I make a copy of the list, changes in one affect the other, even when I use list(orig) or even copy the sublists one by one. I have to manually copy each cell over for it to work. > > Link to broken code: http://jimbopy.pastebay.net/1090401 OK, deepcopy fixed it! And I fixed the catch indexerror thing too. From rosuav at gmail.com Sun Sep 23 18:45:16 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Sep 2012 08:45:16 +1000 Subject: List Problem In-Reply-To: <505f8f1e$0$1612$c3e8da3$76491128@news.astraweb.com> References: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> <505F8734.2020908@davea.name> <505f8f1e$0$1612$c3e8da3$76491128@news.astraweb.com> Message-ID: On Mon, Sep 24, 2012 at 8:37 AM, Steven D'Aprano wrote: > On Mon, 24 Sep 2012 08:27:28 +1000, Chris Angelico wrote: > >> C simply doesn't let you move >> arrays around, only pointers to them, so semantics are actually pretty >> similar to high level languages, only in a completely different way. > > I once dated a girl who looked exactly like Scarlett Johannsen only > completely different. > > Pascal let's you pass arrays around either by value (which copies them, > and may be expensive) or by reference (which doesn't), neither of which > is what Python (or Java, Ruby, etc.) do. Passing pointers by value is not > the same as Python object semantics. If your arrays are allocated on the heap, you can pretty much treat the pointer like a HLL list object. The only real difference is that C, by default, won't garbage-collect your heap allocations, so you'll leak memory. The behaviours you observe will be pretty similar, though. ChrisA From steve+comp.lang.python at pearwood.info Sun Sep 23 18:53:43 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Sep 2012 22:53:43 GMT Subject: Editing Inkscape SVG files with Python? Message-ID: <505f92f7$0$1612$c3e8da3$76491128@news.astraweb.com> I have some SVG files generated with Inkscape containing many text blocks (over 100). I wish to programmatically modify those text blocks using Python. Is there a library I should be using, or any other guidelines or advice anyone can give me? Googling for "python inkscape" comes up with too many hits for Inkscape's plugin system to be much help to me. Thanks in advance. -- Steven From steve+comp.lang.python at pearwood.info Sun Sep 23 18:54:09 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Sep 2012 22:54:09 GMT Subject: For Counter Variable References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> Message-ID: <505f9311$0$1612$c3e8da3$76491128@news.astraweb.com> On Sun, 23 Sep 2012 10:45:53 -0700, jimbo1qaz wrote: > On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: >> Am I missing something obvious, or do I have to manually put in a >> counter in the for loops? That's a very basic request, but I couldn't >> find anything in the documentation. > > Ya, they should really give a better way, but for now, enumerate works > pretty well. Define "a better way". What did you have in mind that would work better? -- Steven From ian.g.kelly at gmail.com Sun Sep 23 18:57:53 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 23 Sep 2012 16:57:53 -0600 Subject: Invalid identifier claimed to be valid by docs (methinks) In-Reply-To: References: Message-ID: On Sun, Sep 23, 2012 at 4:24 PM, Joshua Landau wrote: > The docs describe identifiers to have this grammar: > > identifier ::= xid_start xid_continue* > id_start ::= Nl, the underscore, and characters with the Other_ID_Start property> > id_continue ::= categories Mn, Mc, Nd, Pc and others with the Other_ID_Continue property> > xid_start ::= "id_start xid_continue*"> > xid_continue ::= in "id_continue*"> > > So I would assume that > exec("a{} = None".format(char)) > would be valid if > unicodedata.normalize("NFKC", char) == "1" > as > exec("a1 = None") > is valid. > > BUT "a? = None" is not valid*. > > *a, accessible through +1 if your keyboard's set up > to do that stuff. > > Thank you for your times. Or if you don't have a keyboard for that, you can do the same thing via: exec("x\u00b9 = None") # U+00B9 is superscript 1 On the other hand, this does work: exec("x\u2071 = None") # U+2071 is superscript i So it seems to be only an issue with superscript and subscript digits. Looks like a compiler bug to me. From oscar.j.benjamin at gmail.com Sun Sep 23 19:08:08 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 24 Sep 2012 00:08:08 +0100 Subject: Editing Inkscape SVG files with Python? In-Reply-To: <505f92f7$0$1612$c3e8da3$76491128@news.astraweb.com> References: <505f92f7$0$1612$c3e8da3$76491128@news.astraweb.com> Message-ID: On 23 September 2012 23:53, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > I have some SVG files generated with Inkscape containing many text blocks > (over 100). I wish to programmatically modify those text blocks using > Python. Is there a library I should be using, or any other guidelines or > advice anyone can give me? > > Googling for "python inkscape" comes up with too many hits for Inkscape's > plugin system to be much help to me. > I thought for a moment that PyX would do it. I just checked their roadmap though and SVG support is "not started": http://pyx.sourceforge.net/roadmap.html Since SVG files are a type of XML and you only want to modify the text blocks can you not just use an XML library? Alternatively, if you don't get an answer here it might be worth trying the PyX-user list. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Sun Sep 23 19:14:23 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 24 Sep 2012 00:14:23 +0100 Subject: Java singletonMap in Python Message-ID: Purely for fun I've been porting some code to Python and came across the singletonMap[1]. I'm aware that there are loads of recipes on the web for both singletons e.g.[2] and immutable dictionaries e.g.[3]. I was wondering how to combine any of the recipes to produce the best implementation, where to me best means cleanest and hence most maintainable. I then managed to muddy the waters for myself by recalling the Alex Martelli Borg pattern[4]. Possibly or even probably the latter is irrelevant, but I'm still curious to know how you'd code this beast. First prize for the best solution is a night out with me, no guesses what the second prize is :) [1]http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Collections.html [2]http://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python [3]http://code.activestate.com/recipes/498072-implementing-an-immutable-dictionary/ [4]http://code.activestate.com/recipes/66531-singleton-we-dont-need-no-stinkin-singleton-the-bo/ -- Cheers. Mark Lawrence. From mcepl at redhat.com Sun Sep 23 19:19:07 2012 From: mcepl at redhat.com (Matej Cepl) Date: Mon, 24 Sep 2012 01:19:07 +0200 Subject: pyOpenSSL -> m2crypto conversion? Message-ID: <505F98EB.90508@redhat.com> Hi, gajim (http://gajim.org, Jabber/XMPP instatnt messenger written in PyGtk) uses for crypto mix of some functions from the standard library, pyOpenSSL for SSL communication, and python-crypto for E2E (encryption of the messages ... uses RSA and AES; see https://trac.gajim.org/ticket/5294 for more details). Now I would like to unify external crypto libraries just to m2crypto (a) I think using two crypto libraries is suspicious, b) I would like to eliminate use python-crypto to minimize general number of crypto libraries), for which I would like to first of all port pyOpenSSL-using code to m2crypto. Is there some HOWTO/blogpost/examples of doing so, or is there some help in m2crypto for that? Both libraries are bindings over OpenSSL, so I hope it wouldn't be that difficult. https://bugs.launchpad.net/pyopenssl/+bug/236170/comments/22 seems to suggest that there might be some pyOpenSSL compatibility wrapper for m2crypto ... do I understand it correctly? Any suggestoins, help is highly welcomed. Thank you in advance, Mat?j Cepl From joshua.landau.ws at gmail.com Sun Sep 23 19:28:49 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Mon, 24 Sep 2012 00:28:49 +0100 Subject: Invalid identifier claimed to be valid by docs (methinks) In-Reply-To: References: Message-ID: On 23 September 2012 23:57, Ian Kelly wrote: > On Sun, Sep 23, 2012 at 4:24 PM, Joshua Landau > wrote: > > The docs describe identifiers to have this grammar: > > > > identifier ::= xid_start xid_continue* > > id_start ::= Lo, > > Nl, the underscore, and characters with the Other_ID_Start property> > > id_continue ::= > categories Mn, Mc, Nd, Pc and others with the Other_ID_Continue property> > > xid_start ::= is in > > "id_start xid_continue*"> > > xid_continue ::= normalization is > > in "id_continue*"> > > > > So I would assume that > > exec("a{} = None".format(char)) > > would be valid if > > unicodedata.normalize("NFKC", char) == "1" > > as > > exec("a1 = None") > > is valid. > > > > BUT "a? = None" is not valid*. > > > > *a, accessible through +1 if your keyboard's set > up > > to do that stuff. > >On Sun, Sep 23, 2012 at 4:24 PM, Joshua Landau > wrote: > > The docs describe identifiers to have this grammar: > > > > identifier ::= xid_start xid_continue* > > id_start ::= Lo, > > Nl, the underscore, and characters with the Other_ID_Start property> > > id_continue ::= > categories Mn, Mc, Nd, Pc and others with the Other_ID_Continue property> > > xid_start ::= is in > > "id_start xid_continue*"> > > > Thank you for your times. > > Or if you don't have a keyboard for that, you can do the same thing via: > > exec("x\u00b9 = None") # U+00B9 is superscript 1 > > On the other hand, this does work: > > exec("x\u2071 = None") # U+2071 is superscript i > > So it seems to be only an issue with superscript and subscript digits. > Looks like a compiler bug to me. > W007! Another compiler bug! Thanks for finding one that works. I can confirm that the snippet sets "xi", like the docs claim. Hence, yes, this does look like a compiler bug. I'll post it on the tracker and try and make a test that catches the rest if there are any. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sun Sep 23 19:29:29 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 23 Sep 2012 18:29:29 -0500 Subject: For Counter Variable In-Reply-To: <505f9311$0$1612$c3e8da3$76491128@news.astraweb.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <505f9311$0$1612$c3e8da3$76491128@news.astraweb.com> Message-ID: <505F9B59.6040909@tim.thechases.com> On 09/23/12 17:54, Steven D'Aprano wrote: > On Sun, 23 Sep 2012 10:45:53 -0700, jimbo1qaz wrote: >> On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: >>> Am I missing something obvious, or do I have to manually put in a >>> counter in the for loops? That's a very basic request, but I couldn't >>> find anything in the documentation. >> >> Ya, they should really give a better way, but for now, enumerate works >> pretty well. > > Define "a better way". What did you have in mind that would work better? I can only imagine jimbo1qaz intended "a more C-like way". blech. I **far** prefer The Python Way?. The vast majority of the time, I'm looping over some iterable where indices would only get in the way of readability. Tuple-unpacking the results of enumerate() is an elegant way of getting both the items+indices on the seldom occasion I need the index too (though I'm minorly miffed that enumerate()'s starting-offset wasn't back-ported into earlier 2.x versions and have had to code around it for 1-based indexing; either extra "+1"s or whip up my own simple enumerate() generator). -tkc From oscar.j.benjamin at gmail.com Sun Sep 23 19:50:11 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 24 Sep 2012 00:50:11 +0100 Subject: Java singletonMap in Python In-Reply-To: References: Message-ID: On 24 September 2012 00:14, Mark Lawrence wrote: > Purely for fun I've been porting some code to Python and came across the > singletonMap[1]. I'm aware that there are loads of recipes on the web for > both singletons e.g.[2] and immutable dictionaries e.g.[3]. I was > wondering how to combine any of the recipes to produce the best > implementation, where to me best means cleanest and hence most > maintainable. I then managed to muddy the waters for myself by recalling > the Alex Martelli Borg pattern[4]. Possibly or even probably the latter is > irrelevant, but I'm still curious to know how you'd code this beast. > What exactly is wanted when an attempt is made to instantiate an instance? Should it raise an error or return the previously created instance? This attempt makes all calls to __new__ after the first return the same instance: def singleton(cls): instance = None class sub(cls): def __new__(cls_, *args, **kwargs): nonlocal instance if instance is None: instance = super(sub, cls_).__new__(cls_, *args, **kwargs) return instance sub.__name__ == cls.__name__ return sub @singleton class A(object): pass print(A() is A()) Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Sun Sep 23 19:52:23 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Mon, 24 Sep 2012 09:52:23 +1000 Subject: For Counter Variable In-Reply-To: <505F9B59.6040909@tim.thechases.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <505f9311$0$1612$c3e8da3$76491128@news.astraweb.com> <505F9B59.6040909@tim.thechases.com> Message-ID: You can always use a counter if you don't like our fancy for-each loops; foolist = [1,24,24,234,23,423,4] for i in xrange(len(foolist)): print foolist[i] On Mon, Sep 24, 2012 at 9:29 AM, Tim Chase wrote: > On 09/23/12 17:54, Steven D'Aprano wrote: > > On Sun, 23 Sep 2012 10:45:53 -0700, jimbo1qaz wrote: > >> On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: > >>> Am I missing something obvious, or do I have to manually put in a > >>> counter in the for loops? That's a very basic request, but I couldn't > >>> find anything in the documentation. > >> > >> Ya, they should really give a better way, but for now, enumerate works > >> pretty well. > > > > Define "a better way". What did you have in mind that would work better? > > I can only imagine jimbo1qaz intended "a more C-like way". blech. > > I **far** prefer The Python Way?. The vast majority of the time, > I'm looping over some iterable where indices would only get in the > way of readability. Tuple-unpacking the results of enumerate() is > an elegant way of getting both the items+indices on the seldom > occasion I need the index too (though I'm minorly miffed that > enumerate()'s starting-offset wasn't back-ported into earlier 2.x > versions and have had to code around it for 1-based indexing; either > extra "+1"s or whip up my own simple enumerate() generator). > > -tkc > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sun Sep 23 20:05:23 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 23 Sep 2012 19:05:23 -0500 Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <505f9311$0$1612$c3e8da3$76491128@news.astraweb.com> <505F9B59.6040909@tim.thechases.com> Message-ID: <505FA3C3.8050408@tim.thechases.com> On 09/23/12 18:52, Alec Taylor wrote: > You can always use a counter if you don't like our fancy for-each loops; > > foolist = [1,24,24,234,23,423,4] > for i in xrange(len(foolist)): > print foolist[i] http://www.seas.upenn.edu/~lignos/py_antipatterns.html The first one on the list of anti-patterns is doing exactly this. Just don't. Ewww. Inefficient, ugly, and harder to read. Part of learning to write in Python is, well, learning to write *Python*, not {C,C++,Java,PHP}-in-Python. -tkc From tyler at tysdomain.com Sun Sep 23 20:56:47 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sun, 23 Sep 2012 18:56:47 -0600 Subject: List Problem In-Reply-To: References: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> Message-ID: <505FAFCF.6030502@tysdomain.com> On 9/23/2012 3:44 PM, jimbo1qaz wrote: > On Sunday, September 23, 2012 2:31:48 PM UTC-7, jimbo1qaz wrote: >> I have a nested list. Whenever I make a copy of the list, changes in one affect the other, even when I use list(orig) or even copy the sublists one by one. I have to manually copy each cell over for it to work. >> >> Link to broken code: http://jimbopy.pastebay.net/1090401 > No, actually that's the OK code. http://jimbopy.pastebay.net/1090494 is the broken one. I've not been following this thread fully, but why not just use x=list(y) to copy the list? The issue is that when you assign i=[1,2,3] and then j = i, j is just a reference to i, which is why you change either and the other changes. -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From ben+python at benfinney.id.au Sun Sep 23 21:02:55 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 24 Sep 2012 11:02:55 +1000 Subject: Editing Inkscape SVG files with Python? References: <505f92f7$0$1612$c3e8da3$76491128@news.astraweb.com> Message-ID: <7wtxuodygw.fsf@benfinney.id.au> Steven D'Aprano writes: > I have some SVG files generated with Inkscape containing many text > blocks (over 100). I wish to programmatically modify those text blocks > using Python. Is there a library I should be using, or any other > guidelines or advice anyone can give me? My first step would be to use ?lxml? to manipulate an XML tree, since that's what an SVG document contains. Read the SVG file as a text string, de-serialise the text to an XML tree. Match the nodes of interest using an XPath query, iterate over them. Change the content of each node using Python text manipulation, set the new value on the node. Re-serialise the tree to the SVG file. -- \ ?I distrust those people who know so well what God wants them | `\ to do to their fellows, because it always coincides with their | _o__) own desires.? ?Susan Brownell Anthony, 1896 | Ben Finney From breamoreboy at yahoo.co.uk Sun Sep 23 21:03:15 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 24 Sep 2012 02:03:15 +0100 Subject: For Counter Variable In-Reply-To: <505FA3C3.8050408@tim.thechases.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <505f9311$0$1612$c3e8da3$76491128@news.astraweb.com> <505F9B59.6040909@tim.thechases.com> <505FA3C3.8050408@tim.thechases.com> Message-ID: On 24/09/2012 01:05, Tim Chase wrote: > On 09/23/12 18:52, Alec Taylor wrote: >> You can always use a counter if you don't like our fancy for-each loops; >> >> foolist = [1,24,24,234,23,423,4] >> for i in xrange(len(foolist)): >> print foolist[i] > > http://www.seas.upenn.edu/~lignos/py_antipatterns.html > > The first one on the list of anti-patterns is doing exactly this. > Just don't. Ewww. Inefficient, ugly, and harder to read. > > Part of learning to write in Python is, well, learning to write > *Python*, not {C,C++,Java,PHP}-in-Python. > > -tkc > Maybe my mind is rather more warped than I thought it was, but my first impression was that foolist was a play on foolish. I also like the anti-pattern on the link namely:- for (index, value) in enumerate(alist): print index, value Fancy wasting time, money and effort typing those unnecessary round brackets. -- Cheers. Mark Lawrence. From tyler at tysdomain.com Sun Sep 23 21:32:57 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sun, 23 Sep 2012 19:32:57 -0600 Subject: keeping information about players around Message-ID: <505FB849.2080201@tysdomain.com> ytHello all: I've asked for a couple code reviews lately on a mud I've been working on, to kind of help me with ideas and a better design. I have yet another design question. In my mud, zones are basically objects that manage a collection of rooms; For example, a town would be it's own zone. It holds information like maxRooms, the list of rooms as well as some other data like player owners and access flags. The access flags basically is a list holding the uid of a player, as well as a bitarray of permissions on that zone. For example, a player might have the ability to edit a zone, but not create rooms. So I have a couple of questions based on this: First, how viable would it be to keep a sort of player database around with stats and that? It could contain the player's level, as well as other information like their access (player, admin, builder etc), and then when someone does a whois on the player I don't have to load that player up just to get data about them. How would I keep the information updated? When I delete a player, I could just delete the entry from the database by uid. Second, would it be viable to have both the name and the uid stored in the dictionary? Then I could look up by either of those? Also, I have a couple more general-purpose questions relating to the mud. When I load a zone, a list of rooms get stored on the zone, as well as world. I thought it might make sense to store references to objects located somewhere else but also on the world in WeakValueDictionaries to save memory. It prevents them from being kept around (and thus having to be deleted from the world when they lose their life), but also (I hope) will save memory. Is a weakref going to be less expensive than a full reference? Second, I want to set up scripting so that you can script events for rooms and npcs. For example, I plan to make some type of event system, so that each type of object gets their own events. For example, when a player walks into a room, they could trigger some sort of trap that would poison them. This leads to a question though: I can store scripting on objects or in separate files, but how is that generally associated and executed? Finally, I just want to make sure I'm doing things right. When I store data, I just pickle it all, then load it back up again. My world object has an attribute defined on it called picklevars, which is basically a list of variables to pickle, and my __getstate__ just returns a dictionary of those. All other objects are left "as-is" for now. Zones, (the entire zone and all it's rooms) get pickled, as well as players and then the world object for persistence. Is this the suggested way of doing things? I'll also pickle the HelpManager object, which will basically contain a list of helpfiles that can be accessed, along with their contents. Thanks, and appologies for all the questions. -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From jianbao.tao at gmail.com Sun Sep 23 21:39:42 2012 From: jianbao.tao at gmail.com (JBT) Date: Sun, 23 Sep 2012 18:39:42 -0700 (PDT) Subject: Pass numeric arrays from C extensions to Python Message-ID: <05993015-7be1-4424-b062-1755f59f3142@googlegroups.com> Hi, I am looking for a way to pass numeric arrays, such as *float a[100]; double b[200];*, from C extension codes to python. The use case of this problem is that you have data stored in a particular format, NASA common data format (CDF) in my case, and there exists an official C library to read/create/edit such data, and you want to do data analysis in python. The problem comes down to how to feed the data into python. I did some googling, but so far no luck. Can anyone help me? Thank you very much. Cheers, JBT From rosuav at gmail.com Sun Sep 23 21:52:22 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Sep 2012 11:52:22 +1000 Subject: List Problem In-Reply-To: <505FAFCF.6030502@tysdomain.com> References: <5126348a-8e87-493d-975c-d6273e59784c@googlegroups.com> <505FAFCF.6030502@tysdomain.com> Message-ID: On Mon, Sep 24, 2012 at 10:56 AM, Littlefield, Tyler wrote: > I've not been following this thread fully, but why not just use x=list(y) to > copy the list? > The issue is that when you assign i=[1,2,3] and then j = i, j is just a > reference to i, which is why you change either and the other changes. The problem is with lists as elements of that list, so the key is deepcopy. ChrisA From oscar.j.benjamin at gmail.com Sun Sep 23 22:11:08 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 24 Sep 2012 03:11:08 +0100 Subject: Pass numeric arrays from C extensions to Python In-Reply-To: <05993015-7be1-4424-b062-1755f59f3142@googlegroups.com> References: <05993015-7be1-4424-b062-1755f59f3142@googlegroups.com> Message-ID: On 24 September 2012 02:39, JBT wrote: > Hi, > > I am looking for a way to pass numeric arrays, such as *float a[100]; > double b[200];*, from C extension codes to python. The use case of this > problem is that you have data stored in a particular format, NASA common > data format (CDF) in my case, and there exists an official C library to > read/create/edit such data, and you want to do data analysis in python. The > problem comes down to how to feed the data into python. > You probably want to wrap the c arrays in numpy.ndarray objects that can then be accessed manipulated from Python. Numpy has a function that (I think) does what you want called PyArray_SimpleNewFromData: http://docs.scipy.org/doc/numpy/reference/c-api.array.html#PyArray_SimpleNewFromData I recommend using Cython to create any extension modules that interact with C libraries. In Cython you can: 1) Use the above function to create a numpy array. 2) Manipulate c-pointers directly to extract their data and insert it into a standard Python container. 3) Write a simple extension type to wrap the pointer into an array type that is accessible from Python. In any case it seems that someone has already made a Python library for accessing CDF data, called pycdf (I have no experience of using this library): http://spacepy.lanl.gov/doc/pycdf.html Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun Sep 23 22:20:34 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Sep 2012 02:20:34 GMT Subject: Java singletonMap in Python References: Message-ID: <505fc372$0$1612$c3e8da3$76491128@news.astraweb.com> On Mon, 24 Sep 2012 00:14:23 +0100, Mark Lawrence wrote: > Purely for fun I've been porting some code to Python and came across the > singletonMap[1]. I'm aware that there are loads of recipes on the web > for both singletons e.g.[2] and immutable dictionaries e.g.[3]. I was > wondering how to combine any of the recipes to produce the best > implementation, where to me best means cleanest and hence most > maintainable. I then managed to muddy the waters for myself by > recalling the Alex Martelli Borg pattern[4]. Possibly or even probably > the latter is irrelevant, but I'm still curious to know how you'd code > this beast. > > First prize for the best solution is a night out with me, no guesses > what the second prize is :) > > [1]http://docs.oracle.com/javase/1.4.2/docs/api/java/util/ Collections.html Copied from that page: "static Map singletonMap(Object key, Object value) Returns an immutable map, mapping only the specified key to the specified value." I don't see the point of this. It takes a single key, with a single value, and is immutable so you can't change it or add new keys. What's the point? Why bother storing the key:value pair in a data structure, then look up the same data structure to get the same value every time? # Pseudo-code d = singletonMap(key, calculate(key)) # later: value = d[key] # there's only one key this could be process(value) Why not just store the value, instead of key, value and mapping? value = calculate(key) # later process(value) -- Steven From tjreedy at udel.edu Sun Sep 23 22:42:35 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 23 Sep 2012 22:42:35 -0400 Subject: Invalid identifier claimed to be valid by docs (methinks) In-Reply-To: References: Message-ID: On 9/23/2012 6:57 PM, Ian Kelly wrote: > On Sun, Sep 23, 2012 at 4:24 PM, Joshua Landau > wrote: >> The docs describe identifiers to have this grammar: >> >> identifier ::= xid_start xid_continue* >> id_start ::= > Nl, the underscore, and characters with the Other_ID_Start property> >> id_continue ::= > categories Mn, Mc, Nd, Pc and others with the Other_ID_Continue property> >> xid_start ::= > "id_start xid_continue*"> xid_start is a subset of id_start >> xid_continue ::= > in "id_continue*"> xid_continue is a subset of id_continue. >> So I would assume that >> exec("a{} = None".format(char)) >> would be valid if >> unicodedata.normalize("NFKC", char) == "1" Read more carefully the definition of xid_continue. The un-normalized character must also be in id_continue. >> as >> exec("a1 = None") >> is valid. >> >> BUT "a? = None" is not valid*. >>> ud.category("\u00b9") 'No' Category No is *not* in id_continue, and therefore not in xid_continue. > exec("x\u00b9 = None") # U+00B9 is superscript 1 > > On the other hand, this does work: > > exec("x\u2071 = None") # U+2071 is superscript i > > So it seems to be only an issue with superscript and subscript digits. > Looks like a compiler bug to me. The problem, if there were one, would be in the tokenizer that finds identifiers. However, >>> exec("x\u00b9 = None") ... x? = None ^ SyntaxError: invalid character in identifier this is correct. -- Terry Jan Reedy From wuwei23 at gmail.com Sun Sep 23 22:47:24 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 23 Sep 2012 19:47:24 -0700 (PDT) Subject: cant install livewires References: Message-ID: <252836ec-5243-437b-b4aa-10c71ddc057a@sd5g2000pbc.googlegroups.com> On Sep 23, 10:05?pm, james.kenn... at abingdon.org.uk wrote: > i cant install livewires and their help about making a directory is useless to me as i dont know how > btw im using windows 7 > REALLY DESPERATE :) You're skimming and not reading the README correctly. You are *only* instructed to make a directory if you're using a version of Python before 1.6. I strongly suspect this not the case, so you can instead follow the "Python 1.6 and above" instructions. You will need to know the following: 1. How to unzip a zip file. 2. How to double-click on the "setup.py" file. The instructions even explicitly mention that they've been simplified to remove the need for Windows users to have to do something as esoteric as open a command prompt. Read the instructions. Carefully. From tjreedy at udel.edu Sun Sep 23 22:48:11 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 23 Sep 2012 22:48:11 -0400 Subject: Pass numeric arrays from C extensions to Python In-Reply-To: <05993015-7be1-4424-b062-1755f59f3142@googlegroups.com> References: <05993015-7be1-4424-b062-1755f59f3142@googlegroups.com> Message-ID: On 9/23/2012 9:39 PM, JBT wrote: > Hi, > > I am looking for a way to pass numeric arrays, such as *float a[100]; > double b[200];*, from C extension codes to python. The use case of > this problem is that you have data stored in a particular format, > NASA common data format (CDF) in my case, and there exists an > official C library to read/create/edit such data, and you want to do > data analysis in python. The problem comes down to how to feed the > data into python. > > I did some googling, but so far no luck. Can anyone help me? Thank > you very much. I would look into numpy and scipy. -- Terry Jan Reedy From wuwei23 at gmail.com Sun Sep 23 22:53:07 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 23 Sep 2012 19:53:07 -0700 (PDT) Subject: One of my joomla webpages has been hacked. Please help. References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> Message-ID: <1aaa2aab-985b-49a5-a048-1cba39b39840@rj6g2000pbc.googlegroups.com> On Sep 22, 4:45?am, ????? ?????? wrote: > One webpage of mine,http://www.varsa.gr/has been *hacked* 15 mins ago. Here is your problem: > joomla If you're looking for a more secure solution: http://plone.org/products/plone/security/overview From wuwei23 at gmail.com Sun Sep 23 23:07:57 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 23 Sep 2012 20:07:57 -0700 (PDT) Subject: technologies synergistic with Python References: Message-ID: On Sep 22, 8:16?am, Ethan Furman wrote: > What is the consensus... okay, okay -- what are some wide ranging > opinions on technologies that I should know if my dream job is one that > consists mostly of Python, and might allow telecommuting? A "technology" that I consider *highly* synergistic with Python but that seems to have permanent outsider status is Zope. (It has a reputation for being baroque and/or over-engineered, but to me it just seems to reflect almost 20 years of web development experience. I've also become a big fan of its component architecture approach.) CoffeeScript is a neat little language that compiles to JavaScript. It borrows liberally from Python & Ruby, so you can write this: foods = ['broccoli', 'spinach', 'chocolate'] eat food for food in foods when food isnt 'chocolate' Instead of this: foods = ['broccoli', 'spinach', 'chocolate']; for (_k = 0, _len2 = foods.length; _k < _len2; _k++) { food = foods[_k]; if (food !== 'chocolate') { eat(food); } } Chris Angelico nailed it, though: "Expand out in any direction at all, really. Anything'll make you more employable." My only extension would be to pick the directions you find you enjoy rather than the ones you think will make you more employable. I've found it's more often than not the obscure experience I have that makes me desirable to employers rather than the common ground they can find anywhere. From wuwei23 at gmail.com Sun Sep 23 23:46:23 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 23 Sep 2012 20:46:23 -0700 (PDT) Subject: A little morning puzzle References: Message-ID: On Sep 23, 1:44?pm, Dwight Hutto wrote: > Just because you can use a function, and make it look easier, doesn't > mean the function you used had less code than mine, so if you look at > the whole of what you used to make it simpler, mine was on point. Word of advice: when we use "simpler" around these parts we're referring to cognitive burden on the end developer and not the actual amount of interpreter/library code utilised to solve the problem. Ergo: 'enumerate()' is the correct suggestion over manually maintaining your own index, despite it ostensibly being "more" code due to its implementation. From wuwei23 at gmail.com Sun Sep 23 23:48:18 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 23 Sep 2012 20:48:18 -0700 (PDT) Subject: request for another code review References: Message-ID: On Sep 23, 6:14?am, "Littlefield, Tyler" wrote: > I've gotten a bit farther into my python mud, and wanted to request > another code review for style and the like. Are you familiar with codereview.stackexchange.com ? (This isn't to dissuade you from posting such requests here, just to help increase the chance of eyeballs on your code.) From wuwei23 at gmail.com Sun Sep 23 23:59:37 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 23 Sep 2012 20:59:37 -0700 (PDT) Subject: Does python have built command for package skeleton creation? References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> Message-ID: <26bebff3-c739-419a-86fb-a957f7a78701@t2g2000pbt.googlegroups.com> On Sep 21, 10:14?pm, xliiv wrote: > On Friday, September 21, 2012 1:08:23 PM UTC+2, Tarek Ziad? wrote: > > Python Paste is probably what you are looking for - see > It's a nice beast but: > - it's not built in. Should it be? I think it should. There needs to be a distinction at some point between Python as runtime and development environments. If you assume that there are more users of Python code than developers, then cluttering it with more developer-only tools is a waste of resources for those end users. Also: developers are fussy about their environments. One person's vi is another person's emacs. We keep various package skeletons in our git repository, and that works well for us, so adding Paste to Python is just more useless kruft from our perspective. And: easy_install/pip install paste isn't exactly crippling to type. > - about readme and manifest.in: > "You could add to your template a file called readme.rst" > i dont want to add, i want it already added :) If you'd just did as they asked, you'd already have this issue resolved by now. If you're waiting for the standard library to scratch your itch for you, you're going to be waiting for a long, _long_ time. From tjreedy at udel.edu Mon Sep 24 00:28:43 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 24 Sep 2012 00:28:43 -0400 Subject: Does python have built command for package skeleton creation? In-Reply-To: <26bebff3-c739-419a-86fb-a957f7a78701@t2g2000pbt.googlegroups.com> References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> <26bebff3-c739-419a-86fb-a957f7a78701@t2g2000pbt.googlegroups.com> Message-ID: On 9/23/2012 11:59 PM, alex23 wrote: > On Sep 21, 10:14 pm, xliiv wrote: >> On Friday, September 21, 2012 1:08:23 PM UTC+2, Tarek Ziad? wrote: >>> Python Paste is probably what you are looking for - see > >> It's a nice beast but: >> - it's not built in. Should it be? I think it should. > > There needs to be a distinction at some point between Python as > runtime and development environments. If you assume that there are > more users of Python code than developers, then cluttering it with > more developer-only tools is a waste of resources for those end users. > > Also: developers are fussy about their environments. One person's vi > is another person's emacs. We keep various package skeletons in our > git repository, and that works well for us, so adding Paste to Python > is just more useless kruft from our perspective. > > And: easy_install/pip install paste isn't exactly crippling to type. > >> - about readme and manifest.in: >> "You could add to your template a file called readme.rst" >> i dont want to add, i want it already added :) > > If you'd just did as they asked, you'd already have this issue > resolved by now. > > If you're waiting for the standard library to scratch your itch for > you, you're going to be waiting for a long, _long_ time. Batteries are batteries, not flashlights, phone, radios, toys, clickers, etc. -- Terry Jan Reedy From ian.g.kelly at gmail.com Mon Sep 24 00:51:53 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 23 Sep 2012 22:51:53 -0600 Subject: A little morning puzzle In-Reply-To: References: Message-ID: On Sat, Sep 22, 2012 at 9:44 PM, Dwight Hutto wrote: > Why don't you all look at the code(python and C), and tell me how much > code it took to write the functions the other's examples made use of > to complete the task. > > Just because you can use a function, and make it look easier, doesn't > mean the function you used had less code than mine, so if you look at > the whole of what you used to make it simpler, mine was on point. I understood the sarcastic comments (the first one, at least) to be referring to your solution as bad not due to complexity (I actually thought it was quite simple), but because it does not solve the problem as stated. The problem posed by the OP was to find a set of common keys that are associated with the same values in each dict. Your solution takes only one predetermined key-value pair and counts how many times it occurs in the dicts, which isn't even close to what was requested. With your comment of "Might be better ones, though", I actually thought that you were aware of this and were being intentionally satirical. From wuwei23 at gmail.com Mon Sep 24 01:00:01 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 23 Sep 2012 22:00:01 -0700 (PDT) Subject: Does python have built command for package skeleton creation? References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> <26bebff3-c739-419a-86fb-a957f7a78701@t2g2000pbt.googlegroups.com> Message-ID: On Sep 24, 2:29?pm, Terry Reedy wrote: > Batteries are batteries, not flashlights, phone, radios, toys, clickers, > etc. I decided not to mention "venv" as it undermines my rant a little :) From rosuav at gmail.com Mon Sep 24 01:14:16 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Sep 2012 15:14:16 +1000 Subject: Seome kind of unblocking input In-Reply-To: References: <0be9b4c2-b661-4709-ba8f-40a6f78ad634@googlegroups.com> <593f9c45-9150-4d37-9c9c-e3cd66ed2d8e@googlegroups.com> Message-ID: On Mon, Sep 24, 2012 at 3:50 AM, Dennis Lee Bieber wrote: > On Sun, 23 Sep 2012 18:13:57 +0100, Mark Lawrence > declaimed the following in > gmane.comp.python.general: > >> On 23/09/2012 16:49, Ramchandra Apte wrote: > >> > You can clear the buffer by calling file.flush() >> > >> >> Shock, horror, probe, well I never did. I'm sure that everyone is >> updating their Xmas and birthday card lists to ensure that you're not >> missed out having furnished a piece of information that doubtless not >> one other person on this group knew. > > It probably wouldn't have helped either... The OP was looking for, > as I recall, some means by which a pending input would not block other > output on a console... So what use is flushing a buffer? It all depends on *why* pending input appears to be blocking other output. I say "appears to be" because buffered output can indeed appear to be blocked, but so can other things. Flushing output is an easy thing to try. If it fails, back to square one, but with more knowledge. ChrisA From maniandram01 at gmail.com Mon Sep 24 01:31:50 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sun, 23 Sep 2012 22:31:50 -0700 (PDT) Subject: Seome kind of unblocking input In-Reply-To: References: <0be9b4c2-b661-4709-ba8f-40a6f78ad634@googlegroups.com> <593f9c45-9150-4d37-9c9c-e3cd66ed2d8e@googlegroups.com> Message-ID: <16a8f7bb-a392-48e1-94c5-4fd678ebf63f@googlegroups.com> On Sunday, 23 September 2012 23:20:37 UTC+5:30, Dennis Lee Bieber wrote: > On Sun, 23 Sep 2012 18:13:57 +0100, Mark Lawrence > > declaimed the following in > > gmane.comp.python.general: > > > > > On 23/09/2012 16:49, Ramchandra Apte wrote: > > > > > > You can clear the buffer by calling file.flush() > > > > > > > > > > Shock, horror, probe, well I never did. I'm sure that everyone is > > > updating their Xmas and birthday card lists to ensure that you're not > > > missed out having furnished a piece of information that doubtless not > > > one other person on this group knew. > > > > It probably wouldn't have helped either... The OP was looking for, > > as I recall, some means by which a pending input would not block other > > output on a console... So what use is flushing a buffer? > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ Okay okay! My message was out-of-context. Anyways, nobody in my age group knows that you can clear the buffer of a file in Python by calling file.flush(). From maniandram01 at gmail.com Mon Sep 24 01:31:50 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sun, 23 Sep 2012 22:31:50 -0700 (PDT) Subject: Seome kind of unblocking input In-Reply-To: References: <0be9b4c2-b661-4709-ba8f-40a6f78ad634@googlegroups.com> <593f9c45-9150-4d37-9c9c-e3cd66ed2d8e@googlegroups.com> Message-ID: <16a8f7bb-a392-48e1-94c5-4fd678ebf63f@googlegroups.com> On Sunday, 23 September 2012 23:20:37 UTC+5:30, Dennis Lee Bieber wrote: > On Sun, 23 Sep 2012 18:13:57 +0100, Mark Lawrence > > declaimed the following in > > gmane.comp.python.general: > > > > > On 23/09/2012 16:49, Ramchandra Apte wrote: > > > > > > You can clear the buffer by calling file.flush() > > > > > > > > > > Shock, horror, probe, well I never did. I'm sure that everyone is > > > updating their Xmas and birthday card lists to ensure that you're not > > > missed out having furnished a piece of information that doubtless not > > > one other person on this group knew. > > > > It probably wouldn't have helped either... The OP was looking for, > > as I recall, some means by which a pending input would not block other > > output on a console... So what use is flushing a buffer? > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ Okay okay! My message was out-of-context. Anyways, nobody in my age group knows that you can clear the buffer of a file in Python by calling file.flush(). From maniandram01 at gmail.com Mon Sep 24 01:33:07 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sun, 23 Sep 2012 22:33:07 -0700 (PDT) Subject: Does python have built command for package skeleton creation? In-Reply-To: References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> <26bebff3-c739-419a-86fb-a957f7a78701@t2g2000pbt.googlegroups.com> Message-ID: <5cf91ed7-76af-48bb-8c71-ad6cd3e73d4d@googlegroups.com> On Monday, 24 September 2012 09:59:12 UTC+5:30, Terry Reedy wrote: > On 9/23/2012 11:59 PM, alex23 wrote: > > > On Sep 21, 10:14 pm, xliiv wrote: > > >> On Friday, September 21, 2012 1:08:23 PM UTC+2, Tarek Ziad? wrote: > > >>> Python Paste is probably what you are looking for - see > > > > > >> It's a nice beast but: > > >> - it's not built in. Should it be? I think it should. > > > > > > There needs to be a distinction at some point between Python as > > > runtime and development environments. If you assume that there are > > > more users of Python code than developers, then cluttering it with > > > more developer-only tools is a waste of resources for those end users. > > > > > > Also: developers are fussy about their environments. One person's vi > > > is another person's emacs. We keep various package skeletons in our > > > git repository, and that works well for us, so adding Paste to Python > > > is just more useless kruft from our perspective. > > > > > > And: easy_install/pip install paste isn't exactly crippling to type. > > > > > >> - about readme and manifest.in: > > >> "You could add to your template a file called readme.rst" > > >> i dont want to add, i want it already added :) > > > > > > If you'd just did as they asked, you'd already have this issue > > > resolved by now. > > > > > > If you're waiting for the standard library to scratch your itch for > > > you, you're going to be waiting for a long, _long_ time. > > > > Batteries are batteries, not flashlights, phone, radios, toys, clickers, > > etc. > > > > -- > > Terry Jan Reedy Do remember to include laptops. From maniandram01 at gmail.com Mon Sep 24 01:33:07 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sun, 23 Sep 2012 22:33:07 -0700 (PDT) Subject: Does python have built command for package skeleton creation? In-Reply-To: References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> <26bebff3-c739-419a-86fb-a957f7a78701@t2g2000pbt.googlegroups.com> Message-ID: <5cf91ed7-76af-48bb-8c71-ad6cd3e73d4d@googlegroups.com> On Monday, 24 September 2012 09:59:12 UTC+5:30, Terry Reedy wrote: > On 9/23/2012 11:59 PM, alex23 wrote: > > > On Sep 21, 10:14 pm, xliiv wrote: > > >> On Friday, September 21, 2012 1:08:23 PM UTC+2, Tarek Ziad? wrote: > > >>> Python Paste is probably what you are looking for - see > > > > > >> It's a nice beast but: > > >> - it's not built in. Should it be? I think it should. > > > > > > There needs to be a distinction at some point between Python as > > > runtime and development environments. If you assume that there are > > > more users of Python code than developers, then cluttering it with > > > more developer-only tools is a waste of resources for those end users. > > > > > > Also: developers are fussy about their environments. One person's vi > > > is another person's emacs. We keep various package skeletons in our > > > git repository, and that works well for us, so adding Paste to Python > > > is just more useless kruft from our perspective. > > > > > > And: easy_install/pip install paste isn't exactly crippling to type. > > > > > >> - about readme and manifest.in: > > >> "You could add to your template a file called readme.rst" > > >> i dont want to add, i want it already added :) > > > > > > If you'd just did as they asked, you'd already have this issue > > > resolved by now. > > > > > > If you're waiting for the standard library to scratch your itch for > > > you, you're going to be waiting for a long, _long_ time. > > > > Batteries are batteries, not flashlights, phone, radios, toys, clickers, > > etc. > > > > -- > > Terry Jan Reedy Do remember to include laptops. From mcepl at redhat.com Mon Sep 24 02:06:02 2012 From: mcepl at redhat.com (Matej Cepl) Date: Mon, 24 Sep 2012 08:06:02 +0200 Subject: Editing Inkscape SVG files with Python? In-Reply-To: <505f92f7$0$1612$c3e8da3$76491128@news.astraweb.com> References: <505f92f7$0$1612$c3e8da3$76491128@news.astraweb.com> Message-ID: On 24/09/12 00:53, Steven D'Aprano wrote: > Googling for "python inkscape" comes up with too many hits for Inkscape's > plugin system to be much help to me. Aside from suggesting lxml, I would ask "So why not to follow the stream and create Inkscape plugin"? I have in similar situation created a plugin (https://gitorious.org/inkscape-ungroup-deep/) and I have to say it wasn't that difficult and results are pretty satisfactory. Mat?j From georg at python.org Mon Sep 24 02:18:47 2012 From: georg at python.org (Georg Brandl) Date: Mon, 24 Sep 2012 08:18:47 +0200 Subject: [RELEASED] Python 3.3.0 release candidate 3 Message-ID: <505FFB47.30901@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm delighted to announce the third release candidate of Python 3.3.0. This is a preview release, and its use is not recommended in production settings. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. Major new features and changes in the 3.3 release series are: * PEP 380, syntax for delegating to a subgenerator ("yield from") * PEP 393, flexible string representation (doing away with the distinction between "wide" and "narrow" Unicode builds) * A C implementation of the "decimal" module, with up to 80x speedup for decimal-heavy applications * The import system (__import__) now based on importlib by default * The new "lzma" module with LZMA/XZ support * PEP 397, a Python launcher for Windows * PEP 405, virtual environment support in core * PEP 420, namespace package support * PEP 3151, reworking the OS and IO exception hierarchy * PEP 3155, qualified name for classes and functions * PEP 409, suppressing exception context * PEP 414, explicit Unicode literals to help with porting * PEP 418, extended platform-independent clocks in the "time" module * PEP 412, a new key-sharing dictionary implementation that significantly saves memory for object-oriented code * PEP 362, the function-signature object * The new "faulthandler" module that helps diagnosing crashes * The new "unittest.mock" module * The new "ipaddress" module * The "sys.implementation" attribute * A policy framework for the email package, with a provisional (see PEP 411) policy that adds much improved unicode support for email header parsing * A "collections.ChainMap" class for linking mappings to a single unit * Wrappers for many more POSIX functions in the "os" and "signal" modules, as well as other useful functions such as "sendfile()" * Hash randomization, introduced in earlier bugfix releases, is now switched on by default In total, almost 500 API items are new or improved in Python 3.3. For a more extensive list of changes in 3.3.0, see http://docs.python.org/3.3/whatsnew/3.3.html To download Python 3.3.0 visit: http://www.python.org/download/releases/3.3.0/ Please consider trying Python 3.3.0 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAlBf+0cACgkQN9GcIYhpnLBqfgCglbN63XUr2m4Ya4ff8Hza1Axl SgMAniQZRJi8uYfeqltf5/G4QV/+SdWT =KXTo -----END PGP SIGNATURE----- From andriy.kornatskyy at live.com Mon Sep 24 02:34:48 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Mon, 24 Sep 2012 09:34:48 +0300 Subject: Fastest web framework In-Reply-To: References: , , , Message-ID: David, Thank you for your comments. Please see my response inline to your questions. > Well, lets break down timing something in a more scientific method > approach through questioning. > > What's your processor speed? Please see environment specification at the end of post. Here is a copy just in case: Client: Intel Core 2 Quad CPU Q6600 @ 2.40GHz ? 4 Server: Intel Xeon CPU X3430 @ 2.40GHz x 4 LAN 1 Gb > What is the constant temperature of the internals of your system? The server environment temperature is constant: 18C / 64F > What OS, and version? Server: Debian Testing,?Kernel 3.2.0-3-amd64,?Python 2.7.3,?uwsgi 1.2.6 Client: Debian Testing,?Kernel 3.2.0-3-686-pae > What other processes are running? There were used standalone server and client, with minimal to zero CPU/network activities on other processes (both, client and server, were dedicated to test purpose). Thanks. Andriy Kornatskyy ---------------------------------------- > Date: Sun, 3 Sep 012 6::6::5 -400< > Subject: Re: Fastest web framework > From: dwightdhutto at gmail.com > To: andriy.kornatskyy at live.com > CC: python-list at python.org > >> Hope I understood you correctly. >> > > Well, lets break down timing something in a more scientific method > approach through questioning. > > What's your processor speed? > > What is the constant temperature of the internals of your system? > > What OS, and version? > > What other processes are running? > > > There's a scientific method to what you're benchmarking. There have to > be constants, and variables to benchmark with. > > These will of course vary with other methods of approach with the same code. > > > -- > Best Regards, > David Hutto > CEO: http://www.hitwebdevelopment.com From no.email at nospam.invalid Mon Sep 24 02:37:53 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 23 Sep 2012 23:37:53 -0700 Subject: [RELEASED] Python 3.3.0 release candidate 3 References: Message-ID: <7xsja8ncxq.fsf@ruckus.brouhaha.com> Georg Brandl writes: > Python 3.3 includes a range of improvements of the 3.x series, as well > as easier porting between 2.x and 3.x. Major new features and changes > in the 3.3 release series are: [good stuff snipped] This is cool, and Python 3 is finally starting to show some real advantages over Python 2. I suppose I'll have to start using it. I've sort of pointedly resisted it up til now. Thanks for the good work, to yourself and to everyone else involved. From maniandram01 at gmail.com Mon Sep 24 02:44:26 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sun, 23 Sep 2012 23:44:26 -0700 (PDT) Subject: [RELEASED] Python 3.3.0 release candidate 3 In-Reply-To: <7xsja8ncxq.fsf@ruckus.brouhaha.com> References: <7xsja8ncxq.fsf@ruckus.brouhaha.com> Message-ID: <03dce8d8-0ce7-4ab8-a106-c7b502b402bb@googlegroups.com> On Monday, 24 September 2012 12:07:53 UTC+5:30, Paul Rubin wrote: > Georg Brandl writes: > > > Python 3.3 includes a range of improvements of the 3.x series, as well > > > as easier porting between 2.x and 3.x. Major new features and changes > > > in the 3.3 release series are: [good stuff snipped] > > > > This is cool, and Python 3 is finally starting to show some real > > advantages over Python 2. I suppose I'll have to start using it. I've > > sort of pointedly resisted it up til now. Thanks for the good work, to > > yourself and to everyone else involved. Agree. I wish I knew all the secrets of Python such as in PEP 342 . Guess I'll have to read the tutorial and the PEPs... From andriy.kornatskyy at live.com Mon Sep 24 02:53:58 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Mon, 24 Sep 2012 09:53:58 +0300 Subject: Fastest web framework In-Reply-To: References: , Message-ID: Alex, > Are you on Python Planet? If not, you might want to syndicate your blog > there to reach more of the Python web framework crowd. Thank you for your advise. I will send a request for addition to Python Planet. http://feeds.feedburner.com/MindReference Thanks. Andriy ---------------------------------------- > To: python-list at python.org > From: aclark at aclark.net > Subject: Re: Fastest web framework > Date: Sun, 23 Sep 2012 17:25:20 -0400 > > On 2012-09-23 09:19:16 +0000, Andriy Kornatskyy said: > > > > > I have run recently a benchmark of a trivial 'hello world' application > > for various python web frameworks (bottle, django, flask, pyramid, > > web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... > > you might find it interesting: > > > > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > > > > Comments or suggestions are welcome. > > > Are you on Python Planet? If not, you might want to syndicate your blog > there to reach more of the Python web framework crowd. > > > > > > Thanks. > > > > Andriy Kornatskyy > > > > > -- > Alex Clark ? http://pythonpackages.com > > > -- > http://mail.python.org/mailman/listinfo/python-list From alec.taylor6 at gmail.com Mon Sep 24 03:36:25 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Mon, 24 Sep 2012 17:36:25 +1000 Subject: Fastest web framework In-Reply-To: References: Message-ID: Can you throw in web2py? Thanks On Sun, Sep 23, 2012 at 7:19 PM, Andriy Kornatskyy < andriy.kornatskyy at live.com> wrote: > > I have run recently a benchmark of a trivial 'hello world' application for > various python web frameworks (bottle, django, flask, pyramid, web.py, > wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might > find it interesting: > > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > > Comments or suggestions are welcome. > > Thanks. > > Andriy Kornatskyy > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From huhai103 at gmail.com Mon Sep 24 04:00:31 2012 From: huhai103 at gmail.com (wholesale watches) Date: Mon, 24 Sep 2012 01:00:31 -0700 (PDT) Subject: =?UTF-8?Q?cheap_authentic_jordan_shoes=EF=BC=88www=2Enike=2Dblack=2Ecom=EF=BC=89?= Message-ID: wholesale jordan shoes ?www.nike-black.com? cheap jordan shoes for sale?www.nike-black.com? cheap authentic jordan shoes?www.nike-black.com? cheap jordan shoes online?www.nike-black.com? cheap jordan shoes paypal?www.nike-black.com? cheap jordan shoes for kids?www.nike-black.com? cheap jordan shoes free shipping?www.nike-black.com? cheap jordan nike shoes?www.nike-black.com? cheap authentic air jordan?www.nike-black.com? cheap air jordan shoes?www.nike-black.com? cheap jordans?www.nike-black.com? cheap air jordan 2011?www.nike-black.com? cheap air jordan clothes?www.nike-black.com? cheap nike air jordan?www.nike-black.com? cheap air jordan fusion?www.nike-black.com? cheap air jordan heels?www.nike-black.com? cheap jordan shoes online?www.nike-black.com? cheap jordan shoes?www.nike-black.com? cheap jordan shoes for sale?www.nike-black.com? cheap air jordan?www.nike-black.com? cheap jordan sneakers?www.nike-black.com? cheap jordan nike shoes?www.nike-black.com? cheap jordan 2011?www.nike-black.com? cheap jordan website?www.nike-black.com? wholesale air jordan shoes?www.nike-black.com? cheap wholesale air jordan shoes?www.nike-black.com? cheap air jordan shoes for sale?www.nike-black.com? cheap jordan shoes?www.nike-black.com? cheap nike air jordan?www.nike-black.com? cheap air jordan shoes free shipping?www.nike-black.com? cheap air jordan shoes for men?www.nike-black.com? cheap air jordan basketball shoes?www.nike-black.com? website: http://www.nike-black.com From andriy.kornatskyy at live.com Mon Sep 24 04:42:47 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Mon, 24 Sep 2012 11:42:47 +0300 Subject: Fastest web framework In-Reply-To: References: , Message-ID: Accepted. ________________________________ > Date: Mon, 24 Sep 2012 17:36:25 +1000 > Subject: Re: Fastest web framework > From: alec.taylor6 at gmail.com > To: andriy.kornatskyy at live.com > CC: python-list at python.org > > Can you throw in web2py? > > Thanks > > On Sun, Sep 23, 2012 at 7:19 PM, Andriy Kornatskyy > > wrote: > > I have run recently a benchmark of a trivial 'hello world' application > for various python web frameworks (bottle, django, flask, pyramid, > web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... > you might find it interesting: > > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > > Comments or suggestions are welcome. > > Thanks. > > Andriy Kornatskyy > > -- > http://mail.python.org/mailman/listinfo/python-list > From joshua.landau.ws at gmail.com Mon Sep 24 05:53:43 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Mon, 24 Sep 2012 10:53:43 +0100 Subject: Invalid identifier claimed to be valid by docs (methinks) In-Reply-To: References: Message-ID: On 24 September 2012 03:42, Terry Reedy wrote: > On 9/23/2012 6:57 PM, Ian Kelly wrote: > >> On Sun, Sep 23, 2012 at 4:24 PM, Joshua Landau >> wrote: >> >>> The docs describe identifiers to have this grammar: >>> >>> identifier ::= xid_start xid_continue* >>> id_start ::= >> Lo, >>> Nl, the underscore, and characters with the Other_ID_Start property> >>> id_continue ::= >> categories Mn, Mc, Nd, Pc and others with the Other_ID_Continue property> >>> xid_start ::= >> is in >>> "id_start xid_continue*"> >>> >> > xid_start is a subset of id_start > > > xid_continue ::= >> normalization is >>> in "id_continue*"> >>> >> > xid_continue is a subset of id_continue. > > > So I would assume that >>> exec("a{} = None".format(char)) >>> would be valid if >>> unicodedata.normalize("NFKC", char) == "1" >>> >> > Read more carefully the definition of xid_continue. The un-normalized > character must also be in id_continue. > Correct. Thank you for your time. > as >>> exec("a1 = None") >>> is valid. >>> >>> BUT "a? = None" is not valid*. >>> >> > >>> ud.category("\u00b9") > 'No' > > Category No is *not* in id_continue, and therefore not in xid_continue. > > > exec("x\u00b9 = None") # U+00B9 is superscript 1 >> >> On the other hand, this does work: >> >> exec("x\u2071 = None") # U+2071 is superscript i >> >> So it seems to be only an issue with superscript and subscript digits. >> Looks like a compiler bug to me. >> > > The problem, if there were one, would be in the tokenizer that finds > identifiers. However, > > > >>> exec("x\u00b9 = None") > ... > x? = None > ^ > SyntaxError: invalid character in identifier > > this is correct. Thank you both for helping. The bug is officially closed. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tarek at ziade.org Mon Sep 24 07:50:31 2012 From: tarek at ziade.org (=?UTF-8?B?VGFyZWsgWmlhZMOp?=) Date: Mon, 24 Sep 2012 13:50:31 +0200 Subject: Fastest web framework In-Reply-To: References: Message-ID: <50604907.6060405@ziade.org> On 9/23/12 11:19 AM, Andriy Kornatskyy wrote: > I have run recently a benchmark of a trivial 'hello world' application for various python web frameworks (bottle, django, flask, pyramid, web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find it interesting: > > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > > Comments or suggestions are welcome. > > Thanks. > > Andriy Kornatskyy > I would try this with a web app that does more than 'Hello World' You may argue that you're just trying the server stack, but that's not realistic because you don't really measure how the server behaves with a real app. Have a look at https://github.com/mozilla-services/chaussette/blob/master/chaussette/util.py#L188 (setup_bench and teardow_bench have to be run on startup and tear down of the server) I would be curious to see how things goes then Cheers Tarek From lodeameije at gmail.com Mon Sep 24 08:21:41 2012 From: lodeameije at gmail.com (lodeameije at gmail.com) Date: Mon, 24 Sep 2012 05:21:41 -0700 (PDT) Subject: style-url support for simplekml Message-ID: Hi! I love the simplekml package. I have a lot of files and always use an external file for styles. For the moment, I could not find how to implement a style-url without running over the kml file after generating and changing 'manually'(well, it "is" automated) all styles: i.e.: ..\..\Cada_Styles.kml#B_CaPa instead of #stylesel_459 (when a style was defined...) An idea for the next version or am I looking over something? Kind regards, Lode From ethan at stoneleaf.us Mon Sep 24 09:13:09 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 24 Sep 2012 06:13:09 -0700 Subject: [Python-Dev] [RELEASED] Python 3.3.0 release candidate 3 In-Reply-To: References: <505FFB47.30901@python.org> Message-ID: <50605C65.80202@stoneleaf.us> Mark Lawrence wrote: > On 24/09/2012 07:18, Georg Brandl wrote: [snip impressive list of improvements] > Yes, but apart from all that, what have the python devs ever done for > us? Nothing :) I'll take that kind of nothing any day of the week! ;) ~Ethan~ From invalid at invalid.invalid Mon Sep 24 10:55:37 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 24 Sep 2012 14:55:37 +0000 (UTC) Subject: Pass numeric arrays from C extensions to Python References: <05993015-7be1-4424-b062-1755f59f3142@googlegroups.com> Message-ID: On 2012-09-24, JBT wrote: > I am looking for a way to pass numeric arrays, such as *float a[100]; > double b[200];*, from C extension codes to python. The use case of > this problem is that you have data stored in a particular format, > NASA common data format (CDF) in my case, and there exists an > official C library to read/create/edit such data, and you want to do > data analysis in python. The problem comes down to how to feed the > data into python. In a addition to scipy and scientific python (two different projects), you should probably take a look at the struct module and the ctypes module. -- Grant Edwards grant.b.edwards Yow! Life is a POPULARITY at CONTEST! I'm REFRESHINGLY gmail.com CANDID!! From jeanmichel at sequans.com Mon Sep 24 11:15:22 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 24 Sep 2012 17:15:22 +0200 (CEST) Subject: keeping information about players around In-Reply-To: <505FB849.2080201@tysdomain.com> Message-ID: <1366564286.2609315.1348499722222.JavaMail.root@sequans.com> ----- Original Message ----- > ytHello all: > I've asked for a couple code reviews lately on a mud I've been > working > on, to kind of help me with ideas and a better design. > > I have yet another design question. > In my mud, zones are basically objects that manage a collection of > rooms; For example, a town would be it's own zone. > It holds information like maxRooms, the list of rooms as well as some > other data like player owners and access flags. > The access flags basically is a list holding the uid of a player, as > well as a bitarray of permissions on that zone. For example, a player > might have the ability to edit a zone, but not create rooms. > So I have a couple of questions based on this: > First, how viable would it be to keep a sort of player database > around > with stats and that? > It could contain the player's level, as well as other information > like > their access (player, admin, builder etc), and then when someone does > a > whois on the player I don't have to load that player up just to get > data > about them. How would I keep the information updated? When I delete a > player, I could just delete the entry from the database by uid. > Second, would it be viable to have both the name and the uid stored > in > the dictionary? Then I could look up by either of those? > > Also, I have a couple more general-purpose questions relating to the > mud. > When I load a zone, a list of rooms get stored on the zone, as well > as > world. I thought it might make sense to store references to objects > located somewhere else but also on the world in WeakValueDictionaries > to > save memory. It prevents them from being kept around (and thus having > to > be deleted from the world when they lose their life), but also (I > hope) > will save memory. Is a weakref going to be less expensive than a full > reference? > Second, I want to set up scripting so that you can script events for > rooms and npcs. For example, I plan to make some type of event > system, > so that each type of object gets their own events. For example, when > a > player walks into a room, they could trigger some sort of trap that > would poison them. This leads to a question though: I can store > scripting on objects or in separate files, but how is that generally > associated and executed? > Finally, I just want to make sure I'm doing things right. When I > store > data, I just pickle it all, then load it back up again. My world > object > has an attribute defined on it called picklevars, which is basically > a > list of variables to pickle, and my __getstate__ just returns a > dictionary of those. All other objects are left "as-is" for now. > Zones, > (the entire zone and all it's rooms) get pickled, as well as players > and > then the world object for persistence. Is this the suggested way of > doing things? I'll also pickle the HelpManager object, which will > basically contain a list of helpfiles that can be accessed, along > with > their contents. > Thanks, and appologies for all the questions. > > -- > Take care, > Ty > http://tds-solutions.net > The aspen project: a barebones light-weight mud engine: > http://code.google.com/p/aspenmud > He that will not reason is a bigot; he that cannot reason is a fool; > he that dares not reason is a slave. > > -- > http://mail.python.org/mailman/listinfo/python-list > That's a lot of questions, few specific to python. I have one advice: Don't think too much about performances. Focus on keeping things simple, work on your design and forget about implementation. Pickle everything, use sqllite for your database. When you get things working, then you can start measuring your performances and think about clever implementation to speed up things **if needed** (<- key notion). JM From wrw at mac.com Mon Sep 24 11:29:12 2012 From: wrw at mac.com (wrw at mac.com) Date: Mon, 24 Sep 2012 11:29:12 -0400 Subject: Exact integer-valued floats In-Reply-To: <505E4460.5060301@davea.name> References: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> <7xzk4j6mmq.fsf@ruckus.brouhaha.com> <505d163b$0$29981$c3e8da3$5496439d@news.astraweb.com> <505E4460.5060301@davea.name> Message-ID: On Sep 22, 2012, at 7:06 PM, Dave Angel wrote: > On 09/22/2012 05:05 PM, Tim Roberts wrote: >> Dennis Lee Bieber wrote: >>> On 22 Sep 2012 01:36:59 GMT, Steven D'Aprano wrote: >>>> For non IEEE 754 floating point systems, there is no telling how bad the >>>> implementation could be :( >>> Let's see what can be found... >>> >>> IBM 360: Same as Sigma-6 (no surprise; hearsay is the Sigma was >>> designed by renegade IBM folk; even down to using EBCDIC internally -- >>> but with a much different interrupt system [224 individual interrupt >>> vectors as I recall, vs the IBM's 7 vectors and polling to find what >>> device]). >> The Control Data 6000/Cyber series had sign bit and 11-bit exponent, with >> either a 48-bit mantissa or a 96-bit mantissa, packed into one or two >> 60-bit words. Values were not automatically normalized, so there was no >> assumed 1 bit, as in IEEE-754. > > And it's been a long time (about 39 years), but as I recall the CDC 6400 > (at least) had no integer multiply or divide. You had to convert to > float first. The other oddity about the CDC series is it's the last > machine I've encountered that used ones-complement for ints, with two > values for zero. > > Well, for what it is worth? the DEC Laboratory INstrument Computer (LINC-8, sort of a forced acronym because I believe they were built to specs issued by Lincoln Labs.) and the later DEC PDP-12 (which incorporated the LINC-8 instruction set, along with the PDP-8 basic set) also did ones-complement integer arithmetic. I never used a LINC-8, but I worked for several years around PDP-12s. (They also had a build-in CRT and a MUX'd analog-to-digital converter with CPU instructions for driving both directly.) As I remember, they maxed out at 32k (12-bit) words of RAM. I don't know when they were discontinued, but there were still some PDP-12s in use as late as 1988 when I lost track. -Bil > -- > > DaveA > > -- > http://mail.python.org/mailman/listinfo/python-list From andrea.crotti.0 at gmail.com Mon Sep 24 11:42:50 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Mon, 24 Sep 2012 16:42:50 +0100 Subject: Python presentations In-Reply-To: <2ea7c371-ae27-4d6c-9828-c97a86cec349@googlegroups.com> References: <20120919022003.GB61866@snakebite.org> <2ea7c371-ae27-4d6c-9828-c97a86cec349@googlegroups.com> Message-ID: For anyone interested, I already moved the slides on github (https://github.com/AndreaCrotti/pyconuk2012_slides) and for example the decorator slides will be generated from this: https://raw.github.com/AndreaCrotti/pyconuk2012_slides/master/deco_context/deco.rst Notice the literalinclude with :pyobject: which allows to include any function or class automatically very nicely from external files ;) From jeanmichel at sequans.com Mon Sep 24 11:47:43 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 24 Sep 2012 17:47:43 +0200 (CEST) Subject: keeping information about players around In-Reply-To: <50607AD5.3090702@tysdomain.com> Message-ID: <994735862.2631866.1348501663424.JavaMail.root@sequans.com> ----- Original Message ----- > >Pickle everything, use sqllite for your database. When you get > >things > working, then you can start measuring your performances and think > >about > clever implementation > That was a bunch of information; sorry about that. what do you mean > by > using sqlite for the database? Currently I just drop everything into > files. Is there a better way to do that? > Thanks for your advice. Please keep the discussion on list. If you have a basic knowledge of databases, sure you could use a sqlite database to store you persistent objects. That's pretty reasonable. Not to mention a lot of stuff can interface with that database. If you want to build a web app to manage the player database, you can, most of the frameworks handles sqlite. Actually if you don't need a web app, a lot of sqlite admin app already exists. Note that the database is suitable only for the data. For serializing a python object with its code, you need pickle. JM From duncan.booth at invalid.invalid Mon Sep 24 13:33:29 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 24 Sep 2012 17:33:29 GMT Subject: Java singletonMap in Python References: <505fc372$0$1612$c3e8da3$76491128@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Mon, 24 Sep 2012 00:14:23 +0100, Mark Lawrence wrote: > >> Purely for fun I've been porting some code to Python and came across >> the singletonMap[1]. I'm aware that there are loads of recipes on >> the web for both singletons e.g.[2] and immutable dictionaries >> e.g.[3]. I was wondering how to combine any of the recipes to >> produce the best implementation, where to me best means cleanest and >> hence most maintainable. I then managed to muddy the waters for >> myself by recalling the Alex Martelli Borg pattern[4]. Possibly or >> even probably the latter is irrelevant, but I'm still curious to know >> how you'd code this beast. >> >> First prize for the best solution is a night out with me, no guesses >> what the second prize is :) >> >> [1]http://docs.oracle.com/javase/1.4.2/docs/api/java/util/ > Collections.html > > Copied from that page: > > "static Map singletonMap(Object key, Object value) > Returns an immutable map, mapping only the specified key to the > specified value." > > I don't see the point of this. It takes a single key, with a single > value, and is immutable so you can't change it or add new keys. What's > the point? Why bother storing the key:value pair in a data structure, > then look up the same data structure to get the same value every time? > > # Pseudo-code > d = singletonMap(key, calculate(key)) > # later: > value = d[key] # there's only one key this could be > process(value) > > > Why not just store the value, instead of key, value and mapping? > > value = calculate(key) > # later > process(value) > > > Google is your friend. Searching for "java singletonMap" gives this as the second hit: http://stackoverflow.com/questions/7125536/when-would-i-use-java-collections-singletonmap-method The answers seem to be that it's for all those cases in Java where you have a method that takes a map as an argument and you want to pass in a map with a single kep/value pair. In that case it lets you replace 3 lines of Java with 1. e.g. from the comments: "If you have a simple select statement like "select foo from bar where id = :barId" then you would need a parameter map with a single key-value pair, barId=123. That's a great place to use singletonMap()" Of course in Python you just use a dict literal in that case so it's pointless. -- Duncan Booth http://kupuguy.blogspot.com From inq1ltd at inqvista.com Mon Sep 24 13:39:25 2012 From: inq1ltd at inqvista.com (inq1ltd) Date: Mon, 24 Sep 2012 13:39:25 -0400 Subject: write to a file two dict() In-Reply-To: References: Message-ID: <1956434.KyQTsNE2e6@mach-114-20> On Sunday, September 23, 2012 10:44:30 AM giuseppe.amatulli at gmail.com wrote: > Hi > Have two dict() of the same length and i want print them to a common file. > > > a={1: 1, 2: 2, 3: 3} > b={1: 11, 2: 22, 3: 33} > > in order to obtain > > 1 1 1 11 > 2 2 2 22 > 3 3 3 33 > > I tried > > output = open(dst_file, "w") > for (a), b , (c) , d in a.items() , b.items() : > output.write("%i %i %i %i\n" % (a,b,c,d)) > output.close() Try this, not exactly what you want, but close. Refine it to get what you want. dictC = {} a={1: 1, 2: 2, 3: 3} b={1: 11, 2: 22, 3: 33} for bkey in b.keys(): newlist = [] x = str(b.get(bkey, '')) x = str(bkey)+x newlist.append(x) y = str(a.get(bkey, '')) y = str(bkey)+y newlist.append(y) dictC[bkey] = newlist print dictC, jimonlinux, inqvista.com > > but i get the error ValueError: need more than 3 values to unpack. > > do you have some suggestions?. > Thanks > Giuseppe -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at simplistix.co.uk Mon Sep 24 13:43:33 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 24 Sep 2012 18:43:33 +0100 Subject: metaclass question Message-ID: <50609BC5.3020004@simplistix.co.uk> Hi All, Is there a metaclass-y way I could cause the following: class TheParser(Parser): def handle_ARecord(self): pass def handle_ARecord(self): pass ...to raise an exception as a result of the 'handle_ARecord' name being reused? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From dihedral88888 at googlemail.com Mon Sep 24 14:54:07 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 24 Sep 2012 11:54:07 -0700 (PDT) Subject: Does python have built command for package skeleton creation? In-Reply-To: References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> Message-ID: <0f0efa8d-2d31-4951-b4d8-1dd57e1fc627@googlegroups.com> xliiv? 2012?9?21????UTC+8??9?13?38???? > On Friday, September 21, 2012 3:04:02 PM UTC+2, Tarek Ziad? wrote: > > > On 9/21/12 2:14 PM, xliiv wrote: > > > > > > > > > > > > > > Python Paste is probably what you are looking for - see > > > > > > > > > > > > > > http://lucasmanual.com/mywiki/PythonPaste for example > > > > > > > It's a nice beast but: > > > > > > > - it's not built in. Should it be? I think it should. > > > > > > You can suggest this to python-ideas but I really doubt you will get any > > > > > > traction. The sdtlib don't get new features these days because it's a burden > > > > > > to maintain high level tool on a 2 years release cycle > > > > Why is this '2 years release cycle'? This is good in python to focus on comming HW patforms with varied parameters as the industry is advacing toward all way to avoid a heavy landing of the IT and electronics industry. From dihedral88888 at googlemail.com Mon Sep 24 14:54:07 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 24 Sep 2012 11:54:07 -0700 (PDT) Subject: Does python have built command for package skeleton creation? In-Reply-To: References: <48ed7c38-966a-48d4-97aa-cf3b350ce39b@googlegroups.com> <832435ee-230c-49c2-916c-18e9f807a422@googlegroups.com> Message-ID: <0f0efa8d-2d31-4951-b4d8-1dd57e1fc627@googlegroups.com> xliiv? 2012?9?21????UTC+8??9?13?38???? > On Friday, September 21, 2012 3:04:02 PM UTC+2, Tarek Ziad? wrote: > > > On 9/21/12 2:14 PM, xliiv wrote: > > > > > > > > > > > > > > Python Paste is probably what you are looking for - see > > > > > > > > > > > > > > http://lucasmanual.com/mywiki/PythonPaste for example > > > > > > > It's a nice beast but: > > > > > > > - it's not built in. Should it be? I think it should. > > > > > > You can suggest this to python-ideas but I really doubt you will get any > > > > > > traction. The sdtlib don't get new features these days because it's a burden > > > > > > to maintain high level tool on a 2 years release cycle > > > > Why is this '2 years release cycle'? This is good in python to focus on comming HW patforms with varied parameters as the industry is advacing toward all way to avoid a heavy landing of the IT and electronics industry. From dihedral88888 at googlemail.com Mon Sep 24 15:03:01 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 24 Sep 2012 12:03:01 -0700 (PDT) Subject: Java singletonMap in Python In-Reply-To: References: <505fc372$0$1612$c3e8da3$76491128@news.astraweb.com> Message-ID: <5a943617-2f38-447e-9bb4-c31166f44d0e@googlegroups.com> Duncan Booth? 2012?9?25????UTC+8??1?33?31???? > Steven D'Aprano wrote: > > > > > On Mon, 24 Sep 2012 00:14:23 +0100, Mark Lawrence wrote: > > > > > >> Purely for fun I've been porting some code to Python and came across > > >> the singletonMap[1]. I'm aware that there are loads of recipes on > > >> the web for both singletons e.g.[2] and immutable dictionaries > > >> e.g.[3]. I was wondering how to combine any of the recipes to > > >> produce the best implementation, where to me best means cleanest and > > >> hence most maintainable. I then managed to muddy the waters for > > >> myself by recalling the Alex Martelli Borg pattern[4]. Possibly or > > >> even probably the latter is irrelevant, but I'm still curious to know > > >> how you'd code this beast. > > >> > > >> First prize for the best solution is a night out with me, no guesses > > >> what the second prize is :) > > >> > > >> [1]http://docs.oracle.com/javase/1.4.2/docs/api/java/util/ > > > Collections.html > > > > > > Copied from that page: > > > > > > "static Map singletonMap(Object key, Object value) > > > Returns an immutable map, mapping only the specified key to the > > > specified value." > > > > > > I don't see the point of this. It takes a single key, with a single > > > value, and is immutable so you can't change it or add new keys. What's > > > the point? Why bother storing the key:value pair in a data structure, > > > then look up the same data structure to get the same value every time? > > > > > > # Pseudo-code > > > d = singletonMap(key, calculate(key)) > > > # later: > > > value = d[key] # there's only one key this could be > > > process(value) > > > > > > > > > Why not just store the value, instead of key, value and mapping? > > > > > > value = calculate(key) > > > # later > > > process(value) > > > > > > > > > > > Google is your friend. Searching for "java singletonMap" gives this as > > the second hit: > > > > http://stackoverflow.com/questions/7125536/when-would-i-use-java-collections-singletonmap-method > > > > The answers seem to be that it's for all those cases in Java where you have a > > method that takes a map as an argument and you want to pass in a map with a single > > kep/value pair. In that case it lets you replace 3 lines of Java with 1. > > > > e.g. from the comments: > > "If you have a simple select statement like "select foo from bar where id = :barId" > > then you would need a parameter map with a single key-value pair, barId=123. > > That's a great place to use singletonMap()" > > > > Of course in Python you just use a dict literal in that case so it's pointless. > > > > -- > > Duncan Booth http://kupuguy.blogspot.com Cheers to those who are programmers that really love authoring in the high level one with tools to translate into other computer languages, and also collecting the upgrade fees from clients. From jeanpierreda at gmail.com Mon Sep 24 15:22:07 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 24 Sep 2012 15:22:07 -0400 Subject: Java singletonMap in Python In-Reply-To: References: Message-ID: On Sun, Sep 23, 2012 at 7:14 PM, Mark Lawrence wrote: > Purely for fun I've been porting some code to Python and came across the > singletonMap[1]. I'm aware that there are loads of recipes on the web for > both singletons e.g.[2] and immutable dictionaries e.g.[3]. I was wondering > how to combine any of the recipes to produce the best implementation The word "singleton" usually means "thing with only one item". For example, {a} is a singleton set containing only a, and with matrices, any dimension of size one is called a singleton dimension, and so on. In this case, a singleton map is a map with only one key-value pair, such as {a:b}. The singleton design antipattern is not relevant here. -- Devin From breamoreboy at yahoo.co.uk Mon Sep 24 15:28:14 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 24 Sep 2012 20:28:14 +0100 Subject: Java singletonMap in Python In-Reply-To: References: <505fc372$0$1612$c3e8da3$76491128@news.astraweb.com> Message-ID: On 24/09/2012 18:33, Duncan Booth wrote: > Steven D'Aprano wrote: > >> On Mon, 24 Sep 2012 00:14:23 +0100, Mark Lawrence wrote: >> >>> Purely for fun I've been porting some code to Python and came across >>> the singletonMap[1]. I'm aware that there are loads of recipes on >>> the web for both singletons e.g.[2] and immutable dictionaries >>> e.g.[3]. I was wondering how to combine any of the recipes to >>> produce the best implementation, where to me best means cleanest and >>> hence most maintainable. I then managed to muddy the waters for >>> myself by recalling the Alex Martelli Borg pattern[4]. Possibly or >>> even probably the latter is irrelevant, but I'm still curious to know >>> how you'd code this beast. >>> >>> First prize for the best solution is a night out with me, no guesses >>> what the second prize is :) >>> >>> [1]http://docs.oracle.com/javase/1.4.2/docs/api/java/util/ >> Collections.html >> >> Copied from that page: >> >> "static Map singletonMap(Object key, Object value) >> Returns an immutable map, mapping only the specified key to the >> specified value." >> >> I don't see the point of this. It takes a single key, with a single >> value, and is immutable so you can't change it or add new keys. What's >> the point? Why bother storing the key:value pair in a data structure, >> then look up the same data structure to get the same value every time? >> >> # Pseudo-code >> d = singletonMap(key, calculate(key)) >> # later: >> value = d[key] # there's only one key this could be >> process(value) >> >> >> Why not just store the value, instead of key, value and mapping? >> >> value = calculate(key) >> # later >> process(value) >> >> >> > Google is your friend. Searching for "java singletonMap" gives this as > the second hit: > > http://stackoverflow.com/questions/7125536/when-would-i-use-java-collections-singletonmap-method > > The answers seem to be that it's for all those cases in Java where you have a > method that takes a map as an argument and you want to pass in a map with a single > kep/value pair. In that case it lets you replace 3 lines of Java with 1. > > e.g. from the comments: > "If you have a simple select statement like "select foo from bar where id = :barId" > then you would need a parameter map with a single key-value pair, barId=123. > That's a great place to use singletonMap()" > > Of course in Python you just use a dict literal in that case so it's pointless. > Thank goodness for that, I'd assumed that I'd missed something blatantly obvious. There are two chances of something like this getting into the standard library, zero or none. I think in a way that's a great pity as I'm sure that the Python devs would enjoy supporting the little feller with code such as this http://tinyurl.com/9v7d7ld :) -- Cheers. Mark Lawrence. From marduk at letterboxes.org Mon Sep 24 15:42:00 2012 From: marduk at letterboxes.org (Albert Hopkins) Date: Mon, 24 Sep 2012 15:42:00 -0400 Subject: Fastest web framework In-Reply-To: References: Message-ID: <1348515720.16099.4.camel@stretch> On Sun, 2012-09-23 at 12:19 +0300, Andriy Kornatskyy wrote: > I have run recently a benchmark of a trivial 'hello world' application for various python web frameworks (bottle, django, flask, pyramid, web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find it interesting: > > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > > Comments or suggestions are welcome. > The thing I don't like about these benchmarks is.. they tell you which framework is best for writing a trivial 'hello world' application. But no one writes trivial 'hello world' applications. A framework/programming language/software package/what-have-you. Can be really fast for trivial stuff, but perform much less favorably when performing "real-world" tasks. It's kind of the same argument that's used when people say X computer boots faster than Y computer. That's nice and all, but I spend much more of my time *using* my computer than *booting* it, so it doesn't give me a good picture of how the computers perform. This is why most "good" benchmarks run a series various tests based on real-world use cases. -a From breamoreboy at yahoo.co.uk Mon Sep 24 15:44:25 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 24 Sep 2012 20:44:25 +0100 Subject: Java singletonMap in Python In-Reply-To: References: Message-ID: On 24/09/2012 20:22, Devin Jeanpierre wrote: > On Sun, Sep 23, 2012 at 7:14 PM, Mark Lawrence wrote: >> Purely for fun I've been porting some code to Python and came across the >> singletonMap[1]. I'm aware that there are loads of recipes on the web for >> both singletons e.g.[2] and immutable dictionaries e.g.[3]. I was wondering >> how to combine any of the recipes to produce the best implementation > > The word "singleton" usually means "thing with only one item". For > example, {a} is a singleton set containing only a, and with matrices, > any dimension of size one is called a singleton dimension, and so on. > In this case, a singleton map is a map with only one key-value pair, > such as {a:b}. > > The singleton design antipattern is not relevant here. > > -- Devin > Java thinks so otherwise there wouldn't also be the singleton which is the spelling for singletonSet (don't ask me!!!) and a singletonList. From the Python viewpoint I think YAGNI is perfect. I now understand why the BDFL and others fight so hard to keep bloatware out of the standard library. -- Cheers. Mark Lawrence. From dnogues_mc at hotmail.com Mon Sep 24 15:55:57 2012 From: dnogues_mc at hotmail.com (Daniel Nogues) Date: Mon, 24 Sep 2012 20:55:57 +0100 Subject: Does python have built command for package skeleton creation? In-Reply-To: References: Message-ID: alternatively you can use virtualenv to create virtual environments http://www.virtualenv.org/en/latest/index.html however, if what you want is automated generation of some of the code, you can adopt an IDE or create some macros in your text editor of choice. From: alex23 Date: 24 September 2012 06:00:01 IST To: python-list at python.org Subject: Re: Does python have built command for package skeleton creation? On Sep 24, 2:29 pm, Terry Reedy wrote: > Batteries are batteries, not flashlights, phone, radios, toys, > clickers, > etc. I decided not to mention "venv" as it undermines my rant a little :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From gelonida at gmail.com Mon Sep 24 16:04:45 2012 From: gelonida at gmail.com (Gelonida N) Date: Mon, 24 Sep 2012 22:04:45 +0200 Subject: PIL questions: still supported? Problems on 2.7 for win? alternatives? Message-ID: Hi, I'm trying to migrate a project with legacy code from 2.6 (with PIL 1.1.6) to 2.7 with (PIL 1.1.7) The SW should run on Windows. PIL fails with an error concering '_imagingft' This seems to be a known issue. http://code.google.com/p/pythonxy/issues/detail?id=300 and the bug was never closed. One suggestion is to download an alternative build from a non official site. Looking at the activity of PIL ( http://www.pythonware.com/products/pil/index.htm ) it seems, that development stopped, The latest build (with known bugs and missing functionality for python 2.7.) seems to be from November 15, 2009. In the net I read, that there's so little activity on PIL, because it's stable, which doesn't seem to be the case for the 2.7 binary package. This all does not sound very comforting. Why is there no fix on the official site? I wondered whether some of you have a little more insight into what's going on with PIL. Short term: get PIL working on 2.7 windows? ---------------------------------------------------- My shortterm problem is migrating existing code to 2.7 and keeping the code, that uses PIL. So I'll probably try to install the custom binary, but would like to know whether anybody has experience with this build. http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil Alternatively how tricky is PIL to be compiled with mingw? Mid term: What to use to manipulate images? -------------------------------------------- My midterm problem is to stay with Python 2.7 and to write occasinally new code, that does some basic image manipulations. Can I still count on PIL? The fact, that the official devs don't even bother to fix some basic functionality of their binary release tells me that either very few people use PIL (or at least the broken functionality somehow related to the font libraries) on 2.7 What alternatives do exist for PIL? We just need some lines drawn, some text drown, some scaling, transparency merging, . . . and PIL seend decent enough. There seems to be freeimagepy, but the bindings seem to be 'only' ctypes bindings http://freeimagepy.sourceforge.net/ Any experience with this libraries? Any other suggestions? Longterm Will PIL officially exist for Python 3? ------------------------------------------------- When really all libraries that the project needs are supported I''ll probably migrate to Python 3. For Python 3 there is not even a broken official release, but only forks. Why isn't any of these forks becoming 'official'? If a package is not supported for Windows via official binary releases / easy_install, then I'm a little more afraid, that the package (maintainers included) will disappear in the near future. Thanks a lot in advance for opinions / recommendations / clarifications From andriy.kornatskyy at live.com Mon Sep 24 16:17:19 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Mon, 24 Sep 2012 23:17:19 +0300 Subject: Fastest web framework In-Reply-To: <1348515720.16099.4.camel@stretch> References: , <1348515720.16099.4.camel@stretch> Message-ID: Try to see 'Hello World' benchmark as an answer to the question how effective is the framework inside... If computer X boots faster than Y, it means it is more effective in this particular area. If a sportsman runs a distance 1 second faster than other, he got a medal (it is not quite adequate to say if I load?sportsman?with 50 kilo bag he will not run that fast... just try split the concerns). Thanks. Andriy ---------------------------------------- > Subject: Re: Fastest web framework > From: marduk at letterboxes.org > To: python-list at python.org > Date: Mon, 24 Sep 2012 15:42:00 -0400 > > On Sun, 2012-09-23 at 12:19 +0300, Andriy Kornatskyy wrote: > > I have run recently a benchmark of a trivial 'hello world' application for various python web frameworks (bottle, django, flask, pyramid, web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find it interesting: > > > > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > > > > Comments or suggestions are welcome. > > > > The thing I don't like about these benchmarks is.. they tell you which > framework is best for writing a trivial 'hello world' application. But > no one writes trivial 'hello world' applications. A > framework/programming language/software package/what-have-you. Can be > really fast for trivial stuff, but perform much less favorably when > performing "real-world" tasks. It's kind of the same argument that's > used when people say X computer boots faster than Y computer. That's > nice and all, but I spend much more of my time *using* my computer than > *booting* it, so it doesn't give me a good picture of how the computers > perform. This is why most "good" benchmarks run a series various tests > based on real-world use cases. > > -a > > > -- > http://mail.python.org/mailman/listinfo/python-list From jdildy85 at gmail.com Mon Sep 24 16:27:59 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Mon, 24 Sep 2012 13:27:59 -0700 (PDT) Subject: Anyone able to help on installing packages? In-Reply-To: <2f6f75c5-d96a-48f1-96b3-a8eccbb3d2ef@googlegroups.com> References: <377867f4-d508-4a1b-adba-076f99afbaad@googlegroups.com> <2f6f75c5-d96a-48f1-96b3-a8eccbb3d2ef@googlegroups.com> Message-ID: Anyone have Ideas on nose and distribute? From ian.g.kelly at gmail.com Mon Sep 24 16:53:06 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 24 Sep 2012 14:53:06 -0600 Subject: metaclass question In-Reply-To: <50609BC5.3020004@simplistix.co.uk> References: <50609BC5.3020004@simplistix.co.uk> Message-ID: On Mon, Sep 24, 2012 at 11:43 AM, Chris Withers wrote: > Hi All, > > Is there a metaclass-y way I could cause the following: > > class TheParser(Parser): > def handle_ARecord(self): > pass > def handle_ARecord(self): > pass > > ...to raise an exception as a result of the 'handle_ARecord' name being > reused? In Python 2.x, no. In Python 3.x, the __prepare__ method of the metaclass allows you to specify a custom namespace object for the class definition. The most commonly cited use case is to use an OrderedDict to remember the order in which the attributes are defined, but you could also use a dict subclass that raises an exception if an attribute is redefined. See the docs at: http://docs.python.org/dev/reference/datamodel.html#preparing-the-class-namespace From tyler at tysdomain.com Mon Sep 24 17:08:11 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Mon, 24 Sep 2012 15:08:11 -0600 Subject: request for another code review In-Reply-To: References: Message-ID: <5060CBBB.4070807@tysdomain.com> On 9/23/2012 9:48 PM, alex23 wrote: > On Sep 23, 6:14 am, "Littlefield, Tyler" wrote: >> I've gotten a bit farther into my python mud, and wanted to request >> another code review for style and the like. > Are you familiar with codereview.stackexchange.com ? > I actually wasn't, thanks! > (This isn't to dissuade you from posting such requests here, just to > help increase the chance of eyeballs on your code.) -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From tyler at tysdomain.com Mon Sep 24 17:08:30 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Mon, 24 Sep 2012 15:08:30 -0600 Subject: request for another code review In-Reply-To: References: Message-ID: <5060CBCE.1030709@tysdomain.com> On 9/23/2012 9:48 PM, alex23 wrote: > On Sep 23, 6:14 am, "Littlefield, Tyler" wrote: >> I've gotten a bit farther into my python mud, and wanted to request >> another code review for style and the like. > Are you familiar with codereview.stackexchange.com ? > I actually wasn't, thanks! > (This isn't to dissuade you from posting such requests here, just to > help increase the chance of eyeballs on your code.) -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From dwightdhutto at gmail.com Mon Sep 24 17:14:17 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 17:14:17 -0400 Subject: keeping information about players around In-Reply-To: <505FB849.2080201@tysdomain.com> References: <505FB849.2080201@tysdomain.com> Message-ID: > I have yet another design question. > In my mud, zones are basically objects that manage a collection of rooms; > For example, a town would be it's own zone. > It holds information like maxRooms, the list of rooms as well as some other > data like player owners and access flags. > The access flags basically is a list holding the uid of a player, as well as > a bitarray of permissions on that zone. For example, a player might have the > ability to edit a zone, but not create rooms. > So I have a couple of questions based on this: > First, how viable would it be to keep a sort of player database around with > stats and that? Well, what are the main items you need to retain for the player to return to the game? Also, If this is a browser app I'd go with phpmyadmin, and MySQL If a tkinter/wxpython/etc app, then maybe sqlite. > It could contain the player's level, as well as other information like their > access (player, admin, builder etc), and then when someone does a whois on > the player I don't have to load that player up just to get data about them. > How would I keep the information updated? When I delete a player, I could > just delete the entry from the database by uid. > Second, would it be viable to have both the name and the uid stored in the > dictionary? Then I could look up by either of those? > Why would you use a dictionary, when it's DB manipulation you're after? > Also, I have a couple more general-purpose questions relating to the mud. > When I load a zone, a list of rooms get stored on the zone, as well as > world. I thought it might make sense to store references to objects located > somewhere else but also on the world in WeakValueDictionaries to save > memory. It prevents them from being kept around (and thus having to be > deleted from the world when they lose their life), but also (I hope) will > save memory. Is a weakref going to be less expensive than a full reference? For any case, you're going to have a DB field with a value, so it doesn't look like a high value memory cost in the DB. > Second, I want to set up scripting so that you can script events for rooms > and npcs. For example, I plan to make some type of event system, so that > each type of object gets their own events. For example, when a player walks > into a room, they could trigger some sort of trap that would poison them. > This leads to a question though: I can store scripting on objects or in > separate files, but how is that generally associated and executed? Well, the event doesn't need to be stored unless there is a necessity to store the event, but if it's poisoned, then it's just a life penalty, then no need to store the event, just the score loss. > Finally, I just want to make sure I'm doing things right. When I store data, > I just pickle it all, then load it back up again. My world object has an > attribute defined on it called picklevars, which is basically a list of > variables to pickle, and my __getstate__ just returns a dictionary of those. > All other objects are left "as-is" for now. Zones, (the entire zone and all > it's rooms) get pickled, as well as players and then the world object for > persistence. Is this the suggested way of doing things? I'll also pickle the > HelpManager object, which will basically contain a list of helpfiles that I might suggest you take a look at the Blender Game Engine(python API) at this point, unless you're just liking doing it the hard way to gain experience(just like I have). Design the DB, and let the scene render what needs to be rendered, or list data for, and those are the necessities to be stored. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From ethan at stoneleaf.us Mon Sep 24 17:18:47 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 24 Sep 2012 14:18:47 -0700 Subject: A little morning puzzle In-Reply-To: References: Message-ID: <5060CE37.8080409@stoneleaf.us> Ian Kelly wrote: > On Sat, Sep 22, 2012 at 9:44 PM, Dwight Hutto wrote: >> Why don't you all look at the code(python and C), and tell me how much >> code it took to write the functions the other's examples made use of >> to complete the task. >> >> Just because you can use a function, and make it look easier, doesn't >> mean the function you used had less code than mine, so if you look at >> the whole of what you used to make it simpler, mine was on point. > > I understood the sarcastic comments (the first one, at least) to be > referring to your solution as bad not due to complexity (I actually > thought it was quite simple), but because it does not solve the > problem as stated. The problem posed by the OP was to find a set of > common keys that are associated with the same values in each dict. > Your solution takes only one predetermined key-value pair and counts > how many times it occurs in the dicts, which isn't even close to what > was requested. With your comment of "Might be better ones, though", I > actually thought that you were aware of this and were being > intentionally satirical. Unlikely. ~Ethan~ From dwightdhutto at gmail.com Mon Sep 24 17:22:06 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 17:22:06 -0400 Subject: A little morning puzzle In-Reply-To: References: Message-ID: > Ergo: 'enumerate()' is the correct suggestion over manually > maintaining your own index, despite it ostensibly being "more" code > due to its implementation. But, therefore, that doesn't mean that the coder can just USE a function, and not be able to design it themselves. So 'correct suggestion' is a moot point. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From oscar.j.benjamin at gmail.com Mon Sep 24 17:22:15 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 24 Sep 2012 22:22:15 +0100 Subject: Anyone able to help on installing packages? In-Reply-To: References: <377867f4-d508-4a1b-adba-076f99afbaad@googlegroups.com> <2f6f75c5-d96a-48f1-96b3-a8eccbb3d2ef@googlegroups.com> Message-ID: On 24 September 2012 21:27, John Mordecai Dildy wrote: > Anyone have Ideas on nose and distribute? Your post has no context and simply asks a very vague question. Had you explained what you tried and what happened and perhaps shown an error message I might have been able to answer your question in this post. Presumably you tried something before posting? Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From electrocoder at gmail.com Mon Sep 24 17:24:17 2012 From: electrocoder at gmail.com (=?ISO-8859-9?Q?=FEahin_mersin?=) Date: Tue, 25 Sep 2012 00:24:17 +0300 Subject: Android Python Pypi App Message-ID: *http://* bit.ly/OmiHLR Android Python Pypi App http://bit.ly/OmiHLR -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Mon Sep 24 17:33:51 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 17:33:51 -0400 Subject: Anyone able to help on installing packages? In-Reply-To: <377867f4-d508-4a1b-adba-076f99afbaad@googlegroups.com> References: <377867f4-d508-4a1b-adba-076f99afbaad@googlegroups.com> Message-ID: You could just take the python code, and put it in the site packages file. Depends on the package. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dreamingforward at gmail.com Mon Sep 24 17:35:16 2012 From: dreamingforward at gmail.com (zipher) Date: Mon, 24 Sep 2012 14:35:16 -0700 (PDT) Subject: python file API Message-ID: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> For some time now, I've wanted to suggest a better abstraction for the type in Python. It currently uses an antiquated C-style interface for moving around in a file, with methods like tell() and seek(). But after attributes were introduced to Python, it seems it should be re-addressed. Let file-type have an attribute .pos for position. Now you can get rid of the seek() and tell() methods and manipulate the file pointer more easily with standard arithmetic operations. >>> file.pos = x0ae1 #move file pointer to an absolute address >>> file.pos +=1 #increment the file pointer one byte >>> curr_pos = file.pos #read current file pointer You've now simplified the API by the removal of two obscure legacy methods and replaced them with a more basic one called "position". Thoughts? markj From d at davea.name Mon Sep 24 17:49:16 2012 From: d at davea.name (Dave Angel) Date: Mon, 24 Sep 2012 17:49:16 -0400 Subject: python file API In-Reply-To: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> Message-ID: <5060D55C.3000407@davea.name> On 09/24/2012 05:35 PM, zipher wrote: > For some time now, I've wanted to suggest a better abstraction for the type in Python. It currently uses an antiquated C-style interface for moving around in a file, with methods like tell() and seek(). But after attributes were introduced to Python, it seems it should be re-addressed. > > Let file-type have an attribute .pos for position. Now you can get rid of the seek() and tell() methods and manipulate the file pointer more easily with standard arithmetic operations. > >>>> file.pos = x0ae1 #move file pointer to an absolute address >>>> file.pos +=1 #increment the file pointer one byte >>>> curr_pos = file.pos #read current file pointer > You've now simplified the API by the removal of two obscure legacy methods and replaced them with a more basic one called "position". > > Thoughts? > > markj And what approach would you use for positioning relative to end-of-file? That's currently done with an optional second parameter to seek() method. -- DaveA From oscar.j.benjamin at gmail.com Mon Sep 24 17:56:35 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 24 Sep 2012 22:56:35 +0100 Subject: python file API In-Reply-To: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> Message-ID: On 24 September 2012 22:35, zipher wrote: > For some time now, I've wanted to suggest a better abstraction for the > type in Python. It currently uses an antiquated C-style interface > for moving around in a file, with methods like tell() and seek(). But > after attributes were introduced to Python, it seems it should be > re-addressed. > > Let file-type have an attribute .pos for position. Now you can get rid > of the seek() and tell() methods and manipulate the file pointer more > easily with standard arithmetic operations. > > >>> file.pos = x0ae1 #move file pointer to an absolute address > >>> file.pos +=1 #increment the file pointer one byte > >>> curr_pos = file.pos #read current file pointer > seek() and tell() can raise exceptions on some files. Exposing pos as an attribute and allowing it to be manipulated with attribute access gives the impression that it is always meaningful to do so. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From ckaynor at zindagigames.com Mon Sep 24 17:58:46 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 24 Sep 2012 14:58:46 -0700 Subject: python file API In-Reply-To: <5060D55C.3000407@davea.name> References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: On Mon, Sep 24, 2012 at 2:49 PM, Dave Angel wrote: > > And what approach would you use for positioning relative to > end-of-file? That's currently done with an optional second parameter to > seek() method. > I'm not advocating for or against the idea, but that could be handled the same way indexing into lists can index relative to the end: negative indices. From junkshops at gmail.com Mon Sep 24 17:59:47 2012 From: junkshops at gmail.com (MrsEntity) Date: Mon, 24 Sep 2012 14:59:47 -0700 (PDT) Subject: Memory usage per top 10x usage per heapy Message-ID: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> Hi all, I'm working on some code that parses a 500kb, 2M line file line by line and saves, per line, some derived strings into various data structures. I thus expect that memory use should monotonically increase. Currently, the program is taking up so much memory - even on 1/2 sized files - that on 2GB machine I'm thrashing swap. What's strange is that heapy (http://guppy-pe.sourceforge.net/) is showing that the code uses about 10x less memory than reported by top, and the heapy data seems consistent with what I was expecting based on the objects the code stores. I tried using memory_profiler (http://pypi.python.org/pypi/memory_profiler) but it didn't really provide any illuminating information. The code does create and discard a number of objects per line of the file, but they should not be stored anywhere, and heapy seems to confirm that. So, my questions are: 1) For those of you kind enough to help me figure out what's going on, what additional data would you like? I didn't want swamp everyone with the code and heapy/memory_profiler output but I can do so if it's valuable. 2) How can I diagnose (and hopefully fix) what's causing the massive memory usage when it appears, from heapy, that the code is performing reasonably? Specs: Ubuntu 12.04 in Virtualbox on Win7/64, Python 2.7/64 Thanks very much. From dwightdhutto at gmail.com Mon Sep 24 18:07:20 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 18:07:20 -0400 Subject: A little morning puzzle In-Reply-To: <5060CE37.8080409@stoneleaf.us> References: <5060CE37.8080409@stoneleaf.us> Message-ID: On Mon, Sep 24, 2012 at 5:18 PM, Ethan Furman wrote: > Ian Kelly wrote: >> >> On Sat, Sep 22, 2012 at 9:44 PM, Dwight Hutto >> wrote: >>> >>> Why don't you all look at the code(python and C), and tell me how much >>> code it took to write the functions the other's examples made use of >>> to complete the task.n in or register. >>> >>> Just because you can use a function, and make it look easier, doesn't >>> mean the function you used had less code than mine, so if you look at >>> the whole of what you used to make it simpler, mine was on point. >> >> >> I understood the sarcastic comments (the first one, at least) to be >> referring to your solution as bad not due to complexity (I actually >> thought it was quite simple), but because it does not solve the >> problem as stated. The problem posed by the OP was to find a set of >> common keys that are associated with the same values in each dict. >> Your solution takes only one predetermined key-value pair and counts >> how many times it occurs in the dicts, which isn't even close to what They stated: I have a list of dictionaries. They all have the same keys. I want to find the set of keys where all the dictionaries have the same values. Suggestions? No, to me it meant to find similar values in several dicts with the same key, and value. So I created several dicts, and some with the same key and value, and showed the matches. The OP can comment as to whether that is the correct interpretation of the situation. >> was requested. With your comment of "Might be better ones, though", I >> actually thought that you were aware of this and were being >> intentionally satirical. I am. I just write out the algorithm as I understand the OP to want it, to give my version of the example. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From ethan at stoneleaf.us Mon Sep 24 18:09:04 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 24 Sep 2012 15:09:04 -0700 Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> Message-ID: <5060DA00.10801@stoneleaf.us> jimbo1qaz wrote: > On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: >> Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation. > > Ya, they should really give a better way, but for now, enumerate works pretty well. ROFLOL!! I look forward to the day when you look back on that statement and think, "Wow, I've come a long way!" ~Ethan~ From rosuav at gmail.com Mon Sep 24 18:14:01 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Sep 2012 08:14:01 +1000 Subject: python file API In-Reply-To: <5060D55C.3000407@davea.name> References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: On Tue, Sep 25, 2012 at 7:49 AM, Dave Angel wrote: > On 09/24/2012 05:35 PM, zipher wrote: >> Let file-type have an attribute .pos for position. Now you can get rid of the seek() and tell() methods and manipulate the file pointer more easily with standard arithmetic operations. >> >>>>> file.pos = x0ae1 #move file pointer to an absolute address >>>>> file.pos +=1 #increment the file pointer one byte >>>>> curr_pos = file.pos #read current file pointer > > And what approach would you use for positioning relative to > end-of-file? That's currently done with an optional second parameter to > seek() method. Presumably the same way you reference a list element relative to end-of-list: negative numbers. However, this starts to feel like magic rather than attribute assignment - it's like manipulating the DOM in JavaScript, you set an attribute and stuff happens. Sure it's legal, but is it right? Also, it makes bounds checking awkward: file.pos = 42 # Okay, you're at position 42 file.pos -= 10 # That should put you at position 32 foo = file.pos # Presumably foo is the integer 32 file.pos -= 100 # What should this do? foo -= 100 # But this sets foo to the integer -68 file.pos = foo # And this would set the file pointer 68 bytes from end-of-file. I don't see it making sense for "file.pos -= 100" to suddenly put you near the end of the file; it should either cap and put you at position 0, or do what file.seek(-100,1) would do and throw an exception. But doing the exact same operation on a saved snapshot of the position and reassigning it would then have quite different semantics in an unusual case, while still appearing identical in the normal case. ChrisA From rosuav at gmail.com Mon Sep 24 18:19:34 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Sep 2012 08:19:34 +1000 Subject: keeping information about players around In-Reply-To: References: <505FB849.2080201@tysdomain.com> Message-ID: On Tue, Sep 25, 2012 at 7:14 AM, Dwight Hutto wrote: > Also, If this is a browser app I'd go with phpmyadmin, and MySQL > > If a tkinter/wxpython/etc app, then maybe sqlite. Out of curiosity, why? MySQL isn't magically better for everything where data ends up displayed in a web browser. Unless you're planning to also reference this database from some other language, it's going to make little difference what backend you use; and even if you are using multiple languages, it's usually not difficult to find overlap. ChrisA From dwightdhutto at gmail.com Mon Sep 24 18:26:38 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 18:26:38 -0400 Subject: For Counter Variable In-Reply-To: <5060DA00.10801@stoneleaf.us> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> Message-ID: On Mon, Sep 24, 2012 at 6:09 PM, Ethan Furman wrote: > jimbo1qaz wrote: >> >> On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: >>> >>> Am I missing something obvious, or do I have to manually put in a counter >>> in the for loops? That's a very basic request, but I couldn't find anything >>> in the documentation. >> >> >> Ya, they should really give a better way, but for now, enumerate works >> pretty well. > > > ROFLOL!! > > I look forward to the day when you look back on that statement and think, > "Wow, I've come a long way!" > It's a function usage. Not to be too serious, there are usually simpler solutions, and built in functions. But you usually sticks with what works, and seems timely in return of data output -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Mon Sep 24 18:31:50 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 18:31:50 -0400 Subject: keeping information about players around In-Reply-To: References: <505FB849.2080201@tysdomain.com> Message-ID: On Mon, Sep 24, 2012 at 6:19 PM, Chris Angelico wrote: > On Tue, Sep 25, 2012 at 7:14 AM, Dwight Hutto wrote: >> Also, If this is a browser app I'd go with phpmyadmin, and MySQL >> >> If a tkinter/wxpython/etc app, then maybe sqlite. > > Out of curiosity, why? MySQL isn't magically better for everything > where data ends up displayed in a web browser. No, but phpmyadmin is a great GUI for MySQL Unless you're planning > to also reference this database from some other language, it's going > to make little difference what backend you use; and even if you are > using multiple languages, it's usually not difficult to find overlap. Well this is python, but in the browser a little echo, instead of print, isn't that bad for conversational php. And in the end it's usually html, php, css, javascript in the browser, atleast for me it is. I'm just starting to utilize python in that area, so excuse the naivety. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From d at davea.name Mon Sep 24 18:36:00 2012 From: d at davea.name (Dave Angel) Date: Mon, 24 Sep 2012 18:36:00 -0400 Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: <5060E050.7050900@davea.name> (forwarding to the list) On 09/24/2012 06:23 PM, Mark Adam wrote: > On Mon, Sep 24, 2012 at 4:49 PM, Dave Angel wrote: >> On 09/24/2012 05:35 PM, zipher wrote: >>> For some time now, I've wanted to suggest a better abstraction for the type in Python. It currently uses an antiquated C-style interface for moving around in a file, with methods like tell() and seek(). But after attributes were introduced to Python, it seems it should be re-addressed. >>> >>> Let file-type have an attribute .pos for position. Now you can get rid of the seek() and tell() methods and manipulate the file pointer more easily with standard arithmetic operations. >>> >>>>>> file.pos = x0ae1 #move file pointer to an absolute address >>>>>> file.pos +=1 #increment the file pointer one byte >>>>>> curr_pos = file.pos #read current file pointer > >> And what approach would you use for positioning relative to >> end-of-file? That's currently done with an optional second parameter to >> seek() method. > > As size is an oft-useful construct, let it (like .name) be part of the > descriptor. Then > >>>> file.pos = file.size - 80 #80 chars from end-of-file > > (Or, one could make slices part of the API...) > > mark > Well, if one of the goals was to reduce the number of attributes, we're now back to the original number of them. -- DaveA From dreamingforward at gmail.com Mon Sep 24 18:36:20 2012 From: dreamingforward at gmail.com (zipher) Date: Mon, 24 Sep 2012 15:36:20 -0700 (PDT) Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: You raise a valid point: that by abstracting the file pointer into a position attribute you risk "de-coupling" the conceptual link between the underlying file and your abstraction in the python interpreter, but I think the programmer can take responsibility for maintaining the abstraction. The key possible fault will be whether you can trap (OS-level) exceptions when assigning to the pos attribute beyond the bounds of the actual file on the system... markj From dreamingforward at gmail.com Mon Sep 24 18:36:20 2012 From: dreamingforward at gmail.com (zipher) Date: Mon, 24 Sep 2012 15:36:20 -0700 (PDT) Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: You raise a valid point: that by abstracting the file pointer into a position attribute you risk "de-coupling" the conceptual link between the underlying file and your abstraction in the python interpreter, but I think the programmer can take responsibility for maintaining the abstraction. The key possible fault will be whether you can trap (OS-level) exceptions when assigning to the pos attribute beyond the bounds of the actual file on the system... markj From ian.g.kelly at gmail.com Mon Sep 24 18:37:12 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 24 Sep 2012 16:37:12 -0600 Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: On Mon, Sep 24, 2012 at 4:14 PM, Chris Angelico wrote: > file.pos = 42 # Okay, you're at position 42 > file.pos -= 10 # That should put you at position 32 > foo = file.pos # Presumably foo is the integer 32 > file.pos -= 100 # What should this do? Since ints are immutable, the language specifies that it should be the equivalent of "file.pos = file.pos - 100", so it should set the file pointer to 68 bytes before EOF. > foo -= 100 # But this sets foo to the integer -68 > file.pos = foo # And this would set the file pointer 68 bytes from end-of-file. Which is the same result. > I don't see it making sense for "file.pos -= 100" to suddenly put you > near the end of the file; it should either cap and put you at position > 0, or do what file.seek(-100,1) would do and throw an exception. I agree, but the language doesn't allow those semantics. Also, what about the use of `f.seek(0, os.SEEK_END)` to seek to EOF? I'm not certain what the use cases are, but a quick google reveals that this does happen in real code. If a pos of 0 means BOF, and a pos of -1 means 1 byte before EOF, then how do you seek to EOF without knowing the file length? From dwightdhutto at gmail.com Mon Sep 24 18:39:08 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 18:39:08 -0400 Subject: keeping information about players around In-Reply-To: References: <505FB849.2080201@tysdomain.com> Message-ID: >> Out of curiosity, why? MySQL isn't magically better for everything >> where data ends up displayed in a web browser. > > No, but phpmyadmin is a great GUI for MySQL > Meaning, it gives a great web app, that sqlite doesn't have...yet. It's the tools around MySQL for me, that gives it the umph it needs to be a great DB, with the GUI (phpmyadmin)to match, and short reference/learni8ng curve to use php in this instance. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From joshua.landau.ws at gmail.com Mon Sep 24 18:53:57 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Mon, 24 Sep 2012 23:53:57 +0100 Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> Message-ID: On 24 September 2012 23:26, Dwight Hutto wrote: > On Mon, Sep 24, 2012 at 6:09 PM, Ethan Furman wrote: > > jimbo1qaz wrote: > >> > >> On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: > >>> > >>> Am I missing something obvious, or do I have to manually put in a > counter > >>> in the for loops? That's a very basic request, but I couldn't find > anything > >>> in the documentation. > >> > >> > >> Ya, they should really give a better way, but for now, enumerate works > >> pretty well. > > > > > > ROFLOL!! > > > > I look forward to the day when you look back on that statement and think, > > "Wow, I've come a long way!" > > > > It's a function usage. Not to be too serious, there are usually > simpler solutions, and built in functions. > > But you usually sticks with what works, and seems timely in return of > data output > This is not a criticism, but actual curiosity. *How* would one implement this better, more simply (for the user, not the implementator) or in a more readable manner? Chose *any* one of those. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Sep 24 18:55:58 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Sep 2012 08:55:58 +1000 Subject: keeping information about players around In-Reply-To: References: <505FB849.2080201@tysdomain.com> Message-ID: On Tue, Sep 25, 2012 at 8:31 AM, Dwight Hutto wrote: > And in the end it's usually html, php, css, javascript in the browser, > atleast for me it is. I'm just starting to utilize python in that > area, so excuse the naivety. In the browser it's HTML, CSS, JavaScript (ECMAScript, etc, etc); PHP is just a way of generating that. Any language works on the back end... and PHP isn't the best :) Python does quite well at that task; I have a tiny little Python script that uses a web browser as its front ent. ChrisA From oscar.j.benjamin at gmail.com Mon Sep 24 18:55:59 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 24 Sep 2012 23:55:59 +0100 Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: On 24 September 2012 23:41, Mark Adam wrote: > > seek() and tell() can raise exceptions on some files. Exposing pos as an > > attribute and allowing it to be manipulated with attribute access gives > the > > impression that it is always meaningful to do so. > > It's a good point, python already is allowing exceptions to be caught > within "properties", so exceptions from such an attribute could > presumably be handled similarly. > There are many situations where a little bit of attribute access magic is a good thing. However, operations that involve the underlying OS and that are prone to raising exceptions even in bug free code should not be performed implicitly like this. I find the following a little cryptic: try: f.pos = 256 except IOError: print('Unseekable file') Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Sep 24 18:57:56 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Sep 2012 08:57:56 +1000 Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: On Tue, Sep 25, 2012 at 8:37 AM, Ian Kelly wrote: > On Mon, Sep 24, 2012 at 4:14 PM, Chris Angelico wrote: >> file.pos = 42 # Okay, you're at position 42 >> file.pos -= 10 # That should put you at position 32 >> foo = file.pos # Presumably foo is the integer 32 >> file.pos -= 100 # What should this do? > > Since ints are immutable, the language specifies that it should be the > equivalent of "file.pos = file.pos - 100", so it should set the file > pointer to 68 bytes before EOF. Oh, I forgot that guaranteed equivalency. Well, at least it removes the ambiguity. I don't like it though. ChrisA From dwightdhutto at gmail.com Mon Sep 24 18:58:54 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 18:58:54 -0400 Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> Message-ID: > *How* would one implement this better, more simply (for the user, not the > implementator) or in a more readable manner? Chose *any* one of those. Well if you're learning then the builtin might be more like how we answer students questions here, than those doing work. Write out the algorithmic function, and if you find one you can stuff a few parameters in fine, but you still now how to do it by yourself algorithmically. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From ian.g.kelly at gmail.com Mon Sep 24 19:01:04 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 24 Sep 2012 17:01:04 -0600 Subject: A little morning puzzle In-Reply-To: References: <5060CE37.8080409@stoneleaf.us> Message-ID: On Mon, Sep 24, 2012 at 4:07 PM, Dwight Hutto wrote: > They stated: > > I have a list of dictionaries. They all have the same keys. I want to find the > set of keys where all the dictionaries have the same values. Suggestions? > > No, to me it meant to find similar values in several dicts with the > same key, and value. So I created several dicts, and some with the > same key and value, and showed the matches. Well, to me at least it is clear that when the OP writes "I want to find the *set* of *keys*..." (emphasis added), then setting aside the rest of the problem statement, the result of the algorithm should be a set (or at least something set-like), and the contents of the set should be keys. The posted code produces neither a set nor any keys; it prints out the same predetermined non-key value multiple times. From dwightdhutto at gmail.com Mon Sep 24 19:09:26 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 19:09:26 -0400 Subject: keeping information about players around In-Reply-To: References: <505FB849.2080201@tysdomain.com> Message-ID: > is just a way of generating that. Any language works on the back > end... and PHP isn't the best :) Python does quite well at that task; > I have a tiny little Python script that uses a web browser as its > front ent. This stems from my limited usage of python in the browser(I usually use it for prototype apps). It's usually going to be the difference between echo or print html/javascript, and perform an iteration for table, or formulaic computation within a standard function syntax. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From breamoreboy at yahoo.co.uk Mon Sep 24 19:12:30 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Sep 2012 00:12:30 +0100 Subject: python file API In-Reply-To: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> Message-ID: On 24/09/2012 22:35, zipher wrote: > For some time now, I've wanted to suggest a better abstraction for the type in Python. It currently uses an antiquated C-style interface for moving around in a file, with methods like tell() and seek(). But after attributes were introduced to Python, it seems it should be re-addressed. > > Let file-type have an attribute .pos for position. Now you can get rid of the seek() and tell() methods and manipulate the file pointer more easily with standard arithmetic operations. > >>>> file.pos = x0ae1 #move file pointer to an absolute address >>>> file.pos +=1 #increment the file pointer one byte >>>> curr_pos = file.pos #read current file pointer > > You've now simplified the API by the removal of two obscure legacy methods and replaced them with a more basic one called "position". > > Thoughts? > > markj > This strikes me as being a case of if it ain't broke don't fix it. -- Cheers. Mark Lawrence. From dwightdhutto at gmail.com Mon Sep 24 19:13:39 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 19:13:39 -0400 Subject: A little morning puzzle In-Reply-To: References: <5060CE37.8080409@stoneleaf.us> Message-ID: The posted code produces neither a set nor any keys; > it prints out the same predetermined non-key value multiple times. This shows multiple dicts, with the same keys, and shows different values, and some with the same, and that is, in my opinion what the OP asked for: a = {} a['dict'] = 1 b = {} b['dict'] = 2 c = {} c['dict'] = 1 d = {} d['dict'] = 3 e = {} e['dict'] = 1 x = [a,b,c,d,e] count = 0 collection_count = 0 search_variable = 1 for dict_key_search in x: if dict_key_search['dict'] == search_variable: print "Match count found: #%i = %i" % (count,search_variable) collection_count += 1 count += 1 print collection_count The OP can jump in and tell me to alter the example, if they want to. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From ckaynor at zindagigames.com Mon Sep 24 19:14:37 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 24 Sep 2012 16:14:37 -0700 Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: On Mon, Sep 24, 2012 at 3:37 PM, Ian Kelly wrote: > On Mon, Sep 24, 2012 at 4:14 PM, Chris Angelico wrote: >> file.pos = 42 # Okay, you're at position 42 >> file.pos -= 10 # That should put you at position 32 >> foo = file.pos # Presumably foo is the integer 32 >> file.pos -= 100 # What should this do? > > Since ints are immutable, the language specifies that it should be the > equivalent of "file.pos = file.pos - 100", so it should set the file > pointer to 68 bytes before EOF. There is no reason that it has to be an int object, however. It could well return a "FilePosition" object which does not allow subtraction to produce a negative result. Not saying its a good idea... Similarly, it could be a more complex object with properties on it to determine whether to seek from beginning or end. From python.list at tim.thechases.com Mon Sep 24 19:22:20 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 24 Sep 2012 18:22:20 -0500 Subject: Memory usage per top 10x usage per heapy In-Reply-To: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> Message-ID: <5060EB2C.6080508@tim.thechases.com> On 09/24/12 16:59, MrsEntity wrote: > I'm working on some code that parses a 500kb, 2M line file line > by line and saves, per line, some derived strings into various > data structures. I thus expect that memory use should > monotonically increase. Currently, the program is taking up so > much memory - even on 1/2 sized files - that on 2GB machine I'm > thrashing swap. It might help to know what comprises the "into various data structures". I do a lot of ETL work on far larger files, with similar machine specs, and rarely touch swap. > 2) How can I diagnose (and hopefully fix) what's causing the > massive memory usage when it appears, from heapy, that the code > is performing reasonably? I seem to recall that Python holds on to memory that the VM releases, but that it *should* reuse it later. So you'd get the symptom of the memory-usage always increasing, never decreasing. Things that occur to me: - check how you're reading the data: are you iterating over the lines a row at a time, or are you using .read()/.readlines() to pull in the whole file and then operate on that? - check how you're storing them: are you holding onto more than you think you are? Would it hurt to switch from a dict to store your data (I'm assuming here) to using the anydbm module to temporarily persist the large quantity of data out to disk in order to keep memory usage lower? Without actual code, it's hard to do a more detailed analysis. -tkc From wuwei23 at gmail.com Mon Sep 24 19:28:17 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 24 Sep 2012 16:28:17 -0700 (PDT) Subject: keeping information about players around References: <505FB849.2080201@tysdomain.com> Message-ID: <144ddc26-b1e0-4fad-8651-53b5b6cd100e@n7g2000pbj.googlegroups.com> On Sep 25, 8:32?am, Dwight Hutto wrote: > No, but phpmyadmin is a great GUI for MySQL If you're recommending MySQL use on the basis of phpmyadmin, you should also make sure to mention: http://www.phpmyadmin.net/home_page/security/ Great GUI, maybe. Huge security hole, absolutely. Most organisations I've worked for won't allow it anywhere near their servers. From wuwei23 at gmail.com Mon Sep 24 19:33:05 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 24 Sep 2012 16:33:05 -0700 (PDT) Subject: For Counter Variable References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> Message-ID: <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> On Sep 25, 8:58?am, Dwight Hutto wrote: > Well if you're learning then the builtin might be more like how we > answer students questions here, than those doing work. STOP SAYING THIS NONSENSE. Using a pre-defined function is _not_ the "student" approach. Rolling your own version of an existing function from scratch is _not_ the "professional" approach. If you're unable to realise this, then please stop dispensing advice here like you know something. From wuwei23 at gmail.com Mon Sep 24 19:38:05 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 24 Sep 2012 16:38:05 -0700 (PDT) Subject: PIL questions: still supported? Problems on 2.7 for win? alternatives? References: Message-ID: On Sep 25, 6:04?am, Gelonida N wrote: > This all does not sound very comforting. Why is there no fix on the > official site? Has a bug been logged about the issue? The Plone community keeps a fairly up-to-date fork called Pillow, we've had a lot of success using that locally: http://pypi.python.org/pypi/Pillow/ From dwightdhutto at gmail.com Mon Sep 24 19:39:01 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 19:39:01 -0400 Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> Message-ID: On Sep 25, 8:26 am, Dwight Hutto wrote: > It's a function usage. Not to be too serious, there are usually > simpler solutions, and built in functions. `enumerate` _is_ a built-in function. Please provide an example of a "simpler solution". It's not the simpler solution I'm referring to, it's the fact that if you're learning, then you should be able to design the built-in, not just use it. You don't always know all the built-ins, so the builtin is simpler, but knowing how to code it yourself is the priority of learning to code in a higher level language, which should be simpler to the user of python. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From jayden.shui at gmail.com Mon Sep 24 19:43:24 2012 From: jayden.shui at gmail.com (Jayden) Date: Mon, 24 Sep 2012 16:43:24 -0700 (PDT) Subject: which a is used? Message-ID: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> Dear All, I have a simple code as follows: # Begin a = 1 def f(): print a def g(): a = 20 f() g() #End I think the results should be 20, but it is 1. Would you please tell me why? Thanks a lot! From dwightdhutto at gmail.com Mon Sep 24 19:44:36 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 19:44:36 -0400 Subject: keeping information about players around In-Reply-To: <144ddc26-b1e0-4fad-8651-53b5b6cd100e@n7g2000pbj.googlegroups.com> References: <505FB849.2080201@tysdomain.com> <144ddc26-b1e0-4fad-8651-53b5b6cd100e@n7g2000pbj.googlegroups.com> Message-ID: On Mon, Sep 24, 2012 at 7:28 PM, alex23 wrote: > On Sep 25, 8:32 am, Dwight Hutto wrote: >> No, but phpmyadmin is a great GUI for MySQL > > If you're recommending MySQL use on the basis of phpmyadmin, you > should also make sure to mention: > http://www.phpmyadmin.net/home_page/security/ > > Great GUI, maybe. Huge security hole, absolutely. Most organisations > I've worked for won't allow it anywhere near their servers. What DB are you recommending, check out sqlite's: http://www.cvedetails.com/vulnerability-list/vendor_id-9237/Sqlite.html Maybe just a parsed file with data, and accessing data that you design. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From wuwei23 at gmail.com Mon Sep 24 19:48:20 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 24 Sep 2012 16:48:20 -0700 (PDT) Subject: For Counter Variable References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> Message-ID: <9ae3a20f-9ec1-4ab9-b54f-99cb9ca0139b@c6g2000pba.googlegroups.com> On Sep 25, 9:39?am, Dwight Hutto wrote: > It's not the simpler solution I'm referring to, it's the fact that if > you're learning, then you should be able to design the built-in, not > just use it. Garbage. I don't need to be able to build a SQLAlchemy to use it. I don't need to be able to build an XML parser to use one. The whole goddamn point of abstractions is to _ease the cognitive load_ in building a complex system. > You don't always know all the built-ins, so the builtin is simpler, > but knowing how to code it yourself is the priority of learning to > code in a higher level language, which should be simpler to the user > of python. "Higher level" means, in part, not _having to give a shit_ about the sort of low level coding you're obsessed with. If it rocks your world to declare your own index pointer and increment it on each pass of a loop, knock yourself out. Just accept that others will criticise your code for being "unpythonic". Why even use the language if you're not prepared to _use_ the language...and that means _more than the syntax_. It extends to the standard library and through to the entire ecosystem that has developed around it. People are drawn to Python to get shit done, not to spend pointless time in recreating every wheel. From dwightdhutto at gmail.com Mon Sep 24 19:49:32 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 19:49:32 -0400 Subject: For Counter Variable In-Reply-To: <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> Message-ID: >> Well if you're learning then the builtin might be more like how we >> answer students questions here, than those doing work. > > STOP SAYING THIS NONSENSE. > > Using a pre-defined function is _not_ the "student" approach. What are talking about, I suggested they roll there own in several responses this week. Rolling > your own version of an existing function from scratch is _not_ the > "professional" approach. Yes it is, if you don't know the builtin, and everyone has memory flaws. > If you're unable to realise this, then please stop dispensing advice > here like you know something. Dude, you know jack shit, so go shovel this bullshit somewhere else, where people aren't intelligent enough to read the rest of my posts -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Mon Sep 24 19:50:04 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 19:50:04 -0400 Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> Message-ID: Propaganda over... -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From wuwei23 at gmail.com Mon Sep 24 19:52:22 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 24 Sep 2012 16:52:22 -0700 (PDT) Subject: keeping information about players around References: <505FB849.2080201@tysdomain.com> <144ddc26-b1e0-4fad-8651-53b5b6cd100e@n7g2000pbj.googlegroups.com> Message-ID: <66da5330-e517-4712-a9e0-be01f0bae480@lo4g2000pbb.googlegroups.com> On Sep 25, 9:44?am, Dwight Hutto wrote: > ?What DB are you recommending, check out sqlite's: > > http://www.cvedetails.com/vulnerability-list/vendor_id-9237/Sqlite.html Are you _seriously_ comparing _four_ vulnerabilities to 60+? > Maybe just a parsed file with data, and accessing data that you design. Just stop. From dwightdhutto at gmail.com Mon Sep 24 19:57:27 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 19:57:27 -0400 Subject: which a is used? In-Reply-To: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> Message-ID: On Mon, Sep 24, 2012 at 7:43 PM, Jayden wrote: > Dear All, > > I have a simple code as follows: > > # Begin > a = 1 > > def f(): > print a > > def g(): > a = 20 > f() > > g() > #End > > I think the results should be 20, but it is 1. Would you please tell me why? > > Thanks a lot! > > -- > http://mail.python.org/mailman/listinfo/python-list didn't return the value, or print it out -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From wuwei23 at gmail.com Mon Sep 24 19:58:50 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 24 Sep 2012 16:58:50 -0700 (PDT) Subject: For Counter Variable References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> Message-ID: <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> On Sep 25, 9:49?am, Dwight Hutto wrote: > Rolling> your own version of an existing function from scratch is _not_ the > > "professional" approach. > > Yes it is, if you don't know the builtin, and everyone has memory flaws. Let me break this down for you in simple terms. Code represents experience. Code that is considered important enough to be in the standard library or as a built-in is something that encapsulates a _lot_ of experience over time. You in your naive approach to re-implement will _never capture that experience_. You'll miss the edge cases that were already addressed. You'll over- or under- extend the metaphor in ways the original doesn't. And the first thing any experienced programmer would do when they encountered your code is _refactor it to use the built-in_. > Dude, you know jack shit, so go shovel this bullshit somewhere else, > where people aren't intelligent enough to read the rest of my posts > CEO: http://www.hitwebdevelopment.com Is the animated GIF on your website under 60MB yet? From junkshops at gmail.com Mon Sep 24 19:58:51 2012 From: junkshops at gmail.com (Junkshops) Date: Mon, 24 Sep 2012 16:58:51 -0700 Subject: Memory usage per top 10x usage per heapy In-Reply-To: <5060EB2C.6080508@tim.thechases.com> References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5060EB2C.6080508@tim.thechases.com> Message-ID: <5060F3BB.7010706@gmail.com> Hi Tim, thanks for the response. > - check how you're reading the data: are you iterating over > the lines a row at a time, or are you using > .read()/.readlines() to pull in the whole file and then > operate on that? I'm using enumerate() on an iterable input (which in this case is the filehandle). > - check how you're storing them: are you holding onto more > than you think you are? I've used ipython to look through my data structures (without going into ungainly detail, 2 dicts with X numbers of key/value pairs, where X = number of lines in the file), and everything seems to be working correctly. Like I say, heapy output looks reasonable - I don't see anything surprising there. In one dict I'm storing a id string (the first token in each line of the file) with values as (again, without going into massive detail) the md5 of the contents of the line. The second dict has the md5 as the key and an object with __slots__ set that stores the line number of the file and the type of object that line represents. > Would it hurt to switch from a > dict to store your data (I'm assuming here) to using the > anydbm module to temporarily persist the large quantity of > data out to disk in order to keep memory usage lower? That's the thing though - according to heapy, the memory usage *is* low and is more or less what I expect. What I don't understand is why top is reporting such vastly different memory usage. If a memory profiler is saying everything's ok, it makes it very difficult to figure out what's causing the problem. Based on heapy, a db based solution would be serious overkill. -MrsE On 9/24/2012 4:22 PM, Tim Chase wrote: > On 09/24/12 16:59, MrsEntity wrote: >> I'm working on some code that parses a 500kb, 2M line file line >> by line and saves, per line, some derived strings into various >> data structures. I thus expect that memory use should >> monotonically increase. Currently, the program is taking up so >> much memory - even on 1/2 sized files - that on 2GB machine I'm >> thrashing swap. > It might help to know what comprises the "into various data > structures". I do a lot of ETL work on far larger files, > with similar machine specs, and rarely touch swap. > >> 2) How can I diagnose (and hopefully fix) what's causing the >> massive memory usage when it appears, from heapy, that the code >> is performing reasonably? > I seem to recall that Python holds on to memory that the VM > releases, but that it *should* reuse it later. So you'd get > the symptom of the memory-usage always increasing, never > decreasing. > > Things that occur to me: > > - check how you're reading the data: are you iterating over > the lines a row at a time, or are you using > .read()/.readlines() to pull in the whole file and then > operate on that? > > - check how you're storing them: are you holding onto more > than you think you are? Would it hurt to switch from a > dict to store your data (I'm assuming here) to using the > anydbm module to temporarily persist the large quantity of > data out to disk in order to keep memory usage lower? > > Without actual code, it's hard to do a more detailed > analysis. > > -tkc > From dwightdhutto at gmail.com Mon Sep 24 20:06:41 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 20:06:41 -0400 Subject: which a is used? In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> Message-ID: On Mon, Sep 24, 2012 at 7:57 PM, Dwight Hutto wrote: > On Mon, Sep 24, 2012 at 7:43 PM, Jayden wrote: >> Dear All, >> >> I have a simple code as follows: >> >> # Begin >> a = 1 >> >> def f(): >> print a >> >> def g(): >> a = 20 >> f() this prints a from calling f() function call print a wasn't in a class where it was self.a and changed, so it performed the function f which prints a and a = 1, but g just assigns the 20, and calls the f() function which shows a, there is no self.a, nor a class to show this in. >> >> g() >> #End >> >> I think the results should be 20, but it is 1. Would you please tell me why? >> >> Thanks a lot! >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > > didn't return the value, or print it out > > > -- > Best Regards, > David Hutto > CEO: http://www.hitwebdevelopment.com -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From wuwei23 at gmail.com Mon Sep 24 20:08:45 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 24 Sep 2012 17:08:45 -0700 (PDT) Subject: which a is used? References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> Message-ID: <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> On Sep 25, 9:43?am, Jayden wrote: > Dear All, > > I have a simple code as follows: > > # Begin > a = 1 > > def f(): > ? ? print a > > def g(): > ? ? a = 20 > ? ? f() > > g() > #End > > I think the results should be 20, but it is 1. Would you please tell me why? Because you don't declare 'a' in 'f', it looks for 'a' in the surrounding scope _where it was defined_, not where it was called. Because 'a' in the module scope is 1, you'll get 1. From tyler at tysdomain.com Mon Sep 24 20:14:03 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Mon, 24 Sep 2012 18:14:03 -0600 Subject: keeping information about players around In-Reply-To: References: <505FB849.2080201@tysdomain.com> Message-ID: <5060F74B.4070806@tysdomain.com> On 9/24/2012 3:14 PM, Dwight Hutto wrote: >> I have yet another design question. >> In my mud, zones are basically objects that manage a collection of rooms; >> For example, a town would be it's own zone. >> It holds information like maxRooms, the list of rooms as well as some other >> data like player owners and access flags. >> The access flags basically is a list holding the uid of a player, as well as >> a bitarray of permissions on that zone. For example, a player might have the >> ability to edit a zone, but not create rooms. >> So I have a couple of questions based on this: >> First, how viable would it be to keep a sort of player database around with >> stats and that? > Well, what are the main items you need to retain for the player to > return to the game? > All of their contents are stored, which right now is done through Pickle. The stats is something different, as like I said, I don't want to unpickle an object every time I for example look at a zone and see what players have permissions on it. Also, If this is a browser app I'd go with phpmyadmin, and MySQL If a tkinter/wxpython/etc app, then maybe sqlite. PHPMyAdmin? Might I ask why? This is a mud, so it's all command based, so that's not even a question, but I'm kind of curious how PHPMyAdmin factors in there. It's a database creation tool from all I've ever seen of it, to define tables. Also, using it requires that I have it up on some server or another, and I'd really rather avoid that if I can. >> It could contain the player's level, as well as other information like their >> access (player, admin, builder etc), and then when someone does a whois on >> the player I don't have to load that player up just to get data about them. >> How would I keep the information updated? When I delete a player, I could >> just delete the entry from the database by uid. >> Second, would it be viable to have both the name and the uid stored in the >> dictionary? Then I could look up by either of those? >> > Why would you use a dictionary, when it's DB manipulation you're after? > It is? I don't remember mentioning database anything in my thread. Unless I missed it, I mentioned pickle once or twice. But either way, I'd use a dictionary to keep a copy of {uid:object} for objects and {uid:player} for players. Makes lookup by uid pretty easy, as well as for any loaded objects. >> Also, I have a couple more general-purpose questions relating to the mud. >> When I load a zone, a list of rooms get stored on the zone, as well as >> world. I thought it might make sense to store references to objects located >> somewhere else but also on the world in WeakValueDictionaries to save >> memory. It prevents them from being kept around (and thus having to be >> deleted from the world when they lose their life), but also (I hope) will >> save memory. Is a weakref going to be less expensive than a full reference? > For any case, you're going to have a DB field with a value, so it > doesn't look like a high value memory cost in the DB. > >> Second, I want to set up scripting so that you can script events for rooms >> and npcs. For example, I plan to make some type of event system, so that >> each type of object gets their own events. For example, when a player walks >> into a room, they could trigger some sort of trap that would poison them. >> This leads to a question though: I can store scripting on objects or in >> separate files, but how is that generally associated and executed? > Well, the event doesn't need to be stored unless there is a necessity > to store the event, but if it's poisoned, then it's just a life > penalty, then no need to store the event, just the score loss. > I was asking about scripting the rooms, more than storing it. I need to have python code somewhere, somehow that attaches to the onEnter event in a room and subtracts hp from the player. Obviously you want that to be object specific and not have that script on everything. >> Finally, I just want to make sure I'm doing things right. When I store data, >> I just pickle it all, then load it back up again. My world object has an >> attribute defined on it called picklevars, which is basically a list of >> variables to pickle, and my __getstate__ just returns a dictionary of those. >> All other objects are left "as-is" for now. Zones, (the entire zone and all >> it's rooms) get pickled, as well as players and then the world object for >> persistence. Is this the suggested way of doing things? I'll also pickle the >> HelpManager object, which will basically contain a list of helpfiles that > I might suggest you take a look at the Blender Game Engine(python API) > at this point, unless you're just liking doing it the hard way to gain > experience(just like I have). > That's cool I guess, but I'm not taking your road and doing it the hard way for experience. The setup is more of a game engine, but beyond that, I don't think I need everything i get from a game library, especially since IIRC, Blender is mainly 3d focused? Design the DB, and let the scene render what needs to be rendered, or list data for, and those are the necessities to be stored. -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From dwightdhutto at gmail.com Mon Sep 24 20:17:42 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 20:17:42 -0400 Subject: For Counter Variable In-Reply-To: <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> Message-ID: > Is the animated GIF on your website under 60MB yet? yeah a command line called convert, and taking out a few jpegs used to convert, and I can reduce it to any size, what's the fucking point of that question other than ignorant rhetoric, that you know is easily fixable? -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From wuwei23 at gmail.com Mon Sep 24 20:19:15 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 24 Sep 2012 17:19:15 -0700 (PDT) Subject: For Counter Variable References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> Message-ID: <26493369-8f41-456c-8a89-b4883e37d55c@k13g2000pbq.googlegroups.com> On Sep 25, 10:18?am, Dwight Hutto wrote: > what's the fucking point of that question To highlight the vast gulf between what you think you are and what you actually produce. From dwightdhutto at gmail.com Mon Sep 24 20:25:35 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 20:25:35 -0400 Subject: For Counter Variable In-Reply-To: <26493369-8f41-456c-8a89-b4883e37d55c@k13g2000pbq.googlegroups.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> <26493369-8f41-456c-8a89-b4883e37d55c@k13g2000pbq.googlegroups.com> Message-ID: > To highlight the vast gulf between what you think you are and what you > actually produce. I produce working code, and if it works, then I don't just think...I know. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Mon Sep 24 20:31:08 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 20:31:08 -0400 Subject: keeping information about players around In-Reply-To: <66da5330-e517-4712-a9e0-be01f0bae480@lo4g2000pbb.googlegroups.com> References: <505FB849.2080201@tysdomain.com> <144ddc26-b1e0-4fad-8651-53b5b6cd100e@n7g2000pbj.googlegroups.com> <66da5330-e517-4712-a9e0-be01f0bae480@lo4g2000pbb.googlegroups.com> Message-ID: On Mon, Sep 24, 2012 at 7:52 PM, alex23 wrote: > On Sep 25, 9:44 am, Dwight Hutto wrote: >> What DB are you recommending, check out sqlite's: >> >> http://www.cvedetails.com/vulnerability-list/vendor_id-9237/Sqlite.html > > Are you _seriously_ comparing _four_ vulnerabilities to 60+? > Even less if you use your own DB structure, and evn less in mysql if you reject the injections of the known vulnerablities. >> Maybe just a parsed file with data, and accessing data that you design. > > Just stop. Why not suggest odbm or relational db's, this shows your lack of complexity in design, so please stop your own Dunner-Kruning. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From oscar.j.benjamin at gmail.com Mon Sep 24 20:32:32 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 25 Sep 2012 01:32:32 +0100 Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> Message-ID: On 25 September 2012 01:17, Dwight Hutto wrote: > > Is the animated GIF on your website under 60MB yet? > yeah a command line called convert, and taking out a few jpegs used to > convert, and I can reduce it to any size, what's the fucking point of > that question other than ignorant rhetoric, that you know is easily > fixable? Calm down! I don't want to read you to abusing and baiting each other. If you do both mutually consent to continuing this conversation then do it off list. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tyler at tysdomain.com Mon Sep 24 20:32:50 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Mon, 24 Sep 2012 18:32:50 -0600 Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> <26493369-8f41-456c-8a89-b4883e37d55c@k13g2000pbq.googlegroups.com> Message-ID: <5060FBB2.20704@tysdomain.com> On 9/24/2012 6:25 PM, Dwight Hutto wrote: >> To highlight the vast gulf between what you think you are and what you >> actually produce. > I produce working code, and if it works, then I don't just think...I know. > > Working code != good code. Just an observation. Also, I've noticed a vast differences between someone who can explain their answers as Alix has done on multiple threads you've replied to in the last 5 minutes, and someone who cobbles something together with "your variable isn't being shown right because there's no self.a," which actually really makes no sense at all. Just my $0.02. -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From cjgohlke at gmail.com Mon Sep 24 20:32:53 2012 From: cjgohlke at gmail.com (cjgohlke at gmail.com) Date: Mon, 24 Sep 2012 17:32:53 -0700 (PDT) Subject: PIL questions: still supported? Problems on 2.7 for win? alternatives? In-Reply-To: References: Message-ID: <04b69799-671f-465e-a1ef-802caf9df408@googlegroups.com> On Monday, September 24, 2012 4:38:05 PM UTC-7, alex23 wrote: > On Sep 25, 6:04?am, Gelonida N wrote: > > > This all does not sound very comforting. Why is there no fix on the > > > official site? > > > > Has a bug been logged about the issue? > See issue #1 at Christoph > > > The Plone community keeps a fairly up-to-date fork called Pillow, > > we've had a lot of success using that locally: > > > > http://pypi.python.org/pypi/Pillow/ From dwightdhutto at gmail.com Mon Sep 24 20:45:31 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 20:45:31 -0400 Subject: For Counter Variable In-Reply-To: <5060FBB2.20704@tysdomain.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> <26493369-8f41-456c-8a89-b4883e37d55c@k13g2000pbq.googlegroups.com> <5060FBB2.20704@tysdomain.com> Message-ID: >> Just my $0.02. > I'd estimate it at that value anyday. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Mon Sep 24 20:50:28 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 20:50:28 -0400 Subject: For Counter Variable In-Reply-To: <5060FBB2.20704@tysdomain.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> <26493369-8f41-456c-8a89-b4883e37d55c@k13g2000pbq.googlegroups.com> <5060FBB2.20704@tysdomain.com> Message-ID: On Mon, Sep 24, 2012 at 8:32 PM, Littlefield, Tyler wrote: > On 9/24/2012 6:25 PM, Dwight Hutto wrote: >>> >>> To highlight the vast gulf between what you think you are and what you >>> actually produce. >> >> I produce working code, and if it works, then I don't just think...I know. >> >> Working code != good code. Just an observation. Also, I've noticed a vast >> differences between someone who can explain their answers as Alix has done >> on multiple threads you've replied to in the last 5 minutes, and someone who >> cobbles something together with "your variable isn't being shown right I might have mispoke, forgive me for knowing several languages,and getting a little class syntax wrong,. It's called computer science and interdisciplinary study you dumb fucking double digit IQ'd twit. >> because there's no self.a," which actually really makes no sense at all. That was in a class scenario >> Just my $0.02. > > > -- > Take care, > Ty > http://tds-solutions.net > The aspen project: a barebones light-weight mud engine: > http://code.google.com/p/aspenmud > He that will not reason is a bigot; he that cannot reason is a fool; he that > dares not reason is a slave. > > -- > http://mail.python.org/mailman/listinfo/python-list -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From no.email at nospam.invalid Mon Sep 24 21:10:09 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 24 Sep 2012 18:10:09 -0700 Subject: For Counter Variable References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> <26493369-8f41-456c-8a89-b4883e37d55c@k13g2000pbq.googlegroups.com> Message-ID: <7xtxumhpqm.fsf@ruckus.brouhaha.com> alex23 writes: > To highlight the vast gulf between what you think you are and what you > actually produce. By now I think we're in the DNFTT zone. From dwightdhutto at gmail.com Mon Sep 24 21:13:05 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 21:13:05 -0400 Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> <26493369-8f41-456c-8a89-b4883e37d55c@k13g2000pbq.googlegroups.com> <5060FBB2.20704@tysdomain.com> Message-ID: Anything else bitch? -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Mon Sep 24 21:13:53 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 21:13:53 -0400 Subject: which a is used? In-Reply-To: <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> Message-ID: Anything else bitch, take time to think about it. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From d at davea.name Mon Sep 24 21:14:23 2012 From: d at davea.name (Dave Angel) Date: Mon, 24 Sep 2012 21:14:23 -0400 Subject: Memory usage per top 10x usage per heapy In-Reply-To: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> Message-ID: <5061056F.6080702@davea.name> On 09/24/2012 05:59 PM, MrsEntity wrote: > Hi all, > > I'm working on some code that parses a 500kb, 2M line file Just curious; which is it, two million lines, or half a million bytes? > line by line and saves, per line, some derived strings into various data structures. I thus expect that memory use should monotonically increase. Currently, the program is taking up so much memory - even on 1/2 sized files - that on 2GB machine which machine is 2gb, the Windows machine, or the VM? You could get thrashing at either level. > I'm thrashing swap. What's strange is that heapy (http://guppy-pe.sourceforge.net/) is showing that the code uses about 10x less memory than reported by top, and the heapy data seems consistent with what I was expecting based on the objects the code stores. I tried using memory_profiler (http://pypi.python.org/pypi/memory_profiler) but it didn't really provide any illuminating information. The code does create and discard a number of objects per line of the file, but they should not be stored anywhere, and heapy seems to confirm that. So, my questions are: > > 1) For those of you kind enough to help me figure out what's going on, what additional data would you like? I didn't want swamp everyone with the code and heapy/memory_profiler output but I can do so if it's valuable. > 2) How can I diagnose (and hopefully fix) what's causing the massive memory usage when it appears, from heapy, that the code is performing reasonably? > > Specs: Ubuntu 12.04 in Virtualbox on Win7/64, Python 2.7/64 > > Thanks very much. Tim raised most of my concerns, but I would point out that just because you free up the memory from the Python doesn't mean it gets released back to the system. The C runtime manages its own heap, and is pretty persistent about hanging onto memory once obtained. It's not normally a problem, since most small blocks are reused. But it can get fragmented. And i have no idea how well Virtual Box maps the Linux memory map into the Windows one. -- DaveA From dwightdhutto at gmail.com Mon Sep 24 21:14:34 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 21:14:34 -0400 Subject: keeping information about players around In-Reply-To: References: <505FB849.2080201@tysdomain.com> <144ddc26-b1e0-4fad-8651-53b5b6cd100e@n7g2000pbj.googlegroups.com> <66da5330-e517-4712-a9e0-be01f0bae480@lo4g2000pbb.googlegroups.com> Message-ID: Anything else? -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From steve+comp.lang.python at pearwood.info Mon Sep 24 21:18:41 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Sep 2012 01:18:41 GMT Subject: which a is used? References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> Message-ID: <50610671$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 24 Sep 2012 16:43:24 -0700, Jayden wrote: > Dear All, > > I have a simple code as follows: > > # Begin > a = 1 > > def f(): > print a > > def g(): > a = 20 > f() > > g() > #End > > I think the results should be 20, but it is 1. Would you please tell me > why? You are expecting "dynamic scoping", Python uses "static scoping" (or lexical scoping). With lexical scoping, you can reason about the behaviour of a function by knowing only how and where it is defined. The caller is irrelevant. Since function f is defined globally, and does not have its own local variable a, it will always see the global variable a no matter where it is called. So when you call f() from inside g(), f prints 1, the global a, not 20, g's local a. While dynamic scoping has its uses, it is more tricky to use correctly. One can no longer understand the behaviour of a function just by reading the function's own code, knowing where and how it is defined. You also need to know where it is called. A function f that works perfectly when you call it from functions g, h, k, ... will suddenly misbehave (crash, or worse, behave wrongly) when called from function v because v accidentally changes some global variable that f relies on. This is especially a danger for Python, because built-in functions like len, chr, ord, print (version 3 only), and many others are all global variables. (Technically, they are in a third scope, the builtins, but that's equivalent to being global.) -- Steven From dwightdhutto at gmail.com Mon Sep 24 21:29:23 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 21:29:23 -0400 Subject: Who's laughing at my responses, and who's not? Message-ID: Been getting slammed by a few for some insignificant things, so who's laughing at me, and who takes me seriously. I don't claim to be the best, just trying to help. So who doesn't want me around? -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Mon Sep 24 21:32:56 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 21:32:56 -0400 Subject: For Counter Variable In-Reply-To: <7xtxumhpqm.fsf@ruckus.brouhaha.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> <26493369-8f41-456c-8a89-b4883e37d55c@k13g2000pbq.googlegroups.com> <7xtxumhpqm.fsf@ruckus.brouhaha.com> Message-ID: > By now I think we're in the DNFTT zone. > -- Taking a bite yourself there buddy. Hop under the bridge, and comment...it make you a troll, and you're trying to feed yourself with pile on comment from the rest of the under bridge dwellers. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From steve+comp.lang.python at pearwood.info Mon Sep 24 21:33:50 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Sep 2012 01:33:50 GMT Subject: python file API References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: <506109fe$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Sep 2012 08:14:01 +1000, Chris Angelico wrote: > Presumably the same way you reference a list element relative to > end-of-list: negative numbers. However, this starts to feel like magic > rather than attribute assignment - it's like manipulating the DOM in > JavaScript, you set an attribute and stuff happens. Sure it's legal, but > is it right? Also, it makes bounds checking awkward: > > file.pos = 42 # Okay, you're at position 42 > file.pos -= 10 # That should put you at position 32 > foo = file.pos # Presumably foo is the integer 32 > file.pos -= 100 # What should this do? > foo -= 100 # But this sets foo to the integer -68 > file.pos = foo # And this would set the file pointer 68 bytes > from end-of-file. > > I don't see it making sense for "file.pos -= 100" to suddenly put you > near the end of the file; it should either cap and put you at position > 0, or do what file.seek(-100,1) would do and throw an exception. I would expect it to throw an exception, like file.seek and like list indexing. > But > doing the exact same operation on a saved snapshot of the position and > reassigning it would then have quite different semantics in an unusual > case, while still appearing identical in the normal case. But this applies equally to file.seek and list indexing today. In neither case can you perform your own index operations outside of the file/list and expect to get the same result, for the simple and obvious reason that arithmetic doesn't perform the same bounds checking as actual seeking and indexing. -- Steven From aclark at aclark.net Mon Sep 24 21:46:14 2012 From: aclark at aclark.net (Alex Clark) Date: Mon, 24 Sep 2012 21:46:14 -0400 Subject: PIL questions: still supported? Problems on 2.7 for win? alternatives? References: Message-ID: On 2012-09-24 23:38:05 +0000, alex23 said: > On Sep 25, 6:04?am, Gelonida N wrote: >> This all does not sound very comforting. Why is there no fix on the >> official site? > > Has a bug been logged about the issue? > > The Plone community keeps a fairly up-to-date fork called Pillow, > we've had a lot of success using that locally: > > http://pypi.python.org/pypi/Pillow/ Actually, I started it for the Plone community, but have recently broadened the scope (since most of the contributions came from outside Plone). It now lives here: - https://github.com/python-imaging/Pillow If you have any trouble using it, please open a ticket here: - https://github.com/python-imaging/Pillow/issues Alex -- Alex Clark ? http://pythonpackages.com From dwightdhutto at gmail.com Mon Sep 24 21:47:04 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 21:47:04 -0400 Subject: which a is used? In-Reply-To: <50610671$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <50610671$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Sep 24, 2012 at 9:18 PM, Steven D'Aprano wrote: > On Mon, 24 Sep 2012 16:43:24 -0700, Jayden wrote: > >> Dear All, >> >> I have a simple code as follows: >> >> # Begin >> a = 1 >> >> def f(): >> print a >>Paul Rubin >> def g(): >> a = 20 >> f() >> >> g() >> #End >> >> I think the results should be 20, but it is 1. Would you please tell me >> why? > > You are expecting "dynamic scoping", Python uses "static scoping" (or > lexical scoping). With lexical scoping, you can reason about the > behavioPaul Rubin ur of a function by knowing only how and where it is defined. The > caller is irrelevant. > > Since fuPaul Rubin nction f is defined globally, and does not have its own local > variable a, it will always see the global variable a no matter where it > is called. So when you call f() from inside g(), f prints 1, the global > a, not 20, g's local a. > > While dynamic scoping has its uses, it is more tricky to use correctly. > One can no longer understand the behaviour of a function just by reading > the funcPaul Rubin tion's own code, knowing where and how it is defined. You also > need to know where it is called. A function f that works perfectly when > you call it from functions g, h, k, ... will suddenly misbehave (crash, > or worse, behave wrongly) when called from function v because v > accidentally changes some global variable that f relies on. > > This is especially a danger for Python, because built-in functions like > len, chr, ord, print (version 3 only), and many others are all global > variables. > > (Technically, they are in a third scope, the builtins, but that's > equivalent to being global.) > But within a class this is could be defined as self.x within the functions and changed, correct? class a(): def __init__(self,a): self.a = a def f(self): print self.a def g(self): self.a = 20 print self.a a = a(1) a.f() a.g() > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Mon Sep 24 21:50:56 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 21:50:56 -0400 Subject: which a is used? In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <50610671$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: But within a class this is could be defined as self.x within the functions and changed, correct? class a(): def __init__(self,a): self.a = a def f(self): print self.a def g(self): self.a = 20 print self.a a = a(1) a.f() a.g() Yielding: david at david-desktop:~$ python answer_to_email.py 1 20 david at david-desktop:~$ -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From wuwei23 at gmail.com Mon Sep 24 22:09:21 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 24 Sep 2012 19:09:21 -0700 (PDT) Subject: PIL questions: still supported? Problems on 2.7 for win? alternatives? References: Message-ID: <5f873d2b-3588-4d7b-86c5-9c721a85c655@n7g2000pbj.googlegroups.com> On Sep 25, 6:04?am, Gelonida N wrote: > So I'll probably try to install the custom binary, but would like to > know whether anybody has experience with this > build.http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil Sorry, I missed this the first time. I'm using this version successfully under Windows 7 64-bit. I've had nothing but success with extensions I've used from that site. From wuwei23 at gmail.com Mon Sep 24 22:11:37 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 24 Sep 2012 19:11:37 -0700 (PDT) Subject: PIL questions: still supported? Problems on 2.7 for win? alternatives? References: Message-ID: On Sep 25, 11:46?am, Alex Clark wrote: > Actually, I started it for the Plone community, but have recently > broadened the scope (since most of the contributions came from outside > Plone). You're a saint, thanks for taking this on. From wuwei23 at gmail.com Mon Sep 24 22:14:19 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 24 Sep 2012 19:14:19 -0700 (PDT) Subject: which a is used? References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> Message-ID: On Sep 25, 11:13?am, Dwight Hutto wrote: > bitch I honestly could not care less what you think about me, but don't use that term. This isn't a boys' club and we don't need your hurt ego driving people away from here. From steve+comp.lang.python at pearwood.info Mon Sep 24 22:28:37 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Sep 2012 02:28:37 GMT Subject: python file API References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: <506116d4$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 24 Sep 2012 15:36:20 -0700, zipher wrote: > You raise a valid point: that by abstracting the file pointer into a > position attribute you risk "de-coupling" the conceptual link between > the underlying file and your abstraction in the python interpreter I don't think this argument holds water. With the ease of writing attributes, it is more likely that people will perform file position operations directly on file.pos rather than decoupling it into a variable. Decoupling is more likely with file.seek, because it is so much more verbose to use, and you get exactly the same lack of bounds checking: py> f = open("junk", "w") # make a sample file py> f.write("abcd\n") py> f.close() py> f = open("junk") # now do decoupled seek operations py> p = f.tell() py> p += 2000 py> p -= 4000 py> p += 2 py> p += 2000 py> f.seek(p) py> f.read(1) 'c' But really, who does such a sequence of arithmetic operations on the file pointer without intervening reads or writes? We're arguing about something that almost never happens. By the way, the implementation of this is probably trivial in Python 2.x. Untested: class MyFile(file): @property def pos(self): return self.tell() @pos.setter def pos(self, p): if p < 0: self.seek(p, 2) else: self.seek(p) You could even use a magic sentinel to mean "see to EOF", say, None. if p is None: self.seek(0, 2) although I don't know if I like that. -- Steven From steve+comp.lang.python at pearwood.info Mon Sep 24 22:29:48 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Sep 2012 02:29:48 GMT Subject: keeping information about players around References: <505FB849.2080201@tysdomain.com> Message-ID: <5061171c$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Sep 2012 08:19:34 +1000, Chris Angelico wrote: > On Tue, Sep 25, 2012 at 7:14 AM, Dwight Hutto > wrote: >> Also, If this is a browser app I'd go with phpmyadmin, and MySQL >> >> If a tkinter/wxpython/etc app, then maybe sqlite. > > Out of curiosity, why? MySQL isn't magically better for everything where > data ends up displayed in a web browser. Unless you're planning to also > reference this database from some other language, it's going to make > little difference what backend you use; and even if you are using > multiple languages, it's usually not difficult to find overlap. For a desktop application, you can't expect the application user to have set up MySQL or Postgresql first, so you have to use something like sqlite. For web applications, you're probably expecting (or at least hoping for) tens of thousands of users a day, and sqlite probably won't cut it. If your web app is only used by you, then you might not care. I think it is perfectly reasonable to assume a web app and a desktop app might use different backends. -- Steven From dreamingforward at gmail.com Mon Sep 24 22:32:42 2012 From: dreamingforward at gmail.com (Mark Adam) Date: Mon, 24 Sep 2012 21:32:42 -0500 Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin wrote: > There are many situations where a little bit of attribute access magic is a > good thing. However, operations that involve the underlying OS and that are > prone to raising exceptions even in bug free code should not be performed > implicitly like this. I find the following a little cryptic: > try: > f.pos = 256 > except IOError: > print('Unseekable file') Well it might be that the coupling between the python interpreter and the operating system should be more direct and there should be a special exception class that bypasses the normal overhead in the CPython implementation so that error can be caught in the code without breaking syntax. But I don't think I'm ready to argue that point.... markj From dwightdhutto at gmail.com Mon Sep 24 22:37:14 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 24 Sep 2012 22:37:14 -0400 Subject: which a is used? In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> Message-ID: > I honestly could not care less what you think about me, but don't use > that term. This isn't a boys' club and we don't need your hurt ego > driving people away from here. OOOOOOOOOHHHHH. stirrin up shit and can't stand the smell. Turn and switch technique. "You're so vulgar, and I wasn't."Go get a clue ho, and then you can gumshoe it up the last crack alley on the left, and suck till my nut hair tickles your tonsils. > -- > http://mail.python.org/mailman/listinfo/python-list -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From huhai1005 at gmail.com Mon Sep 24 22:51:39 2012 From: huhai1005 at gmail.com (hai1004 hu) Date: Mon, 24 Sep 2012 19:51:39 -0700 (PDT) Subject: =?UTF-8?B?VmVyeSBDaGVhcCBBaXIgSm9yZGFuIFNob2Vz77yId3d3Lm5pa2UtYmxhY2suY29t77yJ?= Message-ID: wholesale jordan shoes ?www.nike-black.com? cheap jordan shoes for sale?www.nike-black.com? cheap authentic jordan shoes?www.nike-black.com? cheap jordan shoes online?www.nike-black.com? cheap jordan shoes paypal?www.nike-black.com? cheap jordan shoes for kids?www.nike-black.com? cheap jordan shoes free shipping?www.nike-black.com? cheap jordan nike shoes?www.nike-black.com? cheap authentic air jordan?www.nike-black.com? cheap air jordan shoes?www.nike-black.com? cheap jordans?www.nike-black.com? cheap air jordan 2011?www.nike-black.com) wholesale jordan shoes ?www.nike-black.com? cheap jordan shoes for sale?www.nike-black.com? cheap authentic jordan shoes?www.nike-black.com? cheap jordan shoes online?www.nike-black.com? cheap jordan shoes paypal?www.nike-black.com? cheap jordan shoes for kids?www.nike-black.com? cheap jordan shoes free shipping?www.nike-black.com? cheap jordan nike shoes?www.nike-black.com? cheap authentic air jordan?www.nike-black.com? cheap air jordan shoes?www.nike-black.com? cheap jordans?www.nike-black.com? cheap air jordan 2011?www.nike-black.com? cheap air jordan clothes?www.nike-black.com? cheap nike air jordan?www.nike-black.com? cheap air jordan fusion?www.nike-black.com? cheap air jordan heels?www.nike-black.com? cheap jordan shoes online?www.nike-black.com? cheap jordan shoes?www.nike-black.com? cheap jordan shoes for sale?www.nike-black.com? cheap air jordan?www.nike-black.com? cheap jordan sneakers?www.nike-black.com? cheap jordan nike shoes?www.nike-black.com? cheap jordan 2011?www.nike-black.com? cheap jordan website?www.nike-black.com? wholesale air jordan shoes?www.nike-black.com? cheap wholesale air jordan shoes?www.nike-black.com? cheap air jordan shoes for sale?www.nike-black.com? cheap jordan shoes?www.nike-black.com? cheap nike air jordan?www.nike-black.com? cheap air jordan shoes free shipping?www.nike-black.com? cheap air jordan shoes for men?www.nike-black.com? cheap air jordan basketball shoes?www.nike-black.com? website: http://www.nike-black.com k.com? cheap air jordan clothes?www.nike-black.com? cheap nike air jordan?www.nike-black.com? cheap air jordan fusion?www.nike-black.com? cheap air jordan heels?www.nike-black.com? cheap jordan shoes online?www.nike-black.com? cheap jordan shoes?www.nike-black.com? cheap jordan shoes for sale?www.nike-black.com? cheap air jordan?www.nike-black.com? cheap jordan sneakers?www.nike-black.com? cheap jordan nike shoes?www.nike-black.com? cheap jordan 2011?www.nike-black.com? cheap jordan website?www.nike-black.com? wholesale air jordan shoes?www.nike-black.com? cheap wholesale air jordan shoes?www.nike-black.com? cheap air jordan shoes for sale?www.nike-black.com? cheap jordan shoes?www.nike-black.com? cheap nike air jordan?www.nike-black.com? cheap air jordan shoes free shipping?www.nike-black.com? cheap air jordan shoes for men?www.nike-black.com? cheap air jordan basketball shoes?www.nike-black.com? website: http://www.nike-black.com From suziemrezitti at gmail.com Mon Sep 24 23:35:44 2012 From: suziemrezitti at gmail.com (Suzi Mrezutttii) Date: Mon, 24 Sep 2012 20:35:44 -0700 (PDT) Subject: "9/11 Missing Links" is the video that Jews do not want you to see! Message-ID: Google and watch "9/11 Missing Links" before Jews remove it from youtube anytime now! http://joozhatetruth.blogspot.com/ From hamilton at nothere.com Mon Sep 24 23:47:15 2012 From: hamilton at nothere.com (hamilton) Date: Mon, 24 Sep 2012 21:47:15 -0600 Subject: "9/11 Missing Links" is the video that Jews do not want you to see! In-Reply-To: References: Message-ID: On 9/24/2012 9:35 PM, Suzi Mrezutttii wrote: > Google and watch "9/11 Missing Links" before Jews remove it from > youtube anytime now! > > > > Hey dude, Nice name, "a boy named sue" !!! From timr at probo.com Tue Sep 25 00:09:37 2012 From: timr at probo.com (Tim Roberts) Date: Mon, 24 Sep 2012 21:09:37 -0700 Subject: How to limit CPU usage in Python References: <7xpq5d7j5e.fsf@ruckus.brouhaha.com> Message-ID: <0ib2689jpg2d11nlq09sfe1uv25mgbcbv0@4ax.com> Paul Rubin wrote: > >Tim Roberts: reasons to want to do this might involve a shared host >where excessive cpu usage affects other users; That's what priorities are for. >...or a computer with >limited power consumption, where prolonged high cpu activity causes >thermal or other problems. OK, I grant that. However, statistically speaking, it is much more likely that the OP merely has a misunderstanding. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From junkshops at gmail.com Tue Sep 25 00:21:05 2012 From: junkshops at gmail.com (Junkshops) Date: Mon, 24 Sep 2012 21:21:05 -0700 Subject: Memory usage per top 10x usage per heapy In-Reply-To: <5061056F.6080702@davea.name> References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5061056F.6080702@davea.name> Message-ID: <50613131.6030102@gmail.com> > Just curious; which is it, two million lines, or half a million bytes? I have, in fact, this very afternoon, invented a means of writing a carriage return character using only 2 bits of information. I am prepared to sell licenses to this revolutionary technology for the low price of $29.95 plus tax. Sorry, that should've been a 500Mb, 2M line file. > which machine is 2gb, the Windows machine, or the VM? VM. Winders is 4gb. > ...but I would point out that just because > you free up the memory from the Python doesn't mean it gets released > back to the system. The C runtime manages its own heap, and is pretty > persistent about hanging onto memory once obtained. It's not normally a > problem, since most small blocks are reused. But it can get > fragmented. And i have no idea how well Virtual Box maps the Linux > memory map into the Windows one. Right, I understand that - but what's confusing me is that, given the memory use is (I assume) monotonically increasing, the code should never use more than what's reported by heapy once all the data is loaded into memory, given that memory released by the code to the Python runtime is reused. To the best of my ability to tell I'm not storing anything I shouldn't, so the only thing I can think of is that all the object creation and destruction, for some reason, it preventing reuse of memory. I'm at a bit of a loss regarding what to try next. Cheers, MrsE On 9/24/2012 6:14 PM, Dave Angel wrote: > On 09/24/2012 05:59 PM, MrsEntity wrote: >> Hi all, >> >> I'm working on some code that parses a 500kb, 2M line file > Just curious; which is it, two million lines, or half a million bytes? > >> line by line and saves, per line, some derived strings into various data structures. I thus expect that memory use should monotonically increase. Currently, the program is taking up so much memory - even on 1/2 sized files - that on 2GB machine > which machine is 2gb, the Windows machine, or the VM? You could get > thrashing at either level. > >> I'm thrashing swap. What's strange is that heapy (http://guppy-pe.sourceforge.net/) is showing that the code uses about 10x less memory than reported by top, and the heapy data seems consistent with what I was expecting based on the objects the code stores. I tried using memory_profiler (http://pypi.python.org/pypi/memory_profiler) but it didn't really provide any illuminating information. The code does create and discard a number of objects per line of the file, but they should not be stored anywhere, and heapy seems to confirm that. So, my questions are: >> >> 1) For those of you kind enough to help me figure out what's going on, what additional data would you like? I didn't want swamp everyone with the code and heapy/memory_profiler output but I can do so if it's valuable. >> 2) How can I diagnose (and hopefully fix) what's causing the massive memory usage when it appears, from heapy, that the code is performing reasonably? >> >> Specs: Ubuntu 12.04 in Virtualbox on Win7/64, Python 2.7/64 >> >> Thanks very much. > Tim raised most of my concerns, but I would point out that just because > you free up the memory from the Python doesn't mean it gets released > back to the system. The C runtime manages its own heap, and is pretty > persistent about hanging onto memory once obtained. It's not normally a > problem, since most small blocks are reused. But it can get > fragmented. And i have no idea how well Virtual Box maps the Linux > memory map into the Windows one. > > > From timr at probo.com Tue Sep 25 00:28:50 2012 From: timr at probo.com (Tim Roberts) Date: Mon, 24 Sep 2012 21:28:50 -0700 Subject: Who's laughing at my responses, and who's not? References: Message-ID: <5bc2681o43dhv5p13v71jqodtnokbq9mko@4ax.com> Dwight Hutto wrote: > >Been getting slammed by a few for some insignificant things, so who's >laughing at me, and who takes me seriously. I don't claim to be the >best, just trying to help. > >So who doesn't want me around? Who cares? There are probably hundreds of thousands of people reading this forum. A few of those people probably don't like you. So what? Illegitemi non carborondum -- don't let the bastards wear you down. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From dwightdhutto at gmail.com Tue Sep 25 00:38:23 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 25 Sep 2012 00:38:23 -0400 Subject: Java singletonMap in Python In-Reply-To: References: <505fc372$0$1612$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Sep 25, 2012 at 12:29 AM, Dennis Lee Bieber wrote: > On Mon, 24 Sep 2012 20:28:14 +0100, Mark Lawrence > declaimed the following in > gmane.comp.python.general: > >> >> Thank goodness for that, I'd assumed that I'd missed something blatantly >> obvious. There are two chances of something like this getting into the >> standard library, zero or none. I think in a way that's a great pity as >> I'm sure that the Python devs would enjoy supporting the little feller >> with code such as this http://tinyurl.com/9v7d7ld :) > > Oh, the chance /might/ be a bit higher... On par with winning the > jackpot in one of those multi-state lotteries (because you'd have to > donate the entire jackpot to Python.org to persuade them to add a "do > nothing" package ) It's called import time time.sleep(x) -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Tue Sep 25 00:43:18 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 25 Sep 2012 00:43:18 -0400 Subject: Who's laughing at my responses, and who's not? In-Reply-To: <5bc2681o43dhv5p13v71jqodtnokbq9mko@4ax.com> References: <5bc2681o43dhv5p13v71jqodtnokbq9mko@4ax.com> Message-ID: It sounds pretentious, but over the past several days, I've been slammed on every post almost. All because of an argument over me not posting a little context in a conversation, that seemed short and chatty. I was just wondering, if it's just them, or if it's my netiquette. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From tjreedy at udel.edu Tue Sep 25 00:57:23 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 25 Sep 2012 00:57:23 -0400 Subject: Who's laughing at my responses, and who's not? In-Reply-To: References: Message-ID: I am not laughing. Looking back, some of your responses seem sensible. I mostly skip over single word responses, and others that seems content free, whether from you or others. -- Terry Jan Reedy From tejas.tank.mca at gmail.com Tue Sep 25 00:57:56 2012 From: tejas.tank.mca at gmail.com (tejas.tank.mca at gmail.com) Date: Mon, 24 Sep 2012 21:57:56 -0700 (PDT) Subject: PHP vs. Python In-Reply-To: <1103753016.780533.137480@f14g2000cwb.googlegroups.com> References: <1103753016.780533.137480@f14g2000cwb.googlegroups.com> Message-ID: <22c32aaa-104a-46bf-b9a6-347260e6f84a@googlegroups.com> On Thursday, 23 December 2004 03:33:36 UTC+5:30, (unknown) wrote: > Anyone know which is faster? I'm a PHP programmer but considering > getting into Python ... did searches on Google but didn't turn much up > on this. > > Thanks! > Stephen Here some helpful gudance. http://hentenaar.com/serendipity/index.php?/archives/27-Benchmark-PHP-vs.-Python-vs.-Perl-vs.-Ruby.html From tjreedy at udel.edu Tue Sep 25 01:05:09 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 25 Sep 2012 01:05:09 -0400 Subject: which a is used? In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> Message-ID: Revising my answer to your other post. On 9/24/2012 9:13 PM, Dwight Hutto wrote: > Anything else bitch, take time to think about it. This is completely bizarre, and uncalled for as an apparent response to Alex. Your next response is too dirty to read, let alone quote. Please desist. If necessary, learn to wait a few minutes before hitting send. -- Terry Jan Reedy From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Sep 25 01:06:28 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 25 Sep 2012 07:06:28 +0200 Subject: which a is used? In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <50610671$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 25.09.2012 03:47 schrieb Dwight Hutto: > But within a class this is could be defined as self.x within the > functions and changed, correct? > > > class a(): > def __init__(self,a): > self.a = a > > def f(self): > print self.a > > def g(self): > self.a = 20 > print self.a > > > a = a(1) > a.f() > a.g() Yes - this is a different situation. Here, the "self" referred to is the same in all cases (the "a" from top level), and so self.a can be used consistently as well. Thomas From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Sep 25 01:06:53 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 25 Sep 2012 07:06:53 +0200 Subject: which a is used? In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> Message-ID: Am 25.09.2012 03:13 schrieb Dwight Hutto: > Anything else bitch, take time to think about it. And you wonder if people don't like you because of your language? Thomas From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Sep 25 01:07:45 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 25 Sep 2012 07:07:45 +0200 Subject: which a is used? In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> Message-ID: Am 25.09.2012 04:37 schrieb Dwight Hutto: >> I honestly could not care less what you think about me, but don't use >> that term. This isn't a boys' club and we don't need your hurt ego >> driving people away from here. > > OOOOOOOOOHHHHH. stirrin up shit and can't stand the smell. Where did he so? Thomas From tyler at tysdomain.com Tue Sep 25 01:07:46 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Mon, 24 Sep 2012 23:07:46 -0600 Subject: Who's laughing at my responses, and who's not? In-Reply-To: References: <5bc2681o43dhv5p13v71jqodtnokbq9mko@4ax.com> Message-ID: <50613C22.3010502@tysdomain.com> On 9/24/2012 10:43 PM, Dwight Hutto wrote: > It sounds pretentious, but over the past several days, I've been > slammed on every post almost. All because of an argument over me not > posting a little context in a conversation, that seemed short and > chatty. > > I was just wondering, if it's just them, or if it's my netiquette. > > I think you'd have a leg to stand on here if you didn't start cursing at anyone who got on your wrong side. It wasn't really an issue until you threw that > up. Granted you did take your cursing off list finally, but you still continued (and as of about 2 hours ago) continue to post trash like you did in response > to Alix's message. If you want to argue something, by all means argue. But there's no need to resort to comments like you've made. -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From tjreedy at udel.edu Tue Sep 25 01:08:02 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 25 Sep 2012 01:08:02 -0400 Subject: Who's laughing at my responses, and who's not? In-Reply-To: References: <5bc2681o43dhv5p13v71jqodtnokbq9mko@4ax.com> Message-ID: On 9/25/2012 12:43 AM, Dwight Hutto wrote: > It sounds pretentious, but over the past several days, I've been > slammed on every post almost. All because of an argument over me not > posting a little context in a conversation, that seemed short and > chatty. > > I was just wondering, if it's just them, or if it's my netiquette. A 1000 line post with a one line response is not polite. Context free posts are disconcerting, but easier to ignore. Keep at least one sentence of context and cut the potty mouth stuff. -- Terry Jan Reedy From dwightdhutto at gmail.com Tue Sep 25 01:19:05 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 25 Sep 2012 01:19:05 -0400 Subject: Who's laughing at my responses, and who's not? In-Reply-To: References: <5bc2681o43dhv5p13v71jqodtnokbq9mko@4ax.com> Message-ID: > context and cut the potty mouth stuff. It was meant as a little shop talk, but I forgot there were ladies here as well. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Tue Sep 25 01:22:15 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 25 Sep 2012 01:22:15 -0400 Subject: which a is used? In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> Message-ID: On Tue, Sep 25, 2012 at 1:06 AM, Thomas Rachel wrote: > Am 25.09.2012 03:13 schrieb Dwight Hutto: > > >> Anything else bitch, take time to think about it. > > > And you wonder if people don't like you because of your language? > No, not really. If you wanna talk shit, I can reflect that, and if you wanna talk politely I can reflect that. I go t attacked first., and project managers don't get shoved around, they listen, respond, and if wrong correct themselves, if not, they slam back , or their position gets taken. > > Thomas > > -- > http://mail.python.org/mailman/listinfo/python-list -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From ethan at stoneleaf.us Tue Sep 25 01:25:02 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 24 Sep 2012 22:25:02 -0700 Subject: Who's laughing at my responses, and who's not? In-Reply-To: References: <5bc2681o43dhv5p13v71jqodtnokbq9mko@4ax.com> Message-ID: <5061402E.8080706@stoneleaf.us> Dwight Hutto wrote: >> context and cut the potty mouth stuff. > It was meant as a little shop talk, but I forgot there were ladies here as well. Not only ladies, but gentlemen. Foul-mouthed "shop talk" is not necessary to teach Python. Practice some self-control, or at least self-editing. ~Ethan~ From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Sep 25 01:25:48 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 25 Sep 2012 07:25:48 +0200 Subject: python file API In-Reply-To: <506116d4$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> <506116d4$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 25.09.2012 04:28 schrieb Steven D'Aprano: > By the way, the implementation of this is probably trivial in Python 2.x. > Untested: > > class MyFile(file): > @property > def pos(self): > return self.tell() > @pos.setter > def pos(self, p): > if p< 0: > self.seek(p, 2) > else: > self.seek(p) > > You could even use a magic sentinel to mean "see to EOF", say, None. > > if p is None: > self.seek(0, 2) > > although I don't know if I like that. The whole concept is incomplete at one place: self.seek(10, 2) seeks beyond EOF, potentially creating a sparse file. This is a thing you cannot achieve. But the idea is great. I'd suggest to have another property: [...] @pos.setter def pos(self, p): self.seek(p) @property def eofpos(self): # to be consistent return self.tell() @eofpos.setter def eofpos(self, p): self.seek(p, 2) Another option could be a special descriptor which can be used as well for relative seeking: class FilePositionDesc(object): def __init__(self): pass def __get__(self, instance, owner): return FilePosition(self) def __set__(self, value): self.seek(value) class FilePosition(object): def __init__(self, file): self.file = file def __iadd__(self, offset): self.file.seek(offset, 1) def __isub__(self, offset): self.file.seek(-offset, 1) class MyFile(file): pos = FilePositionDesc() [...] Stop. This could be handled with a property as well. Besides, this breaks some other expectations to the pos. So let's introduce a 3rd property named relpos: class FilePosition(object): def __init__(self, file): self.file = file self.seekoffset = 0 def __iadd__(self, offset): self.seekoffset += offset def __isub__(self, offset): self.seekoffset -= offset def __int__(self): return self.file.tell() + self.seekoffset class MyFile(file): @property def relpos(self): return FilePosition(self) # from above @relpos.setter def relpos(self, ofs): try: o = ofs.seekoffset # is it a FilePosition? except AttributeError: self.seek(ofs, 1) # no, but ofs can be an int as well else: self.seek(o, 1) # yes, it is Thomas From dwightdhutto at gmail.com Tue Sep 25 01:30:54 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 25 Sep 2012 01:30:54 -0400 Subject: which a is used? In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> Message-ID: >> OOOOOOOOOHHHHH. stirrin up shit and can't stand the smell. > > > Where did he so? > You'd have to read the other posts. And remember that some of these names are A.K.A.'s, they ask respond, and befriend another name through another proxy. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From ethan at stoneleaf.us Tue Sep 25 01:31:36 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 24 Sep 2012 22:31:36 -0700 Subject: Who's laughing at my responses, and who's not? In-Reply-To: References: Message-ID: <506141B8.20602@stoneleaf.us> Dwight Hutto wrote: > Been getting slammed by a few for some insignificant things, so who's > laughing at me, and who takes me seriously. I don't claim to be the > best, just trying to help. Mis-interpreting posts is not insignificant. Being rude is not insignificant. Refusing to see these things, and instead blaming everyone else, is not insignificant. Being wrong is not fun, but learn from it instead of saying, "I'm not wrong, you just don't understand!" ~Ethan~ From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Sep 25 01:32:31 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 25 Sep 2012 07:32:31 +0200 Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: Am 25.09.2012 00:37 schrieb Ian Kelly: > On Mon, Sep 24, 2012 at 4:14 PM, Chris Angelico wrote: >> file.pos = 42 # Okay, you're at position 42 >> file.pos -= 10 # That should put you at position 32 >> foo = file.pos # Presumably foo is the integer 32 >> file.pos -= 100 # What should this do? > > Since ints are immutable, the language specifies that it should be the > equivalent of "file.pos = file.pos - 100", so it should set the file > pointer to 68 bytes before EOF. But this is not a "real int", it has a special use. So I don't think it is absolutely required to behave like an int. This reminds me of some special purpose registers in embedded programming, where bits can only be set by hardware and are cleared by the application by writing 1 to them. Or some bit setting registers, like on ATxmega: OUT = 0x10 sets bit 7 and clears all others, OUTSET = 0x10 only sets bit 7, OUTTGL = 0x10 toggles it and OUTCLR = 0x10 clears it. If this behaviour is documented properly enough, it is quite OK, IMHO. Thomas From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Sep 25 01:39:23 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 25 Sep 2012 07:39:23 +0200 Subject: which a is used? In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> Message-ID: Am 25.09.2012 07:22 schrieb Dwight Hutto: > No, not really. If you wanna talk shit, I can reflect that, and if you > wanna talk politely I can reflect that. I go t attacked first., But not in this thread. Some people read only selectively and see only your verbal assaults, without noticing that they refer to. If you was really insulted, you should answer to these insults in their thread and not in a different one. Thomas From levinie001 at gmail.com Tue Sep 25 01:43:17 2012 From: levinie001 at gmail.com (Levi Nie) Date: Tue, 25 Sep 2012 13:43:17 +0800 Subject: why do this program not fullscreen? Message-ID: the code: import wx app=wx.App() win=wx.Frame(None) win.ShowFullScreen() app.MainLoop() -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Tue Sep 25 01:52:48 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Tue, 25 Sep 2012 01:52:48 -0400 Subject: Who's laughing at my responses, and who's not? In-Reply-To: <5061402E.8080706@stoneleaf.us> References: <5bc2681o43dhv5p13v71jqodtnokbq9mko@4ax.com> <5061402E.8080706@stoneleaf.us> Message-ID: On Tue, Sep 25, 2012 at 1:25 AM, Ethan Furman wrote: > Dwight Hutto wrote: >>> >>> context and cut the potty mouth stuff. >> >> It was meant as a little shop talk, but I forgot there were ladies here as >> well. > > > Not only ladies, but gentlemen. Foul-mouthed "shop talk" is not necessary > to teach Python. Practice some self-control, or at least self-editing. > It's a little guy talk, and most seem to be guys. A little, "hey buddy, this seems like like bullshit", seems ok around here, and it's a first amendment. > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Sep 25 01:53:55 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 25 Sep 2012 07:53:55 +0200 Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> Message-ID: Am 25.09.2012 01:39 schrieb Dwight Hutto: > It's not the simpler solution I'm referring to, it's the fact that if > you're learning, then you should be able to design the built-in, not > just use it. In some simpler cases you are right here. But the fact that you are able to design it doesn't necessarily mean that you should actually use your self-designed version. But what you post suggests is important as well: if using the neat fancy built-in simplifications, you should always be aware what overhead they imply. An example: Let l be a big, big list. for i in : if i in l: This looks neat and simple and doesn't look as expensive as it really is. If l is converted to a set beforehand, it nearly looks the same, but it is simpler. So even if you use builtins, be aware what they do. > You don't always know all the built-ins, so the builtin is simpler, > but knowing how to code it yourself is the priority of learning to > code in a higher level language, which should be simpler to the user > of python. When learning Python, it often happend me to re-inven the wheel. But as soon as I saw the presence of something I re-wrote, I skipped my re-written version and used the built-in. Thomas From kushaldas at gmail.com Tue Sep 25 02:02:25 2012 From: kushaldas at gmail.com (Kushal Das) Date: Tue, 25 Sep 2012 11:32:25 +0530 Subject: Who's laughing at my responses, and who's not? In-Reply-To: References: <5bc2681o43dhv5p13v71jqodtnokbq9mko@4ax.com> <5061402E.8080706@stoneleaf.us> Message-ID: On Tue, Sep 25, 2012 at 11:22 AM, Dwight Hutto wrote: > It's a little guy talk, and most seem to be guys. A little, "hey > buddy, this seems like like bullshit", seems ok around here, and it's > a first amendment. First amendment does not apply to all the international people here. Everyone should check twice what they are writing in the list. Kushal -- http://fedoraproject.org http://kushaldas.in From ulrich.eckhardt at dominolaser.com Tue Sep 25 02:22:05 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 25 Sep 2012 08:22:05 +0200 Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> Message-ID: Am 24.09.2012 23:49, schrieb Dave Angel: > And what approach would you use for positioning relative to > end-of-file? That's currently done with an optional second > parameter to seek() method. Negative indices. ;) Uli From nad at acm.org Tue Sep 25 02:33:17 2012 From: nad at acm.org (Ned Deily) Date: Mon, 24 Sep 2012 23:33:17 -0700 Subject: Who's laughing at my responses, and who's not? References: <5bc2681o43dhv5p13v71jqodtnokbq9mko@4ax.com> <5061402E.8080706@stoneleaf.us> Message-ID: In article , Dwight Hutto wrote: > It's a little guy talk, and most seem to be guys. A little, "hey > buddy, this seems like like bullshit", seems ok around here, and it's > a first amendment. It's not OK around here. "Spirited" discussion is fine and to be expected but the Python community is *very* serious about mutual respect and respecting diversity. If you want to be taken seriously here, please keep that in mind. http://www.python.org/community/diversity/ -- Ned Deily, nad at acm.org From breamoreboy at yahoo.co.uk Tue Sep 25 03:27:21 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Sep 2012 08:27:21 +0100 Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: On 25/09/2012 03:32, Mark Adam wrote: > On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin > wrote: >> There are many situations where a little bit of attribute access magic is a >> good thing. However, operations that involve the underlying OS and that are >> prone to raising exceptions even in bug free code should not be performed >> implicitly like this. I find the following a little cryptic: >> try: >> f.pos = 256 >> except IOError: >> print('Unseekable file') > > Well it might be that the coupling between the python interpreter and > the operating system should be more direct and there should be a > special exception class that bypasses the normal overhead in the > CPython implementation so that error can be caught in the code without > breaking syntax. But I don't think I'm ready to argue that point.... > > markj > Something along these lines http://docs.python.org/dev/whatsnew/3.3.html#pep-3151-reworking-the-os-and-io-exception-hierarchy ? -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Tue Sep 25 03:28:59 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Sep 2012 07:28:59 GMT Subject: python file API References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> <506116d4$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50615d3b$0$29997$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Sep 2012 07:25:48 +0200, Thomas Rachel wrote: > Am 25.09.2012 04:28 schrieb Steven D'Aprano: > >> By the way, the implementation of this is probably trivial in Python >> 2.x. Untested: >> >> class MyFile(file): >> @property >> def pos(self): >> return self.tell() >> @pos.setter >> def pos(self, p): >> if p< 0: >> self.seek(p, 2) >> else: >> self.seek(p) >> >> You could even use a magic sentinel to mean "see to EOF", say, None. >> >> if p is None: >> self.seek(0, 2) >> >> although I don't know if I like that. > > The whole concept is incomplete at one place: self.seek(10, 2) seeks > beyond EOF, potentially creating a sparse file. This is a thing you > cannot achieve. On the contrary, since the pos attribute is just a wrapper around seek, you can seek beyond EOF easily: f.pos = None f.pos += 10 But for anything but the most trivial usage, I would recommend sticking to the seek method. The problem with this idea is that the seek method takes up to three arguments (the file being operated on, the position, and the mode), and attribute syntax can only take two (the file, the position, e.g.: file.pos = position). So either there are cases that file.pos cannot handle (and so we need to keep tell/seek around, which leaves file.pos redundant), or we need multiple attributes, one for each mode), or we build a complicated, inconvenient API using special data types instead of plain integers. So all up, I'm -1 on trying to replace the tell/seek API, and -0 on adding a second, redundant API. Wait, there is another alternative: tuple arguments: f.pos = (where, whence) being the equivalent to seek(where, whence). At this point you just save two characters "f.pos=a,b" vs "f.seek(a,b)" so it simply isn't worth it for such a trivial benefit. -- Steven From info at egenix.com Tue Sep 25 03:36:08 2012 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 25 Sep 2012 09:36:08 +0200 Subject: ANN: eGenix mxODBC 3.2.1 - Python ODBC Database Interface Message-ID: <50615EE8.1090307@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC Python ODBC Database Interface Version 3.2.1 mxODBC is our commercially supported Python extension providing ODBC database connectivity to Python applications on Windows, Mac OS X, Unix and BSD platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-3.2.1-GA.html ________________________________________________________________________ INTRODUCTION mxODBC provides an easy-to-use, high-performance, reliable and robust Python interface to ODBC compatible databases such as MS SQL Server, MS Access, Oracle Database, IBM DB2 and Informix , Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more: http://www.egenix.com/products/python/mxODBC/ The "eGenix mxODBC - Python ODBC Database Interface" product is a commercial extension to our open-source eGenix mx Base Distribution: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS The 3.2.1 release of our mxODBC is the latest patch level release of our popular Python ODBC Interface. In this release, we've included the following the following enhancements and fixes: Feature Enhancements -------------------- * The next SQLAlchemy release will be fully compatible with mxODBC 3.2.1. Many thanks go to Michael Bayer for working with us to make this happen. Driver Compatibility Enhancements --------------------------------- * Added support for returning SQL Server TIME columns as time value instead of as string. * Added a work-around to prevent truncation warnings with the SQL Server ODBC driver when using .executemany(..., direct=1). mxODBC 3.2 was released on 2012-08-28. These are the highlights of the new release: mxODBC 3.2 Feature Highlights ----------------------------- * Switched to unixODBC 2.3.1+ API: mxODBC is now compiled against unixODBC 2.3.1, which finally removes the problems with the ABI change between 2.2 and 2.3 by switching to a new library version (libodbc.so.2). * mxODBC connection objects can now be used as context managers to implicitly commit/rollback transactions. * mxODBC cursor objects can now be used as context managers to implicitly close the cursor when leaving the block (regardless of whether an exception was raised or not) * mxODBC added support for adjustable .paramstyles. Both 'qmark' (default) and 'named' styles are supported and can be set on connections and cursors. The 'named' style allows easier porting of e.g. Oracle native interface code to mxODBC. * mxODBC now supports a writable connection.autocommit attribute to easily turn on/off the connection's auto commit mode. * mxODBC added support for adjustable TIMESTAMP precision via the new connection/cursor.timestampresolution attribute. * mxODBC will round to nearest nanosecond fraction instead of truncating the value. This will result in fewer conversion errors due to floating point second values. * mxODBC's connect APIs Connect() and DriverConnect() support setting connection options prior to connecting to the database via a new connection_options parameter. This allows enabling e.g. the MARS feature in SQL Server Native Client. * The connection.cursor() constructor now has a new cursor_options parameters which allows configuring the cursor with a set of cursor options. * The .scroll() method supports far more ODBC drivers than before. * Updated the SQL lookup object to include more ODBC SQL parameter codes, including special ones for SQL Server and IBM DB2. * mx.ODBC.Manager will now prefer unixODBC over iODBC. Previous mxODBC releases used the order iODBC, unixODBC, DataDirect when looking for a suitable ODBC manager on Unix platforms. unixODBC is more widely supported nowadays and provides better Unicode support than iODBC. For the full set of features mxODBC has to offer, please see: http://www.egenix.com/products/python/mxODBC/#Features mxODBC 3.2 Driver Compatibility Enhancements -------------------------------------------- * Added work-around for Oracle Instance Client to prevent use of direct execution. cursor.executedirect() will still work, but won't actually use direct execution with the Oracle driver. * Added work-around for Oracle Instant Client to prevent segfaults in the driver when querying the cursor.rowcount or cursor.rownumber. * Added check to make sure that Python type binding mode is not used with Oracle Instance Client as this can cause segfaults with the driver and generally doesn't work. * Added a work-around to have the IBM DB2 driver return correct .rowcount values. * Improved Sybase ASE driver compatibility: this only supports Python type binding, which is now enabled per default. * Added work-around for PostgreSQL driver, which doesn't support scrollable cursors. * Add support for MS SQL Server ODBC Driver 1.0 for Linux to mxODBC * Improved compatibility of the mxODBC native Unicode string format handling with Unix ODBC drivers when running UCS4 builds of Python. * mxODBC 3.2 now always uses direct execution with the FreeTDS ODBC driver. This results in better compatibility with SQL Server and faster execution across the board. * Add work-around to have FreeTDS work with 64-bit integers outside the 32-bit signed integer range. * FreeTDS' .rowcount attribute gave misleading values for SELECTs. This now always returns -1 (until they hopefully fix the driver to return usable data). For the full set of changes please check the mxODBC change log: http://www.egenix.com/products/python/mxODBC/changelog.html mxODBC Editions --------------- mxODBC is available in these three editions: * The low-cost Standard Edition which provides data connectivity to a single database type, e.g. just MS SQL Server. * The Professional Edition, which gives full access to all mxODBC features. * The Product Development Edition, which allows including mxODBC in applications you develop. Compared to mxODBC 3.0, we have simplified our license terms to clarify the situation on multi-core and virtual machines. In most cases, you no longer need to purchase more than one license per processor or virtual machine, scaling down the overall license costs significantly compared to earlier mxODBC releases. For a complete overview of the new editions, please see the product page. http://www.egenix.com/products/python/mxODBC/#mxODBCEditions ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/mxODBC/ In order to use the eGenix mxODBC package you will first need to install the eGenix mx Base package: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ UPGRADING Users are encouraged to upgrade to this latest mxODBC release to benefit from the new features and updated ODBC driver support. We have taken special care, not to introduce backwards incompatible changes, making the upgrade experience as smooth as possible. Customers who have purchased mxODBC 3.2 license can continue to use their licenses with this patch level release. Customers who have purchased mxODBC 2.x, 3.0 or 3.1 licenses, can benefit from upgrade discounts. We will give out 20% discount coupons going from mxODBC 2.x to 3.2 and 50% coupons for upgrades from mxODBC 3.x to 3.2. After upgrade, use of the original license from which you upgraded is no longer permitted. Please contact the eGenix.com Sales Team at sales at egenix.com with your existing license serials for details for an upgrade discount coupon. If you want to try the new release before purchace, you can request 30-day evaluation licenses by visiting our web-site http://www.egenix.com/products/python/mxODBC/#Evaluation or by writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. _______________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 25 2012) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2012-10-29: PyCon DE 2012, Leipzig, Germany ... 34 days to go 2012-10-23: Python Meeting Duesseldorf ... 28 days to go 2012-09-18: Released mxODBC Zope DA 2.1.0 ... http://egenix.com/go32 2012-08-28: Released mxODBC 3.2.0 ... http://egenix.com/go31 eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From breamoreboy at yahoo.co.uk Tue Sep 25 03:44:18 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Sep 2012 08:44:18 +0100 Subject: which a is used? In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> Message-ID: On 25/09/2012 06:07, Thomas Rachel wrote: > Am 25.09.2012 04:37 schrieb Dwight Hutto: >>> I honestly could not care less what you think about me, but don't use >>> that term. This isn't a boys' club and we don't need your hurt ego >>> driving people away from here. >> >> OOOOOOOOOHHHHH. stirrin up shit and can't stand the smell. > > Where did he so? > > > Thomas He's referring to threads on the tutor mailing list where I have repeatedly asking him to provide context when he replies. Unfortunately he doesn't seem to understand the term context so resorts to attacking me. In a part of one thread he referred to my family as pigs. I've have lived with that, using the sticks and stones reply, but then someone had the audacity to protect his stance. I am sure that people have seen enough of his behaviour in the last few hours to see the real Dwight Hutto so I'll leave it at that. -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Tue Sep 25 03:46:31 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Sep 2012 07:46:31 GMT Subject: For Counter Variable References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> Message-ID: <50616157$0$29997$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Sep 2012 07:53:55 +0200, Thomas Rachel wrote: > When learning Python, it often happend me to re-inven the wheel. But as > soon as I saw the presence of something I re-wrote, I skipped my > re-written version and used the built-in. And me. Not just Python either. The very first piece of code I wrote on a Linux machine was a shell script that (very badly, and even more very slowly) counted the number of files in a directory. 20 lines (if I remember correctly) to duplicate a simple: ls | wc -l It was a humbling lesson to always check what features a programming environment or language offers before reinventing the wheel with four sides. -- Steven From steve+comp.lang.python at pearwood.info Tue Sep 25 03:50:16 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Sep 2012 07:50:16 GMT Subject: Who's laughing at my responses, and who's not? References: <5bc2681o43dhv5p13v71jqodtnokbq9mko@4ax.com> Message-ID: <50616238$0$29997$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Sep 2012 00:43:18 -0400, Dwight Hutto wrote: > It sounds pretentious, but over the past several days, I've been slammed > on every post almost. That's a gross exaggeration. Over the last few days you have gotten slammed because you mildly broke etiquette and then, instead of accepting the minor criticism and moving on, you got into an argument about it, and made what seemed like a racially motivated joke. Even if it were completely innocent, it didn't *seem* innocent. And then you make rude comments about people, sexist comments about there being "ladies present" (my wife can turn the air blue, and sometimes she embarrasses me), and you recently accused others of being sock-puppets without a shred of evidence. Dwight, or David if you prefer, sometimes you make useful comments and you can be a welcome, useful member of the Python community, but other times you display an incoherent, rambling, aggressive style that indicates that you are posting while high or drunk. For your own sake, I suggest you stay off the Internet (including email and usenet) unless sober. -- Steven From rosuav at gmail.com Tue Sep 25 03:55:28 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Sep 2012 17:55:28 +1000 Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> <26493369-8f41-456c-8a89-b4883e37d55c@k13g2000pbq.googlegroups.com> <7xtxumhpqm.fsf@ruckus.brouhaha.com> Message-ID: On Tue, Sep 25, 2012 at 11:32 AM, Dwight Hutto wrote: >> By now I think we're in the DNFTT zone. >> -- > Taking a bite yourself there buddy. Hop under the bridge, and > comment...it make you a troll, and you're trying to feed yourself with > pile on comment from the rest of the under bridge dwellers. Dwight/David, may I courteously recommend and request that you refrain from posting until you've calmed down a little? You're really not doing your reputation much good. Unfortunately you're also impacting the reputation of the list/newsgroup. People will come here looking for help, and will see that people are biting and scratching at one another[1], and will turn away. And that, in turn, reflects badly on the language. It's fine to disagree with someone - that's one of the best ways to explore a problem space and turn up more information. What's not fine is the bad language and vitriol. To Paul Rubin (whose name and citation were omitted from Dwight's quoted text): My apologies, I fear I am feeding a troll here. But something needed to be said. [1] Galations 5:15, eg http://bible.cc/galatians/5-15.htm - come to think of it, the whole chapter applies fairly well here. http://www.biblegateway.com/passage/?search=Galatians+5 ChrisA From breamoreboy at yahoo.co.uk Tue Sep 25 03:59:23 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Sep 2012 08:59:23 +0100 Subject: For Counter Variable In-Reply-To: <50616157$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <50616157$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25/09/2012 08:46, Steven D'Aprano wrote: > On Tue, 25 Sep 2012 07:53:55 +0200, Thomas Rachel wrote: > >> When learning Python, it often happend me to re-inven the wheel. But as >> soon as I saw the presence of something I re-wrote, I skipped my >> re-written version and used the built-in. > > And me. > > Not just Python either. The very first piece of code I wrote on a Linux > machine was a shell script that (very badly, and even more very slowly) > counted the number of files in a directory. 20 lines (if I remember > correctly) to duplicate a simple: > > ls | wc -l > > > It was a humbling lesson to always check what features a programming > environment or language offers before reinventing the wheel with four > sides. > > > Thankfully easier in a relatively concise language like Python as opposed to (say) Java. Which reminds me, in what version of Python are we getting the singletonMap? :) -- Cheers. Mark Lawrence. From janis.judvaitis at gmail.com Tue Sep 25 04:05:54 2012 From: janis.judvaitis at gmail.com (janis.judvaitis at gmail.com) Date: Tue, 25 Sep 2012 01:05:54 -0700 (PDT) Subject: Seome kind of unblocking input In-Reply-To: <0be9b4c2-b661-4709-ba8f-40a6f78ad634@googlegroups.com> References: <0be9b4c2-b661-4709-ba8f-40a6f78ad634@googlegroups.com> Message-ID: <784ead86-fc92-48e6-a34e-378a7010c0d5@googlegroups.com> Thanks for reply's. I'll be looking into threading, it seems like right way to go. btw. Why Python developers don't make a wrapper for input() with callback function using threads, so people can easily use nonblocking input? From vlastimil.brom at gmail.com Tue Sep 25 04:14:56 2012 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 25 Sep 2012 10:14:56 +0200 Subject: why do this program not fullscreen? In-Reply-To: References: Message-ID: 2012/9/25 Levi Nie : > the code: > import wx > app=wx.App() > win=wx.Frame(None) > win.ShowFullScreen() > app.MainLoop() > > > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, win.ShowFullScreen(True) should work, the boolean parameter appears to be required. hth, vbr From breamoreboy at yahoo.co.uk Tue Sep 25 04:15:00 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Sep 2012 09:15:00 +0100 Subject: Article on the future of Python Message-ID: Hi all, I though this might be of interest. http://www.ironfroggy.com/software/i-am-worried-about-the-future-of-python -- Cheers. Mark Lawrence. From gelonida at gmail.com Tue Sep 25 04:25:26 2012 From: gelonida at gmail.com (Gelonida N) Date: Tue, 25 Sep 2012 10:25:26 +0200 Subject: PIL questions: still supported? Problems on 2.7 for win? alternatives? In-Reply-To: References: Message-ID: On 09/25/2012 01:38 AM, alex23 wrote: > On Sep 25, 6:04 am, Gelonida N wrote: >> This all does not sound very comforting. Why is there no fix on the >> official site? > > Has a bug been logged about the issue? > > The Plone community keeps a fairly up-to-date fork called Pillow, > we've had a lot of success using that locally: > > http://pypi.python.org/pypi/Pillow/ > Thanks for all your answers. So it seems to be safe to use either Christoph' binary PIL distribution or to use Pillow. The fact, that pillow is accessable via PyPi / easy_install / PIP pushes me slightly towards pillow. I assume it's best to uninstall PIL before installing pillow. How much would I confuse easy_install / pip in a normal windows non virutal environment if I didn't uninstall PIP before (or even worse if I installed PIL, then pillow and uninstalled then PIL) (Just anticipating all the smart thigns, that my collegues (or myself) might do On a Linux machine: What would happen in a virtualenv with sitepackages (amonst them PIL installed and a pillow installed ontop of it? I don't think I can uninstall PIL, as many distro packages depend on it. I don't want to create a virtualenv without site packages, as I have many dependencies and some of them are a little tricky to compile. From jean.ronan.vigouroux at gmail.com Tue Sep 25 04:51:43 2012 From: jean.ronan.vigouroux at gmail.com (JRV) Date: Tue, 25 Sep 2012 01:51:43 -0700 (PDT) Subject: random access to video file Message-ID: <743a4d43-286f-412e-9886-1cda4c8c5cb1@googlegroups.com> Hello, Is there a method for randomly accessing a video file in Python / OpenCV ? A kind of fseek which would allow to go directly to frame n ... Cordially, JRV From jeanmichel at sequans.com Tue Sep 25 05:09:36 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 25 Sep 2012 11:09:36 +0200 (CEST) Subject: keeping information about players around In-Reply-To: <5060F74B.4070806@tysdomain.com> Message-ID: <1227334054.97306.1348564176800.JavaMail.root@sequans.com> ----- Original Message ----- > PHPMyAdmin? Might I ask why? This is a mud, so it's all command > based, > so that's not even a question, but I'm kind of curious how PHPMyAdmin > factors in there. It's a database creation tool from all I've ever > seen > of it, to define tables. Also, using it requires that I have it up on > some server or another, and I'd really rather avoid that if I can. Given the nature of your project forget MysQL and phpAdmin. At most you may use sqlite. Sqlite data is stored in one file, locally, you can move it back it up easily. Sqlite doesn't need any server. If you don't see How sqlite would benefit your mud, that would be strange, but then drop it and use pickled dictionaries if you're familiar with them. > > Why would you use a dictionary, when it's DB manipulation you're > > after? > > It is? I don't remember mentioning database anything in my thread. > Unless I missed it, I mentioned pickle once or twice. But either > way, I'd use a dictionary to keep a copy of {uid:object} for > objects and {uid:player} for players. Makes lookup by uid pretty > easy, as well as for any loaded objects. Actually you mentioned a "player database" in your original post. Player with their stats are typically something that may ends up in a database, along with any object and its properties. That's why people suggested to use a database. Databases provide then powerful tools to fetch, search and edit your data. Performances on disk access would be handled by sqlite itself, something you may care by yourself if you use dictionaries. Or maybe your mud doesn't store anything on disk, every run start fresh, in that case just use dictionaries. JM From jeanmichel at sequans.com Tue Sep 25 05:26:46 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 25 Sep 2012 11:26:46 +0200 (CEST) Subject: Who's laughing at my responses, and who's not? In-Reply-To: <50613C22.3010502@tysdomain.com> Message-ID: <2021942193.114409.1348565206166.JavaMail.root@sequans.com> ----- Original Message ----- > On 9/24/2012 10:43 PM, Dwight Hutto wrote: > > It sounds pretentious, but over the past several days, I've been > > slammed on every post almost. All because of an argument over me > > not > > posting a little context in a conversation, that seemed short and > > chatty. > > > > I was just wondering, if it's just them, or if it's my netiquette. > > > > I think you'd have a leg to stand on here if you didn't start > > cursing at anyone who got on your wrong side. It wasn't really an > > issue until you threw that > > up. Granted you did take your cursing off list finally, but you > > still continued (and as of about 2 hours ago) continue to post > > trash like you did in response > > to Alix's message. If you want to argue something, by all means > > argue. But there's no need to resort to comments like you've made. > Speaking of netiquette, Tyler you're messing (with ?) your replies a lot. You actually answer with the same indent level than the poster. In some thread with a lot of replies, it makes it impossible to see who's writing what. Only your (long, very long) signature is at the correct level. JM From alain at dpt-info.u-strasbg.fr Tue Sep 25 05:30:54 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 25 Sep 2012 11:30:54 +0200 Subject: which a is used? References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> Message-ID: <871uhqih4h.fsf@dpt-info.u-strasbg.fr> Jayden writes: > # Begin > a = 1 > > def f(): > print a > > def g(): > a = 20 > f() > > g() > #End > > I think the results should be 20, but it is 1. Would you please tell me why? When python looks at g(), it sees that a variable a is assigned to, and decides it is a local variable. When it looks at f(), it sees a use of a but no assignment, so it decides it is a global variable and fetches the value from the outer scope. If you change f() to: def f(): print a a = 30 you change a into a local variable (and get another error). If you want to change the binding of a in g(), you can declare it global: def g(): global a a = 20 f() Very tricky, actually. -- Alain. From wxjmfauth at gmail.com Tue Sep 25 05:32:04 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 25 Sep 2012 02:32:04 -0700 (PDT) Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <50616157$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <46c1b87a-7407-4c7e-9aee-0fe44ae3b07a@googlegroups.com> I wrote my first program on a PDP-8. I discovered Python at release 1.5.? Now years later... I find Python more and more unusable. As an exemple related to this topic, which summarizes a little bit the situation. I just opened my interactive interpreter and produced this: >>> for i in range(len(s)-1, -1,-1): ... '{} {}'.format(i, s[i]) ... '2 c' '1 b' '0 a' I did it so many times with a reverse/enumerate combination, I'm unable to do it again, I simply do not remember! One another really annoying aspect of Python, illustrated in my previous code: ''.format() . Was it not supposed to be *the* new formating scheme? I'm toying more and more with the go language. I really appreciate and rediscover the strictness I learned with Pascal. jmf From wxjmfauth at gmail.com Tue Sep 25 05:32:04 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 25 Sep 2012 02:32:04 -0700 (PDT) Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <50616157$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <46c1b87a-7407-4c7e-9aee-0fe44ae3b07a@googlegroups.com> I wrote my first program on a PDP-8. I discovered Python at release 1.5.? Now years later... I find Python more and more unusable. As an exemple related to this topic, which summarizes a little bit the situation. I just opened my interactive interpreter and produced this: >>> for i in range(len(s)-1, -1,-1): ... '{} {}'.format(i, s[i]) ... '2 c' '1 b' '0 a' I did it so many times with a reverse/enumerate combination, I'm unable to do it again, I simply do not remember! One another really annoying aspect of Python, illustrated in my previous code: ''.format() . Was it not supposed to be *the* new formating scheme? I'm toying more and more with the go language. I really appreciate and rediscover the strictness I learned with Pascal. jmf From ian.g.kelly at gmail.com Tue Sep 25 05:32:54 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 25 Sep 2012 03:32:54 -0600 Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: On Mon, Sep 24, 2012 at 11:32 PM, Thomas Rachel wrote: > Am 25.09.2012 00:37 schrieb Ian Kelly: >> Since ints are immutable, the language specifies that it should be the >> equivalent of "file.pos = file.pos - 100", so it should set the file >> pointer to 68 bytes before EOF. > > > But this is not a "real int", it has a special use. So I don't think it is > absolutely required to behave like an int. The point of the proposal was to simplify the API. With that in mind, if it's supposed to look like an int, then it should *be* an int. From breamoreboy at yahoo.co.uk Tue Sep 25 05:46:18 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Sep 2012 10:46:18 +0100 Subject: For Counter Variable In-Reply-To: <46c1b87a-7407-4c7e-9aee-0fe44ae3b07a@googlegroups.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <50616157$0$29997$c3e8da3$5496439d@news.astraweb.com> <46c1b87a-7407-4c7e-9aee-0fe44ae3b07a@googlegroups.com> Message-ID: On 25/09/2012 10:32, wxjmfauth at gmail.com wrote: > I wrote my first program on a PDP-8. I discovered Python > at release 1.5.? > > Now years later... I find Python more and more unusable. Dementia is a growing problem for us older people :) > > As an exemple related to this topic, which summarizes a > little bit the situation. I just opened my interactive > interpreter and produced this: > >>>> for i in range(len(s)-1, -1,-1): > ... '{} {}'.format(i, s[i]) > ... > '2 c' > '1 b' > '0 a' > > I did it so many times with a reverse/enumerate combination, > I'm unable to do it again, I simply do not remember! Based on things I've read as I've never used it myself try using Perl as that should simplify things for you. > > > One another really annoying aspect of Python, illustrated > in my previous code: ''.format() . > Was it not supposed to be *the* new formating scheme? That might have been the original intention but it's not going to take over the world as there's too much legacy code using the C style % formatters. IIRC isn't there also something about string templates??? > > I'm toying more and more with the go language. I really > appreciate and rediscover the strictness I learned with > Pascal. So go and use go as nobody here is stopping you. > > jmf > -- Cheers. Mark Lawrence. From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Sep 25 05:53:08 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 25 Sep 2012 11:53:08 +0200 Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: Am 25.09.2012 10:13 schrieb Dennis Lee Bieber: >> Or some bit setting registers, like on ATxmega: OUT = 0x10 sets bit 7 >> and clears all others, OUTSET = 0x10 only sets bit 7, OUTTGL = 0x10 >> toggles it and OUTCLR = 0x10 clears it. Umpfzg. s/bit 7/bit 4/. > I don't think I'd want to work with any device where 0x10 (00010000 > binary) modifies bit SEVEN. 0x40, OTOH, would fit my mental impression > of bit 7. Of course. My fault. It can as well be a bit mask, with OUTTGL = 0x11 toggling bit 4 and bit 0. Very handy sometimes. Thomas From clp2 at rebertia.com Tue Sep 25 05:53:11 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 25 Sep 2012 02:53:11 -0700 Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <50616157$0$29997$c3e8da3$5496439d@news.astraweb.com> <46c1b87a-7407-4c7e-9aee-0fe44ae3b07a@googlegroups.com> Message-ID: On Tue, Sep 25, 2012 at 2:46 AM, Mark Lawrence wrote: > On 25/09/2012 10:32, wxjmfauth at gmail.com wrote: >> >> I wrote my first program on a PDP-8. I discovered Python >> at release 1.5.? >> >> Now years later... I find Python more and more unusable. >> I'm toying more and more with the go language. I really >> appreciate and rediscover the strictness I learned with >> Pascal. > > So go and use go as nobody here is stopping you. Well, the PSU might, except they emphatically do not exist... Cheers, Chris -- PEP-401 compliant From oscar.j.benjamin at gmail.com Tue Sep 25 05:58:25 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 25 Sep 2012 10:58:25 +0100 Subject: python file API In-Reply-To: <60q268tnj9mqhvdtlehv59ob9bvpf8lgjr@invalid.netcom.com> References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <60q268tnj9mqhvdtlehv59ob9bvpf8lgjr@invalid.netcom.com> Message-ID: On Sep 25, 2012 9:28 AM, "Dennis Lee Bieber" wrote: > > On Tue, 25 Sep 2012 08:22:05 +0200, Ulrich Eckhardt > declaimed the following in > gmane.comp.python.general: > > > Am 24.09.2012 23:49, schrieb Dave Angel: > > > And what approach would you use for positioning relative to > > > end-of-file? That's currently done with an optional second > > > parameter to seek() method. > > > > Negative indices. > > > > Which still doesn't handle the third seek mode -- relative to > current position. f.pos += delta That's the only part of the proposal that I really think is an improvement over the current method: f.seek(delta, 1) I actually had to google the whence code for relative seeking which I wouldn't need to do if it were more descriptive. But then I never do relative seeking. I'm pretty sure my programs have always either read the whole file in order with no seeking or used random access with absolute seeking. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrea.crotti.0 at gmail.com Tue Sep 25 06:01:58 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Tue, 25 Sep 2012 11:01:58 +0100 Subject: PHP vs. Python In-Reply-To: <22c32aaa-104a-46bf-b9a6-347260e6f84a@googlegroups.com> References: <1103753016.780533.137480@f14g2000cwb.googlegroups.com> <22c32aaa-104a-46bf-b9a6-347260e6f84a@googlegroups.com> Message-ID: 2012/9/25 : > On Thursday, 23 December 2004 03:33:36 UTC+5:30, (unknown) wrote: >> Anyone know which is faster? I'm a PHP programmer but considering >> getting into Python ... did searches on Google but didn't turn much up >> on this. >> >> Thanks! >> Stephen > > > Here some helpful gudance. > > http://hentenaar.com/serendipity/index.php?/archives/27-Benchmark-PHP-vs.-Python-vs.-Perl-vs.-Ruby.html > -- > http://mail.python.org/mailman/listinfo/python-list Quite ancient versions of everything, would be interesting to see if things are different now.. Anyway you can switch to Python happily, it might not be faster but 99% of the times that's not an issue.. From breamoreboy at yahoo.co.uk Tue Sep 25 06:16:40 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Sep 2012 11:16:40 +0100 Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <50616157$0$29997$c3e8da3$5496439d@news.astraweb.com> <46c1b87a-7407-4c7e-9aee-0fe44ae3b07a@googlegroups.com> Message-ID: On 25/09/2012 10:53, Chris Rebert wrote: [snip] > > Well, the PSU might, except they emphatically do not exist... I know that they exist but if I admit to it I'd have to shoot myself. If I can get the bra off of the debutante that is. > > Cheers, > Chris > -- > PEP-401 compliant > -- Cheers. Mark Lawrence. From tejas.tank.mca at gmail.com Tue Sep 25 06:22:53 2012 From: tejas.tank.mca at gmail.com (Tejas) Date: Tue, 25 Sep 2012 15:52:53 +0530 Subject: PHP vs. Python In-Reply-To: References: <1103753016.780533.137480@f14g2000cwb.googlegroups.com> <22c32aaa-104a-46bf-b9a6-347260e6f84a@googlegroups.com> Message-ID: How to configure python in apache2 ? So my html embedded code will works. -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Tue Sep 25 06:38:35 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 25 Sep 2012 11:38:35 +0100 Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: On 25 September 2012 08:27, Mark Lawrence wrote: > On 25/09/2012 03:32, Mark Adam wrote: > >> On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin >> wrote: >> >>> try: >>> f.pos = 256 >>> except IOError: >>> print('Unseekable file') >> >> > Something along these lines http://docs.python.org/dev/** > whatsnew/3.3.html#pep-3151-**reworking-the-os-and-io-**exception-hierarchy? I just tried to find out what error would be raised by seeking on a file that doesn't support seeking and II think it's just OSError in the reworked hierarchy. The error in Python 2.7 is Traceback (most recent call last): File "tmp.py", line 2, in sys.stdin.seek(5) IOError: [Errno 29] Illegal seek This corresponds to ESPIPE from errno.h which isn't referred to anywhere in pip 3151: http://www.python.org/dev/peps/pep-3151/ So I guess it would still need to be try: f.pos = 256 except OSError as e: if e.errno != 29: raise print('Unseekable file') Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Tue Sep 25 06:41:22 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Sep 2012 11:41:22 +0100 Subject: PHP vs. Python In-Reply-To: References: <1103753016.780533.137480@f14g2000cwb.googlegroups.com> <22c32aaa-104a-46bf-b9a6-347260e6f84a@googlegroups.com> Message-ID: On 25/09/2012 11:22, Tejas wrote: > How to configure python in apache2 ? > > So my html embedded code will works. > > > Please follow the instructions that you'll find by searching the web. -- Cheers. Mark Lawrence. From python.list at tim.thechases.com Tue Sep 25 06:51:02 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 25 Sep 2012 05:51:02 -0500 Subject: Memory usage per top 10x usage per heapy In-Reply-To: References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> Message-ID: <50618C96.4000709@tim.thechases.com> On 09/24/12 23:41, Dennis Lee Bieber wrote: > On Mon, 24 Sep 2012 14:59:47 -0700 (PDT), MrsEntity > declaimed the following in > gmane.comp.python.general: > >> Hi all, >> >> I'm working on some code that parses a 500kb, 2M line file line by line and saves, per line, some derived strings > > Pardon? A 2million line file will contain, at the minimum 2million > line-end characters. That four times 500kB just in the line-ends, > ignoring any data. As corrected later in the thread, MrsEntity writes """ I have, in fact, this very afternoon, invented a means of writing a carriage return character using only 2 bits of information. I am prepared to sell licenses to this revolutionary technology for the low price of $29.95 plus tax. Sorry, that should've been a 500Mb, 2M line file. """ If only other unnamed persons on the list were so gracious rather than turning the flame-dial to 11. I hope that when people come to the list, *this* is what they see, laugh, and want to participate. Although, MrsEntity could be zombie David A. Huffman, whose encoding scheme actually *can* store 2M lines in 500kb :-) -tkc From m.harleman at yahoo.com Tue Sep 25 06:51:09 2012 From: m.harleman at yahoo.com (Michael Harleman) Date: Tue, 25 Sep 2012 03:51:09 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: Message-ID: <1348570269.7713.YahooMailNeo@web45511.mail.sp1.yahoo.com> That's a very interesting article.? It is encouraging to me, from reading many of the comments made, that I have chosen a good language to spend time learning despite the misgivings offered by the author.? I think Python does have a future in mobile markets as it is being used by some today according to one comment, and I can also see that apparently more development may need to be done, but I would think that would be true of any language.? What I like about Python among so many other things, is that it lends itself to be useful in almost any way I need it to.? Right now I am reading the Jython book, and realizing that Python can be wrapped around just about anything.? It truly is an amazing and versatile language.? Of course this is speaking as someone who has little experience at this point.? Thank you for sharing.? I'll be keeping this article bookmarked for future comparison. Michael Harleman >________________________________ > From: Mark Lawrence >To: python-list at python.org >Sent: Tuesday, September 25, 2012 4:15 AM >Subject: Article on the future of Python > >Hi all, > >I though this might be of interest. > >http://www.ironfroggy.com/software/i-am-worried-about-the-future-of-python > >-- Cheers. > >Mark Lawrence. > >-- http://mail.python.org/mailman/listinfo/python-list > > >? From breamoreboy at yahoo.co.uk Tue Sep 25 06:51:56 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Sep 2012 11:51:56 +0100 Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: On 25/09/2012 11:38, Oscar Benjamin wrote: > On 25 September 2012 08:27, Mark Lawrence wrote: > >> On 25/09/2012 03:32, Mark Adam wrote: >> >>> On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin >>> wrote: >>> >>>> try: >>>> f.pos = 256 >>>> except IOError: >>>> print('Unseekable file') >>> >>> >> Something along these lines http://docs.python.org/dev/** >> whatsnew/3.3.html#pep-3151-**reworking-the-os-and-io-**exception-hierarchy? > > > I just tried to find out what error would be raised by seeking on a file > that doesn't support seeking and II think it's just OSError in the reworked > hierarchy. The error in Python 2.7 is > > Traceback (most recent call last): > File "tmp.py", line 2, in > sys.stdin.seek(5) > IOError: [Errno 29] Illegal seek > > This corresponds to ESPIPE from errno.h which isn't referred to anywhere in > pip 3151: > http://www.python.org/dev/peps/pep-3151/ > > So I guess it would still need to be > > try: > f.pos = 256 > except OSError as e: > if e.errno != 29: > raise > print('Unseekable file') > > Oscar > > > The thing I was thinking of is actually in the thread "syntax to continue into the next subsequent except block" over on Python ideas. -- Cheers. Mark Lawrence. From andriy.kornatskyy at live.com Tue Sep 25 06:52:25 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Tue, 25 Sep 2012 13:52:25 +0300 Subject: Fastest web framework In-Reply-To: References: Message-ID: The post has been updated with two more frameworks (per community request):?tornado and web2py. Comments or suggestions are welcome. Thanks. Andriy Kornatskyy ---------------------------------------- > From: andriy.kornatskyy at live.com > To: python-list at python.org > Subject: Fastest web framework > Date: Sun, 23 Sep 2012 12:19:16 +0300 > > > I have run recently a benchmark of a trivial 'hello world' application for various python web frameworks (bottle, django, flask, pyramid, web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find it interesting: > > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > > Comments or suggestions are welcome. > > Thanks. > > Andriy Kornatskyy > > -- > http://mail.python.org/mailman/listinfo/python-list From python.list at tim.thechases.com Tue Sep 25 06:57:32 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 25 Sep 2012 05:57:32 -0500 Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> Message-ID: <50618E1C.5060703@tim.thechases.com> On 09/25/12 00:53, Thomas Rachel wrote: > Am 25.09.2012 01:39 schrieb Dwight Hutto: >> You don't always know all the built-ins, so the builtin is >> simpler, but knowing how to code it yourself is the priority of >> learning to code in a higher level language, which should be >> simpler to the user of python. > > When learning Python, it often happend me to re-inven the wheel. > But as soon as I saw the presence of something I re-wrote, I > skipped my re-written version and used the built-in. As a beginning Pythonista, I found myself doing the same thing. I implemented my own CSV parsing until I discovered how easy it was to do with the built-in library. I implemented my own option-parsing until I found optparse/argparse. I implemented config-files until I found ConfigFile. Coming from C where just about *nothing* is in the stdlib and Java & PHP where only some core functionalities are in the stdlib, to Python where just the list of modules in the stdlib is humongous, I have to make http://docs.python.org/library/ my first stop before I try implementing anything I think might have even a remote possibility of being there. -tkc From andriy.kornatskyy at live.com Tue Sep 25 07:01:19 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Tue, 25 Sep 2012 14:01:19 +0300 Subject: Fastest web framework In-Reply-To: References: , Message-ID: Alec While performing benchmark for web2py I noticed a memory leak. It constantly grows and never release it... Thanks. Andriy Kornatskyy ________________________________ > Date: Mon, 24 Sep 2012 17:36:25 +1000 > Subject: Re: Fastest web framework > From: alec.taylor6 at gmail.com > To: andriy.kornatskyy at live.com > CC: python-list at python.org > > Can you throw in web2py? > > Thanks > > On Sun, Sep 23, 2012 at 7:19 PM, Andriy Kornatskyy > > wrote: > > I have run recently a benchmark of a trivial 'hello world' application > for various python web frameworks (bottle, django, flask, pyramid, > web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... > you might find it interesting: > > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > > Comments or suggestions are welcome. > > Thanks. > > Andriy Kornatskyy > > -- > http://mail.python.org/mailman/listinfo/python-list > From d at davea.name Tue Sep 25 07:06:29 2012 From: d at davea.name (Dave Angel) Date: Tue, 25 Sep 2012 07:06:29 -0400 Subject: Memory usage per top 10x usage per heapy In-Reply-To: <50613131.6030102@gmail.com> References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5061056F.6080702@davea.name> <50613131.6030102@gmail.com> Message-ID: <50619035.3080106@davea.name> On 09/25/2012 12:21 AM, Junkshops wrote: >> Just curious; which is it, two million lines, or half a million bytes? > > Sorry, that should've been a 500Mb, 2M line file. > >> which machine is 2gb, the Windows machine, or the VM? > VM. Winders is 4gb. > >> ...but I would point out that just because >> you free up the memory from the Python doesn't mean it gets released >> back to the system. The C runtime manages its own heap, and is pretty >> persistent about hanging onto memory once obtained. It's not normally a >> problem, since most small blocks are reused. But it can get >> fragmented. And i have no idea how well Virtual Box maps the Linux >> memory map into the Windows one. > Right, I understand that - but what's confusing me is that, given the > memory use is (I assume) monotonically increasing, the code should never > use more than what's reported by heapy once all the data is loaded into > memory, given that memory released by the code to the Python runtime is > reused. To the best of my ability to tell I'm not storing anything I > shouldn't, so the only thing I can think of is that all the object > creation and destruction, for some reason, it preventing reuse of > memory. I'm at a bit of a loss regarding what to try next. I'm not familiar with heapy, but perhaps it's missing something there. I'm a bit surprised you aren't beyond the 2gb limit, just with the structures you describe for the file. You do realize that each object has quite a few bytes of overhead, so it's not surprising to use several times the size of a file, to store the file in an organized way. I also wonder if heapy has been written to take into account the larger size of pointers in a 64bit build. Perhaps one way to save space would be to use a long to store those md5 values. You'd have to measure it, but I suspect it'd help (at the cost of lots of extra hexlify-type calls). Another thing is to make sure that the md5 object used in your two maps is the same object, and not just one with the same value. -- DaveA From oscar.j.benjamin at gmail.com Tue Sep 25 07:09:44 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 25 Sep 2012 12:09:44 +0100 Subject: python file API In-Reply-To: References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> Message-ID: On 25 September 2012 11:51, Mark Lawrence wrote: > On 25/09/2012 11:38, Oscar Benjamin wrote: > >> On 25 September 2012 08:27, Mark Lawrence >> wrote: >> >> On 25/09/2012 03:32, Mark Adam wrote: >>> >>> On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin >>>> wrote: >>>> >>>> try: >>>>> f.pos = 256 >>>>> except IOError: >>>>> print('Unseekable file') >>>>> >>>> >>>> >>>> Something along these lines http://docs.python.org/dev/** >>> whatsnew/3.3.html#pep-3151-****reworking-the-os-and-io-**** >>> exception-hierarchy>> 3.3.html#pep-3151-reworking-**the-os-and-io-exception-**hierarchy >>> >? >>> >> >> >> I just tried to find out what error would be raised by seeking on a file >> that doesn't support seeking and II think it's just OSError in the >> reworked >> hierarchy. The error in Python 2.7 is >> >> Traceback (most recent call last): >> File "tmp.py", line 2, in >> sys.stdin.seek(5) >> IOError: [Errno 29] Illegal seek >> >> This corresponds to ESPIPE from errno.h which isn't referred to anywhere >> in >> pip 3151: >> http://www.python.org/dev/**peps/pep-3151/ >> >> So I guess it would still need to be >> >> try: >> f.pos = 256 >> except OSError as e: >> if e.errno != 29: >> raise >> print('Unseekable file') >> >> Oscar >> >> >> >> > The thing I was thinking of is actually in the thread "syntax to continue > into the next subsequent except block" over on Python ideas. This? try: f.pos = 256 except OSError as e if e.errno == 29: print('Unseekable file') Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Tue Sep 25 07:10:24 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Sep 2012 12:10:24 +0100 Subject: Memory usage per top 10x usage per heapy In-Reply-To: <50618C96.4000709@tim.thechases.com> References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <50618C96.4000709@tim.thechases.com> Message-ID: On 25/09/2012 11:51, Tim Chase wrote: [snip] > > If only other unnamed persons on the list were so gracious rather > than turning the flame-dial to 11. > Oh heck what have I said this time? > > -tkc -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Tue Sep 25 07:20:48 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Sep 2012 12:20:48 +0100 Subject: For Counter Variable In-Reply-To: <50618E1C.5060703@tim.thechases.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <50618E1C.5060703@tim.thechases.com> Message-ID: On 25/09/2012 11:57, Tim Chase wrote: [snip] > > Coming from C where just about *nothing* is in the stdlib and Java & > PHP where only some core functionalities are in the stdlib, to > Python where just the list of modules in the stdlib is humongous, I > have to make http://docs.python.org/library/ my first stop before I > try implementing anything I think might have even a remote > possibility of being there. > > -tkc I find the above paragraph amusing given the recent discussion about the Java singletonMap, i.e. it's someone that is rarely if ever needed but core functionalities are missing, how strange. I think the next port of call after the standard library should be pypi followed by the search engine, possibly targetted at sites like github, followed by a question here. I'm not certain about the next step, help please. -- Cheers. Mark Lawrence. From rwrsantos at gmail.com Tue Sep 25 07:32:30 2012 From: rwrsantos at gmail.com (Robison Santos) Date: Tue, 25 Sep 2012 08:32:30 -0300 Subject: Python 3 crashes with 'Py_Initialize: can't initialize sys standard streams' + 'EOFError: EOF read where not expected' Message-ID: Hello guys, I'm having a very serious problem with my python3 environment and I'm completely lost about the problem. In my server I run two python apps (custom apps) during system start time, and sometime when the apps are starting a corefile is generated for one one them (not always the same) and the following error is reported: "Fatal Python error: Py_Initialize: can't initialize sys standard streams EOFError: EOF read where not expected" Does anyone knows more about this problem and how can I fix it? Looking on the internet, I found issues related to the first line "Py_Initialize: can't initialize sys standard streams" and issues for the second line "EOF read where not expected" but none correlating both problems. Thanks a lot. PS.: I'm not part of this list, so a direct reply to my personal email would be great. -- Robison W R Santos -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Tue Sep 25 07:33:59 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 25 Sep 2012 12:33:59 +0100 Subject: Memory usage per top 10x usage per heapy In-Reply-To: <5060F3BB.7010706@gmail.com> References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5060EB2C.6080508@tim.thechases.com> <5060F3BB.7010706@gmail.com> Message-ID: On 25 September 2012 00:58, Junkshops wrote: > Hi Tim, thanks for the response. > > > - check how you're reading the data: are you iterating over >> the lines a row at a time, or are you using >> .read()/.readlines() to pull in the whole file and then >> operate on that? >> > I'm using enumerate() on an iterable input (which in this case is the > filehandle). > > > - check how you're storing them: are you holding onto more >> than you think you are? >> > I've used ipython to look through my data structures (without going into > ungainly detail, 2 dicts with X numbers of key/value pairs, where X = > number of lines in the file), and everything seems to be working correctly. > Like I say, heapy output looks reasonable - I don't see anything surprising > there. In one dict I'm storing a id string (the first token in each line of > the file) with values as (again, without going into massive detail) the md5 > of the contents of the line. The second dict has the md5 as the key and an > object with __slots__ set that stores the line number of the file and the > type of object that line represents. Can you give an example of how these data structures look after reading only the first 5 lines? Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Tue Sep 25 07:40:14 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 25 Sep 2012 06:40:14 -0500 Subject: gracious responses (was: Memory usage per top 10x usage per heapy) In-Reply-To: References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <50618C96.4000709@tim.thechases.com> Message-ID: <5061981E.2090500@tim.thechases.com> On 09/25/12 06:10, Mark Lawrence wrote: > On 25/09/2012 11:51, Tim Chase wrote: >> If only other unnamed persons on the list were so gracious rather >> than turning the flame-dial to 11. >> > > Oh heck what have I said this time? You'd *like* to take credit? ;-) Nah, not you or any of the regulars here. The comment was regarding the flame-fest that's been running in some parallel threads over the last ~12hr or so. Mostly instigated by one person with a particularly quick trigger, vitriolic tongue, and a disregard for pythonic code. -tkc From breamoreboy at yahoo.co.uk Tue Sep 25 07:54:05 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Sep 2012 12:54:05 +0100 Subject: gracious responses In-Reply-To: <5061981E.2090500@tim.thechases.com> References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <50618C96.4000709@tim.thechases.com> <5061981E.2090500@tim.thechases.com> Message-ID: On 25/09/2012 12:40, Tim Chase wrote: > On 09/25/12 06:10, Mark Lawrence wrote: >> On 25/09/2012 11:51, Tim Chase wrote: >>> If only other unnamed persons on the list were so gracious rather >>> than turning the flame-dial to 11. >>> >> >> Oh heck what have I said this time? > > You'd *like* to take credit? ;-) > > Nah, not you or any of the regulars here. The comment was regarding > the flame-fest that's been running in some parallel threads over the > last ~12hr or so. Mostly instigated by one person with a > particularly quick trigger, vitriolic tongue, and a disregard for > pythonic code. > > -tkc > > Well thank goodness for that. Of course the person to whom you've alluded has been defended over on the tutor mailing list, seriously, and as I've said elsewhere after referring to my family as pigs!!! -- Cheers. Mark Lawrence. From andriy.kornatskyy at live.com Tue Sep 25 08:27:59 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Tue, 25 Sep 2012 15:27:59 +0300 Subject: Fastest template engine In-Reply-To: References: Message-ID: The post has been updated due to comment from Makoto Kuwata (author of tenjin) related to use of optimized version of HTML escape in tenjin templates. I believe Mako and Jinja2 both are using MarkupSafe which serves exactly for that purpose there. The test assert the output is unicode. http://mindref.blogspot.com/2012/07/python-fastest-template.html Thanks. Andriy ---------------------------------------- > From: andriy.kornatskyy at live.com > To: python-list at python.org > Subject: Fastest template engine > Date: Sun, 23 Sep 2012 12:24:36 +0300 > > > I have run recently a benchmark of a trivial 'big table' example for various python template engines (jinja2, mako, tenjin, tornado and wheezy.template) run on cpython2.7 and pypy1.9...... you might find it interesting: > > http://mindref.blogspot.com/2012/07/python-fastest-template.html > > Comments or suggestions are welcome. > > Thanks. > > Andriy Kornatskyy > -- > http://mail.python.org/mailman/listinfo/python-list From wuwei23 at gmail.com Tue Sep 25 08:42:47 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 25 Sep 2012 05:42:47 -0700 (PDT) Subject: PIL questions: still supported? Problems on 2.7 for win? alternatives? References: Message-ID: On Sep 25, 6:25?pm, Gelonida N wrote: > So it seems to be safe to use either Christoph' binary PIL distribution > or to use Pillow. > > The fact, that pillow is accessable via PyPi / easy_install / PIP pushes > me slightly towards pillow. > I assume it's best to uninstall PIL before installing pillow. I would expect you'd be fine. Being a different package, it's a different namespace, so they shouldn't conflict. > On a Linux machine: > What would happen in a virtualenv with sitepackages (amonst them PIL > installed and a pillow installed ontop of it? > I don't think I can uninstall PIL, as many distro packages depend on it. > I don't want to create a virtualenv without site packages, as I have > many dependencies and some of them are a little tricky to compile. Again, you should be fine, as it's in a separate namespace. You definitely don't want to mess with PIL if you have other dependencies. From wuwei23 at gmail.com Tue Sep 25 08:44:18 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 25 Sep 2012 05:44:18 -0700 (PDT) Subject: gracious responses (was: Memory usage per top 10x usage per heapy) References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <50618C96.4000709@tim.thechases.com> Message-ID: On Sep 25, 9:39?pm, Tim Chase wrote: > Mostly instigated by one person with a > particularly quick trigger, vitriolic tongue, and a disregard for > pythonic code. I'm sorry. I'll get me coat. From wuwei23 at gmail.com Tue Sep 25 08:48:31 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 25 Sep 2012 05:48:31 -0700 (PDT) Subject: which a is used? References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> Message-ID: <661d9632-978f-47b0-9103-f6b8d72359e3@b9g2000pbc.googlegroups.com> On Sep 25, 3:30?pm, Dwight Hutto wrote: > You'd have to read the other posts. And remember that some of these > names are A.K.A.'s, they ask respond, and befriend another name > through another proxy. You've actively accused me of this several times. If you have evidence that there's sockpuppeting, please provide it. From oscar.j.benjamin at gmail.com Tue Sep 25 08:49:46 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 25 Sep 2012 13:49:46 +0100 Subject: Python 3 crashes with 'Py_Initialize: can't initialize sys standard streams' + 'EOFError: EOF read where not expected' In-Reply-To: References: Message-ID: On 25 September 2012 12:32, Robison Santos wrote: > Hello guys, > > I'm having a very serious problem with my python3 environment and I'm > completely lost about the problem. > In my server I run two python apps (custom apps) during system start time, > and sometime when the apps are starting a corefile is generated for one one > them (not always the same) and the following error is reported: > > "Fatal Python error: Py_Initialize: can't initialize sys standard streams > EOFError: EOF read where not expected" > What OS etc. are you using and how are you starting the apps? Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From cjw at ncf.ca Tue Sep 25 08:52:49 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Tue, 25 Sep 2012 08:52:49 -0400 Subject: which a is used? In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> Message-ID: On 24/09/2012 10:14 PM, alex23 wrote: > On Sep 25, 11:13 am, Dwight Hutto wrote: >> bitch > > I honestly could not care less what you think about me, but don't use > that term. This isn't a boys' club and we don't need your hurt ego > driving people away from here. > +1 From breamoreboy at yahoo.co.uk Tue Sep 25 08:53:42 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Sep 2012 13:53:42 +0100 Subject: gracious responses In-Reply-To: References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <50618C96.4000709@tim.thechases.com> Message-ID: On 25/09/2012 13:44, alex23 wrote: > On Sep 25, 9:39 pm, Tim Chase wrote: >> Mostly instigated by one person with a >> particularly quick trigger, vitriolic tongue, and a disregard for >> pythonic code. > > I'm sorry. I'll get me coat. > Oi, back of the queue if you don't mind :) -- Cheers. Mark Lawrence. From andriy.kornatskyy at live.com Tue Sep 25 09:21:07 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Tue, 25 Sep 2012 16:21:07 +0300 Subject: Fastest web framework In-Reply-To: <50604907.6060405@ziade.org> References: , <50604907.6060405@ziade.org> Message-ID: Tarek, With all respect, running benchmark on something that has sleeps, etc is pretty far from real world use case. So I went a little bit different way. Here is a live demo (a semi real world web application) that comes with wheezy.web framework as a template: http://wheezy.pythonanywhere.com/ I have implemented it in a way that it uses one web framework (wheezy.web) and various template engines (jinja2, mako, tenjin, wheezy.template and wheezy.template with preprocessor)... Please see the following post under `Real World Example` section: http://mindref.blogspot.com/2012/07/python-fastest-template.html Source code here: https://bitbucket.org/akorn/wheezy.web/src/tip/demos/template The real world example shows the difference between template engines implementing the same things. The same applies to web frameworks (more or less depending on your choice). Thanks. Andriy ---------------------------------------- > Date: Mon, 24 Sep 2012 13:50:31 +0200 > From: tarek at ziade.org > To: python-list at python.org > Subject: Re: Fastest web framework > > On 9/23/12 11:19 AM, Andriy Kornatskyy wrote: > > I have run recently a benchmark of a trivial 'hello world' application for various python web frameworks (bottle, django, flask, pyramid, web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find it interesting: > > > > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > > > > Comments or suggestions are welcome. > > > > Thanks. > > > > Andriy Kornatskyy > > > I would try this with a web app that does more than 'Hello World' > > You may argue that you're just trying the server stack, but that's not > realistic because you don't really measure how the server behaves with a > real app. > > Have a look at > https://github.com/mozilla-services/chaussette/blob/master/chaussette/util.py#L188 > > (setup_bench and teardow_bench have to be run on startup and tear down > of the server) > > I would be curious to see how things goes then > > Cheers > Tarek > -- > http://mail.python.org/mailman/listinfo/python-list From kw at codebykevin.com Tue Sep 25 09:26:19 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 25 Sep 2012 09:26:19 -0400 Subject: Article on the future of Python In-Reply-To: References: Message-ID: On 9/25/12 4:15 AM, Mark Lawrence wrote: > Hi all, > > I though this might be of interest. > > http://www.ironfroggy.com/software/i-am-worried-about-the-future-of-python > Interesting article, but the comments of those who say "the only language I need to know is Python" strike me as a bit limited. If this is the case, then Python can never be moved forward, because it is written in C. I program in Python, C, Objective C, JavaScript, Tcl, AppleScript, and I'm learning Perl. Python could *not* handle all the domains I target in my projects. For instance: if I want to access Mac-native functionality via Tkinter that isn't currently available in the library, I have to drill down into C or Objective-C, write a wrapper that hooks in to the primitives via Tcl's C API, then possibly write some additional Tcl code to provide a cleaner interface, *then* write some kind of Python wrapper that I can access in my Tkinter app. I can understand loving the language and wanting to work just in the language, but it's another thing entirely to call Python the One Language to Rule Them All. (That's C, because all other languages are implemented in it. :-) ) --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From jayden.shui at gmail.com Tue Sep 25 09:41:43 2012 From: jayden.shui at gmail.com (Jayden) Date: Tue, 25 Sep 2012 06:41:43 -0700 (PDT) Subject: data attributes override method attributes? Message-ID: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Dear All, In the Python Tutorial, Section 9.4, it is said that "Data attributes override method attributes with the same name." But in my testing as follows: #Begin class A: i = 10 def i(): print 'i' A.i #End I think A.i should be the number 10 but it is the method. There must be something I misunderstand. Would you please tell me why? Thanks, Jayden From roy at panix.com Tue Sep 25 09:44:40 2012 From: roy at panix.com (Roy Smith) Date: Tue, 25 Sep 2012 09:44:40 -0400 Subject: Article on the future of Python References: Message-ID: In article , Kevin Walzer wrote: > the comments of those who say "the only > language I need to know is Python" strike me as a bit limited. I have been convinced that "X is the only language I need to know", for many different values of X over the years. From wuwei23 at gmail.com Tue Sep 25 09:52:26 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 25 Sep 2012 06:52:26 -0700 (PDT) Subject: data attributes override method attributes? References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Message-ID: <683be2ae-28ea-491f-bb00-c37187886415@pz10g2000pbb.googlegroups.com> On Sep 25, 11:41?pm, Jayden wrote: > Dear All, > > In the Python Tutorial, Section 9.4, it is said that > > "Data attributes override method attributes with the same name." > > But in my testing as follows: > > #Begin > class A: > ? ? ? ? i = 10 > ? ? ? ? def i(): > ? ? ? ? ? ? ? ? print 'i' > > A.i > ? ? > #End > > I think A.i should be the number 10 but it is the method. There must be something I misunderstand. Would you please tell me why? What the tutorial is referring to is this, I think: class A(object): def i(self): print 'i' >>> a = A() >>> a.i = 10 >>> a.i 10 That is, you can create a data attribute on an object even if a method attribute of the same name exists. From darcy at druid.net Tue Sep 25 09:53:27 2012 From: darcy at druid.net (D'Arcy Cain) Date: Tue, 25 Sep 2012 09:53:27 -0400 Subject: Stop feeding the trolls (Was: which a is used?) In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> Message-ID: <20120925095327.aa0d222bad8678f6c0339fbf@druid.net> On Tue, 25 Sep 2012 08:44:18 +0100 Mark Lawrence wrote: > On 25/09/2012 06:07, Thomas Rachel wrote: > > Am 25.09.2012 04:37 schrieb Dwight Hutto: [...usual nonsense] > someone had the audacity to protect his stance. I am sure that people > have seen enough of his behaviour in the last few hours to see the real > Dwight Hutto so I'll leave it at that. Now if only people would stop feeding the troll, those of us who have already *plonked* him can stop seeing his ramblings in the responses. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From rwrsantos at gmail.com Tue Sep 25 09:56:19 2012 From: rwrsantos at gmail.com (Robison Santos) Date: Tue, 25 Sep 2012 10:56:19 -0300 Subject: Python 3 crashes with 'Py_Initialize: can't initialize sys standard streams' + 'EOFError: EOF read where not expected' In-Reply-To: References: Message-ID: I'm using python3.2.1 on Enterprise Linux Server release 5.3 (Carthage). I'm starting my apps calling python3 file.py I have a script that runs on system startup executing my python scripts. Any other info you need? Thanks so far, Robison On Tue, Sep 25, 2012 at 9:49 AM, Oscar Benjamin wrote: > On 25 September 2012 12:32, Robison Santos wrote: > >> Hello guys, >> >> I'm having a very serious problem with my python3 environment and I'm >> completely lost about the problem. >> In my server I run two python apps (custom apps) during system start >> time, and sometime when the apps are starting a corefile is generated for >> one one them (not always the same) and the following error is reported: >> >> "Fatal Python error: Py_Initialize: can't initialize sys standard streams >> EOFError: EOF read where not expected" >> > > What OS etc. are you using and how are you starting the apps? > > Oscar > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.hellwig at gmail.com Tue Sep 25 09:56:21 2012 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Tue, 25 Sep 2012 06:56:21 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: Message-ID: <9e5df5d3-514b-4257-b9a8-473379dc542f@googlegroups.com> On Tuesday, 25 September 2012 09:14:27 UTC+1, Mark Lawrence wrote: > Hi all, > > I though this might be of interest. > http://www.ironfroggy.com/software/i-am-worried-about-the-future-of-python > -- > > Cheers. > Mark Lawrence. I glanced over the article but it seems to me another 'I am afraid this is not the silver bullet I wanted it to be' article without actually going into the need of a silver bullet or whether the concept of a silver bullet is sound at all. -- mph From martin.hellwig at gmail.com Tue Sep 25 09:56:21 2012 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Tue, 25 Sep 2012 06:56:21 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: Message-ID: <9e5df5d3-514b-4257-b9a8-473379dc542f@googlegroups.com> On Tuesday, 25 September 2012 09:14:27 UTC+1, Mark Lawrence wrote: > Hi all, > > I though this might be of interest. > http://www.ironfroggy.com/software/i-am-worried-about-the-future-of-python > -- > > Cheers. > Mark Lawrence. I glanced over the article but it seems to me another 'I am afraid this is not the silver bullet I wanted it to be' article without actually going into the need of a silver bullet or whether the concept of a silver bullet is sound at all. -- mph From oscar.j.benjamin at gmail.com Tue Sep 25 09:59:00 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 25 Sep 2012 14:59:00 +0100 Subject: Python 3 crashes with 'Py_Initialize: can't initialize sys standard streams' + 'EOFError: EOF read where not expected' In-Reply-To: References: Message-ID: On 25 September 2012 14:56, Robison Santos wrote: > I'm using python3.2.1 > on Enterprise Linux Server release 5.3 (Carthage). > > I'm starting my apps calling python3 file.py > > I have a script that runs on system startup executing my python scripts. > What happens if you just run the scripts from the shell after starting up? What arrangement does the startup script provide for the stdio streams? Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwrsantos at gmail.com Tue Sep 25 10:06:53 2012 From: rwrsantos at gmail.com (Robison Santos) Date: Tue, 25 Sep 2012 11:06:53 -0300 Subject: Python 3 crashes with 'Py_Initialize: can't initialize sys standard streams' + 'EOFError: EOF read where not expected' In-Reply-To: References: Message-ID: This problem does not happen very often, but when it happen is only on system startup, and I couldn't reproduce by starting by hand. My startup script tries to initiate a lot of services in sequence (ruby, java, C and python), but does not do anything with stdio streams, at least not directly. At first, I thought this could be related to this python issue: http://bugs.python.org/issue13146 but this does not relate with "can't initialize sys standard streams" error. I didn't have time, though, to update my python version and check this won't happen again. Robison On Tue, Sep 25, 2012 at 10:59 AM, Oscar Benjamin wrote: > On 25 September 2012 14:56, Robison Santos wrote: > >> I'm using python3.2.1 >> on Enterprise Linux Server release 5.3 (Carthage). >> >> I'm starting my apps calling python3 file.py >> >> I have a script that runs on system startup executing my python scripts. >> > > What happens if you just run the scripts from the shell after starting up? > > What arrangement does the startup script provide for the stdio streams? > > Oscar > -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Tue Sep 25 10:07:41 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 25 Sep 2012 14:07:41 +0000 (UTC) Subject: python file API References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> Message-ID: On 2012-09-25, Dennis Lee Bieber wrote: > On Tue, 25 Sep 2012 08:22:05 +0200, Ulrich Eckhardt > declaimed the following in > gmane.comp.python.general: > >> Am 24.09.2012 23:49, schrieb Dave Angel: >> > And what approach would you use for positioning relative to >> > end-of-file? That's currently done with an optional second >> > parameter to seek() method. >> >> Negative indices. >> > > Which still doesn't handle the third seek mode -- relative to > current position. fileobj.pos += -- Grant Edwards grant.b.edwards Yow! Am I in GRADUATE at SCHOOL yet? gmail.com From __peter__ at web.de Tue Sep 25 10:08:08 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 25 Sep 2012 16:08:08 +0200 Subject: data attributes override method attributes? References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Message-ID: Jayden wrote: > In the Python Tutorial, Section 9.4, it is said that > > "Data attributes override method attributes with the same name." The tutorial is wrong here. That should be "Instance attributes override class attributes with the same name." As methods are usually defined in the class and data attributes are usually set in the instance it will look like data override method attributes. What the author had in mind: >>> class A: ... def i(self): print "method" ... >>> >>> a = A() >>> a.i() method >>> a.i = 42 # this could also happen in a method with self.i = 42 >>> a.i() Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not callable >>> a.i 42 > But in my testing as follows: > > #Begin > class A: > i = 10 > def i(): > print 'i' > > A.i > > #End but class A: def i(self): print "i" i = 42 print A().i # 42 If two objects are assigned to the same name the last assignment always wins. > I think A.i should be the number 10 but it is the method. There must be something I misunderstand. Would you please tell me why? No, you're right. Please file a bug report at http://bugs.python.org From wuwei23 at gmail.com Tue Sep 25 10:11:46 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 25 Sep 2012 07:11:46 -0700 (PDT) Subject: data attributes override method attributes? References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Message-ID: On Sep 26, 12:08?am, Peter Otten <__pete... at web.de> wrote: > Jayden wrote: > > In the Python Tutorial, Section 9.4, it is said that > > > "Data attributes override method attributes with the same name." > > The tutorial is wrong here. That should be > > "Instance attributes override class attributes with the same name." > > As methods are usually defined in the class and data attributes are usually > set in the instance it will look like data override method attributes. But you can assign attributes on the class, which has the same impact, so the tutorial is correct. > No, you're right. Please file a bug report athttp://bugs.python.org Didn't you just demonstrate the behaviour you're now saying is a bug? From steve+comp.lang.python at pearwood.info Tue Sep 25 10:12:09 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Sep 2012 14:12:09 GMT Subject: data attributes override method attributes? References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Message-ID: <5061bbb9$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Sep 2012 06:41:43 -0700, Jayden wrote: > Dear All, > > In the Python Tutorial, Section 9.4, it is said that > > "Data attributes override method attributes with the same name." > > But in my testing as follows: > > #Begin > class A: > i = 10 > def i(): > print 'i' > > A.i > > #End > > I think A.i should be the number 10 but it is the method. There must be > something I misunderstand. Would you please tell me why? When you create the class, two things happen: first you define a class- level attribute i, then you define a method i. Since you can only have a single object with the same name in the same place, the method replaces the attribute. In this case, classes and methods are irrelevant. It is exactly the same behaviour as this: i = 10 i = 20 # i now equals 20, not 10 except that instead of 20, you use a function object: i = 10 def i(): return "something" # i is now a function object, not 10 What the manual refers to is the use of attributes on an instance: py> class Test(object): ... def f(self): ... return "something" ... py> t = Test() py> t.f = 20 py> t.f 20 In this case, there is an attribute called "f" (a method) which lives in the class and is shared by all instances, and another attribute called "f" which lives in the instance t, is not shared, and has the value 20. This instance attribute masks the method with the same name. We can see that it is only hidden, not gone, by creating a new instance: py> u = Test() py> u.f > -- Steven From steve+comp.lang.python at pearwood.info Tue Sep 25 10:19:33 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Sep 2012 14:19:33 GMT Subject: For Counter Variable References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <50616157$0$29997$c3e8da3$5496439d@news.astraweb.com> <46c1b87a-7407-4c7e-9aee-0fe44ae3b07a@googlegroups.com> Message-ID: <5061bd75$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Sep 2012 11:16:40 +0100, Mark Lawrence wrote: > On 25/09/2012 10:53, Chris Rebert wrote: > > [snip] > >> Well, the PSU might, except they emphatically do not exist... > > I know that they exist You are delusional. The PSU certainly do not exist and it is a myth that they From maniandram01 at gmail.com Tue Sep 25 10:37:34 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 25 Sep 2012 07:37:34 -0700 (PDT) Subject: Who's laughing at my responses, and who's not? In-Reply-To: References: <5bc2681o43dhv5p13v71jqodtnokbq9mko@4ax.com> Message-ID: <3bbd6b64-0fee-4a38-b81a-d922671c2d65@googlegroups.com> On Tuesday, 25 September 2012 10:40:02 UTC+5:30, Terry Reedy wrote: > On 9/25/2012 12:43 AM, Dwight Hutto wrote: > > > It sounds pretentious, but over the past several days, I've been > > > slammed on every post almost. All because of an argument over me not > > > posting a little context in a conversation, that seemed short and > > > chatty. > > > > > > I was just wondering, if it's just them, or if it's my netiquette. > > > > A 1000 line post with a one line response is not polite. Context free > > posts are disconcerting, but easier to ignore. Keep at least one > > sentence of context and cut the potty mouth stuff. > > > > -- > > Terry Jan Reedy +1 From maniandram01 at gmail.com Tue Sep 25 10:37:34 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 25 Sep 2012 07:37:34 -0700 (PDT) Subject: Who's laughing at my responses, and who's not? In-Reply-To: References: <5bc2681o43dhv5p13v71jqodtnokbq9mko@4ax.com> Message-ID: <3bbd6b64-0fee-4a38-b81a-d922671c2d65@googlegroups.com> On Tuesday, 25 September 2012 10:40:02 UTC+5:30, Terry Reedy wrote: > On 9/25/2012 12:43 AM, Dwight Hutto wrote: > > > It sounds pretentious, but over the past several days, I've been > > > slammed on every post almost. All because of an argument over me not > > > posting a little context in a conversation, that seemed short and > > > chatty. > > > > > > I was just wondering, if it's just them, or if it's my netiquette. > > > > A 1000 line post with a one line response is not polite. Context free > > posts are disconcerting, but easier to ignore. Keep at least one > > sentence of context and cut the potty mouth stuff. > > > > -- > > Terry Jan Reedy +1 From rosuav at gmail.com Tue Sep 25 10:38:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Sep 2012 00:38:29 +1000 Subject: For Counter Variable In-Reply-To: <5061bd75$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <50616157$0$29997$c3e8da3$5496439d@news.astraweb.com> <46c1b87a-7407-4c7e-9aee-0fe44ae3b07a@googlegroups.com> <5061bd75$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 26, 2012 at 12:19 AM, Steven D'Aprano wrote: > On Tue, 25 Sep 2012 11:16:40 +0100, Mark Lawrence wrote: > >> On 25/09/2012 10:53, Chris Rebert wrote: >> >> [snip] >> >>> Well, the PSU might, except they emphatically do not exist... >> >> I know that they exist > > You are delusional. The PSU certainly do not exist and it is a myth that > they Something got cut off. I wonder if Steven's computer's Power Supply Unit just let off its magic smoke... ChrisA From jayden.shui at gmail.com Tue Sep 25 10:44:04 2012 From: jayden.shui at gmail.com (Jayden) Date: Tue, 25 Sep 2012 07:44:04 -0700 (PDT) Subject: new-style class or old-style class? Message-ID: <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com> In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!! From __peter__ at web.de Tue Sep 25 10:54:12 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 25 Sep 2012 16:54:12 +0200 Subject: data attributes override method attributes? References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Message-ID: alex23 wrote: > On Sep 26, 12:08 am, Peter Otten <__pete... at web.de> wrote: >> Jayden wrote: >> > In the Python Tutorial, Section 9.4, it is said that >> >> > "Data attributes override method attributes with the same name." >> >> The tutorial is wrong here. That should be >> >> "Instance attributes override class attributes with the same name." >> >> As methods are usually defined in the class and data attributes are >> usually set in the instance it will look like data override method >> attributes. > > But you can assign attributes on the class, which has the same impact, > so the tutorial is correct. > >> No, you're right. Please file a bug report athttp://bugs.python.org > > Didn't you just demonstrate the behaviour you're now saying is a bug? > To me "Data attributes override method attributes with the same name" implies that data attributes take precedence over method attributes, not that they replace them only when there is an assignment of data after the method definition. With your interpretation (if I understand you correctly) "Method attributes override data attributes with the same name" is equally correct, and therefore I think it is misleading to focus on the type of the attributes at all. I would even consider replacing the whole paragraph """ Data attributes override method attributes with the same name; to avoid accidental name conflicts, which may cause hard-to-find bugs in large programs, it is wise to use some kind of convention that minimizes the chance of conflicts. Possible conventions include capitalizing method names, prefixing data attribute names with a small unique string (perhaps just an underscore), or using verbs for methods and nouns for data attributes. """ http://docs.python.org/dev/py3k/tutorial/classes.html with something like "Data attributes and method attributes share the same namespace. To avoid name conflicts consider using verbs for methods and nouns for data attributes" From ulrich.eckhardt at dominolaser.com Tue Sep 25 10:54:37 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 25 Sep 2012 16:54:37 +0200 Subject: data attributes override method attributes? In-Reply-To: References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Message-ID: Am 25.09.2012 16:11, schrieb alex23: > On Sep 26, 12:08 am, Peter Otten <__pete... at web.de> wrote: >> Jayden wrote: >>> In the Python Tutorial, Section 9.4, it is said that >> >>> "Data attributes override method attributes with the same name." >> >> The tutorial is wrong here. That should be >> >> "Instance attributes override class attributes with the same name." >> >> As methods are usually defined in the class and data attributes are usually >> set in the instance it will look like data override method attributes. > > But you can assign attributes on the class, which has the same impact, > so the tutorial is correct. You can assign attributes of the class or the instance, and you can assign with functions or data (actually, both functions and data are objects, Python doesn't make a distinction there). The important thing is that lookup first looks in the instance (where data attributes are usually set) before looking in the class (where method attributes are usually set). Observing typical use and deriving a rule from this is misleading though. >> No, you're right. Please file a bug report athttp://bugs.python.org > > Didn't you just demonstrate the behaviour you're now saying is a bug? I think he meant a bug in the tutorial, not in the implementation of Python. Uli From tyler at tysdomain.com Tue Sep 25 11:02:00 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Tue, 25 Sep 2012 09:02:00 -0600 Subject: new-style class or old-style class? In-Reply-To: <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com> References: <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com> Message-ID: <5061C768.2070401@tysdomain.com> On 9/25/2012 8:44 AM, Jayden wrote: > In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!! Perhaps this is useful: http://docs.python.org/reference/datamodel.html It's 3.3 I think. -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From rosuav at gmail.com Tue Sep 25 11:03:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Sep 2012 01:03:12 +1000 Subject: data attributes override method attributes? In-Reply-To: References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Message-ID: On Wed, Sep 26, 2012 at 12:54 AM, Peter Otten <__peter__ at web.de> wrote: > To me > > "Data attributes override method attributes with the same name" > > implies that data attributes take precedence over method attributes, not > that they replace them only when there is an assignment of data after the > method definition. > > I would even consider replacing the whole paragraph > with something like > > "Data attributes and method attributes share the same namespace. To avoid > name conflicts consider using verbs for methods and nouns for data > attributes" Instance attributes override (shadow) class attributes. Since methods tend to be on the class and data tends to be on the instance, the original sentence does make some sense. The section is talking about conventions, so it's not inherently wrong, but perhaps just needs a comment about methods not usually being attached to the instance. ChrisA From rosuav at gmail.com Tue Sep 25 11:05:23 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Sep 2012 01:05:23 +1000 Subject: new-style class or old-style class? In-Reply-To: <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com> References: <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com> Message-ID: On Wed, Sep 26, 2012 at 12:44 AM, Jayden wrote: > In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!! Definitely go with new-style. In Python 3, old-style classes aren't supported, and the syntax that would create an old-style class in Python 2 will implicitly create a new-style class. (Explicitly subclassing object still works in Py3, so you can happily use that syntax for both.) ChrisA From dpalao.python at gmail.com Tue Sep 25 11:07:07 2012 From: dpalao.python at gmail.com (DPalao) Date: Tue, 25 Sep 2012 17:07:07 +0200 Subject: How to limit CPU usage in Python In-Reply-To: <505B326C.1060503@cnic.edu.cu> References: <505B326C.1060503@cnic.edu.cu> Message-ID: <1484238.g6mEfzlyva@twisted> On Jueves septiembre 20 2012 11:12:44 Rolando Ca?er Roblejo escribi?: > Hi all, > > Is it possible for me to put a limit in the amount of processor usage (% > CPU) that my current python script is using? Is there any module useful > for this task? I saw Resource module but I think it is not the module I > am looking for. Some people recommend to use nice and cpulimit unix > tools, but those are external to python and I prefer a python solution. > I am working with Linux (Ubuntu 10.04). > > Best regards. Hola, Sometimes a stupid solution like the following does the trick: > import time > for t in tasks: > do_something(t) > time.sleep(some_seconds) where "some_seconds" is a number related to the typical time-scale of the tasks you are doing. Hope it helps, Regards -- Miller's Slogan: Lose a few, lose a few. From steve+comp.lang.python at pearwood.info Tue Sep 25 11:17:51 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Sep 2012 15:17:51 GMT Subject: gracious responses References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <50618C96.4000709@tim.thechases.com> <5061981E.2090500@tim.thechases.com> Message-ID: <5061cb1f$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Sep 2012 12:54:05 +0100, Mark Lawrence wrote: > Well thank goodness for that. Of course the person to whom you've > alluded has been defended over on the tutor mailing list, seriously, and > as I've said elsewhere after referring to my family as pigs!!! Since pigs are at least as intelligent as dogs, and in their natural state nowhere near as filthy as the stereotype of the pig in a sty, that isn't as big an insult as it was intended. -- Steven From steve+comp.lang.python at pearwood.info Tue Sep 25 11:35:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Sep 2012 15:35:01 GMT Subject: Article on the future of Python References: Message-ID: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Sep 2012 09:26:19 -0400, Kevin Walzer wrote: > On 9/25/12 4:15 AM, Mark Lawrence wrote: >> Hi all, >> >> I though this might be of interest. >> >> http://www.ironfroggy.com/software/i-am-worried-about-the-future-of- >> python >> >> > Interesting article, but the comments of those who say "the only > language I need to know is Python" strike me as a bit limited. If this > is the case, then Python can never be moved forward, because it is > written in C. Incorrect. IronPython in C#. Jython is written in Java. CLPython is written in Lisp. Berp and HoPe are written in Haskell. Nuitka is written in C++. Skulpt is written in Javascript. Vyper is written in Ocaml. PyPy is written in RPython. Some of those Python compilers are obsolete, unmaintained or experimental. Others are not. But either way, it is certainly not true that Python is written in C. One specific Python compiler happens to be written in C, that is all. > I program in Python, C, Objective C, JavaScript, Tcl, AppleScript, and > I'm learning Perl. Python could *not* handle all the domains I target in > my projects. Unless you are writing code that operates on the bare metal (device drivers, operating system kernels) Python probably *could*, even if it doesn't *yet*. PyPy now allows you to write real-time video processing filters in pure Python: http://morepypy.blogspot.com.au/2011/07/realtime-image-processing-in-python.html And if performance was irrelevant, you could even write an operating system in Python. A really slow, painful operating system, but still an operating system. Given a sufficiently smart compiler, and sufficiently powerful libraries, or sufficiently low expectations, pretty much any programming language can do anything any other language can do. Almost all of them are Turing complete. But of course, in practice languages differ in their power and capabilities. > For instance: if I want to access Mac-native functionality > via Tkinter that isn't currently available in the library, That "isn't currently available" part is precisely what I'm talking about. Just because it's not available now doesn't mean it can't be made available. > I can understand loving the language and wanting to work just in the > language, but it's another thing entirely to call Python the One > Language to Rule Them All. (That's C, because all other languages are > implemented in it. :-) ) I see your smiley, but that is factually incorrect. Not all compilers or interpreters are written in C. Many languages are self-hosted, that is, they are written in themselves, using some clever bootstrapping techniques. C is neither the most powerful, the oldest, the best, or the most fundamental language around. -- Steven From rosuav at gmail.com Tue Sep 25 11:48:06 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Sep 2012 01:48:06 +1000 Subject: Article on the future of Python In-Reply-To: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 26, 2012 at 1:35 AM, Steven D'Aprano wrote: > I see your smiley, but that is factually incorrect. Not all compilers or > interpreters are written in C. Many languages are self-hosted, that is, > they are written in themselves, using some clever bootstrapping > techniques. C is neither the most powerful, the oldest, the best, or the > most fundamental language around. Many compiled languages are bootstrapped, yes, but interpreted languages less often so. And the bulk of implementations of the bulk of interpreted languages seem to be implemented in C. But that's largely because the bulk of Unix software is written in either C or a high level language. ChrisA From rosuav at gmail.com Tue Sep 25 12:12:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Sep 2012 02:12:09 +1000 Subject: python file API In-Reply-To: <5cl3685bv3a2gidce2fn64grjtk9ch7kp5@invalid.netcom.com> References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <60q268tnj9mqhvdtlehv59ob9bvpf8lgjr@invalid.netcom.com> <5cl3685bv3a2gidce2fn64grjtk9ch7kp5@invalid.netcom.com> Message-ID: On Wed, Sep 26, 2012 at 2:07 AM, Dennis Lee Bieber wrote: > f.pos += delta > > would be a "seek.set" and with a naive driver might trigger a rewind to > the start of the tape followed by a seek to the absolute position, > whereas the seek from current location would only move the tape by the > specified amount... But a smart driver should always optimize the absolute seek to a relative seek, unless there's a hard difference between them. After all, the standard "read-ahead" technique is going to do an absolute seek: opaque_value = f.tell() f.read(blah blah blah) f.seek(opaque_value) ChrisA From vincent.vandevyvre at swing.be Tue Sep 25 12:15:32 2012 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Tue, 25 Sep 2012 18:15:32 +0200 Subject: How to export a logging level? Message-ID: <5061D8A4.40107@swing.be> In my application I import a module and I want to set the same logging level as the main app to this module. I've tried this code main.py import logging logger = logging.getLogger(__name__) lvl = logging.DEBUG LOG_FORMAT = "%(asctime)-6s %(levelname)s: %(name)s - %(message)s" logging.basicConfig(format=LOG_FORMAT, datefmt='%H:%M:%S', level=lvl) from mymodule.myfile import MyClass ... def load_myclass(self): lvl = logger.getEffectiveLevel() mc = MyClass(self, lvl) myfile.py import logging logger = logging.getLogger(__name__) class MyClass(object): def __init__(self, main, lvl): logger.setLevel(lvl) If I set the level to logging.DEBUG I can see all infos from the main but anything from my module. Thanks for your advice. -- Vincent V.V. Oqapy . Qarte . PaQager From steve+comp.lang.python at pearwood.info Tue Sep 25 12:20:44 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Sep 2012 16:20:44 GMT Subject: new-style class or old-style class? References: <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com> Message-ID: <5061d9db$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Sep 2012 07:44:04 -0700, Jayden wrote: > In learning Python, I found there are two types of classes? Which one > are widely used in new Python code? New-style classes. > Is the new-style much better than old-style? Yes. Always use new-style classes, unless you have some specific reason for needing old-style ("classic") classes. Advantages of new-style classes: 1) They are the future. In Python 3, all classes are "new-style" and classic classes are gone. 2) Multiple inheritance works correctly. Multiple inheritance for classic classes is buggy. 3) New-style classes support awesome features like super(), properties, descriptors, and __getattribute__. Old-style do not. The main disadvantage is that automatic delegation is a pain to do correctly in new-style classes, but trivially simple in classic classes. Still, all things considered, it's a good trade. -- Steven From __peter__ at web.de Tue Sep 25 13:01:38 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 25 Sep 2012 19:01:38 +0200 Subject: How to export a logging level? References: <5061D8A4.40107@swing.be> Message-ID: Vincent Vande Vyvre wrote: > In my application I import a module and I want to set the same logging > level as the main app to this module. Isn't that the default? If you set the logging level with basicConfig() that level should be applied to all messages. From no.email at nospam.invalid Tue Sep 25 13:27:03 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 25 Sep 2012 10:27:03 -0700 Subject: Article on the future of Python References: Message-ID: <7xa9wef1y0.fsf@ruckus.brouhaha.com> Kevin Walzer writes: > language, but it's another thing entirely to call Python the One > Language to Rule Them All. (That's C, because all other languages are > implemented in it. :-) ) I got into a discussion about that in another newsgroup and noticed that C seems to have been a 20th-century language that is still used for maintaining old programs and in the embedded niche, but that very few languages or compilers seem to have been newly implemented in C in the current century. The main counterexample I was able to find was LuaJIT. From junkshops at gmail.com Tue Sep 25 13:39:00 2012 From: junkshops at gmail.com (Junkshops) Date: Tue, 25 Sep 2012 10:39:00 -0700 Subject: Memory usage per top 10x usage per heapy In-Reply-To: <50619035.3080106@davea.name> References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5061056F.6080702@davea.name> <50613131.6030102@gmail.com> <50619035.3080106@davea.name> Message-ID: <5061EC34.5050009@gmail.com> > I'm a bit surprised you aren't beyond the 2gb limit, just with the > structures you describe for the file. You do realize that each object > has quite a few bytes of overhead, so it's not surprising to use several > times the size of a file, to store the file in an organized way. I did some back of the envelope calcs which more or less agreed with heapy. The code stores 1 string, which is, on average, about 50 chars or so, and one MD5 hex string per line of code. There's about 40 bytes or so of overhead per string per sys.getsizeof(). I'm also storing an int (24b) and a <10 char string in an object with __slots__ set. Each object, per heapy (this is one area where I might be underestimating things) takes 64 bytes plus instance variable storage, so per line: 50 + 32 + 10 + 3 * 40 + 24 + 64 = 300 bytes per line * 2M lines = ~600MB plus some memory for the dicts, which is about what heapy is reporting (note I'm currently not actually running all 2M lines, I'm just running subsets for my tests). Is there something I'm missing? Here's the heapy output after loading ~300k lines: Partition of a set of 1199849 objects. Total size = 89965376 bytes. Index Count % Size % Cumulative % Kind 0 599999 50 38399920 43 38399920 43 str 1 5 0 25167224 28 63567144 71 dict 2 299998 25 19199872 21 82767016 92 0xa13330 3 299836 25 7196064 8 89963080 100 int 4 4 0 1152 0 89964232 100 collections.defaultdict Note that 3 of the dicts are empty. I assume that 0xa13330 is the address of the object. I'd actually expect to see 900k strings, but the <10 char string is always the same in this case so perhaps the runtime is using the same object...? At this point, top reports python as using 1.1g of virt and 1.0g of res. > I also > wonder if heapy has been written to take into account the larger size of > pointers in a 64bit build. That I don't know, but that would only explain, at most, a 2x increase in memory over the heapy report, wouldn't it? Not the ~10x I'm seeing. > Another thing is to make sure > that the md5 object used in your two maps is the same object, and not > just one with the same value. That's certainly the way the code is written, and heapy seems to confirm that the strings aren't duplicated in memory. Thanks for sticking with me on this, MrsE On 9/25/2012 4:06 AM, Dave Angel wrote: > On 09/25/2012 12:21 AM, Junkshops wrote: >>> Just curious; which is it, two million lines, or half a million bytes? > >> Sorry, that should've been a 500Mb, 2M line file. >> >>> which machine is 2gb, the Windows machine, or the VM? >> VM. Winders is 4gb. >> >>> ...but I would point out that just because >>> you free up the memory from the Python doesn't mean it gets released >>> back to the system. The C runtime manages its own heap, and is pretty >>> persistent about hanging onto memory once obtained. It's not normally a >>> problem, since most small blocks are reused. But it can get >>> fragmented. And i have no idea how well Virtual Box maps the Linux >>> memory map into the Windows one. >> Right, I understand that - but what's confusing me is that, given the >> memory use is (I assume) monotonically increasing, the code should never >> use more than what's reported by heapy once all the data is loaded into >> memory, given that memory released by the code to the Python runtime is >> reused. To the best of my ability to tell I'm not storing anything I >> shouldn't, so the only thing I can think of is that all the object >> creation and destruction, for some reason, it preventing reuse of >> memory. I'm at a bit of a loss regarding what to try next. > I'm not familiar with heapy, but perhaps it's missing something there. > I'm a bit surprised you aren't beyond the 2gb limit, just with the > structures you describe for the file. You do realize that each object > has quite a few bytes of overhead, so it's not surprising to use several > times the size of a file, to store the file in an organized way. I also > wonder if heapy has been written to take into account the larger size of > pointers in a 64bit build. > > Perhaps one way to save space would be to use a long to store those md5 > values. You'd have to measure it, but I suspect it'd help (at the cost > of lots of extra hexlify-type calls). Another thing is to make sure > that the md5 object used in your two maps is the same object, and not > just one with the same value. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent.vandevyvre at swing.be Tue Sep 25 13:41:38 2012 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Tue, 25 Sep 2012 19:41:38 +0200 Subject: How to export a logging level? In-Reply-To: References: <5061D8A4.40107@swing.be> Message-ID: <5061ECD2.2020603@swing.be> Le 25/09/12 19:01, Peter Otten a ?crit : > Vincent Vande Vyvre wrote: > >> In my application I import a module and I want to set the same logging >> level as the main app to this module. > Isn't that the default? If you set the logging level with basicConfig() that > level should be applied to all messages. > > Not, only the messages from the main class and the others class that are in the same module (folder) appears into the console. Any message from the module imported. -- Vincent V.V. Oqapy . Qarte . PaQager From jeanmichel at sequans.com Tue Sep 25 13:47:20 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 25 Sep 2012 19:47:20 +0200 (CEST) Subject: How to export a logging level? In-Reply-To: <5061D8A4.40107@swing.be> Message-ID: <276124593.587150.1348595240697.JavaMail.root@sequans.com> ----- Original Message ----- > In my application I import a module and I want to set the same > logging > level > as the main app to this module. > > I've tried this code > > main.py > > import logging > logger = logging.getLogger(__name__) > lvl = logging.DEBUG > LOG_FORMAT = "%(asctime)-6s %(levelname)s: %(name)s - %(message)s" > logging.basicConfig(format=LOG_FORMAT, datefmt='%H:%M:%S', level=lvl) > > from mymodule.myfile import MyClass > > ... > def load_myclass(self): > lvl = logger.getEffectiveLevel() > mc = MyClass(self, lvl) > > > myfile.py > > import logging > logger = logging.getLogger(__name__) > > class MyClass(object): > def __init__(self, main, lvl): > logger.setLevel(lvl) > > If I set the level to logging.DEBUG I can see all infos from the main > but anything > from my module. > > Thanks for your advice. > -- > Vincent V.V. > Oqapy . Qarte > . PaQager > > -- > http://mail.python.org/mailman/listinfo/python-list > Life is actually simpler, one rule to remember: you don't configure your loggers, ever. You let this worthless task to the user (in your case the main.py file or however import your module). In myfile.py, the only logging related lines are: import logging logger = logging.getLogger(__name_) Then you just log. How the logs are processed, at which level, for which formatter, you don't care. The root logger will take care of that. Keep your main.py as it is and it should work. JM From junkshops at gmail.com Tue Sep 25 14:08:29 2012 From: junkshops at gmail.com (Junkshops) Date: Tue, 25 Sep 2012 11:08:29 -0700 Subject: Memory usage per top 10x usage per heapy In-Reply-To: References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5060EB2C.6080508@tim.thechases.com> <5060F3BB.7010706@gmail.com> Message-ID: <5061F31D.3020207@gmail.com> > > Can you give an example of how these data structures look after > reading only the first 5 lines? Sure, here you go: In [38]: mpef._ustore._store Out[38]: defaultdict(, {'Measurement': {'8991c2dc67a49b909918477ee4efd767': , '7b38b429230f00fe4731e60419e92346': , 'b53531471b261c44d52f651add647544': , '44ea6d949f7c8c8ac3bb4c0bf4943f82': , '0de96f928dc471b297f8a305e71ae3e1': }}) In [39]: mpef._ustore._store['Measurement']['b53531471b261c44d52f651add647544'].typeStr Out[39]: 'Measurement' In [40]: mpef._ustore._store['Measurement']['b53531471b261c44d52f651add647544'].lineNumber Out[40]: 5 In [41]: mpef._ustore._idstore Out[41]: defaultdict(, {'Measurement': }) In [43]: mpef._ustore._idstore['Measurement']._SIDstore Out[43]: defaultdict( at 0x2ece7d0>, {'emailRemoved': defaultdict( at 0x2c4caa0>, {'microPhenoShew2011': defaultdict(, {0: {'MLR_124572462': '8991c2dc67a49b909918477ee4efd767', 'MLR_124572161': '7b38b429230f00fe4731e60419e92346', 'SMMLR_12551352': 'b53531471b261c44d52f651add647544', 'SMMLR_12551051': '0de96f928dc471b297f8a305e71ae3e1', 'SMMLR_12550750': '44ea6d949f7c8c8ac3bb4c0bf4943f82'}})})}) -MrsE On 9/25/2012 4:33 AM, Oscar Benjamin wrote: > On 25 September 2012 00:58, Junkshops > wrote: > > Hi Tim, thanks for the response. > > > - check how you're reading the data: are you iterating over > the lines a row at a time, or are you using > .read()/.readlines() to pull in the whole file and then > operate on that? > > I'm using enumerate() on an iterable input (which in this case is > the filehandle). > > > - check how you're storing them: are you holding onto more > than you think you are? > > I've used ipython to look through my data structures (without > going into ungainly detail, 2 dicts with X numbers of key/value > pairs, where X = number of lines in the file), and everything > seems to be working correctly. Like I say, heapy output looks > reasonable - I don't see anything surprising there. In one dict > I'm storing a id string (the first token in each line of the file) > with values as (again, without going into massive detail) the md5 > of the contents of the line. The second dict has the md5 as the > key and an object with __slots__ set that stores the line number > of the file and the type of object that line represents. > > > Can you give an example of how these data structures look after > reading only the first 5 lines? > > Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent.vandevyvre at swing.be Tue Sep 25 14:11:47 2012 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Tue, 25 Sep 2012 20:11:47 +0200 Subject: How to export a logging level? In-Reply-To: <276124593.587150.1348595240697.JavaMail.root@sequans.com> References: <276124593.587150.1348595240697.JavaMail.root@sequans.com> Message-ID: <5061F3E3.50507@swing.be> Le 25/09/12 19:47, Jean-Michel Pichavant a ?crit : > ----- Original Message ----- >> In my application I import a module and I want to set the same >> logging >> level >> as the main app to this module. >> >> I've tried this code >> >> main.py >> >> import logging >> logger = logging.getLogger(__name__) >> lvl = logging.DEBUG >> LOG_FORMAT = "%(asctime)-6s %(levelname)s: %(name)s - %(message)s" >> logging.basicConfig(format=LOG_FORMAT, datefmt='%H:%M:%S', level=lvl) >> >> from mymodule.myfile import MyClass >> >> ... >> def load_myclass(self): >> lvl = logger.getEffectiveLevel() >> mc = MyClass(self, lvl) >> >> >> myfile.py >> >> import logging >> logger = logging.getLogger(__name__) >> >> class MyClass(object): >> def __init__(self, main, lvl): >> logger.setLevel(lvl) >> >> If I set the level to logging.DEBUG I can see all infos from the main >> but anything >> from my module. >> >> Thanks for your advice. >> -- >> Vincent V.V. >> Oqapy . Qarte >> . PaQager >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > Life is actually simpler, one rule to remember: you don't configure your loggers, ever. You let this worthless task to the user (in your case the main.py file or however import your module). > > In myfile.py, the only logging related lines are: > > import logging > logger = logging.getLogger(__name_) > > Then you just log. How the logs are processed, at which level, for which formatter, you don't care. The root logger will take care of that. Keep your main.py as it is and it should work. > > JM > > Oops, my fault, I've forgotten a line "logger.setLevel(logging.WARNING)" into my module. Thanks -- Vincent V.V. Oqapy . Qarte . PaQager From oscar.j.benjamin at gmail.com Tue Sep 25 14:17:46 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 25 Sep 2012 19:17:46 +0100 Subject: Memory usage per top 10x usage per heapy In-Reply-To: <5061F31D.3020207@gmail.com> References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5060EB2C.6080508@tim.thechases.com> <5060F3BB.7010706@gmail.com> <5061F31D.3020207@gmail.com> Message-ID: On 25 September 2012 19:08, Junkshops wrote: > > Can you give an example of how these data structures look after reading > only the first 5 lines? > > Sure, here you go: > > In [38]: mpef._ustore._store > Out[38]: defaultdict(, {'Measurement': > {'8991c2dc67a49b909918477ee4efd767': > , > '7b38b429230f00fe4731e60419e92346': > , > 'b53531471b261c44d52f651add647544': > , > '44ea6d949f7c8c8ac3bb4c0bf4943f82': > , > '0de96f928dc471b297f8a305e71ae3e1': > }}) > Have these exceptions been raised from somewhere before being stored? I wonder if you're inadvertently keeping execution frames alive. There are some problems in CPython with this that are related to storing exceptions. > > In [39]: > mpef._ustore._store['Measurement']['b53531471b261c44d52f651add647544'].typeStr > Out[39]: 'Measurement' > Seeing how long these hex strings are, I'm confident that you would save a significant amount of memory by converting them to int. > > In [40]: > mpef._ustore._store['Measurement']['b53531471b261c44d52f651add647544'].lineNumber > Out[40]: 5 > > In [41]: mpef._ustore._idstore > Out[41]: defaultdict(, > {'Measurement': 0x2f0f950>}) > > In [43]: mpef._ustore._idstore['Measurement']._SIDstore > Out[43]: defaultdict( at 0x2ece7d0>, {'emailRemoved': > defaultdict( at 0x2c4caa0>, {'microPhenoShew2011': > defaultdict(, {0: {'MLR_124572462': > '8991c2dc67a49b909918477ee4efd767', 'MLR_124572161': > '7b38b429230f00fe4731e60419e92346', 'SMMLR_12551352': > 'b53531471b261c44d52f651add647544', 'SMMLR_12551051': > '0de96f928dc471b297f8a305e71ae3e1', 'SMMLR_12550750': > '44ea6d949f7c8c8ac3bb4c0bf4943f82'}})})}) > Also I think lambda functions might be able to keep the frame alive. Are they by any chance being created in a function that is called in a loop? >>> def f(): ... x = 4 ... return lambda : x ... >>> g = f() >>> g() # Accesses local variable from kept-alive frame 4 >>> x Traceback (most recent call last): File "", line 1, in NameError: name 'x' is not defined Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Tue Sep 25 14:25:30 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 25 Sep 2012 18:25:30 +0000 (UTC) Subject: Article on the future of Python References: Message-ID: On 2012-09-25, Martin P. Hellwig wrote: > On Tuesday, 25 September 2012 09:14:27 UTC+1, Mark Lawrence wrote: >> Hi all, >> >> I though this might be of interest. >> http://www.ironfroggy.com/software/i-am-worried-about-the-future-of-python > I glanced over the article but it seems to me another 'I am afraid > this is not the silver bullet I wanted it to be' article Strange. I didn't get that _at_all_ from the article. To me it was expressing concern about what happens when the range of "niches" where Python is a good solution falls below a certain critical mass -- will the "Python Community" start to stagnate because it isn't attacting new developers in the quantity or diversity that it used to... -- Grant Edwards grant.b.edwards Yow! Alright, you!! at Imitate a WOUNDED SEAL gmail.com pleading for a PARKING SPACE!! From breamoreboy at yahoo.co.uk Tue Sep 25 14:45:37 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Sep 2012 19:45:37 +0100 Subject: new-style class or old-style class? In-Reply-To: <5061d9db$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com> <5061d9db$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25/09/2012 17:20, Steven D'Aprano wrote: > On Tue, 25 Sep 2012 07:44:04 -0700, Jayden wrote: > >> In learning Python, I found there are two types of classes? Which one >> are widely used in new Python code? > > New-style classes. > >> Is the new-style much better than old-style? > > Yes. > > Always use new-style classes, unless you have some specific reason for > needing old-style ("classic") classes. > > Advantages of new-style classes: > > 1) They are the future. In Python 3, all classes are "new-style" and > classic classes are gone. > > 2) Multiple inheritance works correctly. Multiple inheritance for classic > classes is buggy. > > 3) New-style classes support awesome features like super(), properties, > descriptors, and __getattribute__. Old-style do not. > > The main disadvantage is that automatic delegation is a pain to do > correctly in new-style classes, but trivially simple in classic classes. > Still, all things considered, it's a good trade. > > > Thanks for this reminder, my port of the J word code to Python has just been simplified :) -- Cheers. Mark Lawrence. From d at davea.name Tue Sep 25 14:50:35 2012 From: d at davea.name (Dave Angel) Date: Tue, 25 Sep 2012 14:50:35 -0400 Subject: Memory usage per top 10x usage per heapy In-Reply-To: <5061EC34.5050009@gmail.com> References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5061056F.6080702@davea.name> <50613131.6030102@gmail.com> <50619035.3080106@davea.name> <5061EC34.5050009@gmail.com> Message-ID: <5061FCFB.3030900@davea.name> On 09/25/2012 01:39 PM, Junkshops wrote: Procedural point: I know you're trying to conform to the standard that this mailing list uses, but you're off a little, and it's distracting. It's also probably more work for you, and certainly for us. You need an attribution in front of the quoted portions. This next section is by me, but you don't say so. That's because you copy/pasted it from elsewhere in the reply, and didn't copy the "... Dave Angel wrote" part. Much easier is to take the reply, and remove the parts you're not going to respond to, putting your own comments in between the parts that are left (as you're doing). And generally, there's no need for anything after your last remark, so you just delete up to your signature, if any. >> I'm a bit surprised you aren't beyond the 2gb limit, just with the >> structures you describe for the file. You do realize that each object >> has quite a few bytes of overhead, so it's not surprising to use several >> times the size of a file, to store the file in an organized way. > I did some back of the envelope calcs which more or less agreed with > heapy. The code stores 1 string, which is, on average, about 50 chars or > so, and one MD5 hex string per line of code. There's about 40 bytes or > so of overhead per string per sys.getsizeof(). I'm also storing an int > (24b) and a <10 char string in an object with __slots__ set. Each > object, per heapy (this is one area where I might be underestimating > things) takes 64 bytes plus instance variable storage, so per line: > > 50 + 32 + 10 + 3 * 40 + 24 + 64 = 300 bytes per line * 2M lines = ~600MB > plus some memory for the dicts, which is about what heapy is reporting > (note I'm currently not actually running all 2M lines, I'm just running > subsets for my tests). > > Is there something I'm missing? Here's the heapy output after loading > ~300k lines: > > Partition of a set of 1199849 objects. Total size = 89965376 bytes. > Index Count % Size % Cumulative % Kind > 0 599999 50 38399920 43 38399920 43 str > 1 5 0 25167224 28 63567144 71 dict > 2 299998 25 19199872 21 82767016 92 0xa13330 > 3 299836 25 7196064 8 89963080 100 int > 4 4 0 1152 0 89964232 100 > collections.defaultdict > > Note that 3 of the dicts are empty. I assumet 0xa13330 is the > address of the object. I'd actually expect to see 900k strings, but the > <10 char string is always the same in this case so perhaps the runtime > is using the same object...? CPython currently interns short strings that conform to variable name rules. You can't count on that behavior (and i probably don't have it quite right anyway), but it's probably what you're seeing. > At this point, top reports python as using > 1.1g of virt and 1.0g of res. > >> I also >> wonder if heapy has been written to take into account the larger size of >> pointers in a 64bit build. > That I don't know, but that would only explain, at most, a 2x increase > in memory over the heapy report, wouldn't it? Not the ~10x I'm seeing. > >> Another thing is to make sure >> that the md5 object used in your two maps is the same object, and not >> just one with the same value. > That's certainly the way the code is written, and heapy seems to confirm > that the strings aren't duplicated in memory. > > Thanks for sticking with me on this, You're certainly welcome. I suspect that heapy has some limitation in its reporting, and that's what the discrepancy. Oscar points out that you have a bunch of exception objects, which certainly looks suspicious. If you're somehow storing one of these per line, and heapy isn't reporting them, that could be a large discrepancy. He also points out that you have a couple of lambda functions stored in one of your dictionary. A lambda function can be an expensive proposition if you are building millions of them. So can nested functions with non-local variable references, in case you have any of those. Oscar also reminds you of what I suggested for the md5 fields. Stored as ints instead of hex strings could save a good bit. Just remember to use the same one for both dicts, as you've been doing with the strings. Other than that, I'm stumped. -- DaveA From tyler at tysdomain.com Tue Sep 25 15:04:26 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Tue, 25 Sep 2012 13:04:26 -0600 Subject: google api and oauth2 Message-ID: <5062003A.9020208@tysdomain.com> Hello all: I've been trying to figure out the oauth2client part of google's api, and I am really confused. It shows a flow, and even with the client flow, you need a redirect uri. This isn't important because I just want to get both an access and refresh token. Has anyone had any experience with this? Is it easier to use a more developed oauth2 library to handle this? If so, can anyone make any suggestions? If I understand everything correctly, it doesn't matter what library I would use to work with the oauth2 protocol, so I could break out of this workflow thing that looks like it's more designed for web apps. Finally, they caution you about being careful about your client id and your client secret; is there much in the way of obviscation or something I can do to keep this secret? -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Sep 25 15:40:49 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 25 Sep 2012 21:40:49 +0200 Subject: python file API In-Reply-To: <50615d3b$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> <5060D55C.3000407@davea.name> <506116d4$0$29981$c3e8da3$5496439d@news.astraweb.com> <50615d3b$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 25.09.2012 09:28 schrieb Steven D'Aprano: >> The whole concept is incomplete at one place: self.seek(10, 2) seeks >> beyond EOF, potentially creating a sparse file. This is a thing you >> cannot achieve. > > On the contrary, since the pos attribute is just a wrapper around seek, > you can seek beyond EOF easily: > > f.pos = None > f.pos += 10 Yes, from a syscall perspective, it is different: it is a tell() combined with a seek set instead of a relative seek. As someone mentionned, e. g. in the case of a streamer tape this might make a big difference. > But for anything but the most trivial usage, I would recommend sticking > to the seek method. ACK. This should be kept as a fallback. > ... or we need multiple attributes, one for each mode ... Yes. That's what I would favourize: 3 attributes which each take a value to be passed to seek. > So all up, I'm -1 on trying to replace the tell/seek API, and -0 on > adding a second, redundant API. ACK. Thomas From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Sep 25 15:52:23 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 25 Sep 2012 21:52:23 +0200 Subject: data attributes override method attributes? In-Reply-To: References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Message-ID: Am 25.09.2012 16:08 schrieb Peter Otten: > Jayden wrote: > >> In the Python Tutorial, Section 9.4, it is said that >> >> "Data attributes override method attributes with the same name." > > The tutorial is wrong here. That should be > > "Instance attributes override class attributes with the same name." I jump in here: THere is one point to consider: if you work with descriptors, it makes a difference if they are "data descriptors" (define __set__ and/or __delete__) or "non-data descriptors" (define neither). As http://docs.python.org/reference/datamodel.html#invoking-descriptors tells us, methods are non-data descriptors, so they can be overridden by instances. OTOH, properties are data descriptors which cannot be overridden by the instance. So, to stick to the original example: class TestDesc(object): def a(self): pass @property def b(self): print "trying to get value - return None"; return None @b.setter def b(self, v): print "value", v, "ignored." @b.deleter def b(self): print "delete called and ignored" and now >>> t=TestDesc() >>> t.a > >>> t.b trying to get value - return None >>> t.a=12 >>> t.b=12 value 12 ignored. >>> t.a 12 >>> t.b trying to get value - return None >>> del t.a >>> del t.b delete called and ignored >>> t.a > >>> t.b trying to get value - return None Thomas From tjreedy at udel.edu Tue Sep 25 15:58:26 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 25 Sep 2012 15:58:26 -0400 Subject: data attributes override method attributes? In-Reply-To: References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Message-ID: On 9/25/2012 11:03 AM, Chris Angelico wrote: > On Wed, Sep 26, 2012 at 12:54 AM, Peter Otten <__peter__ at web.de> wrote: >> To me >> >> "Data attributes override method attributes with the same name" >> >> implies that data attributes take precedence over method attributes, not >> that they replace them only when there is an assignment of data after the >> method definition. >> >> I would even consider replacing the whole paragraph >> with something like >> >> "Data attributes and method attributes share the same namespace. To avoid >> name conflicts consider using verbs for methods and nouns for data >> attributes" > > Instance attributes override (shadow) class attributes. except for (some? all?) special methods > Since methods > tend to be on the class and data tends to be on the instance, the > original sentence does make some sense. but it *is* wrong The section is talking about > conventions, so it's not inherently wrong, The suggestion to Capitalize method names and prefix data names with '_' are wrong with respect to the style guide. but perhaps just needs a > comment about methods not usually being attached to the instance. > > ChrisA > -- Terry Jan Reedy From demianbrecht at gmail.com Tue Sep 25 16:05:48 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Tue, 25 Sep 2012 13:05:48 -0700 Subject: google api and oauth2 In-Reply-To: <5062003A.9020208@tysdomain.com> References: <5062003A.9020208@tysdomain.com> Message-ID: This is a shameless plug, but if you want a much easier to understand method of accessing protected resources via OAuth2, I have a 55 LOC client implementation with docs and examples here: https://github.com/demianbrecht/sanction (Google is one of the tested providers with an access example). Are you trying to access resources client side (through Javascript) or server side? Either way, the redirect URI *is* important. The first step is to have your user authorize your application using Google's authorization page. As one of the query parameters, you must specify the redirect URI (which must match those registered through Google's app console). Once the user has authorized your application, they're redirected back to your site (via the specified redirect URI), with a "code" attached as a query param. Once you get that code, you must exchange that with Google's token endpoint to retrieve the access and refresh tokens. No, it doesn't matter which library you use. Google's (imho) is overly verbose and difficult to grok (especially for someone new to either OAuth 2.0 or Python, or both). The client ID doesn't need to be kept private, but the secret does. You should *never* put this anywhere that can be read publicly. On Tue, Sep 25, 2012 at 12:04 PM, Littlefield, Tyler wrote: > Hello all: > I've been trying to figure out the oauth2client part of google's api, and > I am really confused. > It shows a flow, and even with the client flow, you need a redirect uri. > This isn't important because I just want to get both an access and refresh > token. > Has anyone had any experience with this? Is it easier to use a more > developed oauth2 library to handle this? If so, can anyone make any > suggestions? > > If I understand everything correctly, it doesn't matter what library I > would use to work with the oauth2 protocol, so I could break out of this > workflow thing that looks like it's more designed for web apps. > Finally, they caution you about being careful about your client id and > your client secret; is there much in the way of obviscation or something I > can do to keep this secret? > > -- > Take care, > Ty > http://tds-solutions.net > The aspen project: a barebones light-weight mud engine: > http://code.google.com/p/**aspenmud > He that will not reason is a bigot; he that cannot reason is a fool; he > that dares not reason is a slave. > > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Sep 25 16:07:58 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 25 Sep 2012 14:07:58 -0600 Subject: data attributes override method attributes? In-Reply-To: References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Message-ID: On Tue, Sep 25, 2012 at 1:58 PM, Terry Reedy wrote: > On 9/25/2012 11:03 AM, Chris Angelico wrote: >> Instance attributes override (shadow) class attributes. > > > except for (some? all?) special methods Those names are shadowed too. If you call foo.__len__() and the name is bound on the instance, it will call that function preferentially. It's just that when the special Python machinery calls the method, it skips the instance and goes straight to the class. From tjreedy at udel.edu Tue Sep 25 16:18:26 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 25 Sep 2012 16:18:26 -0400 Subject: data attributes override method attributes? In-Reply-To: References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Message-ID: On 9/25/2012 10:54 AM, Peter Otten wrote: > alex23 wrote: > >> On Sep 26, 12:08 am, Peter Otten <__pete... at web.de> wrote: >>> Jayden wrote: >>>> In the Python Tutorial, Section 9.4, it is said that >>> >>>> "Data attributes override method attributes with the same name." >>> >>> The tutorial is wrong here. That should be >>> >>> "Instance attributes override class attributes with the same name." Except for special methods. > I would even consider replacing the whole paragraph I agree > > """ > Data attributes override method attributes with the same name; to avoid > accidental name conflicts, which may cause hard-to-find bugs in large > programs, it is wise to use some kind of convention that minimizes the > chance of conflicts. Possible conventions include capitalizing method names, > prefixing data attribute names with a small unique string (perhaps just an > underscore), or using verbs for methods and nouns for data attributes. > """ > http://docs.python.org/dev/py3k/tutorial/classes.html > > with something like > > "Data attributes and method attributes share the same namespace. and instance attributes usually override class attributes > To avoid > name conflicts consider using verbs for methods and nouns for data > attributes" This applies within and between. I opened http://bugs.python.org/issue16048 -- Terry Jan Reedy From tyler at tysdomain.com Tue Sep 25 16:22:17 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Tue, 25 Sep 2012 14:22:17 -0600 Subject: google api and oauth2 In-Reply-To: References: <5062003A.9020208@tysdomain.com> Message-ID: <50621279.8060700@tysdomain.com> On 9/25/2012 2:05 PM, Demian Brecht wrote: > This is a shameless plug, but if you want a much easier to understand > method of accessing protected resources via OAuth2, I have a 55 LOC > client implementation with docs and examples > here:https://github.com/demianbrecht/sanction (Google is one of the > tested providers with an access example). > No complaints from me if it works. Honestly I was a bit discouraged at Google's decent lack of documentation and the quality of the code. > Are you trying to access resources client side (through Javascript) or > server side? Either way, the redirect URI *is* important. The first > step is to have your user authorize your application using Google's > authorization page. As one of the query parameters, you must specify > the redirect URI (which must match those registered through Google's > app console). > I'm trying to access it through a desktop Python application, which made me really confused. There was something else that talked about returning the tokens in a different way, but it talked about returning them in the title of the webpage, and since I'd be spawning a browser to request authorization, I'd have to write something that would pull the window information and then parse out the token from the title, which doesn't sound to stable. > Once the user has authorized your application, they're redirected back > to your site (via the specified redirect URI), with a "code" attached > as a query param. Once you get that code, you must exchange that with > Google's token endpoint to retrieve the access and refresh tokens. > Awesome. I could theoretically just create a webpage on my server to redirect people to with the query, but I'm still not quite sure how I'd retrieve that from the desktop application. > No, it doesn't matter which library you use. Google's (imho) is overly > verbose and difficult to grok (especially for someone new to either > OAuth 2.0 or Python, or both). The client ID doesn't need to be kept > private, but the secret does. You should *never* put this anywhere > that can be read publicly. > I plan on storing them both in variables. It's not going to be the best solution, but I plan to use python -O to create pyo files, which from what I understand are harder to decompile, and it'll be in a py2exe executable. Still not to hard to get at, but it's not right there either. > On Tue, Sep 25, 2012 at 12:04 PM, Littlefield, Tyler > > wrote: > > Hello all: > I've been trying to figure out the oauth2client part of google's > api, and I am really confused. > It shows a flow, and even with the client flow, you need a > redirect uri. This isn't important because I just want to get both > an access and refresh token. > Has anyone had any experience with this? Is it easier to use a > more developed oauth2 library to handle this? If so, can anyone > make any suggestions? > > If I understand everything correctly, it doesn't matter what > library I would use to work with the oauth2 protocol, so I could > break out of this workflow thing that looks like it's more > designed for web apps. > Finally, they caution you about being careful about your client id > and your client secret; is there much in the way of obviscation > or something I can do to keep this secret? > > -- > Take care, > Ty > http://tds-solutions.net > The aspen project: a barebones light-weight mud engine: > http://code.google.com/p/aspenmud > He that will not reason is a bigot; he that cannot reason is a > fool; he that dares not reason is a slave. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. -------------- next part -------------- An HTML attachment was scrubbed... URL: From junkshops at gmail.com Tue Sep 25 16:26:07 2012 From: junkshops at gmail.com (Junkshops) Date: Tue, 25 Sep 2012 13:26:07 -0700 Subject: Memory usage per top 10x usage per heapy In-Reply-To: References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5060EB2C.6080508@tim.thechases.com> <5060F3BB.7010706@gmail.com> <5061F31D.3020207@gmail.com> Message-ID: <5062135F.5010400@gmail.com> On 9/25/2012 11:17 AM, Oscar Benjamin wrote: > On 25 September 2012 19:08, Junkshops > wrote: > > > In [38]: mpef._ustore._store > Out[38]: defaultdict(, {'Measurement': > {'8991c2dc67a49b909918477ee4efd767': > 0x2f0fe90>, '7b38b429230f00fe4731e60419e92346': > 0x2f0fad0>, 'b53531471b261c44d52f651add647544': > 0x2f0f4d0>, '44ea6d949f7c8c8ac3bb4c0bf4943f82': > 0x2f0f910>, '0de96f928dc471b297f8a305e71ae3e1': > 0x2f0f550>}}) > > > Have these exceptions been raised from somewhere before being stored? > I wonder if you're inadvertently keeping execution frames alive. There > are some problems in CPython with this that are related to storing > exceptions. FileContext objects aren't exceptions. They store information about where the stored object originally came from, so if there's an MD5 or ID clash with a later line in the file the code can report both the current line and the older clashing line to the user. I have an Exception subclass that takes a FileContext as an argument. There are no exceptions thrown in the file I processed to get the heapy results earlier in the thread. >> In [43]: mpef._ustore._idstore['Measurement']._SIDstore >> Out[43]: defaultdict( at 0x2ece7d0>, >> {'emailRemoved': defaultdict( at 0x2c4caa0>, >> {'microPhenoShew2011': defaultdict(, {0: >> {'MLR_124572462': '8991c2dc67a49b909918477ee4efd767', >> 'MLR_124572161': '7b38b429230f00fe4731e60419e92346', >> 'SMMLR_12551352': 'b53531471b261c44d52f651add647544', >> 'SMMLR_12551051': '0de96f928dc471b297f8a305e71ae3e1', >> 'SMMLR_12550750': '44ea6d949f7c8c8ac3bb4c0bf4943f82'}})})}) > Also I think lambda functions might be able to keep the frame alive. > Are they by any chance being created in a function that is called in a > loop? > Here's the context for the lambdas: def __init__(self): self._SIDstore = defaultdict(lambda: defaultdict(lambda: defaultdict(dict))) So the lambda is only being called when a new key is added to the top 3 levels of the datastructure, which in the test case I've been discussing, only happens once each. Although the suggestion to change the hex strings to ints is a good one and I'll do it, what I'm really trying to understand is why there's such a large difference between the memory use per top (and the fact that the code appears to thrash swap) and per heapy and my calculations of how much memory the code should be using. Cheers, MrsEntity -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Sep 25 16:34:12 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 25 Sep 2012 16:34:12 -0400 Subject: data attributes override method attributes? In-Reply-To: References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Message-ID: On 9/25/2012 4:07 PM, Ian Kelly wrote: > On Tue, Sep 25, 2012 at 1:58 PM, Terry Reedy wrote: >> On 9/25/2012 11:03 AM, Chris Angelico wrote: >>> Instance attributes override (shadow) class attributes. >> >> >> except for (some? all?) special methods > > Those names are shadowed too. If you call foo.__len__() and the name > is bound on the instance, it will call that function preferentially. > It's just that when the special Python machinery calls the method, it > skips the instance and goes straight to the class. I added "Ian Kelly reminds me that instance.__xxx__ is only skipped by the internal machinery and not by direct accesses in user code. In the other hand, docs, official or otherwise, are filled with things like 'len(a) calls a.__len__', so I think something should be said that giving instances special method attributes does not have the effect one might expect." to the issue. -- Terry Jan Reedy From junkshops at gmail.com Tue Sep 25 17:02:56 2012 From: junkshops at gmail.com (Junkshops) Date: Tue, 25 Sep 2012 14:02:56 -0700 Subject: Memory usage per top 10x usage per heapy In-Reply-To: <5061FCFB.3030900@davea.name> References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5061056F.6080702@davea.name> <50613131.6030102@gmail.com> <50619035.3080106@davea.name> <5061EC34.5050009@gmail.com> <5061FCFB.3030900@davea.name> Message-ID: <50621C00.5070909@gmail.com> On 9/25/2012 11:50 AM, Dave Angel wrote: > I suspect that heapy has some limitation in its reporting, and that's > what the discrepancy. That would be my first suspicion as well - except that heapy's results agree so well with what I expect, and I can't think of any reason I'd be using 10x more memory. If heapy is wrong, then I need to try and figure out what's using up all that memory some other way... but I don't know what that way might be. > ... can be an expensive proposition if you are building millions of > them. So can nested functions with non-local variable references, in > case you have any of those. Not as far as I know. Cheers, MrsEntity From oscar.j.benjamin at gmail.com Tue Sep 25 17:17:52 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 25 Sep 2012 22:17:52 +0100 Subject: Memory usage per top 10x usage per heapy In-Reply-To: <5062135F.5010400@gmail.com> References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5060EB2C.6080508@tim.thechases.com> <5060F3BB.7010706@gmail.com> <5061F31D.3020207@gmail.com> <5062135F.5010400@gmail.com> Message-ID: On 25 September 2012 21:26, Junkshops wrote: > On 9/25/2012 11:17 AM, Oscar Benjamin wrote: > > On 25 September 2012 19:08, Junkshops wrote: > >> >> In [38]: mpef._ustore._store >> Out[38]: defaultdict(, {'Measurement': >> {'8991c2dc67a49b909918477ee4efd767': >> , >> '7b38b429230f00fe4731e60419e92346': >> , >> 'b53531471b261c44d52f651add647544': >> , >> '44ea6d949f7c8c8ac3bb4c0bf4943f82': >> , >> '0de96f928dc471b297f8a305e71ae3e1': >> }}) >> > > Have these exceptions been raised from somewhere before being stored? I > wonder if you're inadvertently keeping execution frames alive. There are > some problems in CPython with this that are related to storing exceptions. > > FileContext objects aren't exceptions. They store information about where > the stored object originally came from, so if there's an MD5 or ID clash > with a later line in the file the code can report both the current line and > the older clashing line to the user. I have an Exception subclass that > takes a FileContext as an argument. There are no exceptions thrown in the > file I processed to get the heapy results earlier in the thread. > I don't know whether it would be better or worse but it might be worth seeing what happens if you replace the FileContext objects with tuples. > > > In [43]: mpef._ustore._idstore['Measurement']._SIDstore > Out[43]: defaultdict( at 0x2ece7d0>, {'emailRemoved': > defaultdict( at 0x2c4caa0>, {'microPhenoShew2011': > defaultdict(, {0: {'MLR_124572462': > '8991c2dc67a49b909918477ee4efd767', 'MLR_124572161': > '7b38b429230f00fe4731e60419e92346', 'SMMLR_12551352': > 'b53531471b261c44d52f651add647544', 'SMMLR_12551051': > '0de96f928dc471b297f8a305e71ae3e1', 'SMMLR_12550750': > '44ea6d949f7c8c8ac3bb4c0bf4943f82'}})})}) > > Also I think lambda functions might be able to keep the frame alive. Are > they by any chance being created in a function that is called in a loop? > > Here's the context for the lambdas: > > def __init__(self): > self._SIDstore = defaultdict(lambda: defaultdict(lambda: > defaultdict(dict))) > > So the lambda is only being called when a new key is added to the top 3 > levels of the datastructure, which in the test case I've been discussing, > only happens once each. > I can't see anything wrong with that but then I'm not sure if the lambda function always keeps its frame alive. If there's only that one line in the __init__ function then I'd expect it to be fine. > > Although the suggestion to change the hex strings to ints is a good one > and I'll do it, what I'm really trying to understand is why there's such a > large difference between the memory use per top (and the fact that the code > appears to thrash swap) and per heapy and my calculations of how much > memory the code should be using. > Perhaps you could see what objgraph comes up with: http://pypi.python.org/pypi/objgraph So far as I know objgraph doesn't tell you how big objects are but it does give a nice graphical representation of which objects are alive and which other objects they are referenced by. You might find that some other object is kept alive that you didn't expect. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From junkshops at gmail.com Tue Sep 25 17:35:28 2012 From: junkshops at gmail.com (Junkshops) Date: Tue, 25 Sep 2012 14:35:28 -0700 Subject: Memory usage per top 10x usage per heapy In-Reply-To: References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5060EB2C.6080508@tim.thechases.com> <5060F3BB.7010706@gmail.com> <5061F31D.3020207@gmail.com> <5062135F.5010400@gmail.com> Message-ID: <506223A0.2020003@gmail.com> On 9/25/2012 2:17 PM, Oscar Benjamin wrote: > I don't know whether it would be better or worse but it might be worth > seeing what happens if you replace the FileContext objects with tuples. I originally used a string, and it was slightly better since you don't have the object overhead, but I wanted to code to an interface for the context information so started a Context abstract class that FileContext inherits from (both have __slots__ set). Using an object without __slots__ set was a disaster. However, the difference between a string and an object with __slots__ isn't severe. > > I can't see anything wrong with that but then I'm not sure if the > lambda function always keeps its frame alive. If there's only that one > line in the __init__ function then I'd expect it to be fine. That's it, I'm afraid. > > Perhaps you could see what objgraph comes up with: > http://pypi.python.org/pypi/objgraph > > So far as I know objgraph doesn't tell you how big objects are but it > does give a nice graphical representation of which objects are alive > and which other objects they are referenced by. You might find that > some other object is kept alive that you didn't expect. > I'll give it a shot and see what happens. Cheers, MrsEntity From ian.g.kelly at gmail.com Tue Sep 25 18:09:24 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 25 Sep 2012 16:09:24 -0600 Subject: Memory usage per top 10x usage per heapy In-Reply-To: References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5060EB2C.6080508@tim.thechases.com> <5060F3BB.7010706@gmail.com> <5061F31D.3020207@gmail.com> Message-ID: On Tue, Sep 25, 2012 at 12:17 PM, Oscar Benjamin wrote: > Also I think lambda functions might be able to keep the frame alive. Are > they by any chance being created in a function that is called in a loop? I'm pretty sure they don't. Closures don't keep a reference to the calling frame, only to the appropriate cellvars. Also note that whether a function is a closure has nothing to do with whether it was defined by a lambda or a def statement. In fact, there's no difference between functions created by one vs. the other, except that one has an interesting __name__ and the other does not. :-) From python.list at tim.thechases.com Tue Sep 25 18:10:43 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 25 Sep 2012 17:10:43 -0500 Subject: Memory usage per top 10x usage per heapy In-Reply-To: References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5060EB2C.6080508@tim.thechases.com> <5060F3BB.7010706@gmail.com> <5061F31D.3020207@gmail.com> <5062135F.5010400@gmail.com> Message-ID: <50622BE3.6020306@tim.thechases.com> On 09/25/12 16:17, Oscar Benjamin wrote: > I don't know whether it would be better or worse but it might be > worth seeing what happens if you replace the FileContext objects > with tuples. If tuples provide a savings but you find them opaque, you might also consider named-tuples for clarity. -tkc From dihedral88888 at googlemail.com Tue Sep 25 18:39:39 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 25 Sep 2012 15:39:39 -0700 (PDT) Subject: How to limit CPU usage in Python In-Reply-To: References: <505B326C.1060503@cnic.edu.cu> Message-ID: <5c05ff8d-9bca-4c21-a7b6-93e010c3cb20@googlegroups.com> DPalao? 2012?9?25????UTC+8??11?13?54???? > On Jueves septiembre 20 2012 11:12:44 Rolando Ca?er Roblejo escribi?: > > > Hi all, > > > > > > Is it possible for me to put a limit in the amount of processor usage (% > > > CPU) that my current python script is using? Is there any module useful > > > for this task? I saw Resource module but I think it is not the module I > > > am looking for. Some people recommend to use nice and cpulimit unix > > > tools, but those are external to python and I prefer a python solution. > > > I am working with Linux (Ubuntu 10.04). > > > > > > Best regards. > > > > Hola, > > Sometimes a stupid solution like the following does the trick: > > > > > import time > > > for t in tasks: > > > do_something(t) > > > time.sleep(some_seconds) > > > > where "some_seconds" is a number related to the typical time-scale of the > > tasks you are doing. > > > > Hope it helps, > > > > Regards > > > > > > -- > > Miller's Slogan: > > Lose a few, lose a few. I think I'll prefer to use a generator of my object in python to replace the sleep from the unix world. The reason is that I am not paid from selling or buying work-stations in some business unit directly and immediately. From dihedral88888 at googlemail.com Tue Sep 25 18:39:39 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 25 Sep 2012 15:39:39 -0700 (PDT) Subject: How to limit CPU usage in Python In-Reply-To: References: <505B326C.1060503@cnic.edu.cu> Message-ID: <5c05ff8d-9bca-4c21-a7b6-93e010c3cb20@googlegroups.com> DPalao? 2012?9?25????UTC+8??11?13?54???? > On Jueves septiembre 20 2012 11:12:44 Rolando Ca?er Roblejo escribi?: > > > Hi all, > > > > > > Is it possible for me to put a limit in the amount of processor usage (% > > > CPU) that my current python script is using? Is there any module useful > > > for this task? I saw Resource module but I think it is not the module I > > > am looking for. Some people recommend to use nice and cpulimit unix > > > tools, but those are external to python and I prefer a python solution. > > > I am working with Linux (Ubuntu 10.04). > > > > > > Best regards. > > > > Hola, > > Sometimes a stupid solution like the following does the trick: > > > > > import time > > > for t in tasks: > > > do_something(t) > > > time.sleep(some_seconds) > > > > where "some_seconds" is a number related to the typical time-scale of the > > tasks you are doing. > > > > Hope it helps, > > > > Regards > > > > > > -- > > Miller's Slogan: > > Lose a few, lose a few. I think I'll prefer to use a generator of my object in python to replace the sleep from the unix world. The reason is that I am not paid from selling or buying work-stations in some business unit directly and immediately. From oscar.j.benjamin at gmail.com Tue Sep 25 18:44:00 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 25 Sep 2012 23:44:00 +0100 Subject: Memory usage per top 10x usage per heapy In-Reply-To: References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5060EB2C.6080508@tim.thechases.com> <5060F3BB.7010706@gmail.com> <5061F31D.3020207@gmail.com> Message-ID: On 25 September 2012 23:09, Ian Kelly wrote: > On Tue, Sep 25, 2012 at 12:17 PM, Oscar Benjamin > wrote: > > Also I think lambda functions might be able to keep the frame alive. Are > > they by any chance being created in a function that is called in a loop? > > I'm pretty sure they don't. Closures don't keep a reference to the > calling frame, only to the appropriate cellvars. > OK, that's good to know. > > Also note that whether a function is a closure has nothing to do with > whether it was defined by a lambda or a def statement. In fact, > there's no difference between functions created by one vs. the other, > except that one has an interesting __name__ and the other does not. > :-) That's true but in my experience most lambda functions are defined inside another function, whereas most ordinary functions are not. Also when creating a closure with an ordinary function it's very clear what you are doing (which is why I don't use lambda functions for this) so I think it's a little easier to accidentally create a closure with a lambda function. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Tue Sep 25 18:55:59 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 25 Sep 2012 23:55:59 +0100 Subject: Memory usage per top 10x usage per heapy In-Reply-To: <50622BE3.6020306@tim.thechases.com> References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5060EB2C.6080508@tim.thechases.com> <5060F3BB.7010706@gmail.com> <5061F31D.3020207@gmail.com> <5062135F.5010400@gmail.com> <50622BE3.6020306@tim.thechases.com> Message-ID: On 25 September 2012 23:10, Tim Chase wrote: > On 09/25/12 16:17, Oscar Benjamin wrote: > > I don't know whether it would be better or worse but it might be > > worth seeing what happens if you replace the FileContext objects > > with tuples. > > If tuples provide a savings but you find them opaque, you might also > consider named-tuples for clarity. > Do they have the same memory usage? Since tuples don't have a per-instance __dict__, I'd expect them to be a lot lighter. I'm not sure if I'm interpreting the results below properly but they seem to suggest that a namedtuple can have a memory consumption several times larger than an ordinary tuple. >>> import sys >>> import collections >>> A = collections.namedtuple('A', ['x', 'y']) >>> sys.getsizeof(a) 72 >>> sys.getsizeof(A(1, 2)) 72 >>> sys.getsizeof((1, 2)) 72 >>> sys.getsizeof(A(1, 2).__dict__) 280 >>> A(1, 2).__dict__ OrderedDict([('x', 1), ('y', 2)]) >>> sys.getsizeof((1, 2).__dict__) Traceback (most recent call last): File "", line 1, in AttributeError: 'tuple' object has no attribute '__dict__' >>> A(1, 2).__dict__ is A(3, 4).__dict__ False Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruceg113355 at gmail.com Tue Sep 25 19:17:24 2012 From: bruceg113355 at gmail.com (bruceg113355 at gmail.com) Date: Tue, 25 Sep 2012 16:17:24 -0700 (PDT) Subject: Need to archive a MySQL database using a python script Message-ID: <3dce14bc-cdec-4bcb-a41d-d5de1ef10bf6@googlegroups.com> Python Users Group, I need to archive a MySQL database using a python script. I found a good example at: https://gist.github.com/3175221 The following line executes however, the archive file is empty. os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" % (user,password,host,database,database+"_"+filestamp)) Where: User = ?someUser? password = ?somePassword? host = ?someRemote.database.server? database = ?someDatabase? If I execute mysqldump from the command line, an archive is created. Using Python 2.6 and MySQL-python-1.2.2.win32-py2.6 (MySQLdb) Mysql-5.5.27 from the command line. Any ideas? Thanks, Bruce From oscar.j.benjamin at gmail.com Tue Sep 25 19:32:13 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 26 Sep 2012 00:32:13 +0100 Subject: Need to archive a MySQL database using a python script In-Reply-To: <3dce14bc-cdec-4bcb-a41d-d5de1ef10bf6@googlegroups.com> References: <3dce14bc-cdec-4bcb-a41d-d5de1ef10bf6@googlegroups.com> Message-ID: On 26 September 2012 00:17, wrote: > Python Users Group, > > I need to archive a MySQL database using a python script. > I found a good example at: https://gist.github.com/3175221 > > The following line executes however, the archive file is empty. > > os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" % > (user,password,host,database,database+"_"+filestamp)) > Where: > User = ?someUser? > password = ?somePassword? > host = ?someRemote.database.server? > database = ?someDatabase? > I hope you're getting those variables from a trusted source as this code is vulnerable to injection. Use subprocess.check_call instead of os.popen. os.popen is obsolete and it also doesn't quite do what you think. It returns a file object. You need to read the data from the file object and then close it to make the process actually run. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From dihedral88888 at googlemail.com Tue Sep 25 19:34:01 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 25 Sep 2012 16:34:01 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: Message-ID: Grant Edwards? 2012?9?26????UTC+8??2?25?31???? > On 2012-09-25, Martin P. Hellwig wrote: > > > On Tuesday, 25 September 2012 09:14:27 UTC+1, Mark Lawrence wrote: > > >> Hi all, > > >> > > >> I though this might be of interest. > > >> http://www.ironfroggy.com/software/i-am-worried-about-the-future-of-python > > > > > I glanced over the article but it seems to me another 'I am afraid > > > this is not the silver bullet I wanted it to be' article > > > > Strange. I didn't get that _at_all_ from the article. > > > > To me it was expressing concern about what happens when the range of > > "niches" where Python is a good solution falls below a certain > > critical mass -- will the "Python Community" start to stagnate because > > it isn't attacting new developers in the quantity or diversity that it > > used to... > > > > -- > > Grant Edwards grant.b.edwards Yow! Alright, you!! > > at Imitate a WOUNDED SEAL > > gmail.com pleading for a PARKING > > SPACE!! I don't think so in 201X. The uni-code support for users and clients all over the world should not be taxed by WINTEL only in multi-language support under the OS. I am glad to see a lot smart phones or pads are fostering applications in various languages to help the IT industry keeping growing and expanding to those regeions covered by wirelees digital communications with devices priced in the range 200 to 12000 usd. From python.list at tim.thechases.com Tue Sep 25 19:35:53 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 25 Sep 2012 18:35:53 -0500 Subject: Memory usage per top 10x usage per heapy In-Reply-To: References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5060EB2C.6080508@tim.thechases.com> <5060F3BB.7010706@gmail.com> <5061F31D.3020207@gmail.com> <5062135F.5010400@gmail.com> <50622BE3.6020306@tim.thechases.com> Message-ID: <50623FD9.7000907@tim.thechases.com> On 09/25/12 17:55, Oscar Benjamin wrote: > On 25 September 2012 23:10, Tim Chase wrote: >> If tuples provide a savings but you find them opaque, you might also >> consider named-tuples for clarity. > > Do they have the same memory usage? > > Since tuples don't have a per-instance __dict__, I'd expect them to be a > lot lighter. I'm not sure if I'm interpreting the results below properly > but they seem to suggest that a namedtuple can have a memory consumption > several times larger than an ordinary tuple. I think the "how much memory is $METHOD using" topic of the thread is the root of the problem. From my testing of your question: >>> import collections, sys >>> A = collections.namedtuple('A', ['x', 'y']) >>> nt = A(1,3) >>> t = (1,3) >>> sys.getsizeof(nt) 72 >>> sys.getsizeof(t) 72 >>> nt_s = set(dir(nt)) >>> t_s = set(dir(t)) >>> t_s ^ nt_s set(['__module__', '_make', '_asdict', '_replace', '_fields', '__slots__', 'y', 'x']) >>> t_s - nt_s set([]) So a named-tuple has 6+n (where "n" is the number of fields) extra attributes, but it seems that namedtuples & tuples seem to occupy the same amount of space (72). Additionally, pulling up a second console and issuing ps v | grep [p]ython shows the memory usage of the process as I perform these, and after them, and they both show the same usage (actual test was 1) pull up a fresh python 2) import sys, collections; A = collections.namedtuple('A',['x','y']) 3) check memory usage in other window 4a) x = (1,2) 4b) x = A(1,2) 5) check memory usage again in other window 6) quit python performing 4a on one run, and 4b on the second run. Both showed identical memory usage as well (Debian Linux (Stable), stock Python 2.6.6) at the system level. I don't know if that little testing is actually worth anything, but at least it's another data-point as we muddle towards helping MrsEntity/junkshops. -tkc From oscar.j.benjamin at gmail.com Tue Sep 25 19:48:55 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 26 Sep 2012 00:48:55 +0100 Subject: Memory usage per top 10x usage per heapy In-Reply-To: <50623FD9.7000907@tim.thechases.com> References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5060EB2C.6080508@tim.thechases.com> <5060F3BB.7010706@gmail.com> <5061F31D.3020207@gmail.com> <5062135F.5010400@gmail.com> <50622BE3.6020306@tim.thechases.com> <50623FD9.7000907@tim.thechases.com> Message-ID: On 26 September 2012 00:35, Tim Chase wrote: > On 09/25/12 17:55, Oscar Benjamin wrote: > > On 25 September 2012 23:10, Tim Chase > wrote: > >> If tuples provide a savings but you find them opaque, you might also > >> consider named-tuples for clarity. > > > > Do they have the same memory usage? > > > > Since tuples don't have a per-instance __dict__, I'd expect them to be a > > lot lighter. I'm not sure if I'm interpreting the results below properly > > but they seem to suggest that a namedtuple can have a memory consumption > > several times larger than an ordinary tuple. > > I think the "how much memory is $METHOD using" topic of the thread > is the root of the problem. From my testing of your question: > > >>> import collections, sys > >>> A = collections.namedtuple('A', ['x', 'y']) > >>> nt = A(1,3) > >>> t = (1,3) > >>> sys.getsizeof(nt) > 72 > >>> sys.getsizeof(t) > 72 > >>> nt_s = set(dir(nt)) > >>> t_s = set(dir(t)) > >>> t_s ^ nt_s > set(['__module__', '_make', '_asdict', '_replace', '_fields', > '__slots__', 'y', 'x']) > >>> t_s - nt_s > set([]) > On my system these is an additional __dict__ attribute and it is bigger than the original tuple: $ python Python 2.7.3 (default, Apr 20 2012, 22:39:59) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import collections, sys >>> A = collections.namedtuple('A', ['x', 'y']) >>> nt = A(1,3) >>> t = (1,3) >>> set(dir(nt)) - set(dir(t)) set(['__module__', '_replace', '_make', 'y', '__slots__', '_asdict', '__dict__', 'x', '_fields']) >>> sys.getsizeof(nt.__dict__) 280 >>> sys.getsizeof(t.__dict__) Traceback (most recent call last): File "", line 1, in AttributeError: 'tuple' object has no attribute '__dict__' > > So a named-tuple has 6+n (where "n" is the number of fields) extra > attributes, but it seems that namedtuples & tuples seem to occupy > the same amount of space (72). > > Additionally, pulling up a second console and issuing > > ps v | grep [p]ython > > shows the memory usage of the process as I perform these, and after > them, and they both show the same usage (actual test was > > 1) pull up a fresh python > 2) import sys, collections; A = collections.namedtuple('A',['x','y']) > 3) check memory usage in other window > 4a) x = (1,2) > 4b) x = A(1,2) > 5) check memory usage again in other window > 6) quit python > > performing 4a on one run, and 4b on the second run. > > Both showed identical memory usage as well (Debian Linux (Stable), > stock Python 2.6.6) at the system level. > Python uses memory pools for small memory allocations. I don't think it's possible to tell from the outside how much memory is being used at such a fine level. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Sep 25 20:54:51 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Sep 2012 00:54:51 GMT Subject: Article on the future of Python References: Message-ID: <5062525b$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Sep 2012 18:25:30 +0000, Grant Edwards wrote: > On 2012-09-25, Martin P. Hellwig wrote: >> On Tuesday, 25 September 2012 09:14:27 UTC+1, Mark Lawrence wrote: >>> Hi all, >>> >>> I though this might be of interest. >>> http://www.ironfroggy.com/software/i-am-worried-about-the-future-of- python > >> I glanced over the article but it seems to me another 'I am afraid this >> is not the silver bullet I wanted it to be' article > > Strange. I didn't get that _at_all_ from the article. > > To me it was expressing concern about what happens when the range of > "niches" where Python is a good solution falls below a certain critical > mass -- will the "Python Community" start to stagnate because it isn't > attacting new developers in the quantity or diversity that it used to... Sounds like the same thing to me. Since Python fails to capture all the development niches, it is not a silver bullet for programming, and therefore it won't attract the fresh new blood it needs, because everyone is programming for . I guarantee you that you could pick *any* language in existence, and find three areas that are dominated by other languages, which *somebody* could have convinced themselves is essential to the health of the community. C? Once upon a time the C community was growing at a rapid rate because of the Unix admins that picked it up from day-to-day scripting tasks using c-shell. C became popular on the back of Unix, Unix has stagnated and people have moved on from csh to bash and other shells. The default shell on Linux is bash! C is in danger of no longer attracting new developers, and if you think the Python 2 -> 3 transition was disruptive, you should see what's happened in C: you have C, C++, Objective-C, C#, even C-- and D. SQL? All the exciting, innovative work in databases is happening in the non-relational field of NoSQL languages. Without the ability to handle Google's database needs, and with a name like NoSQL attracting all the best and brightest database developers away from SQL, it's time to sell your shares in Oracle. Java? More and more development is moving to HTML5 and Javascript. With the public's abandonment of the Java plugin for browsers, and schools moving towards Python and PHP as a first language, Java's days are numbered. Cobol? Sure, eighty percent of the code in active use is written in Cobol. Sure, there are 200 times more Cobol transactions per day than Google searches -- about three quarters of *all* computer transactions are done using Cobol. But Cobol only gets used for such boring stuff as keeping your money safe in the bank. All the real innovation is in, well, everything except Cobol. The imminent demise of Cobol is predicted for 1975^W 1980^W 1985^W 1990^W 1995^W 2005^W 2010^W 2015. -- Steven From drobinow at gmail.com Tue Sep 25 21:00:43 2012 From: drobinow at gmail.com (David Robinow) Date: Tue, 25 Sep 2012 21:00:43 -0400 Subject: Stop feeding the trolls (Was: which a is used?) In-Reply-To: <20120925095327.aa0d222bad8678f6c0339fbf@druid.net> References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> <20120925095327.aa0d222bad8678f6c0339fbf@druid.net> Message-ID: On Tue, Sep 25, 2012 at 9:53 AM, D'Arcy Cain wrote: > ... > Now if only people would stop feeding the troll, those of us who have > already *plonked* him can stop seeing his ramblings in the responses. I'm hating myself for jumping in to this nonsense, but ... +1 From no.email at nospam.invalid Tue Sep 25 21:04:33 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 25 Sep 2012 18:04:33 -0700 Subject: Article on the future of Python References: <5062525b$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7x392561cu.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > C? Once upon a time the C community was growing at a rapid rate > because of the Unix admins that picked it up from day-to-day scripting > tasks using c-shell. Er, I think it was developers rather than admins back then... the sysadmin languages were awk then Perl. > SQL? All the exciting, innovative work in databases is happening in the > non-relational field of NoSQL languages. Where have you been? That was LAST week... http://highscalability.com/blog/2012/9/24/google-spanners-most-surprising-revelation-nosql-is-out-and.html (shorter: http://tinyurl.com/8v3dzyr ) ;-) > More and more development is moving to HTML5 and Javascript. Yes. Python, Ruby, and Javascript are all pretty similar languages. I'm pretty comfortable with Python so I don't feel much need to pursue Ruby, and from the Ruby side the Python picture looks similar. Javascript used to live mostly in browsers so it didn't come into the question except for client-side web programmers. But, web client programming has gotten more ubiquitous than ever, and Javascript is metastasizing to the desktop and server through things like node.js. So it may in fact put pressure on Python. From ben+python at benfinney.id.au Tue Sep 25 21:47:30 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 26 Sep 2012 11:47:30 +1000 Subject: Who's laughing at my responses, and who's not? References: <5bc2681o43dhv5p13v71jqodtnokbq9mko@4ax.com> <5061402E.8080706@stoneleaf.us> Message-ID: <7wpq59eerx.fsf@benfinney.id.au> Dwight Hutto writes: > It's a little guy talk, and most seem to be guys. Potty mouth is not ?guy talk?, and sexism is not welcome here. -- \ ?The opposite of a correct statement is a false statement. But | `\ the opposite of a profound truth may well be another profound | _o__) truth.? ?Niels Bohr | Ben Finney From rosuav at gmail.com Wed Sep 26 00:10:28 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Sep 2012 14:10:28 +1000 Subject: Article on the future of Python In-Reply-To: <7x392561cu.fsf@ruckus.brouhaha.com> References: <5062525b$0$29981$c3e8da3$5496439d@news.astraweb.com> <7x392561cu.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Sep 26, 2012 at 10:54 AM, Steven D'Aprano wrote: > SQL? ... it's time to sell your shares in Oracle. Ehh, I wouldn't be investing in Oracle, but that's more because I think free RDBMSes like PostgreSQL outshine it. And this is even more true of MS SQL Server - this last week I've been researching options for moving work's services to the cloud, and SQL Server licenses cost ridiculous amounts (per month or per hour); what do you get for that money that you can't get from Postgres? On Wed, Sep 26, 2012 at 11:04 AM, Paul Rubin wrote: > Yes. Python, Ruby, and Javascript are all pretty similar languages. > I'm pretty comfortable with Python so I don't feel much need to pursue > Ruby, and from the Ruby side the Python picture looks similar. > Javascript used to live mostly in browsers so it didn't come into the > question except for client-side web programmers. But, web client > programming has gotten more ubiquitous than ever, and Javascript is > metastasizing to the desktop and server through things like node.js. So > it may in fact put pressure on Python. Well, Python, Ruby, and JavaScript/Javascript/ECMAScript/etceterascript aren't what I'd call "similar languages", except that they're all modern high level languages. But they're all able to solve similar problems, which I think is what you're saying here. The flip side to node.js is pyjs. One lets you write your server in Javascript... the other lets you write your client in Python. And there are quite a few other options for writing browser scripts in other languages. Is JS dead yet? Nope. There's room in this world for a lot of languages. ChrisA From steve+comp.lang.python at pearwood.info Wed Sep 26 01:16:37 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Sep 2012 05:16:37 GMT Subject: Article on the future of Python References: <5062525b$0$29981$c3e8da3$5496439d@news.astraweb.com> <7x392561cu.fsf@ruckus.brouhaha.com> Message-ID: <50628fb5$0$29997$c3e8da3$5496439d@news.astraweb.com> On Wed, 26 Sep 2012 14:10:28 +1000, Chris Angelico wrote: > The flip side to node.js is pyjs. After the ham-fisted, nasty way pyjamas project was hijacked this year, I'm not entirely sure I'd want to touch it with a fifty-foot pole. http://technogems.blogspot.com.au/2012/05/pyjamas-hijacked.html Any pajamas users here want to comment on the fallout? Is the project alive, dead, or walking dead? -- Steven From kushal.kumaran+python at gmail.com Wed Sep 26 01:24:23 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Wed, 26 Sep 2012 10:54:23 +0530 Subject: google api and oauth2 In-Reply-To: <50621279.8060700@tysdomain.com> References: <5062003A.9020208@tysdomain.com> <50621279.8060700@tysdomain.com> Message-ID: (making no attempt to fix messed up quoting, please take a look at your mail client configuration) On Wed, Sep 26, 2012 at 1:52 AM, Littlefield, Tyler wrote: > On 9/25/2012 2:05 PM, Demian Brecht wrote: > > This is a shameless plug, but if you want a much easier to understand method > of accessing protected resources via OAuth2, I have a 55 LOC client > implementation with docs and examples here: > https://github.com/demianbrecht/sanction (Google is one of the tested > providers with an access example). > > > No complaints from me if it works. Honestly I was a bit discouraged at > Google's decent lack of documentation and the quality of the code. > If you are writing a desktop application, read this: https://developers.google.com/accounts/docs/OAuth2#clientside > > Are you trying to access resources client side (through Javascript) or > server side? Either way, the redirect URI *is* important. The first step is > to have your user authorize your application using Google's authorization > page. As one of the query parameters, you must specify the redirect URI > (which must match those registered through Google's app console). > > I'm trying to access it through a desktop Python application, which made me > really confused. There was something else that talked about returning the > tokens in a different way, but it talked about returning them in the title > of the webpage, and since I'd be spawning a browser to request > authorization, I'd have to write something that would pull the window > information and then parse out the token from the title, which doesn't sound > to stable. > After authenticating with google from a web browser, and authorizing your application, the user will be presented with a web page from which they can copy the access token (from the url or a text field presented in the web page) and input into your application using whatever mechanism you choose. If you are a simple text-based app, you can just use input() to ask for the token. If you are a GUI app, you can do other things, such as embedding a web browser into your application and reading the redirected URL. > > Once the user has authorized your application, they're redirected back to > your site (via the specified redirect URI), with a "code" attached as a > query param. Once you get that code, you must exchange that with Google's > token endpoint to retrieve the access and refresh tokens. > > Awesome. I could theoretically just create a webpage on my server to > redirect people to with the query, but I'm still not quite sure how I'd > retrieve that from the desktop application. > > > No, it doesn't matter which library you use. Google's (imho) is overly > verbose and difficult to grok (especially for someone new to either OAuth > 2.0 or Python, or both). The client ID doesn't need to be kept private, but > the secret does. You should *never* put this anywhere that can be read > publicly. > > I plan on storing them both in variables. It's not going to be the best > solution, but I plan to use python -O to create pyo files, which from what I > understand are harder to decompile, and it'll be in a py2exe executable. > Still not to hard to get at, but it's not right there either. > Don't worry about it. There is no way to keep it secret for desktop applications. It is exactly the same as the DRM problem. The google documentation itself admits: "... These applications, in general, cannot keep secrets.". You should store the given tokens persistently, though. > In the past, I made a half-hearted attempt to writing something to upload stuff to google calendar from .ics files. Here's the google-authentication part of the code, if you can use it. I cannot, at the moment, recall why I did not use the oauth2client library from google. #!/usr/bin/env python3 import datetime import json import os.path import configparser import requests import webbrowser import urllib.parse def _store_tokens(auth_data, filename): expiry_time = (datetime.datetime.now() + datetime.timedelta(seconds=int(auth_data['expires_in']))) auth_data['expiry_time'] = expiry_time.isoformat() with open(filename, 'w') as file_stream: json.dump(auth_data, file_stream) def _get_new_token(config, token_file): payload = { 'response_type' : 'code', 'client_id' : config['api']['client_id'], 'redirect_uri' : config['api']['redirect_uri'], 'scope' : 'https://www.googleapis.com/auth/calendar', 'state' : 'init' } url = 'https://accounts.google.com/o/oauth2/auth' params = ['{}={}'.format(key, urllib.parse.quote(value)) for (key, value) in payload.items()] webbrowser.open('{}?{}'.format(url, '&'.join(params)), new=2) auth_code = input('Enter authorization code obtained: ') payload = { 'code' : auth_code, 'client_id' : config['api']['client_id'], 'client_secret' : config['api']['client_secret'], 'redirect_uri' : config['api']['redirect_uri'], 'grant_type' : 'authorization_code' } r = requests.post('https://accounts.google.com/o/oauth2/token', data=payload) auth_data = json.loads(r.text) _store_tokens(auth_data, token_file) return auth_data['access_token'] def _refreshed_token(config, auth_data, token_file): payload = { 'refresh_token' : auth_data['refresh_token'], 'client_id' : config['api']['client_id'], 'client_secret' : config['api']['client_secret'], 'grant_type' : 'refresh_token' } r = requests.post('https://accounts.google.com/o/oauth2/token', data=payload) auth_data = json.loads(r.text) _store_tokens(auth_data, token_file) return auth_data['access_token'] def _get_existing_token(config, token_file): with open(token_file) as token_stream: auth_data = json.load(token_stream) now = datetime.datetime.now().isoformat() if auth_data['expiry_time'] < now: return _refreshed_token(config, auth_data, token_file) return auth_data['access_token'] def auth(config): token_file = os.path.expanduser(config['api']['token_file']) if os.path.exists(token_file): return _get_existing_token(config, token_file) else: return _get_new_token(config, token_file) The "config" object required by the auth function is from a config file that looks like this: [api] client_id = client_secret = redirect_uri = urn:ietf:wg:oauth:2.0:oob token_file = ~/.google-tokens The "scope" value in the _get_new_token function will need to be changed to whatever scope your application needs. This code uses the python requests module for http(s) requests. It will start up a web browser to let the user authenticate and then asks for the token. The google api will issue two tokens: an "access" token and a "refresh" token. The access token will have a short expiry time, after which you need to get another access token issued. You use the refresh token for that reissue request. -- regards, kushal From rosuav at gmail.com Wed Sep 26 02:02:39 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Sep 2012 16:02:39 +1000 Subject: Article on the future of Python In-Reply-To: <50628fb5$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <5062525b$0$29981$c3e8da3$5496439d@news.astraweb.com> <7x392561cu.fsf@ruckus.brouhaha.com> <50628fb5$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 26, 2012 at 3:16 PM, Steven D'Aprano wrote: > On Wed, 26 Sep 2012 14:10:28 +1000, Chris Angelico wrote: > >> The flip side to node.js is pyjs. > > After the ham-fisted, nasty way pyjamas project was hijacked this year, > I'm not entirely sure I'd want to touch it with a fifty-foot pole. > > http://technogems.blogspot.com.au/2012/05/pyjamas-hijacked.html > > Any pajamas users here want to comment on the fallout? Is the project > alive, dead, or walking dead? That is true, but the concept is still around - that you can write your code in some other language and compile to js. Personally, I'd rather just write my js directly, and use Python to write Python code, but I'm sufficiently multilingual to be able to do that. If you know only 1-2 languages, there's (short-term) benefit in using them for more tasks. ChrisA From no.email at nospam.invalid Wed Sep 26 02:09:36 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 25 Sep 2012 23:09:36 -0700 Subject: Article on the future of Python References: <5062525b$0$29981$c3e8da3$5496439d@news.astraweb.com> <7x392561cu.fsf@ruckus.brouhaha.com> <50628fb5$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xvcf1fh7j.fsf@ruckus.brouhaha.com> Chris Angelico writes: > That is true, but the concept is still around - that you can write > your code in some other language and compile to js. http://www.haskell.org/haskellwiki/The_JavaScript_Problem From demianbrecht at gmail.com Wed Sep 26 02:15:50 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Tue, 25 Sep 2012 23:15:50 -0700 Subject: google api and oauth2 In-Reply-To: References: <5062003A.9020208@tysdomain.com> <50621279.8060700@tysdomain.com> Message-ID: > > > If you are writing a desktop application, read this: > https://developers.google.com/accounts/docs/OAuth2#clientside You mean https://developers.google.com/accounts/docs/OAuth2#installed? Your link discusses client side browser implementations. I'd be curious to know the shortcomings of sanction in the context of installed apps. My original intent was to provide a server flow implementation. If the installed flow isn't too much of a change (doesn't seem like it would be, according to the docs, it's how the "code" is retrieved by the application), I'd happily add it in or take a patch to cover it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Wed Sep 26 02:35:39 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 25 Sep 2012 23:35:39 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: Message-ID: Le mercredi 26 septembre 2012 01:34:01 UTC+2, 88888 Dihedral a ?crit?: > Grant Edwards? 2012?9?26????UTC+8??2?25?31???? > > > On 2012-09-25, Martin P. Hellwig wrote: > > > > > > > On Tuesday, 25 September 2012 09:14:27 UTC+1, Mark Lawrence wrote: > > > > > > >> Hi all, > > > > > > >> > > > > > > >> I though this might be of interest. > > > > > > >> http://www.ironfroggy.com/software/i-am-worried-about-the-future-of-python > > > > > > > > > > > > > I glanced over the article but it seems to me another 'I am afraid > > > > > > > this is not the silver bullet I wanted it to be' article > > > > > > > > > > > > Strange. I didn't get that _at_all_ from the article. > > > > > > > > > > > > To me it was expressing concern about what happens when the range of > > > > > > "niches" where Python is a good solution falls below a certain > > > > > > critical mass -- will the "Python Community" start to stagnate because > > > > > > it isn't attacting new developers in the quantity or diversity that it > > > > > > used to... > > > > > > > > > > > > -- > > > > > > Grant Edwards grant.b.edwards Yow! Alright, you!! > > > > > > at Imitate a WOUNDED SEAL > > > > > > gmail.com pleading for a PARKING > > > > > > SPACE!! > > I don't think so in 201X. The uni-code support for users and clients > > all over the world should not be taxed by WINTEL only in > > multi-language support under the OS. I am glad to see a lot smart phones > > or pads are fostering applications in various languages to help the IT > > industry keeping growing and expanding to those regeions covered > > by wirelees digital communications with devices priced in the range > > 200 to 12000 usd. Py 3.3 succeeded to somehow kill unicode and it has been transformed into an "American" product for "American" users. --- >From nnn: > ...schools moving towards Python... I do not know what "schools" covers. Interestingly (and unfortunately), it just becomes a no-tool for those who wish to teach Unicode. Or, in one sense, it just become one! PS I spent my last days with XeTeX and unicode-math. jmf From articles.sharing.blog at gmail.com Wed Sep 26 02:54:50 2012 From: articles.sharing.blog at gmail.com (Articles Sharing) Date: Tue, 25 Sep 2012 23:54:50 -0700 (PDT) Subject: www.articles-sharing.blogspot.com Message-ID: <0e1aa5ee-df53-451e-b185-2ded1453cc59@b8g2000yqh.googlegroups.com> www.articles-sharing.blogspot.com nice one.. From dwightdhutto at gmail.com Wed Sep 26 03:06:13 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 26 Sep 2012 03:06:13 -0400 Subject: Stop feeding the trolls (Was: which a is used?) In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> <20120925095327.aa0d222bad8678f6c0339fbf@druid.net> Message-ID: You can "Plonk" my dick bitches. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Wed Sep 26 03:07:05 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 26 Sep 2012 03:07:05 -0400 Subject: Stop feeding the trolls (Was: which a is used?) In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> <20120925095327.aa0d222bad8678f6c0339fbf@druid.net> Message-ID: On Wed, Sep 26, 2012 at 3:06 AM, Dwight Hutto wrote: > You can "Plonk" my dick bitches. > > > -- > Best Regards, > David Hutto > CEO: http://www.hitwebdevelopment.com +5.75 From ethan at stoneleaf.us Wed Sep 26 03:17:52 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 26 Sep 2012 00:17:52 -0700 Subject: Article on the future of Python In-Reply-To: References: Message-ID: <5062AC20.6060904@stoneleaf.us> wxjmfauth at gmail.com wrote: > Py 3.3 succeeded to somehow kill unicode and it has > been transformed into an "American" product for > "American" users. *plonk* From steve+comp.lang.python at pearwood.info Wed Sep 26 03:23:47 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Sep 2012 07:23:47 GMT Subject: Article on the future of Python References: Message-ID: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Sep 2012 23:35:39 -0700, wxjmfauth wrote: > Py 3.3 succeeded to somehow kill unicode and it has been transformed > into an "American" product for "American" users. For the first time in Python's history, Python on 32-bit systems handles strings containing Supplementary Multilingual Plane characters correctly, and it does so without doubling or quadrupling the amount of memory every single string takes up. Strings are ubiquitous in Python -- every module, every variable, every function, every class is associated with at least one and often many strings, and they are nearly all ASCII strings. The overhead of using four bytes instead of one for every string is considerable. Python finally has correct unicode handling for characters beyond the BMP, and it does so with more efficient strings that potentially use as little as one quarter of the memory that they otherwise would use, at the cost of a small slowdown in the artificial and unrealistic case that you repeatedly create millions of strings and then just throw them away immediately. Most realistic cases of string handling are unchanged in speed, either trivially faster or trivially slower. The real saving is in memory. According to wxjmfauth, this has "killed" unicode. Judge for yourself his credibility. The best I can determine, he believes this because Americans aren't made to suffer for using mostly ASCII strings. -- Steven From redstone-cold at 163.com Wed Sep 26 03:38:50 2012 From: redstone-cold at 163.com (iMath) Date: Wed, 26 Sep 2012 00:38:50 -0700 (PDT) Subject: =?UTF-8?Q?regular_expression_=3A__the_dollar_sign_=28=24=29_work_with_?= =?UTF-8?Q?re=2Ematch=28=29_or_re=2Esearch=28=29__=EF=BC=9F?= Message-ID: <5d913584-b5ea-4ff1-8094-f4d5b273c0b6@googlegroups.com> I only know the dollar sign ($) will match a pattern from the end of a string,but which method does it work with ,re.match() or re.search() ? From dwightdhutto at gmail.com Wed Sep 26 03:39:19 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 26 Sep 2012 03:39:19 -0400 Subject: Article on the future of Python In-Reply-To: <5062AC20.6060904@stoneleaf.us> References: <5062AC20.6060904@stoneleaf.us> Message-ID: On Wed, Sep 26, 2012 at 3:17 AM, Ethan Furman wrote: > wxjmfauth at gmail.com wrote: >> >> Py 3.3 succeeded to somehow kill unicode and it has >> been transformed into an "American" product for >> "American" users. > > Well, we can all use american as a standard, or maybe you'd prefer to borrow my Latin for Idiots handbook. But then again google has a Universal Communicator going, so, does it matter? -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From rosuav at gmail.com Wed Sep 26 03:44:55 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Sep 2012 17:44:55 +1000 Subject: Article on the future of Python In-Reply-To: References: <5062AC20.6060904@stoneleaf.us> Message-ID: On Wed, Sep 26, 2012 at 5:39 PM, Dwight Hutto wrote: > On Wed, Sep 26, 2012 at 3:17 AM, Ethan Furman wrote: >> wxjmfauth at gmail.com wrote: >>> >>> Py 3.3 succeeded to somehow kill unicode and it has >>> been transformed into an "American" product for >>> "American" users. >> > Well, we can all use american as a standard, or maybe you'd prefer to > borrow my Latin for Idiots handbook. But then again google has a > Universal Communicator going, so, does it matter? Never in the field of human discussion has there been so much reason for so many to plonk so few. ChrisA From jpiitula at ling.helsinki.fi Wed Sep 26 03:48:00 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 26 Sep 2012 10:48:00 +0300 Subject: regular expression : the dollar sign ($) work with re.match() or re.search() References: <5d913584-b5ea-4ff1-8094-f4d5b273c0b6@googlegroups.com> Message-ID: iMath writes: > I only know the dollar sign ($) will match a pattern from the end of > a string, but which method does it work with, re.match() or > re.search() It works with both. With re.match, the pattern has to match at the start of the string _and_ the $ has to match the end of the string (or a line); re.search scans the string until it finds a suitable start. What was the weird character that you used as a question mark? I removed them because they confuse the newsreader I use. From rosuav at gmail.com Wed Sep 26 03:57:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Sep 2012 17:57:59 +1000 Subject: regular expression : the dollar sign ($) work with re.match() or re.search() In-Reply-To: References: <5d913584-b5ea-4ff1-8094-f4d5b273c0b6@googlegroups.com> Message-ID: On Wed, Sep 26, 2012 at 5:48 PM, Jussi Piitulainen wrote: > What was the weird character that you used as a question mark? I > removed them because they confuse the newsreader I use. It appears to be Unicode Character 'FULLWIDTH QUESTION MARK' (U+FF1F). Normally I'd be inclined to simply use U+003F instead, but hey, it's a question mark still. ChrisA From dwightdhutto at gmail.com Wed Sep 26 04:11:25 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 26 Sep 2012 04:11:25 -0400 Subject: Article on the future of Python In-Reply-To: References: <5062AC20.6060904@stoneleaf.us> Message-ID: >> Well, we can all use american as a standard, or maybe you'd prefer to >> borrow my Latin for Idiots handbook. But then again google has a >> Universal Communicator going, so, does it matter? > > Never in the field of human discussion has there been so much reason > for so many to plonk so few. > "Plonk" it if you want. Your homosexual ideologies have no effect on me. Butt, back to the discussion, there are quite a few ways to encode, as well as translate code. Plonk it in your mouth, and let the nut hairs tickle your throat. > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From tjreedy at udel.edu Wed Sep 26 04:13:22 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 26 Sep 2012 04:13:22 -0400 Subject: Article on the future of Python In-Reply-To: References: Message-ID: On 9/26/2012 2:35 AM, wxjmfauth at gmail.com wrote: > Py 3.3 succeeded to somehow kill unicode and it has > been transformed into an "American" product for > "American" users. Python 3.3 is the first version that handles the full unicode character set correctly on all platforms. If anything, it will make unicode more alive and Python better suited for international applications. -- Terry Jan Reedy From info at egenix.com Wed Sep 26 04:19:53 2012 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 26 Sep 2012 10:19:53 +0200 Subject: ANN: eGenix mxODBC Connect - Python Database Interface 2.0.1 Message-ID: <5062BAA9.2070706@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC Connect Python Database Interface Version 2.0.1 mxODBC Connect is our commercially supported client-server product for connecting Python applications to relational databases in a truly cross-platform way. This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-Connect-2.0.1-GA.html ________________________________________________________________________ INTRODUCTION The mxODBC Connect Database Interface for Python allows users to easily connect Python applications to all major databases on the market today in a highly portable, convenient and secure way. Python Database Connectivity the Easy Way ----------------------------------------- Unlike our mxODBC Python extension, mxODBC Connect is designed as client-server application, so you no longer need to find production quality ODBC drivers for all the platforms you target with your Python application. Instead you use an easy to install Python client library which connects directly to the mxODBC Connect database server over the network. This makes mxODBC Connect a great basis for writing cross-platform multi-tier database applications and utilities in Python, especially if you run applications that need to communicate with databases such as MS SQL Server and MS Access, Oracle Database, IBM DB2 and Informix, Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more, that run on Windows or Linux machines. Ideal for Database Driven Client Applications --------------------------------------------- By removing the need to install and configure ODBC drivers on the client side and dealing with complicated network setups for each set of drivers, mxODBC Connect greatly simplifies deployment of database driven client applications, while at the same time making the network communication between client and database server more efficient and more secure. For more information, please have a look at the mxODBC Connect product page, in particular, the full list of available features. For more information, please see the product page: http://www.egenix.com/products/python/mxODBCConnect/ ________________________________________________________________________ NEWS The 2.0.1 release of mxODBC Connect includes the following enhancements and fixes: API Enhancements ---------------- * Added support for returning SQL Server TIME columns as time value instead of as string. * Added a work-around to prevent truncation warnings with the SQL Server ODBC driver when using .executemany(..., direct=1). Thanks for Michael Bayer. Server Enhancements ------------------- * Upgraded the mxODBC used in the server to version mxODBC 3.2.1. Client Enhancements ------------------- * Added egenix-mx-base dependency to mxODBC Connect egg files. Misc ---- * Added hint on how to work with REF CURSORS in Oracle stored procedures. Thanks to Etienne Desgagn?. mxODBC Connect 2.0.0 was released on 2012-08-20. These are the highlights of the new release: mxODBC Connect 2.0 Enhanced API ------------------------------- * mxODBC Connect Server now uses mxODBC 3.2 internally and makes its API available in the mxODBC Connect Client. This is a major step forward from the mxODBC 3.0 version used in mxODBC Connect Server 1.0. * mxODBC Connect Client comes with all the mxODBC enhancements, including: - connection and cursor objects can be used as context managers - adjustable parameter styles (qmark or named) - connection .autocommit attribute to easily switch on autocommit - adjustable timestamp resolution - new possibilities to set connection and cursor options to adjust the ODBC objects to your application needs, e.g. set a connection read-only or set a query timeout - adjustable decimal, datetime and string formats - adjustable warning format to be able to handle server warnings without client interaction - greatly improved result set scrolling support - Unicode support for all catalog methods - Access to additional result set meta data via cursor.getcolattribute() Updated Compatibility --------------------- * The server now features all the ODBC driver compatibility enhancements provided by mxODBC 3.2, including improved and updated support for MS SQL Server Native Client, Oracle Instant Client, Sybase ASE, IBM DB2, Teradata and Netezza. * Native Windows x64 builds with signed executables and a tray app rewritten in C are available for Windows 2008R2, Vista and 7 x64, so you can benefit from better performance, fewer UAC dialogs and smaller memory footprint. Asynchronous Execution ---------------------- * mxODBC Connect Client now integrates directly with gevent, allowing client applications to run asynchronous tasks while performing remote database queries. Better Integration ------------------ * mxODBC Connect now uses the official IANA registered port 6632 for both plain text and SSL-encrypted communication. * mxODBC Connect Client now allows selecting the used SSL module from two available options: Python standard lib ssl module and pyOpenSSL. For the full set of changes, please check the mxODBC Connect change log. http://www.egenix.com/products/python/mxODBCConnect/changelog.html ________________________________________________________________________ UPGRADING You are encouraged to upgrade to this latest mxODBC Connect release. When upgrading, please always upgrade both the server and the client installations to the same version - even for patch level releases. Customers who have purchased mxODBC Connect 2.0 licenses can continue to use their licenses with this patch level release. Customers who have purchased mxODBC Connect 1.x licenses can request 20% discount coupons for upgrade purchases. Please contact the eGenix.com Sales Team (sales at egenix.com) with your existing license serials for details. Users of our stand-alone mxODBC product will have to purchase new licenses from our online shop in order to use mxODBC Connect. You can request 30-day evaluation licenses by visiting our web-site or writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. http://www.egenix.com/products/python/mxODBCConnect/#Evaluation ________________________________________________________________________ DOWNLOADS The download archives as well as instructions for installation and configuration of the product can be found on the product page: http://www.egenix.com/products/python/mxODBCConnect/ If you want to try the package, jump straight to the download instructions: https://cms.egenix.com/products/python/mxODBCConnect/#Download Fully functional evaluation licenses for the mxODBC Connect Server are available free of charge: http://www.egenix.com/products/python/mxODBCConnect/#Evaluation mxODBC Connect Client is always free of charge. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. _______________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 26 2012) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2012-10-29: PyCon DE 2012, Leipzig, Germany ... 33 days to go 2012-10-23: Python Meeting Duesseldorf ... 27 days to go 2012-09-26: Released mxODBC.Connect 2.0.1 ... http://egenix.com/go34 2012-09-25: Released mxODBC 3.2.1 ... http://egenix.com/go33 eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From anthony.hw.kong at gmail.com Wed Sep 26 04:23:02 2012 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Wed, 26 Sep 2012 01:23:02 -0700 (PDT) Subject: Looking for pointers/suggestion - how to make a webbrowser with these restriction? Message-ID: <8f1ed0ca-2dec-4462-964b-dc645ce0f081@googlegroups.com> Hi, all, It is kind of a MacGyver question. I am just looking for some general suggestions/pointer. First let me first describe the development environment I am in: it is a locked down WinXP PC with limited development tools and libraries. At my disposal I have python 2.6 , webkit 5.33 dll, wx 2.8 and probably a V8 dll. No visual studio or any C/C++ compiler. Do not have admin right. So given these existing ingredients, is it possible to build a rudimentary web browser using python as a glue language? What will be the main challenge/bottleneck in this sort of project? In particular how can I hook up V8 and Webkit? I have some working experience with Win32 APIs, so you may throw some low level stuff at me if needed. :-) Cheers From kushal.kumaran+python at gmail.com Wed Sep 26 04:24:17 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Wed, 26 Sep 2012 13:54:17 +0530 Subject: google api and oauth2 In-Reply-To: References: <5062003A.9020208@tysdomain.com> <50621279.8060700@tysdomain.com> Message-ID: On Wed, Sep 26, 2012 at 11:45 AM, Demian Brecht wrote: >> >> If you are writing a desktop application, read this: >> https://developers.google.com/accounts/docs/OAuth2#clientside > > > You mean https://developers.google.com/accounts/docs/OAuth2#installed? Your > link discusses client side browser implementations. > Ah yes, I made a mistake in linking displayed url and scrolled position. > I'd be curious to know the shortcomings of sanction in the context of > installed apps. My original intent was to provide a server flow > implementation. If the installed flow isn't too much of a change (doesn't > seem like it would be, according to the docs, it's how the "code" is > retrieved by the application), I'd happily add it in or take a patch to > cover it. I tried out sanction from a python shell. In an installed application, the user can either start a little web server to handle redirect_uri, or pass in the special value "urn:ietf:wg:oauth:2.0:oob" to have the authorization code be shown in a text field in the browser (all of this is for google, I have no idea how other implementations or the oauth spec differ). At the moment, the auth_uri function gives out a URI and leaves it up to the client to deal with it however it likes. The library could provide a function (let's call it drive_auth) to drive the entire process: start a little web server on any available port, give a url to that server as redirect_uri, then start the user's web browser to connect to the authentication endpoint. The embedded web server will need to handle redirect_uri to grab the authorization code, generate an HTML response that will close the browser window (or instruct the user to do so), and then stop itself. For GUI applications which can embed a web browser widget, there is no need to start a separate web browser application. To support such applications, the drive_auth function can take a callback argument to navigate to a particular URL. Then the client applications can hook in their particular GUI toolkit, or just pass in webbrowser.open if they like. All this may be beyond the intended scope of your library. -- regards, kushal From breamoreboy at yahoo.co.uk Wed Sep 26 04:32:26 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 26 Sep 2012 09:32:26 +0100 Subject: Article on the future of Python In-Reply-To: References: <5062525b$0$29981$c3e8da3$5496439d@news.astraweb.com> <7x392561cu.fsf@ruckus.brouhaha.com> Message-ID: On 26/09/2012 05:10, Chris Angelico wrote: > On Wed, Sep 26, 2012 at 10:54 AM, Steven D'Aprano > wrote: >> SQL? ... it's time to sell your shares in Oracle. > > Ehh, I wouldn't be investing in Oracle, but that's more because I > think free RDBMSes like PostgreSQL outshine it. And this is even more > true of MS SQL Server - this last week I've been researching options > for moving work's services to the cloud, and SQL Server licenses cost > ridiculous amounts (per month or per hour); what do you get for that > money that you can't get from Postgres? > > ChrisA > Maybe true but do free RDBMes have the sales and marketing budgets that effectively shot down Ingres? -- Cheers. Mark Lawrence. From __peter__ at web.de Wed Sep 26 04:33:11 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 26 Sep 2012 10:33:11 +0200 Subject: regular expression : the dollar sign ($) work with re.match() or re.search() =?UTF-8?B?77yf?= References: <5d913584-b5ea-4ff1-8094-f4d5b273c0b6@googlegroups.com> Message-ID: iMath wrote: > I only know the dollar sign ($) will match a pattern from the > end of a string,but which method does it work with ,re.match() or > re.search() ? Why not try it out in the interactive interpreter? Here's the "deluxe version": >>> def demo(pattern="mid$", texts=["start mid end", "start mid", "mid end", "mid"], matchers=[re.match, re.search]): ... print "pattern:", pattern ... for text in texts: ... for matcher in matchers: ... name = matcher.__name__ ... print u"\N{CHECK MARK}" + name if matcher(pattern, text) else (" "*(len(name)+1)), ... print repr(text) ... >>> demo() pattern: mid$ 'start mid end' ?search 'start mid' 'mid end' ?match ?search 'mid' From breamoreboy at yahoo.co.uk Wed Sep 26 04:34:14 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 26 Sep 2012 09:34:14 +0100 Subject: Article on the future of Python In-Reply-To: References: Message-ID: On 26/09/2012 07:35, wxjmfauth at gmail.com wrote: > > Py 3.3 succeeded to somehow kill unicode and it has > been transformed into an "American" product for > "American" users. > jmf > Why do you keep repeating this rubbish when you've already been shot to pieces? Don't you know when it's time to make sure that you're safely strapped in and reach for and use the release button for the ejector seat. Further for somebody who is apparently up in the high tech world, why are you using a gmail account and hence sending garbage in more ways than one to mailing lists like this? -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Wed Sep 26 04:37:00 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 26 Sep 2012 09:37:00 +0100 Subject: Article on the future of Python In-Reply-To: References: <5062AC20.6060904@stoneleaf.us> Message-ID: On 26/09/2012 08:44, Chris Angelico wrote: > On Wed, Sep 26, 2012 at 5:39 PM, Dwight Hutto wrote: >> On Wed, Sep 26, 2012 at 3:17 AM, Ethan Furman wrote: >>> wxjmfauth at gmail.com wrote: >>>> >>>> Py 3.3 succeeded to somehow kill unicode and it has >>>> been transformed into an "American" product for >>>> "American" users. >>> >> Well, we can all use american as a standard, or maybe you'd prefer to >> borrow my Latin for Idiots handbook. But then again google has a >> Universal Communicator going, so, does it matter? > > Never in the field of human discussion has there been so much reason > for so many to plonk so few. > > ChrisA > I tried to make a play on that some days ago and failed dismally. Thanks for putting me out of my misery :) -- Cheers. Mark Lawrence. From rosuav at gmail.com Wed Sep 26 04:44:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Sep 2012 18:44:14 +1000 Subject: Article on the future of Python In-Reply-To: References: Message-ID: On Wed, Sep 26, 2012 at 6:34 PM, Mark Lawrence wrote: > Further for somebody who is apparently up in the high tech world, why are > you using a gmail account and hence sending garbage in more ways than one to > mailing lists like this? I use gmail too, largely because I prefer to keep mailing list posts off my primary account. ChrisA From dwightdhutto at gmail.com Wed Sep 26 04:45:35 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 26 Sep 2012 04:45:35 -0400 Subject: Article on the future of Python In-Reply-To: References: Message-ID: > > Why do you keep repeating this rubbish when you've already been shot to > pieces? I still feel intact, so whatever little shards of pain you intended to emit were lost on my ego. Don't you know when it's time to make sure that you're safely > strapped in and reach for and use the release button for the ejector seat. You ain't shot down shit, but your own reputation. Look at the full conversation. > Further for somebody who is apparently up in the high tech world, why are > you using a gmail account and hence sending garbage in more ways than one to > mailing lists like this? Um, using gmail instead of reinventing the wheel is now appropriate to you? -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Wed Sep 26 04:47:29 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 26 Sep 2012 04:47:29 -0400 Subject: Article on the future of Python In-Reply-To: References: <5062AC20.6060904@stoneleaf.us> Message-ID: > I tried to make a play on that some days ago and failed dismally. That's the fucking understatement of the year. Thanks for > putting me out of my misery :) -- No prob. Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From gelonida at gmail.com Wed Sep 26 04:54:34 2012 From: gelonida at gmail.com (Gelonida N) Date: Wed, 26 Sep 2012 10:54:34 +0200 Subject: mimetypes.guess_type broken in windows on py2.7 and python 3.X Message-ID: Hi, I'm still experiencing the pleasure of migrating legacy code from Python 2.6. to 2.7 which I expected to be much less painful. (In fact migration on Linux is rather smooth, but Windows is another story) Let's take the simple command import mimetypes print mimetypes.guess_type('a.jpg') The result an old pythons ( 2.7) is ('image/jpeg', None) Ther result on non windows platform is for python 2.7 / 3.X is the same However. The result for 2.7 / 3.x on windows is now ('image/pjpeg', None) # pjpeg instead of jpeg On Windows many file suffixes will report wrong mime types. The problem is know for about two years. http://bugs.python.org/issue10551 The main reason is, that under wWindows default values are fetched from Python and then 'updated' mime-types are fetched from the Windows registry. The major problem is, that almost ALL windows PCs have BROKEN mime types. so the good predefined mime types are just replaced with broken MS mime types. I wonder how many applications, that will try to migrate to 2.7 / 3.0 will fail due to this incompatibility in the mimetypes library There is a workaround (but first people have to detect the problem and to find it): Add these two lines somewhere in your code BEFORE any other imported library might have called a mimetypes function import mimetypes mimetypes.init([]) I still wonder if it wouldn't be better to have the default behaviour of 2.7 / 3.0 on windows such, that all the users who're not aware of this issue will not have their code broken. My suggestion for windows would be to have following default behaviour: - !st read the mimetypes from the registry if possible - 2nd read the Python default mimetypes and override the 'broken' MS definitions Only if a user explicitely calls mimetypes.init() they would have differente behaviour. The new behaviour breaks portability of Python code between Windows and Linux and I think the attempt should be to be as cross platform as possible. and not to be. At least one of the reasons why I use pythin is, that it allows to be rather cross-platform An alternative suggestion could be to never read the registry or /etc/mimetypes by default. What would definitely be rather important is add a big warning in the documentation and a recommendation of how to write cross platform compatible code. Somebody developing on Linux might not even know, that the code will not work on windows jsst because of this tiny issue. The unfortunate fact, that this issue was not fixed two years ago means, that perhaps meanwhile some code is out, that relies on the current behaviour. However I'm not sure, that anybody relies on the fact, that code will not work the same way on windows and on Linux. Any thoughts? From breamoreboy at yahoo.co.uk Wed Sep 26 05:01:11 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 26 Sep 2012 10:01:11 +0100 Subject: Article on the future of Python In-Reply-To: References: <5062AC20.6060904@stoneleaf.us> Message-ID: On 26/09/2012 09:47, Dwight Hutto wrote: >> I tried to make a play on that some days ago and failed dismally. > > That's the fucking understatement of the year. > You remind me of the opening to the song Plaistow Patricia by Ian Dury and the Blockheads. > Thanks for >> putting me out of my misery :) -- Cheers. Mark Lawrence. From tarek at ziade.org Wed Sep 26 05:08:19 2012 From: tarek at ziade.org (=?UTF-8?B?VGFyZWsgWmlhZMOp?=) Date: Wed, 26 Sep 2012 11:08:19 +0200 Subject: Fastest web framework In-Reply-To: References: , <50604907.6060405@ziade.org> Message-ID: <5062C603.90905@ziade.org> On 9/25/12 3:21 PM, Andriy Kornatskyy wrote: > Tarek, > > With all respect, running benchmark on something that has sleeps, etc is pretty far from real world use case. So I went a little bit different way. That's not a good summary of what the function does. It does not just sleep. It does some I/O and CPU bound tasks. The sleep is here to simulate a blocking I/O call, besides the DB calls. The whole function tries to simulate a real application, unlike printing 'Hello World' - to put the stack under realistic conditions. The multiplication is cached by the processor, but will still push some CPU work on every call. > > Here is a live demo (a semi real world web application) that comes with wheezy.web framework as a template: > > http://wheezy.pythonanywhere.com/ > > I have implemented it in a way that it uses one web framework (wheezy.web) and various template engines (jinja2, mako, tenjin, wheezy.template and wheezy.template with preprocessor)... Please see the following post under `Real World Example` section: > > http://mindref.blogspot.com/2012/07/python-fastest-template.html > > Source code here: > > https://bitbucket.org/akorn/wheezy.web/src/tip/demos/template > > The real world example shows the difference between template engines implementing the same things. The same applies to web frameworks (more or less depending on your choice). > > Thanks. Great, thanks for the update ! -- that's cool to bench the template engines, but this is still not what I had in mind. What I had in mind was to try each one of the framework with an application that does things, and see how the whole stack reacts on high load. But I guess we have different goals - wheezy seems really fast, congrats. Cheers Tarek > Andriy > > > ---------------------------------------- >> Date: Mon, 24 Sep 2012 13:50:31 +0200 >> From: tarek at ziade.org >> To: python-list at python.org >> Subject: Re: Fastest web framework >> >> On 9/23/12 11:19 AM, Andriy Kornatskyy wrote: >>> I have run recently a benchmark of a trivial 'hello world' application for various python web frameworks (bottle, django, flask, pyramid, web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find it interesting: >>> >>> http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html >>> >>> Comments or suggestions are welcome. >>> >>> Thanks. >>> >>> Andriy Kornatskyy >>> >> I would try this with a web app that does more than 'Hello World' >> >> You may argue that you're just trying the server stack, but that's not >> realistic because you don't really measure how the server behaves with a >> real app. >> >> Have a look at >> https://github.com/mozilla-services/chaussette/blob/master/chaussette/util.py#L188 >> >> (setup_bench and teardow_bench have to be run on startup and tear down >> of the server) >> >> I would be curious to see how things goes then >> >> Cheers >> Tarek >> -- >> http://mail.python.org/mailman/listinfo/python-list > From dwightdhutto at gmail.com Wed Sep 26 05:09:46 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 26 Sep 2012 05:09:46 -0400 Subject: Article on the future of Python In-Reply-To: References: <5062AC20.6060904@stoneleaf.us> Message-ID: >> That's the fucking understatement of the year. >> > > You remind me of the opening to the song Plaistow Patricia by Ian Dury and > the Blockheads. Make a modern day/mainstream reference, and maybe someone will get it. > > >> Thanks for >>> >>> putting me out of my misery :) Again, no problem...anytime buddy. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From andriy.kornatskyy at live.com Wed Sep 26 05:26:50 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Wed, 26 Sep 2012 12:26:50 +0300 Subject: Fastest web framework In-Reply-To: <5062C603.90905@ziade.org> References: , <50604907.6060405@ziade.org> , <5062C603.90905@ziade.org> Message-ID: Tarek, Thank you for the response back. Yes, your idea is pretty clear to me. The point is that higher workload you put in your application business logic, repository, backend, whatever... less you will see in final results comparison. This is obvious and we, as technical people, very well understand this (somebody even laugh). The reality is that not all web applications do heavy CPU computations and/or experience IO delays (due to response from database running a query over table that has no index, let say), some use caches, some split jobs to be run in background, some parallel them... I have to state that simple things must perform really fast to give more room for one that are not so. That in turn makes your infrastructure more effective. Some prefer to add a box, some see that a likely to be a problem further it goes. The good thing - you have a choice, you are not locked, and as result you are responsible for the effectiveness of the system you build today and definitely next one. Take care. Andriy ---------------------------------------- > Date: Wed, 26 Sep 2012 11:08:19 +0200 > From: tarek at ziade.org > To: andriy.kornatskyy at live.com > CC: python-list at python.org > Subject: Re: Fastest web framework > > On 9/25/12 3:21 PM, Andriy Kornatskyy wrote: > > Tarek, > > > > With all respect, running benchmark on something that has sleeps, etc is pretty far from real world use case. So I went a little bit different way. > That's not a good summary of what the function does. It does not just > sleep. It does some I/O and CPU bound tasks. The sleep is here to > simulate a blocking I/O call, besides the DB calls. > > The whole function tries to simulate a real application, unlike printing > 'Hello World' - to put the stack under realistic conditions. > > The multiplication is cached by the processor, but will still push some > CPU work on every call. > > > > > Here is a live demo (a semi real world web application) that comes with wheezy.web framework as a template: > > > > http://wheezy.pythonanywhere.com/ > > > > I have implemented it in a way that it uses one web framework (wheezy.web) and various template engines (jinja2, mako, tenjin, wheezy.template and wheezy.template with preprocessor)... Please see the following post under `Real World Example` section: > > > > http://mindref.blogspot.com/2012/07/python-fastest-template.html > > > > Source code here: > > > > https://bitbucket.org/akorn/wheezy.web/src/tip/demos/template > > > > The real world example shows the difference between template engines implementing the same things. The same applies to web frameworks (more or less depending on your choice). > > > > Thanks. > Great, thanks for the update ! -- that's cool to bench the template > engines, but this is still not what I had in mind. > > What I had in mind was to try each one of the framework with an > application that does things, and see how the whole stack reacts on high > load. > > But I guess we have different goals - wheezy seems really fast, congrats. > > > Cheers > Tarek > > > Andriy > > > > > > ---------------------------------------- > >> Date: Mon, 24 Sep 2012 13:50:31 +0200 > >> From: tarek at ziade.org > >> To: python-list at python.org > >> Subject: Re: Fastest web framework > >> > >> On 9/23/12 11:19 AM, Andriy Kornatskyy wrote: > >>> I have run recently a benchmark of a trivial 'hello world' application for various python web frameworks (bottle, django, flask, pyramid, web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find it interesting: > >>> > >>> http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > >>> > >>> Comments or suggestions are welcome. > >>> > >>> Thanks. > >>> > >>> Andriy Kornatskyy > >>> > >> I would try this with a web app that does more than 'Hello World' > >> > >> You may argue that you're just trying the server stack, but that's not > >> realistic because you don't really measure how the server behaves with a > >> real app. > >> > >> Have a look at > >> https://github.com/mozilla-services/chaussette/blob/master/chaussette/util.py#L188 > >> > >> (setup_bench and teardow_bench have to be run on startup and tear down > >> of the server) > >> > >> I would be curious to see how things goes then > >> > >> Cheers > >> Tarek > >> -- > >> http://mail.python.org/mailman/listinfo/python-list > > > From maniandram01 at gmail.com Wed Sep 26 05:28:46 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 26 Sep 2012 02:28:46 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4511598a-62ef-48c2-8016-6e8e6e7cd9ce@googlegroups.com> On Tuesday, 25 September 2012 21:05:01 UTC+5:30, Steven D'Aprano wrote: > On Tue, 25 Sep 2012 09:26:19 -0400, Kevin Walzer wrote: > > > > > On 9/25/12 4:15 AM, Mark Lawrence wrote: > > >> Hi all, > > >> > > >> I though this might be of interest. > > >> > > >> http://www.ironfroggy.com/software/i-am-worried-about-the-future-of- > > >> python > > >> > > >> > > > Interesting article, but the comments of those who say "the only > > > language I need to know is Python" strike me as a bit limited. If this > > > is the case, then Python can never be moved forward, because it is > > > written in C. > > > > Incorrect. > > > > IronPython in C#. Jython is written in Java. CLPython is written in Lisp. > > Berp and HoPe are written in Haskell. Nuitka is written in C++. Skulpt is > > written in Javascript. Vyper is written in Ocaml. PyPy is written in > > RPython. > > > > Some of those Python compilers are obsolete, unmaintained or > > experimental. Others are not. But either way, it is certainly not true > > that Python is written in C. One specific Python compiler happens to be > > written in C, that is all. > > > > > > > I program in Python, C, Objective C, JavaScript, Tcl, AppleScript, and > > > I'm learning Perl. Python could *not* handle all the domains I target in > > > my projects. > > > > Unless you are writing code that operates on the bare metal (device > > drivers, operating system kernels) Python probably *could*, even if it > > doesn't *yet*. PyPy now allows you to write real-time video processing > > filters in pure Python: > > > > http://morepypy.blogspot.com.au/2011/07/realtime-image-processing-in-python.html > > > > > > And if performance was irrelevant, you could even write an operating > > system in Python. A really slow, painful operating system, but still an > > operating system. > That's what I plan to do. But it will be converted to C/C++ > > > Given a sufficiently smart compiler, and sufficiently powerful libraries, > > or sufficiently low expectations, pretty much any programming language > > can do anything any other language can do. Almost all of them are Turing > > complete. > > > > But of course, in practice languages differ in their power and > > capabilities. > > > > > > > For instance: if I want to access Mac-native functionality > > > via Tkinter that isn't currently available in the library, > > > > That "isn't currently available" part is precisely what I'm talking > > about. Just because it's not available now doesn't mean it can't be made > > available. > > > > > > > I can understand loving the language and wanting to work just in the > > > language, but it's another thing entirely to call Python the One > > > Language to Rule Them All. (That's C, because all other languages are > > > implemented in it. :-) ) > > > > I see your smiley, but that is factually incorrect. Not all compilers or > > interpreters are written in C. Many languages are self-hosted, that is, > > they are written in themselves, using some clever bootstrapping > > techniques. C is neither the most powerful, the oldest, the best, or the > > most fundamental language around. > > > > > > -- > > Steven From wxjmfauth at gmail.com Wed Sep 26 05:31:24 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 02:31:24 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> Le mercredi 26 septembre 2012 09:23:47 UTC+2, Steven D'Aprano a ?crit?: > On Tue, 25 Sep 2012 23:35:39 -0700, wxjmfauth wrote: > > > > > Py 3.3 succeeded to somehow kill unicode and it has been transformed > > > into an "American" product for "American" users. > > > Steven, you are correct. But the price you pay for this is extremely high. Now, practically all characters are affected, espacially those *in* the Basic *** Multilingual*** Plane, these characters used by non "American" user (No offense here, I just use this word for ascii/latin-1). I'm ready to be considered as an idiot, but I'm not blind. As soon as I tested these characters, Py3.3 performs really badly. It seems to me it is legitimate to consider, there is a serious problem here. - I'm speaking about "language characters", one should speak about "scripting characters". - Obviously affected are not only the "language characters", but all characters, typographical signs, polytonic Greek, up to mathematical "Bold italic sans serif, Latin, uppercase", logically because all the "code points" are equivalent. Many people are commmenting, I have the feeling, I'm the only one who tested this. It is not necessary to dive in the Python code, understanding all this "characters stuff" is enough. And I am sorry, just saying "if you are not happy, switch back to Python 2.7 or use Ruby" (you know where you can read it) is in my mind not a correct answer. It only reflect a "yes, there is a problem, but..." Do not worry about me, I attempt to keep a neutral eye. It is my point of view (and facts). I will not open a blog with a "Python blah, blah, blah". jmf > For the first time in Python's history, Python on 32-bit systems handles > > strings containing Supplementary Multilingual Plane characters correctly, > > and it does so without doubling or quadrupling the amount of memory every > > single string takes up. > > > From dwightdhutto at gmail.com Wed Sep 26 05:39:59 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 26 Sep 2012 05:39:59 -0400 Subject: Article on the future of Python In-Reply-To: <4511598a-62ef-48c2-8016-6e8e6e7cd9ce@googlegroups.com> References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <4511598a-62ef-48c2-8016-6e8e6e7cd9ce@googlegroups.com> Message-ID: >> >> they are written in themselves, using some clever bootstrapping >> >> techniques. C is neither the most powerful, the oldest, the best, or the >> >> most fundamental language around. Would you recommend Assembly, because C just becomea macros of Assembly, or better yet machine language, which is line for line procedural Assembly for the processor instruction set working in line with the OS.. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From tarek at ziade.org Wed Sep 26 05:41:26 2012 From: tarek at ziade.org (=?UTF-8?B?VGFyZWsgWmlhZMOp?=) Date: Wed, 26 Sep 2012 11:41:26 +0200 Subject: Fastest web framework In-Reply-To: References: , <50604907.6060405@ziade.org> , <5062C603.90905@ziade.org> Message-ID: <5062CDC6.40703@ziade.org> On 9/26/12 11:26 AM, Andriy Kornatskyy wrote: > Tarek, > > Thank you for the response back. Yes, your idea is pretty clear to me. The point is that higher workload you put in your application business logic, repository, backend, whatever... less you will see in final results comparison. This is obvious and we, as technical people, very well understand this (somebody even laugh). I am happy somebody got a good laugh, I had a myself a good coffee :) > The reality is that not all web applications do heavy CPU computations and/or experience IO delays (due to response from database running a query over table that has no index, let say), some use caches, some split jobs to be run in background, some parallel them... I have to state that simple things must perform really fast to give more room for one that are not so. That in turn makes your infrastructure more effective. Some prefer to add a box, some see that a likely to be a problem further it goes. The good thing - you have a choice, you are not locked, and as result you are responsible for the effectiveness of the system you build today and definitely next one. > > Take care. > > Andriy You are not getting my point. What happens to weezhy or XXX framework when you are running it in a given stack, under heavy load ? There are many interactions that may impact the behavior of the stack - most of them are in the web server itself, but they can be things in the framework too, depending on the architectural choice. And you will not know it with an hello world app. To put it more bluntly, your benchmark is going to join the big pile of hello worlds benchmarks that are completely meaningless. If you want to prove that weezhy is faster than another py framework, because, I dunno, the number of function calls are smaller ? then you need to isolate this and do a different kind of bench. Have a look at http://plope.com/pyroptimization , it's a good example Same thing for the raw speed of your templating engine - isolation is required. One good read: http://blog.ianbicking.org/2010/03/16/web-server-benchmarking-we-need/ Cheers Tarek > > > ---------------------------------------- >> Date: Wed, 26 Sep 2012 11:08:19 +0200 >> From: tarek at ziade.org >> To: andriy.kornatskyy at live.com >> CC: python-list at python.org >> Subject: Re: Fastest web framework >> >> On 9/25/12 3:21 PM, Andriy Kornatskyy wrote: >>> Tarek, >>> >>> With all respect, running benchmark on something that has sleeps, etc is pretty far from real world use case. So I went a little bit different way. >> That's not a good summary of what the function does. It does not just >> sleep. It does some I/O and CPU bound tasks. The sleep is here to >> simulate a blocking I/O call, besides the DB calls. >> >> The whole function tries to simulate a real application, unlike printing >> 'Hello World' - to put the stack under realistic conditions. >> >> The multiplication is cached by the processor, but will still push some >> CPU work on every call. >> >>> Here is a live demo (a semi real world web application) that comes with wheezy.web framework as a template: >>> >>> http://wheezy.pythonanywhere.com/ >>> >>> I have implemented it in a way that it uses one web framework (wheezy.web) and various template engines (jinja2, mako, tenjin, wheezy.template and wheezy.template with preprocessor)... Please see the following post under `Real World Example` section: >>> >>> http://mindref.blogspot.com/2012/07/python-fastest-template.html >>> >>> Source code here: >>> >>> https://bitbucket.org/akorn/wheezy.web/src/tip/demos/template >>> >>> The real world example shows the difference between template engines implementing the same things. The same applies to web frameworks (more or less depending on your choice). >>> >>> Thanks. >> Great, thanks for the update ! -- that's cool to bench the template >> engines, but this is still not what I had in mind. >> >> What I had in mind was to try each one of the framework with an >> application that does things, and see how the whole stack reacts on high >> load. >> >> But I guess we have different goals - wheezy seems really fast, congrats. >> >> >> Cheers >> Tarek >> >>> Andriy >>> >>> >>> ---------------------------------------- >>>> Date: Mon, 24 Sep 2012 13:50:31 +0200 >>>> From: tarek at ziade.org >>>> To: python-list at python.org >>>> Subject: Re: Fastest web framework >>>> >>>> On 9/23/12 11:19 AM, Andriy Kornatskyy wrote: >>>>> I have run recently a benchmark of a trivial 'hello world' application for various python web frameworks (bottle, django, flask, pyramid, web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find it interesting: >>>>> >>>>> http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html >>>>> >>>>> Comments or suggestions are welcome. >>>>> >>>>> Thanks. >>>>> >>>>> Andriy Kornatskyy >>>>> >>>> I would try this with a web app that does more than 'Hello World' >>>> >>>> You may argue that you're just trying the server stack, but that's not >>>> realistic because you don't really measure how the server behaves with a >>>> real app. >>>> >>>> Have a look at >>>> https://github.com/mozilla-services/chaussette/blob/master/chaussette/util.py#L188 >>>> >>>> (setup_bench and teardow_bench have to be run on startup and tear down >>>> of the server) >>>> >>>> I would be curious to see how things goes then >>>> >>>> Cheers >>>> Tarek >>>> -- >>>> http://mail.python.org/mailman/listinfo/python-list > From dwightdhutto at gmail.com Wed Sep 26 05:48:48 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Wed, 26 Sep 2012 05:48:48 -0400 Subject: Fastest web framework In-Reply-To: <5062C603.90905@ziade.org> References: <50604907.6060405@ziade.org> <5062C603.90905@ziade.org> Message-ID: to Andriy You can use a framework, however, the function from the framework has to be used, and the parameters utilized by the frameworks functions. It would seem that writing your own witin the main page, or using the original function in place from the framework would run a timeit better. I'll look later, but it seems correct in terms of enhancing the frameworks estimated(OS ops)time to completion. Andriy Kornatskyy 5:39 AM (5 minutes ago) to me David, This makes sense... and probably can pretend to be most accurate. Well, in a higher level language, such as Python, you have to remove layers in order to reduce interpreter completion time. So just the usage of a framework makes you utilize a function that has to be imported, accessed and run before the function completes using the parameters. It might be faster if you just used the function itself, or optimized it. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From rosuav at gmail.com Wed Sep 26 05:55:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Sep 2012 19:55:12 +1000 Subject: Article on the future of Python In-Reply-To: <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> Message-ID: On Wed, Sep 26, 2012 at 7:31 PM, wrote: > you are correct. But the price you pay for this is extremely > high. Now, practically all characters are affected, espacially > those *in* the Basic *** Multilingual*** Plane, these characters > used by non "American" user (No offense here, I just use this > word for ascii/latin-1). > > I'm ready to be considered as an idiot, but I'm not blind. > As soon as I tested these characters, Py3.3 performs really > badly. It seems to me it is legitimate to consider, there > is a serious problem here. We've been over this thread. The only reason you're counting 3.3 as worse is because you're comparing against a narrow build of Python 3.2. Narrow builds are **BUGGY** and this needed to be resolved. When you compare against a wide build, semantics of 3.2 and 3.3 are identical, and then - and ONLY then - can you sanely compare performance. And 3.3 stacks up much better. ChrisA From hannu at krosing.net Wed Sep 26 06:01:28 2012 From: hannu at krosing.net (Hannu Krosing) Date: Wed, 26 Sep 2012 12:01:28 +0200 Subject: Article on the future of Python In-Reply-To: References: <5062525b$0$29981$c3e8da3$5496439d@news.astraweb.com> <7x392561cu.fsf@ruckus.brouhaha.com> Message-ID: <5062D278.3050204@krosing.net> On 09/26/2012 10:32 AM, Mark Lawrence wrote: > On 26/09/2012 05:10, Chris Angelico wrote: >> On Wed, Sep 26, 2012 at 10:54 AM, Steven D'Aprano >> wrote: >>> SQL? ... it's time to sell your shares in Oracle. >> >> Ehh, I wouldn't be investing in Oracle, but that's more because I >> think free RDBMSes like PostgreSQL outshine it. And this is even more >> true of MS SQL Server - this last week I've been researching options >> for moving work's services to the cloud, and SQL Server licenses cost >> ridiculous amounts (per month or per hour); what do you get for that >> money that you can't get from Postgres? >> >> ChrisA >> > > Maybe true but do free RDBMes have the sales and marketing budgets > that effectively shot down Ingres? > Nope. They don't have budget to shoot down Ingres. Also, free RDBMs do not engage in dubious promise-and-dont-deliver- then-ask-more-money sales policies that got Oracle kicked out of US Government simplified buying processes. You can get only so far using "sales". At some point you have to deliver. Hannu From rosuav at gmail.com Wed Sep 26 06:05:57 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Sep 2012 20:05:57 +1000 Subject: Looking for pointers/suggestion - how to make a webbrowser with these restriction? In-Reply-To: <8f1ed0ca-2dec-4462-964b-dc645ce0f081@googlegroups.com> References: <8f1ed0ca-2dec-4462-964b-dc645ce0f081@googlegroups.com> Message-ID: On Wed, Sep 26, 2012 at 6:23 PM, Anthony Kong wrote: > Hi, all, > > It is kind of a MacGyver question. I am just looking for some general suggestions/pointer. > > First let me first describe the development environment I am in: it is a locked down WinXP PC with limited development tools and libraries. At my disposal I have python 2.6 , webkit 5.33 dll, wx 2.8 and probably a V8 dll. No visual studio or any C/C++ compiler. Do not have admin right. XP shouldn't stop you adding another program, even without admin rights. Maybe not a "classic" web browser, but something uber-thin like HTMLayout [1], though it's not FOSS (it's free for non-commercial use though). It's perhaps too thin for you, but start by loading that up and see how it goes. > So given these existing ingredients, is it possible to build a rudimentary web browser using python as a glue language? What will be the main challenge/bottleneck in this sort of project? In particular how can I hook up V8 and Webkit? > > I have some working experience with Win32 APIs, so you may throw some low level stuff at me if needed. :-) Unless someone else has done it already, you're probably going to have to do some C++ work to embed V8 inside Python. It's not difficult but will need to be done. Webkit is another pile of work. By the time you're done, you'll most likely have written a whole web browser (minus the decades of experience in performance, security vulnerabilities, etc), and it'll probably have problems with your lack of admin rights. What are your actual requirements? What can't you do? There are some really REALLY insane possibilities you could try. Can you install PuTTY [2] and Xming [3], and ssh to a Linux box to run a web browser? (See, I told you it was insane.) ChrisA [1] http://www.terrainformatica.com/htmlayout/ [2] http://www.putty.org/ [3] http://sourceforge.net/projects/xming/ From andriy.kornatskyy at live.com Wed Sep 26 06:06:53 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Wed, 26 Sep 2012 13:06:53 +0300 Subject: Fastest web framework In-Reply-To: References: , <50604907.6060405@ziade.org>, , <5062C603.90905@ziade.org>, Message-ID: David / Tarek, I believe you and Tarek are pointing the same things. If we want to get that far, we need, first of all, itemize the functions list and find their correspondences in other frameworks... or provide some script of potential calls to framework internal and translate those call to be specific for each framework. In this case we can profile results, capture benchmarks (e.g. with `timeit`) and figure out something more meaningful... yet point framework developers to attention. Does that sound like a thing you are trying to communicate? Thanks. Andriy ---------------------------------------- > Date: Wed, 26 Sep 2012 05:48:48 -0400 > Subject: Re: Fastest web framework > From: dwightdhutto at gmail.com > To: tarek at ziade.org > CC: andriy.kornatskyy at live.com; python-list at python.org > > to Andriy > You can use a framework, however, the function from the framework has > to be used, and the parameters utilized by the frameworks functions. > > It would seem that writing your own witin the main page, or using the > original function in place from the framework would run a timeit > better. > > I'll look later, but it seems correct in terms of enhancing the > frameworks estimated(OS ops)time to completion. > Andriy Kornatskyy > > 5:39 AM (5 minutes ago) > > to me > David, > > This makes sense... and probably can pretend to be most accurate. > > > Well, in a higher level language, such as Python, you have to remove > layers in order to reduce interpreter completion time. > > So just the usage of a framework makes you utilize a function that has > to be imported, accessed and run before the function completes using > the parameters. > > It might be faster if you just used the function itself, or optimized it. > > > > -- > Best Regards, > David Hutto > CEO: http://www.hitwebdevelopment.com From anthony.hw.kong at gmail.com Wed Sep 26 06:41:00 2012 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Wed, 26 Sep 2012 03:41:00 -0700 (PDT) Subject: Looking for pointers/suggestion - how to make a webbrowser with these restriction? In-Reply-To: References: <8f1ed0ca-2dec-4462-964b-dc645ce0f081@googlegroups.com> Message-ID: <664fc219-a785-405f-a563-8980d683ad9f@googlegroups.com> Hi, Chris, Thanks for your reply. I really do not have any requirement. It is more a curiosity question (not work related). I'd like to find out how python can be used to 'glue' all these moving parts together. Performance and security are definitely not a concern as it is just a toy idea/project. Cheers From anthony.hw.kong at gmail.com Wed Sep 26 06:41:00 2012 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Wed, 26 Sep 2012 03:41:00 -0700 (PDT) Subject: Looking for pointers/suggestion - how to make a webbrowser with these restriction? In-Reply-To: References: <8f1ed0ca-2dec-4462-964b-dc645ce0f081@googlegroups.com> Message-ID: <664fc219-a785-405f-a563-8980d683ad9f@googlegroups.com> Hi, Chris, Thanks for your reply. I really do not have any requirement. It is more a curiosity question (not work related). I'd like to find out how python can be used to 'glue' all these moving parts together. Performance and security are definitely not a concern as it is just a toy idea/project. Cheers From hansmu at xs4all.nl Wed Sep 26 07:50:49 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 26 Sep 2012 13:50:49 +0200 Subject: Need to archive a MySQL database using a python script In-Reply-To: <3dce14bc-cdec-4bcb-a41d-d5de1ef10bf6@googlegroups.com> References: <3dce14bc-cdec-4bcb-a41d-d5de1ef10bf6@googlegroups.com> Message-ID: <5062ec1b$0$6859$e4fe514c@news2.news.xs4all.nl> On 26/09/12 01:17:24, bruceg113355 at gmail.com wrote: > Python Users Group, > > I need to archive a MySQL database using a python script. > I found a good example at: https://gist.github.com/3175221 > > The following line executes however, the archive file is empty. > > os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" % > (user,password,host,database,database+"_"+filestamp)) > Where: > User = ?someUser? > password = ?somePassword? > host = ?someRemote.database.server? > database = ?someDatabase? > > If I execute mysqldump from the command line, an archive is created. > > Using Python 2.6 and MySQL-python-1.2.2.win32-py2.6 (MySQLdb) > Mysql-5.5.27 from the command line. > > Any ideas? * If there are shell meta characters in the password, you'd have need to use single quotes, as in -p'%s'. Actually, that's true for any of the parameters, but the password is one most likely to contain punctuation characters. * You could try print("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" % (user,password,host,database,database+"_"+filestamp)) and if the result looks okay, copy and paste it to the command line (do not retype; use copy and paste) and see if it works. * In your script, add a line os.popen("monty_python") This should produce an error message. If it doesn't, find out why. * Check the timestamp of your empty output file. If it was created yesterday, then maybe your script is now writing its file in another directory and you're looking at the output of yesterday's test. Hope this helps, -- HansM From wxjmfauth at gmail.com Wed Sep 26 08:17:56 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 05:17:56 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: Message-ID: <04e6e8dd-1549-4792-9bf2-4190b8874925@googlegroups.com> Le mercredi 26 septembre 2012 10:35:04 UTC+2, Mark Lawrence a ?crit?: > On 26/09/2012 07:35, wxjmfauth at gmail.com wrote: > > > > > > Py 3.3 succeeded to somehow kill unicode and it has > > > been transformed into an "American" product for > > > "American" users. > > > jmf > > > > > > > Why do you keep repeating this rubbish when you've already been shot to > > pieces? Don't you know when it's time to make sure that you're safely > > strapped in and reach for and use the release button for the ejector > > seat. Further for somebody who is apparently up in the high tech world, > > why are you using a gmail account and hence sending garbage in more ways > > than one to mailing lists like this? > > > > -- > > Cheers. > > > > Mark Lawrence. At least when the others are sending a msg containing non asii characters. I see them correctly. When you send such a text, I'm only able to see something like this (your_string): >>> import fourbiunicode >>> for c in your_string: ... fourbiunicode.FrenchNames[c] ... 'LETTRE MINUSCULE LATINE TR?MA' "POINT D'INTERROGATION RENVERS?" 'FRACTION UN DEMI' You have all the elements to reconstruct what is happening. (Notice, I'm not a Unicode illiterate) jmf From wxjmfauth at gmail.com Wed Sep 26 08:17:56 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 05:17:56 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: Message-ID: <04e6e8dd-1549-4792-9bf2-4190b8874925@googlegroups.com> Le mercredi 26 septembre 2012 10:35:04 UTC+2, Mark Lawrence a ?crit?: > On 26/09/2012 07:35, wxjmfauth at gmail.com wrote: > > > > > > Py 3.3 succeeded to somehow kill unicode and it has > > > been transformed into an "American" product for > > > "American" users. > > > jmf > > > > > > > Why do you keep repeating this rubbish when you've already been shot to > > pieces? Don't you know when it's time to make sure that you're safely > > strapped in and reach for and use the release button for the ejector > > seat. Further for somebody who is apparently up in the high tech world, > > why are you using a gmail account and hence sending garbage in more ways > > than one to mailing lists like this? > > > > -- > > Cheers. > > > > Mark Lawrence. At least when the others are sending a msg containing non asii characters. I see them correctly. When you send such a text, I'm only able to see something like this (your_string): >>> import fourbiunicode >>> for c in your_string: ... fourbiunicode.FrenchNames[c] ... 'LETTRE MINUSCULE LATINE TR?MA' "POINT D'INTERROGATION RENVERS?" 'FRACTION UN DEMI' You have all the elements to reconstruct what is happening. (Notice, I'm not a Unicode illiterate) jmf From wxjmfauth at gmail.com Wed Sep 26 08:19:07 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 05:19:07 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: Message-ID: Le mercredi 26 septembre 2012 10:13:58 UTC+2, Terry Reedy a ?crit?: > On 9/26/2012 2:35 AM, wxjmfauth at gmail.com wrote: > > > > > Py 3.3 succeeded to somehow kill unicode and it has > > > been transformed into an "American" product for > > > "American" users. > > > > Python 3.3 is the first version that handles the full unicode character > > set correctly on all platforms. If anything, it will make unicode more > > alive and Python better suited for international applications. > > > > -- > > Terry Jan Reedy Remember the TeX discussion a few days ago? You are always selling the same argument. Py3.3 is the only computer language I'm aware of which is maltreating Unicode in such a way. After all, if replacing a Nabla operator in a string take 10 times more times in Py33 than in Python32, it takes 10 times more . There is nothing more to say. I proposed to make some tests with the characters used by the IMPRIMERIE NATINALE", I can now suggest to make some tests with random texts exceprt form the "Guide du typographe romand". What? Never heard from these? Do not worry too much. The corporates (software producers) and the foundries know these documents. Finally, all in all, it's no a suprise, end users are sticking with these products. I'm not complaining, only disappointed. jmf (Time to go back to TeX) From wxjmfauth at gmail.com Wed Sep 26 08:19:07 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 05:19:07 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: Message-ID: Le mercredi 26 septembre 2012 10:13:58 UTC+2, Terry Reedy a ?crit?: > On 9/26/2012 2:35 AM, wxjmfauth at gmail.com wrote: > > > > > Py 3.3 succeeded to somehow kill unicode and it has > > > been transformed into an "American" product for > > > "American" users. > > > > Python 3.3 is the first version that handles the full unicode character > > set correctly on all platforms. If anything, it will make unicode more > > alive and Python better suited for international applications. > > > > -- > > Terry Jan Reedy Remember the TeX discussion a few days ago? You are always selling the same argument. Py3.3 is the only computer language I'm aware of which is maltreating Unicode in such a way. After all, if replacing a Nabla operator in a string take 10 times more times in Py33 than in Python32, it takes 10 times more . There is nothing more to say. I proposed to make some tests with the characters used by the IMPRIMERIE NATINALE", I can now suggest to make some tests with random texts exceprt form the "Guide du typographe romand". What? Never heard from these? Do not worry too much. The corporates (software producers) and the foundries know these documents. Finally, all in all, it's no a suprise, end users are sticking with these products. I'm not complaining, only disappointed. jmf (Time to go back to TeX) From bsj at abzinc.com Wed Sep 26 08:49:26 2012 From: bsj at abzinc.com (Benjamin Jessup) Date: Wed, 26 Sep 2012 08:49:26 -0400 Subject: [python-list] python application file format Message-ID: <5062F9D6.2060402@abzinc.com> Hello all, What do people recommend for a file format for a python desktop application? Data is complex with 100s/1000s of class instances, which reference each other. Write the file with struct module? (Rebuild object pointers, safe, compact, portable, not expandable without reserved space) Use cPickle with a module/class whitelist? (Can't easily port, not entirely safe, compact enough, expandable) Use JSON or similar? (Rebuild object pointers, portable, expandable, size?) Any advice is greatly appreciated! From maniandram01 at gmail.com Wed Sep 26 08:59:54 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 26 Sep 2012 05:59:54 -0700 (PDT) Subject: new-style class or old-style class? In-Reply-To: <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com> References: <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com> Message-ID: <31ea72b0-353e-4eb4-85e1-cae52ec85260@googlegroups.com> On Tuesday, 25 September 2012 20:14:05 UTC+5:30, Jayden wrote: > In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!! Next time just Google your questions. :-) Good luck with Python From roy at panix.com Wed Sep 26 09:01:20 2012 From: roy at panix.com (Roy Smith) Date: Wed, 26 Sep 2012 09:01:20 -0400 Subject: Article on the future of Python References: <5062525b$0$29981$c3e8da3$5496439d@news.astraweb.com> <7x392561cu.fsf@ruckus.brouhaha.com> Message-ID: In article , Hannu Krosing wrote: > You can get only so far using "sales". At some point you have to deliver. But, by that time, the guy who closed the sale has already cashed his bonus check, bought his new BMW, and moved on to another company. And around that time, some poor schmuck of a dev manager is telling his team what the sales guy sold. And that they have 12 weeks to design, build, and deliver it. From maniandram01 at gmail.com Wed Sep 26 09:01:29 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 26 Sep 2012 06:01:29 -0700 (PDT) Subject: [python-list] python application file format In-Reply-To: References: Message-ID: <3af2cb43-0b12-4f98-8d29-895f173317d5@googlegroups.com> On Wednesday, 26 September 2012 18:29:14 UTC+5:30, Benjamin Jessup wrote: > Hello all, > > > > What do people recommend for a file format for a python desktop > > application? Data is complex with 100s/1000s of class instances, which > > reference each other. > > > > Write the file with struct module? (Rebuild object pointers, safe, > > compact, portable, not expandable without reserved space) > > > > Use cPickle with a module/class whitelist? (Can't easily port, not > > entirely safe, compact enough, expandable) > > > > Use JSON or similar? (Rebuild object pointers, portable, expandable, size?) > > > > Any advice is greatly appreciated! JSON is generally used for configuration. From maniandram01 at gmail.com Wed Sep 26 09:01:29 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 26 Sep 2012 06:01:29 -0700 (PDT) Subject: [python-list] python application file format In-Reply-To: References: Message-ID: <3af2cb43-0b12-4f98-8d29-895f173317d5@googlegroups.com> On Wednesday, 26 September 2012 18:29:14 UTC+5:30, Benjamin Jessup wrote: > Hello all, > > > > What do people recommend for a file format for a python desktop > > application? Data is complex with 100s/1000s of class instances, which > > reference each other. > > > > Write the file with struct module? (Rebuild object pointers, safe, > > compact, portable, not expandable without reserved space) > > > > Use cPickle with a module/class whitelist? (Can't easily port, not > > entirely safe, compact enough, expandable) > > > > Use JSON or similar? (Rebuild object pointers, portable, expandable, size?) > > > > Any advice is greatly appreciated! JSON is generally used for configuration. From roy at panix.com Wed Sep 26 09:12:33 2012 From: roy at panix.com (Roy Smith) Date: Wed, 26 Sep 2012 09:12:33 -0400 Subject: new-style class or old-style class? References: <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com> Message-ID: In article <2e8a9e88-9e7e-43f7-a070-ea9054e625f2 at googlegroups.com>, Jayden wrote: > In learning Python, I found there are two types of classes? Which one are > widely used in new Python code? Is the new-style much better than old-style? > Thanks!! If you're just learning Python 2.x, you might as well use new-style classes, since that's what all classes are in 3.x. On the other hand, if you're just learning, it probably doesn't matter which kind you use. Until you get into some pretty sophisticated stuff, you won't notice any difference between the two. On the third hand, all it takes to create a new-style class is to have it inherit from object. It's no big deal to write >>> class Foo(object): instead of just >>> class Foo: so you might as well use new-style classes :-) From breamoreboy at yahoo.co.uk Wed Sep 26 09:21:06 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 26 Sep 2012 14:21:06 +0100 Subject: Article on the future of Python In-Reply-To: <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> Message-ID: On 26/09/2012 10:31, wxjmfauth at gmail.com wrote: > > I'm ready to be considered as an idiot, but I'm not blind. People here have seen enough of your writings to know that you're not an idiot. I'm feeling far too polite right now to state what they actually know about you. > As soon as I tested these characters, Py3.3 performs really > badly. It seems to me it is legitimate to consider, there > is a serious problem here. Your tests (for the lack of a better term) have been repeatedly shot to pieces, refuted, you've shown nothing at all to indicate that Python 3.3 performs really badly. > > Many people are commmenting, I have the feeling, I'm the only > one who tested this. It is not necessary to dive in the Python > code, understanding all this "characters stuff" is enough. Complete dross from a person who seems to know as much about the combination of Python 3.3 and unicode as Hitler, Stalin and Pol Pot amongst others knew about human rights. -- Cheers. Mark Lawrence. From andriy.kornatskyy at live.com Wed Sep 26 09:21:21 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Wed, 26 Sep 2012 16:21:21 +0300 Subject: Fastest template engine In-Reply-To: References: Message-ID: The post has been updated with the following template engines added (per community request): 1. chameleon 2. django 3. web2py Here is a link: http://mindref.blogspot.com/2012/07/python-fastest-template.html Comments or suggestions are welcome. Thanks. Andriy ---------------------------------------- > From: andriy.kornatskyy at live.com > To: python-list at python.org > Subject: Fastest template engine > Date: Sun, 23 Sep 2012 12:24:36 +0300 > > > I have run recently a benchmark of a trivial 'big table' example for various python template engines (jinja2, mako, tenjin, tornado and wheezy.template) run on cpython2.7 and pypy1.9...... you might find it interesting: > > http://mindref.blogspot.com/2012/07/python-fastest-template.html > > Comments or suggestions are welcome. > > Thanks. > > Andriy Kornatskyy > -- > http://mail.python.org/mailman/listinfo/python-list From breamoreboy at yahoo.co.uk Wed Sep 26 09:28:16 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 26 Sep 2012 14:28:16 +0100 Subject: Article on the future of Python In-Reply-To: References: <5062525b$0$29981$c3e8da3$5496439d@news.astraweb.com> <7x392561cu.fsf@ruckus.brouhaha.com> Message-ID: On 26/09/2012 14:01, Roy Smith wrote: > In article , > Hannu Krosing wrote: > >> You can get only so far using "sales". At some point you have to deliver. > > But, by that time, the guy who closed the sale has already cashed his > bonus check, bought his new BMW, and moved on to another company. > > And around that time, some poor schmuck of a dev manager is telling his > team what the sales guy sold. And that they have 12 weeks to design, > build, and deliver it. > How long did you just say??? I promised it in 8 weeks, not 12 you complete moron :) -- Cheers. Mark Lawrence. From kw at codebykevin.com Wed Sep 26 09:30:19 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 26 Sep 2012 09:30:19 -0400 Subject: Article on the future of Python In-Reply-To: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/25/12 11:35 AM, Steven D'Aprano wrote: > IronPython in C#. Jython is written in Java. CLPython is written in Lisp. > Berp and HoPe are written in Haskell. Nuitka is written in C++. Skulpt is > written in Javascript. Vyper is written in Ocaml. PyPy is written in > RPython. > > Some of those Python compilers are obsolete, unmaintained or > experimental. Others are not. But either way, it is certainly not true > that Python is written in C. One specific Python compiler happens to be > written in C, that is all. Apart from IronPython, what constituency do these alternative implementations of Python have that would raise them above the level of interesting experiments? -- Kevin Walzer Code by Kevin http://www.codebykevin.com From tyler at tysdomain.com Wed Sep 26 09:31:46 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Wed, 26 Sep 2012 07:31:46 -0600 Subject: Article on the future of Python In-Reply-To: References: <5062AC20.6060904@stoneleaf.us> Message-ID: <506303C2.8090802@tysdomain.com> On 9/26/2012 2:11 AM, Dwight Hutto wrote: >>> Well, we can all use american as a standard, or maybe you'd prefer to >>> borrow my Latin for Idiots handbook. But then again google has a >>> Universal Communicator going, so, does it matter? >> Never in the field of human discussion has there been so much reason >> for so many to plonk so few. >> > "Plonk" it if you want. Your homosexual ideologies have no effect on > me. Butt, back to the discussion, there are quite a few ways to > encode, as well as translate code. You remind me of a little kid. When anything doesn't go your way, we revert to homosexual comments (who said anything about homosexual anyway), and you keep bringing up this whole nut hair deal. I think it's you leaning that way buddy, especially since "most of us on here are guys." > Plonk it in your mouth, and let the nut hairs tickle your throat. > Take your trash somewhere else. You've provided nothing in terms of good feedback or responses, and I doubt you will provide more than insults. PS: Anyone know if rantingrik had relatives? ;) >> ChrisA >> -- >> http://mail.python.org/mailman/listinfo/python-list > > -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From rosuav at gmail.com Wed Sep 26 09:43:23 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Sep 2012 23:43:23 +1000 Subject: Article on the future of Python In-Reply-To: References: Message-ID: On Wed, Sep 26, 2012 at 10:19 PM, wrote: > You are always selling the same argument. > Py3.3 is the only computer language I'm aware of which > is maltreating Unicode in such a way. You mean, the only computer language that represents Unicode characters as integers, and then stores them as an array of 8-bit, 16-bit, or 32-bit numbers depending on the highest codepoint? No, it's not. I can disprove your statement with a single counterexample, but it's entirely possible and (IMHO) likely that there are others too: http://pike.lysator.liu.se/generated/manual/modref/ex/predef_3A_3A/String/width.html Pike stores strings in largely the same way Python 3.3 does. Pike strings are immutable and guaranteed to be interned, so it makes good sense to store them as compactly as possible. > After all, if replacing a Nabla operator in a string take > 10 times more times in Py33 than in Python32, it takes 10 > times more . There is nothing more to say. Comparing against a Py32 wide build, I find it hard to believe that anything would take ten times as long. But I'll give you the benefit of the doubt; maybe your number is in binary. I still do not expect that it'd take twice as long. Would you believe... barely slower? And even that's pushing it. sigh... Why am I arguing this. I should get plonked myself for feeding the trolls. Sorry all. ChrisA From breamoreboy at yahoo.co.uk Wed Sep 26 09:43:27 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 26 Sep 2012 14:43:27 +0100 Subject: Article on the future of Python In-Reply-To: <506303C2.8090802@tysdomain.com> References: <5062AC20.6060904@stoneleaf.us> <506303C2.8090802@tysdomain.com> Message-ID: On 26/09/2012 14:31, Littlefield, Tyler wrote: > > PS: Anyone know if rantingrik had relatives? ;) > I say steady on old chap that's just not cricket. I've been known to have a go at rr in the past for good reasons, but when he gets stuck into Tkinter he is an extremely useful contributor. I certainly prefer him to Xah Lee, who's attempts at improving Python documentation were beautifully torn to pieces here, IIRC by Ethan Furman, apologies to him and the actual author if I'm incorrect. -- Cheers. Mark Lawrence. From rosuav at gmail.com Wed Sep 26 09:51:08 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Sep 2012 23:51:08 +1000 Subject: Article on the future of Python In-Reply-To: References: <5062AC20.6060904@stoneleaf.us> <506303C2.8090802@tysdomain.com> Message-ID: On Wed, Sep 26, 2012 at 11:43 PM, Mark Lawrence wrote: > On 26/09/2012 14:31, Littlefield, Tyler wrote: > >> >> PS: Anyone know if rantingrik had relatives? ;) >> > > I say steady on old chap that's just not cricket. I've been known to have a > go at rr in the past for good reasons, but when he gets stuck into Tkinter > he is an extremely useful contributor. I certainly prefer him to Xah Lee, > who's attempts at improving Python documentation were beautifully torn to > pieces here, IIRC by Ethan Furman, apologies to him and the actual author if > I'm incorrect. You know how people sometimes ask "What sort of idiot do you think I am??!?", thus falling foul of the sage advice "Never test for an error condition you don't know how to handle" [1]... well, on this list, it makes good sense to ask what sort of troll someone is. We even have Troll Rankings in which there's very definite striations of "useful contributors who sometimes troll", "useless people who nevertheless trigger interesting threads", and "utterly useless flamers". Troll taxonomy is a science we could all benefit from studying... ChrisA [1] eg http://www.theregister.co.uk/2008/10/24/bofh_2008_episode_34/ From rosuav at gmail.com Wed Sep 26 10:04:31 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Sep 2012 00:04:31 +1000 Subject: Looking for pointers/suggestion - how to make a webbrowser with these restriction? In-Reply-To: <664fc219-a785-405f-a563-8980d683ad9f@googlegroups.com> References: <8f1ed0ca-2dec-4462-964b-dc645ce0f081@googlegroups.com> <664fc219-a785-405f-a563-8980d683ad9f@googlegroups.com> Message-ID: On Wed, Sep 26, 2012 at 8:41 PM, Anthony Kong wrote: > Hi, Chris, > > Thanks for your reply. I really do not have any requirement. It is more a curiosity question (not work related). I'd like to find out how python can be used to 'glue' all these moving parts together. Performance and security are definitely not a concern as it is just a toy idea/project. Okay! Toy project. Here goes then! (BTW, you don't need to send to both python-list and comp.lang.python - they mirror each other.) 1) It's straight-forward to extend Python using C, so you could fairly readily make thin wrappers around the C APIs of whatever components you want to glue together. 2) V8 may be a smidge more fiddly, though; it uses a C++ API that's designed to be really convenient, using automatic variables and such. You may want to consider embedding a different engine, but if you do use V8, you'll end up largely undoing all that convenience work they've done. A pity really; V8's the first language engine I've ever seen that makes it so easy on the embedder. 3) Networking is easy to do in Python. Obviously you can do TCP sockets in pretty much any language, but Python also has handy facilities for higher level protocols like HTTP, already built-in. (So do quite a few high level languages, these days. It's nothing unique, but no less handy.) 4) Security is going to be a pain. But you said you don't care. Just promise me you won't unleash this thing on the world :) 5) This is going to be a huge job. You're going to get bored of it long before it's finished. But it'll still be educative for as long as you stick it. Have you ever done anything with networking? If not, I'd recommend you start there - not because it's the hardest (it isn't), but because it's the most fun. At least, *I* think it is. But I'm biased majorly. :D ChrisA From wxjmfauth at gmail.com Wed Sep 26 10:19:56 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 07:19:56 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> Message-ID: <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> Le mercredi 26 septembre 2012 11:55:16 UTC+2, Chris Angelico a ?crit?: > On Wed, Sep 26, 2012 at 7:31 PM, wrote: > > > you are correct. But the price you pay for this is extremely > > > high. Now, practically all characters are affected, espacially > > > those *in* the Basic *** Multilingual*** Plane, these characters > > > used by non "American" user (No offense here, I just use this > > > word for ascii/latin-1). > > > > > > I'm ready to be considered as an idiot, but I'm not blind. > > > As soon as I tested these characters, Py3.3 performs really > > > badly. It seems to me it is legitimate to consider, there > > > is a serious problem here. > > > > We've been over this thread. The only reason you're counting 3.3 as > > worse is because you're comparing against a narrow build of Python > > 3.2. Narrow builds are **BUGGY** and this needed to be resolved. > > > > When you compare against a wide build, semantics of 3.2 and 3.3 are > > identical, and then - and ONLY then - can you sanely compare > > performance. And 3.3 stacks up much better. > > > > ChrisA No, I'm comparing Py33 with Py32 narrow build [*]. And I am not a Python newbie. Others in a previous discussion have pointed "bad" numbers and even TR wrote something like "I'm baffled (?) by these numbers". I took a look at the test suites, unfortunatelly they are mainly testing "special cases", something like one of the 3 internal representations, eg "latin-1". I can also add to this, that it is not only one of the internal representation which may be suspect (it is probably different now, Py32/Py33) but also the "switch" between these representations which is causing troubles. [*] I have not the knowledge to compile a wide build and I do not wish to spend my time in something that will be most probably a nightmare for me. I'm reacting like a "normal" Python user. jmf From wxjmfauth at gmail.com Wed Sep 26 10:19:56 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 07:19:56 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> Message-ID: <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> Le mercredi 26 septembre 2012 11:55:16 UTC+2, Chris Angelico a ?crit?: > On Wed, Sep 26, 2012 at 7:31 PM, wrote: > > > you are correct. But the price you pay for this is extremely > > > high. Now, practically all characters are affected, espacially > > > those *in* the Basic *** Multilingual*** Plane, these characters > > > used by non "American" user (No offense here, I just use this > > > word for ascii/latin-1). > > > > > > I'm ready to be considered as an idiot, but I'm not blind. > > > As soon as I tested these characters, Py3.3 performs really > > > badly. It seems to me it is legitimate to consider, there > > > is a serious problem here. > > > > We've been over this thread. The only reason you're counting 3.3 as > > worse is because you're comparing against a narrow build of Python > > 3.2. Narrow builds are **BUGGY** and this needed to be resolved. > > > > When you compare against a wide build, semantics of 3.2 and 3.3 are > > identical, and then - and ONLY then - can you sanely compare > > performance. And 3.3 stacks up much better. > > > > ChrisA No, I'm comparing Py33 with Py32 narrow build [*]. And I am not a Python newbie. Others in a previous discussion have pointed "bad" numbers and even TR wrote something like "I'm baffled (?) by these numbers". I took a look at the test suites, unfortunatelly they are mainly testing "special cases", something like one of the 3 internal representations, eg "latin-1". I can also add to this, that it is not only one of the internal representation which may be suspect (it is probably different now, Py32/Py33) but also the "switch" between these representations which is causing troubles. [*] I have not the knowledge to compile a wide build and I do not wish to spend my time in something that will be most probably a nightmare for me. I'm reacting like a "normal" Python user. jmf From rosuav at gmail.com Wed Sep 26 10:24:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Sep 2012 00:24:12 +1000 Subject: Article on the future of Python In-Reply-To: <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> Message-ID: On Thu, Sep 27, 2012 at 12:19 AM, wrote: > No, I'm comparing Py33 with Py32 narrow build [*]. Then look at the broken behaviour that Python, up until now, shared with Javascript and various other languages, in which a one-character string appears as two characters, and slicing and splicing strings can split surrogates apart. The new rule is simple: One Unicode codepoint takes up the space of one character. Anything else is mindbogglingly counterintuitive. ChrisA From wxjmfauth at gmail.com Wed Sep 26 10:50:52 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 07:50:52 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> Message-ID: <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> I should add that I have not the knowledge to dive in the Python code. But I "see" what has been done. As I have a very good understanding of all this coding of characters stuff, I can just pick up - in fact select characters or combination of characters - which I supspect to be problematic and I see the results. Not only this, I can select characters, I know a user is supposed to use or will use eg. a specific scrit/language, a typographical work, ... (Do not ask how and why, I know this). I'm not interesting in the other languages or in unicode therory (also I not bad on this level). I just see the results and the facts. For an end user, this is the only thing that counts. jmf From wxjmfauth at gmail.com Wed Sep 26 10:50:52 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 07:50:52 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> Message-ID: <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> I should add that I have not the knowledge to dive in the Python code. But I "see" what has been done. As I have a very good understanding of all this coding of characters stuff, I can just pick up - in fact select characters or combination of characters - which I supspect to be problematic and I see the results. Not only this, I can select characters, I know a user is supposed to use or will use eg. a specific scrit/language, a typographical work, ... (Do not ask how and why, I know this). I'm not interesting in the other languages or in unicode therory (also I not bad on this level). I just see the results and the facts. For an end user, this is the only thing that counts. jmf From rosuav at gmail.com Wed Sep 26 10:56:51 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Sep 2012 00:56:51 +1000 Subject: Article on the future of Python In-Reply-To: <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> Message-ID: On Thu, Sep 27, 2012 at 12:50 AM, wrote: > I just see the results and the facts. For an end > user, this is the only thing that counts. Then what counts is that Python 3.2 (like Javascript) exhibits incorrect behaviour, and Python (like Pike) performs correctly. I think this tee applies to you. http://www.thinkgeek.com/product/f147/ ChrisA wouldn't have bothered to respond except that that link was asking to be shared From breamoreboy at yahoo.co.uk Wed Sep 26 11:08:44 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 26 Sep 2012 16:08:44 +0100 Subject: Article on the future of Python In-Reply-To: <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> Message-ID: On 26/09/2012 15:50, wxjmfauth at gmail.com wrote: > I should add that I have not the knowledge to dive > in the Python code. But I "see" what has been done. How? > As I have a very good understanding of all this > coding of characters stuff, I can just pick up > - in fact select characters or combination > of characters - which I supspect to be problematic > and I see the results. Have you run the Python benchmarks yet, as people have more trust in something tangible than a claim that "I see the results"? You were asked to do this one month ago. If yes please publish your results. If no why not, if your claims were correct running the benchmarks would obviously support you? > > Not only this, I can select characters, I know > a user is supposed to use or will use eg. a specific > scrit/language, a typographical work, ... > (Do not ask how and why, I know this). Please state how and why. > > I'm not interesting in the other languages or in > unicode therory (also I not bad on this level). Please prove your statement in brackets, nothing less is acceptable if you're making claims, you need to substantiate them. > > I just see the results and the facts. For an end > user, this is the only thing that counts. The modern day Pinball Wizard? Or a physic? Or what? > > jmf > #pseudo code for _ in range(-inf, +inf, 1): print(FUD) -- Cheers. Mark Lawrence. From wxjmfauth at gmail.com Wed Sep 26 11:17:57 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 08:17:57 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> Message-ID: Le mercredi 26 septembre 2012 16:56:55 UTC+2, Chris Angelico a ?crit?: > On Thu, Sep 27, 2012 at 12:50 AM, wrote: > > > I just see the results and the facts. For an end > > > user, this is the only thing that counts. > > > > Then what counts is that Python 3.2 (like Javascript) exhibits > > incorrect behaviour, and Python (like Pike) performs correctly. > > > > I think this tee applies to you. http://www.thinkgeek.com/product/f147/ > > > > ChrisA > > wouldn't have bothered to respond except that that link was asking to be shared "You" have gained a broader range of unicode code points and the same time you "broke" a correct BMP behaviour. There is a simple solution to solve this. "You" do not wish to use it. Luckily for me, the tools I'm using use that one. jmf From wxjmfauth at gmail.com Wed Sep 26 11:17:57 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 08:17:57 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> Message-ID: Le mercredi 26 septembre 2012 16:56:55 UTC+2, Chris Angelico a ?crit?: > On Thu, Sep 27, 2012 at 12:50 AM, wrote: > > > I just see the results and the facts. For an end > > > user, this is the only thing that counts. > > > > Then what counts is that Python 3.2 (like Javascript) exhibits > > incorrect behaviour, and Python (like Pike) performs correctly. > > > > I think this tee applies to you. http://www.thinkgeek.com/product/f147/ > > > > ChrisA > > wouldn't have bothered to respond except that that link was asking to be shared "You" have gained a broader range of unicode code points and the same time you "broke" a correct BMP behaviour. There is a simple solution to solve this. "You" do not wish to use it. Luckily for me, the tools I'm using use that one. jmf From rosuav at gmail.com Wed Sep 26 11:18:25 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Sep 2012 01:18:25 +1000 Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> Message-ID: On Thu, Sep 27, 2012 at 1:08 AM, Mark Lawrence wrote: > for _ in range(-inf, +inf, 1): print(FUD) That'll never work. Try this: import itertools list(map(print,itertools.cycle(('FUD',)))) ChrisA From demianbrecht at gmail.com Wed Sep 26 11:40:19 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Wed, 26 Sep 2012 08:40:19 -0700 Subject: google api and oauth2 In-Reply-To: References: <5062003A.9020208@tysdomain.com> <50621279.8060700@tysdomain.com> Message-ID: Yes, dealing with the embedded web server is out of the scope of the library and not something that I'd want to introduce. Having said that, there wouldn't be any harm in a sanction-embedded library that would add that capability. Thanks for the info. -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Wed Sep 26 11:45:30 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 08:45:30 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> Message-ID: <2f605c2b-c2e3-4af4-be5d-019d2799f6d1@googlegroups.com> Sorry guys, I'm "only" able to see this (with the Python versions an end user can download): >>> timeit.repeat("('?'*10000).replace('?', 'a')") [31.44532887821319, 31.409585124813844, 31.40705548932476] >>> timeit.repeat("('?'*10000).replace('?', 'a')") [323.56687741054805, 323.1660997337247, 325.52611455786905] >>> timeit.repeat("('\u2207'*10000).replace('\u2207', 'a')") [31.48614883771855, 31.472262820580987, 31.467803762040184] >>> timeit.repeat("('\u2207'*10000).replace('\u2207', 'a')") [320.55378064913526, 321.6890182785167, 321.4132045160866] (Will wait for the final) jmf From wxjmfauth at gmail.com Wed Sep 26 11:45:30 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 08:45:30 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> Message-ID: <2f605c2b-c2e3-4af4-be5d-019d2799f6d1@googlegroups.com> Sorry guys, I'm "only" able to see this (with the Python versions an end user can download): >>> timeit.repeat("('?'*10000).replace('?', 'a')") [31.44532887821319, 31.409585124813844, 31.40705548932476] >>> timeit.repeat("('?'*10000).replace('?', 'a')") [323.56687741054805, 323.1660997337247, 325.52611455786905] >>> timeit.repeat("('\u2207'*10000).replace('\u2207', 'a')") [31.48614883771855, 31.472262820580987, 31.467803762040184] >>> timeit.repeat("('\u2207'*10000).replace('\u2207', 'a')") [320.55378064913526, 321.6890182785167, 321.4132045160866] (Will wait for the final) jmf From alister.ware at ntlworld.com Wed Sep 26 11:47:46 2012 From: alister.ware at ntlworld.com (Alister) Date: Wed, 26 Sep 2012 15:47:46 GMT Subject: regular expression : the dollar sign ($) work with re.match() or re.search() References: <5d913584-b5ea-4ff1-8094-f4d5b273c0b6@googlegroups.com> Message-ID: On Wed, 26 Sep 2012 10:48:00 +0300, Jussi Piitulainen wrote: > iMath writes: > >> I only know the dollar sign ($) will match a pattern from the end of a >> string, but which method does it work with, re.match() or re.search() > > It works with both. With re.match, the pattern has to match at the start > of the string _and_ the $ has to match the end of the string (or a > line); re.search scans the string until it finds a suitable start. > > What was the weird character that you used as a question mark? I removed > them because they confuse the newsreader I use. It shows fine in my news reader, perhaps you should consider changing to one that works properly (btw I am using pan on a fedora 17 netbook) -- Q: Why is Microsoft's Product Support a failure? A: Because Microsoft needs a Support Group instead. From ian.g.kelly at gmail.com Wed Sep 26 11:53:30 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 26 Sep 2012 09:53:30 -0600 Subject: Article on the future of Python In-Reply-To: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 26, 2012 at 1:23 AM, Steven D'Aprano wrote: > On Tue, 25 Sep 2012 23:35:39 -0700, wxjmfauth wrote: > >> Py 3.3 succeeded to somehow kill unicode and it has been transformed >> into an "American" product for "American" users. > > For the first time in Python's history, Python on 32-bit systems handles > strings containing Supplementary Multilingual Plane characters correctly, > and it does so without doubling or quadrupling the amount of memory every > single string takes up. Indeed. Here's an interesting article about Unicode handling that identifies Python 3.3 as one of only four programming languages that handle Unicode correctly (the other three being Bash, Haskell 98, and Scheme R6RS). http://unspecified.wordpress.com/2012/04/19/the-importance-of-language-level-abstract-unicode-strings/ From wayne at waynewerner.com Wed Sep 26 11:55:47 2012 From: wayne at waynewerner.com (Wayne Werner) Date: Wed, 26 Sep 2012 10:55:47 -0500 (CDT) Subject: Algorithms using Python? In-Reply-To: References: Message-ID: On Fri, 21 Sep 2012, Dennis Lee Bieber wrote: > On Fri, 21 Sep 2012 14:26:04 +0530, Mayuresh Kathe > declaimed the following in gmane.comp.python.general: > >> Is there a good book on foundational as well as advanced algorithms >> using Python? >> > Depends on what you mean by "foundational"... > > Since Python has dynamic lists and dictionaries, I suspect you won't > find any textbook focusing on linked-list or hashed lookup algorithms > using Python. > > You can probably implement them, but they're not going to be very > efficient. (And never "remove" an element from the linked-list > implementation because Python would shift all the other elements, hence > your "links" become invalid). It's quite inefficient, but it would be fairly trivial to create a LL implementation like this: class Link: def __init__(self): self.next = None self.value = None class LinkedList: def __init__(self): self.head = None def add(self, value): node = Link() node.value = value self.append(node) def append(self, node): # Write some code It's fairly easy to use reference types as one would use pointers in . But it might actually require understanding pointers and such in the first place... I'm not really aware of any algorithm that's impossible/harder to implement in Python - Python just makes most things a lot easier so you never have to deal with the lower level algorithms. Which makes *me* happy :) -Wayne From ethan at stoneleaf.us Wed Sep 26 12:05:35 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 26 Sep 2012 09:05:35 -0700 Subject: Article on the future of Python In-Reply-To: References: <5062AC20.6060904@stoneleaf.us> <506303C2.8090802@tysdomain.com> Message-ID: <506327CF.9010707@stoneleaf.us> Mark Lawrence wrote: > On 26/09/2012 14:31, Littlefield, Tyler wrote: > >> >> PS: Anyone know if rantingrik had relatives? ;) >> > > I say steady on old chap that's just not cricket. I've been known to > have a go at rr in the past for good reasons, but when he gets stuck > into Tkinter he is an extremely useful contributor. I certainly prefer > him to Xah Lee, who's attempts at improving Python documentation were > beautifully torn to pieces here, IIRC by Ethan Furman, apologies to him > and the actual author if I'm incorrect. I don't think it was me -- my troll tolerance is extremely low; currently there are sixteen in my troll trap. I could easily see it being D'Aprano, though -- he's excellent at shredding ridiculous arguments and even seems to enjoy it. Least ways, I enjoy reading his responses. :) ~Ethan~ From ethan at stoneleaf.us Wed Sep 26 12:08:37 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 26 Sep 2012 09:08:37 -0700 Subject: Article on the future of Python In-Reply-To: References: Message-ID: <50632885.1030105@stoneleaf.us> Chris Angelico wrote: > On Wed, Sep 26, 2012 at 10:19 PM, wrote: >> After all, if replacing a Nabla operator in a string take >> 10 times more times in Py33 than in Python32 [. . .] > > But I'll give you the benefit > of the doubt; maybe your number is in binary. +1 QOTW From jeanmichel at sequans.com Wed Sep 26 12:10:24 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 26 Sep 2012 18:10:24 +0200 (CEST) Subject: Fastest template engine In-Reply-To: Message-ID: <131977999.1114173.1348675824390.JavaMail.root@sequans.com> ----- Original Message ----- > > The post has been updated with the following template engines added > (per community request): > > 1. chameleon > 2. django > 3. web2py > > Here is a link: > > http://mindref.blogspot.com/2012/07/python-fastest-template.html > > Comments or suggestions are welcome. > > Thanks. > > Andriy http://www.cherrypy.org is quite popular as well. JM PS : please don't top post From jeanmichel at sequans.com Wed Sep 26 12:11:45 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 26 Sep 2012 18:11:45 +0200 (CEST) Subject: Fastest template engine In-Reply-To: <131977999.1114173.1348675824390.JavaMail.root@sequans.com> Message-ID: <1003801723.1114476.1348675905692.JavaMail.root@sequans.com> ----- Original Message ----- > ----- Original Message ----- > > > > The post has been updated with the following template engines added > > (per community request): > > > > 1. chameleon > > 2. django > > 3. web2py > > > > Here is a link: > > > > http://mindref.blogspot.com/2012/07/python-fastest-template.html > > > > Comments or suggestions are welcome. > > > > Thanks. > > > > Andriy > > http://www.cherrypy.org is quite popular as well. > > JM > > PS : please don't top post Kindly ignore my post, I don't know why, I read web framework instead of template engine. JM From wxjmfauth at gmail.com Wed Sep 26 12:18:36 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 09:18:36 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2bebeb46-9e2f-4a21-b089-e692a42b0d85@googlegroups.com> Le mercredi 26 septembre 2012 17:54:04 UTC+2, Ian a ?crit?: > On Wed, Sep 26, 2012 at 1:23 AM, Steven D'Aprano > > wrote: > > > On Tue, 25 Sep 2012 23:35:39 -0700, wxjmfauth wrote: > > > > > >> Py 3.3 succeeded to somehow kill unicode and it has been transformed > > >> into an "American" product for "American" users. > > > > > > For the first time in Python's history, Python on 32-bit systems handles > > > strings containing Supplementary Multilingual Plane characters correctly, > > > and it does so without doubling or quadrupling the amount of memory every > > > single string takes up. > > > > Indeed. Here's an interesting article about Unicode handling that > > identifies Python 3.3 as one of only four programming languages that > > handle Unicode correctly (the other three being Bash, Haskell 98, and > > Scheme R6RS). > > > > http://unspecified.wordpress.com/2012/04/19/the-importance-of-language-level-abstract-unicode-strings/ May I suggest, you dive in the TeX documentation (sometimes, no so easy to find quickly). In my mind much better than all these web pages around. The big plus, you will also understand "characters" as whole. jmf From wxjmfauth at gmail.com Wed Sep 26 12:18:36 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 09:18:36 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2bebeb46-9e2f-4a21-b089-e692a42b0d85@googlegroups.com> Le mercredi 26 septembre 2012 17:54:04 UTC+2, Ian a ?crit?: > On Wed, Sep 26, 2012 at 1:23 AM, Steven D'Aprano > > wrote: > > > On Tue, 25 Sep 2012 23:35:39 -0700, wxjmfauth wrote: > > > > > >> Py 3.3 succeeded to somehow kill unicode and it has been transformed > > >> into an "American" product for "American" users. > > > > > > For the first time in Python's history, Python on 32-bit systems handles > > > strings containing Supplementary Multilingual Plane characters correctly, > > > and it does so without doubling or quadrupling the amount of memory every > > > single string takes up. > > > > Indeed. Here's an interesting article about Unicode handling that > > identifies Python 3.3 as one of only four programming languages that > > handle Unicode correctly (the other three being Bash, Haskell 98, and > > Scheme R6RS). > > > > http://unspecified.wordpress.com/2012/04/19/the-importance-of-language-level-abstract-unicode-strings/ May I suggest, you dive in the TeX documentation (sometimes, no so easy to find quickly). In my mind much better than all these web pages around. The big plus, you will also understand "characters" as whole. jmf From alec.taylor6 at gmail.com Wed Sep 26 12:22:39 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Thu, 27 Sep 2012 02:22:39 +1000 Subject: Fastest web framework In-Reply-To: References: Message-ID: Thanks Andriy for benchmarking web2py. With this public benchmark the entire web2py community will be hard at work to bring our numbers up higher :) On Tue, Sep 25, 2012 at 9:01 PM, Andriy Kornatskyy < andriy.kornatskyy at live.com> wrote: > > Alec > > While performing benchmark for web2py I noticed a memory leak. It > constantly grows and never release it... > > Thanks. > > Andriy Kornatskyy > > ________________________________ > > Date: Mon, 24 Sep 2012 17:36:25 +1000 > > Subject: Re: Fastest web framework > > From: alec.taylor6 at gmail.com > > To: andriy.kornatskyy at live.com > > CC: python-list at python.org > > > > Can you throw in web2py? > > > > Thanks > > > > On Sun, Sep 23, 2012 at 7:19 PM, Andriy Kornatskyy > > > wrote: > > > > I have run recently a benchmark of a trivial 'hello world' application > > for various python web frameworks (bottle, django, flask, pyramid, > > web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... > > you might find it interesting: > > > > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > > > > Comments or suggestions are welcome. > > > > Thanks. > > > > Andriy Kornatskyy > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jpiitula at ling.helsinki.fi Wed Sep 26 12:29:51 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 26 Sep 2012 19:29:51 +0300 Subject: regular expression : the dollar sign ($) work with re.match() or re.search() References: <5d913584-b5ea-4ff1-8094-f4d5b273c0b6@googlegroups.com> Message-ID: Alister writes: > On Wed, 26 Sep 2012 10:48:00 +0300, Jussi Piitulainen wrote: > > > iMath writes: > > > >> I only know the dollar sign ($) will match a pattern from the end > >> of a string, but which method does it work with, re.match() or > >> re.search() > > > > It works with both. With re.match, the pattern has to match at the > > start of the string _and_ the $ has to match the end of the string > > (or a line); re.search scans the string until it finds a suitable > > start. > > > > What was the weird character that you used as a question mark? I > > removed them because they confuse the newsreader I use. > > It shows fine in my news reader, perhaps you should consider changing to > one that works properly (btw I am using pan on a fedora 17 netbook) I was just curious why anyone would use anything other than the ASCII question mark as an ordinary question mark when writing in English in a newsgroup. The post had this: 0000520 61 72 63 68 28 29 20 20 ef bc 9f 0a a r c h ( ) sp sp o < us nl od is showing (ef bc 9f) as (o < us) but since they are not individual characters anyway, never mind that. Google tells me (ef bc 9f) is UTF-8 for U+FF1F FULLWIDTH QUESTION MARK, so now I basically have my answer as to what it is, though still not as to why one would use it. The ordinary question mark would look like this: 0000000 61 72 63 68 28 29 20 3f 0a a r c h ( ) sp ? nl From no.email at nospam.invalid Wed Sep 26 12:52:43 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 26 Sep 2012 09:52:43 -0700 Subject: Article on the future of Python References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> Message-ID: <7xmx0cg204.fsf@ruckus.brouhaha.com> Chris Angelico writes: > When you compare against a wide build, semantics of 3.2 and 3.3 are > identical, and then - and ONLY then - can you sanely compare > performance. And 3.3 stacks up much better. I like to have seen real world benchmarks against a pure UTF-8 implementation. That means O(n) access to the n'th character of a string which could theoretically slow some programs down terribly, but I wonder how often that actually matters in ways that can't easily be worked around. From rosuav at gmail.com Wed Sep 26 13:04:50 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Sep 2012 03:04:50 +1000 Subject: Article on the future of Python In-Reply-To: <7xmx0cg204.fsf@ruckus.brouhaha.com> References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <7xmx0cg204.fsf@ruckus.brouhaha.com> Message-ID: On Thu, Sep 27, 2012 at 2:52 AM, Paul Rubin wrote: > Chris Angelico writes: >> When you compare against a wide build, semantics of 3.2 and 3.3 are >> identical, and then - and ONLY then - can you sanely compare >> performance. And 3.3 stacks up much better. > > I like to have seen real world benchmarks against a pure UTF-8 > implementation. That means O(n) access to the n'th character of a > string which could theoretically slow some programs down terribly, but I > wonder how often that actually matters in ways that can't easily be > worked around. That's pretty much what we have with the PHP parts of our web site. We've decreed that everything should be UTF-8 byte streams (actually, it took some major campaigning from me to get rid of the underlying thinking that "binary-safe" and "UTF-8" and "characters" and so on were all equivalent), but there are very few places where we actually index strings in PHP. There's a small amount of parsing, but it's all done by splitting on particular strings - if you search for 0x0A in a UTF-8 bytestream and split at that index, it's the same as searching for U+000A in a Unicode string and splitting there - and all of our structural elements fit inside ASCII. The few times we actually care about character length (eg limiting user-specified rule names to N characters), we don't much care about performance, because they're unusual checks. So, I don't actually have any stats for you, because it's really easy to just not index strings at all. ChrisA From no.email at nospam.invalid Wed Sep 26 13:32:40 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 26 Sep 2012 10:32:40 -0700 Subject: Article on the future of Python References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <7xmx0cg204.fsf@ruckus.brouhaha.com> Message-ID: <7xipb0g05j.fsf@ruckus.brouhaha.com> Chris Angelico writes: > So, I don't actually have any stats for you, because it's really easy > to just not index strings at all. Right, that's why I think the O(n) indexing issue of UTF-8 may be overblown. Haskell 98 was mentioned earlier as a language that did Unicode "correctly", but its strings are linked lists of code points. They are a performance pig to be sure but the O(n) indexing is usually not the bottleneck. These days there is a "Text" module that I think is basically UTF-16 arrays. I have been meaning to find out what happens with non-BMP characters. From wxjmfauth at gmail.com Wed Sep 26 14:35:56 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 11:35:56 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: <7xmx0cg204.fsf@ruckus.brouhaha.com> References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <7xmx0cg204.fsf@ruckus.brouhaha.com> Message-ID: Le mercredi 26 septembre 2012 18:52:44 UTC+2, Paul Rubin a ?crit?: > Chris Angelico writes: > > > When you compare against a wide build, semantics of 3.2 and 3.3 are > > > identical, and then - and ONLY then - can you sanely compare > > > performance. And 3.3 stacks up much better. > > > > I like to have seen real world benchmarks against a pure UTF-8 > > implementation. That means O(n) access to the n'th character of a > > string which could theoretically slow some programs down terribly, but I > > wonder how often that actually matters in ways that can't easily be > > worked around. The selection of a coding scheme is a problem per se. In Py33 there is a mixin of coding schemes, an artificial construction supposed to be a new coding scheme. As an exercise, pickup characters of each individual coding, toy with them and see what happen. This poor Python has not only the task to handle the bytes of a coding scheme, now it has the task to select the coding scheme it will use with probably plenty of side effects. Completely absurd. I am penalized simply because I add a French character to a French word. A character which does not belong to the same "category" of the characters composing this word. jmf From ian.g.kelly at gmail.com Wed Sep 26 14:58:08 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 26 Sep 2012 12:58:08 -0600 Subject: Fwd: Re: Article on the future of Python In-Reply-To: References: Message-ID: Resending to the list. ---------- Forwarded message ---------- From: "Ian Kelly" Date: Sep 26, 2012 12:57 PM Subject: Re: Article on the future of Python To: On Sep 26, 2012 12:42 AM, wrote: > Py 3.3 succeeded to somehow kill unicode and it has > been transformed into an "American" product for > "American" users. You know, usually when I see software decried as America-centric, it's because it doesn't support Unicode. This must be the first time I've seen that label applied to software that dares to *fully* support Unicode. -------------- next part -------------- An HTML attachment was scrubbed... URL: From phpyjs at gmail.com Wed Sep 26 15:19:39 2012 From: phpyjs at gmail.com (phpyjs at gmail.com) Date: Wed, 26 Sep 2012 12:19:39 -0700 (PDT) Subject: FirePlus Message-ID: <0151ce62-c926-476b-9307-9688cc9d72fa@googlegroups.com> http://bin.phpyjs.com/firen.zip by WatchMan From wxjmfauth at gmail.com Wed Sep 26 16:15:56 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 26 Sep 2012 13:15:56 -0700 (PDT) Subject: new-style class or old-style class? In-Reply-To: <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com> References: <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com> Message-ID: Le mardi 25 septembre 2012 16:44:05 UTC+2, Jayden a ?crit?: > In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!! Use Python 3 and classes. ------- The interesting point or my question. Why a Python beginner arrives here and should ask about this? jmf From tjreedy at udel.edu Wed Sep 26 16:27:03 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 26 Sep 2012 16:27:03 -0400 Subject: Article on the future of Python In-Reply-To: References: Message-ID: On 9/26/2012 4:45 AM, Dwight Hutto wrote: >> >> Why do you keep repeating this rubbish when you've already been shot to >> pieces? > > I still feel intact, so whatever little shards of pain you intended to > emit were lost on my ego. Uh, Dwight, he was not talking to you. -- Terry Jan Reedy From TP at frenoespam.fr.invalid Wed Sep 26 17:20:10 2012 From: TP at frenoespam.fr.invalid (TP) Date: Wed, 26 Sep 2012 23:20:10 +0200 Subject: using "*" to make a list of lists with repeated (and independent) elements Message-ID: Hi everybody, I have tried, naively, to do the following, so as to make lists quickly: >>> a=[0]*2 >>> a [0, 0] >>> a[0]=3 >>> a [3, 0] All is working fine, so I extended the technique to do: >>> a=[[0]*3]*2 >>> a [[0, 0, 0], [0, 0, 0]] >>> a[0][0]=2 >>> a [[2, 0, 0], [2, 0, 0]] The behavior is no more expected! The reason is probably that in the first case, 0 is an integer, not a list, so Python copies two elements that are independent. In the second case, the elements are [0,0,0], which is a list; when Python copies a list, he copies in fact the *pointer* to the list, such that we obtain this apparently strange behavior. Is it the correct explanation? In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" without this behavior? Thanks, TP From ian.g.kelly at gmail.com Wed Sep 26 17:39:32 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 26 Sep 2012 15:39:32 -0600 Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: References: Message-ID: On Wed, Sep 26, 2012 at 3:20 PM, TP wrote: > Hi everybody, > > I have tried, naively, to do the following, so as to make lists quickly: > >>>> a=[0]*2 >>>> a > [0, 0] >>>> a[0]=3 >>>> a > [3, 0] > > All is working fine, so I extended the technique to do: > >>>> a=[[0]*3]*2 >>>> a > [[0, 0, 0], [0, 0, 0]] >>>> a[0][0]=2 >>>> a > [[2, 0, 0], [2, 0, 0]] > > The behavior is no more expected! > The reason is probably that in the first case, 0 is an integer, not a list, > so Python copies two elements that are independent. > In the second case, the elements are [0,0,0], which is a list; when Python > copies a list, he copies in fact the *pointer* to the list, such that we > obtain this apparently strange behavior. Mostly correct. When you do [foo] * 3 it extends the list with the *same objects* no matter what type they are. In the case of integers, it doesn't matter that it's the same objects, because integers are immutable. Lists are mutable, however, and so it becomes apparent that the same objects are repeated when you try to modify one of the lists. > In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" > without this behavior? Use a list comprehension: a = [[0] * 3 for _ in range(2)] This way the expression `[0] * 3` is re-evaluated at each position in the outer list, rather than evaluated just once and then copied. From gelonida at gmail.com Wed Sep 26 17:43:32 2012 From: gelonida at gmail.com (Gelonida N) Date: Wed, 26 Sep 2012 23:43:32 +0200 Subject: PIL questions: still supported? Problems on 2.7 for win? alternatives? In-Reply-To: References: Message-ID: On 09/25/2012 02:42 PM, alex23 wrote: > On Sep 25, 6:25 pm, Gelonida N wrote: >> So it seems to be safe to use either Christoph' binary PIL distribution >> or to use Pillow. >> >> The fact, that pillow is accessable via PyPi / easy_install / PIP pushes >> me slightly towards pillow. > > >> I assume it's best to uninstall PIL before installing pillow. > > I would expect you'd be fine. Being a different package, it's a > different namespace, so they shouldn't conflict. This is what is confusing me. if I start with a new python and I just install Pillow, then pillow is imported via import PIL so it does not seem to have a separate name space If I had PIL and pillow installed, then I wouldn't even know how to choose which one to import. > >> On a Linux machine: >> What would happen in a virtualenv with sitepackages (amonst them PIL >> installed and a pillow installed ontop of it? >> I don't think I can uninstall PIL, as many distro packages depend on it. >> I don't want to create a virtualenv without site packages, as I have >> many dependencies and some of them are a little tricky to compile. > > Again, you should be fine, as it's in a separate namespace. You > definitely don't want to mess with PIL if you have other dependencies. Well I'm slightly confused, but will play a little to see what exactly works From no.email at nospam.invalid Wed Sep 26 17:43:58 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 26 Sep 2012 14:43:58 -0700 Subject: using "*" to make a list of lists with repeated (and independent) elements References: Message-ID: <7x7grgtq75.fsf@ruckus.brouhaha.com> TP writes: > copies a list, he copies in fact the *pointer* to the list .... > Is it the correct explanation? Yes, that is correct. > In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" > without this behavior? >>> a = [[0]*3 for i in xrange(2)] >>> a[0][0]=2 >>> a [[2, 0, 0], [0, 0, 0]] From dihedral88888 at googlemail.com Wed Sep 26 17:45:58 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 26 Sep 2012 14:45:58 -0700 (PDT) Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: References: Message-ID: TP? 2012?9?27????UTC+8??5?25?04???? > Hi everybody, > > > > I have tried, naively, to do the following, so as to make lists quickly: > > > > >>> a=[0]*2 > > >>> a > > [0, 0] > > >>> a[0]=3 > > >>> a > > [3, 0] > > > > All is working fine, so I extended the technique to do: > > > > >>> a=[[0]*3]*2 > > >>> a > > [[0, 0, 0], [0, 0, 0]] > > >>> a[0][0]=2 > > >>> a > > [[2, 0, 0], [2, 0, 0]] > > > > The behavior is no more expected! > > The reason is probably that in the first case, 0 is an integer, not a list, > > so Python copies two elements that are independent. > > In the second case, the elements are [0,0,0], which is a list; when Python > > copies a list, he copies in fact the *pointer* to the list, such that we > > obtain this apparently strange behavior. > > > > Is it the correct explanation? > > In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" > > without this behavior? > > > > Thanks, > > > > TP def zeros(m,n): for i in xrange(m): for j in xrange(n): a[i][j]=0 return a >>> a=zeros(3,2) >>> a [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] >>> I think this is what you want. From gelonida at gmail.com Wed Sep 26 17:46:17 2012 From: gelonida at gmail.com (Gelonida N) Date: Wed, 26 Sep 2012 23:46:17 +0200 Subject: templating performance Message-ID: http://mindref.blogspot.fr/2012/07/python-fastest-template.html From dihedral88888 at googlemail.com Wed Sep 26 18:07:35 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 26 Sep 2012 15:07:35 -0700 (PDT) Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: <7x7grgtq75.fsf@ruckus.brouhaha.com> References: <7x7grgtq75.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin? 2012?9?27????UTC+8??5?43?58???? > TP writes: > > > copies a list, he copies in fact the *pointer* to the list .... > > > Is it the correct explanation? > > > > Yes, that is correct. > > > > > In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" > > > without this behavior? > > > > >>> a = [[0]*3 for i in xrange(2)] > > >>> a[0][0]=2 > > >>> a > > [[2, 0, 0], [0, 0, 0]] I used numpy before. Python is not lisp but python can emulate the lisp behaviors. From dihedral88888 at googlemail.com Wed Sep 26 18:28:15 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 26 Sep 2012 15:28:15 -0700 (PDT) Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: References: <7x7grgtq75.fsf@ruckus.brouhaha.com> Message-ID: <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> 88888 Dihedral? 2012?9?27????UTC+8??6?07?35???? > Paul Rubin? 2012?9?27????UTC+8??5?43?58???? > > > TP writes: > > > > > > > copies a list, he copies in fact the *pointer* to the list .... > > > > > > > Is it the correct explanation? > > > > > > > > > > > > Yes, that is correct. > > > > > > > > > > > > > In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" > > > > > > > without this behavior? > > > > > > > > > > > > >>> a = [[0]*3 for i in xrange(2)] > > > > > > >>> a[0][0]=2 > > > > > > >>> a > > > > > > [[2, 0, 0], [0, 0, 0]] > > > > I used numpy before. > > > > Python is not lisp but python can emulate the lisp behaviors. def zeros(m,n): a=[] for i in xrange(m): a.append([0]*n) return a If one wants to tranlate to C, this is the style. From mcepl at redhat.com Wed Sep 26 18:44:37 2012 From: mcepl at redhat.com (Matej Cepl) Date: Thu, 27 Sep 2012 00:44:37 +0200 Subject: Article on the future of Python In-Reply-To: References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 26/09/12 15:30, Kevin Walzer wrote: > Apart from IronPython, what constituency do these alternative and Jython ... that is widely used in the Java server world > implementations of Python have that would raise them above the level of > interesting experiments? Mat?j From python.list at tim.thechases.com Wed Sep 26 18:45:19 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 26 Sep 2012 17:45:19 -0500 Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> References: <7x7grgtq75.fsf@ruckus.brouhaha.com> <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> Message-ID: <5063857F.4080301@tim.thechases.com> On 09/26/12 17:28, 88888 Dihedral wrote: > 88888 Dihedral? 2012?9?27????UTC+8??6?07?35???? >>>> In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" >>>> without this behavior? >>> >>> a = [[0]*3 for i in xrange(2)] >>> >>> a[0][0]=2 >>> >>> a >>> [[2, 0, 0], [0, 0, 0]] > > def zeros(m,n): > a=[] > for i in xrange(m): > a.append([0]*n) > return a > > If one wants to tranlate to C, this is the style. But this is Python, so why the heck would anybody want to emulate *C* style? It could also be written in an assembly-language style, COBOL style, or a Fortran style...none of which are particularly valuable. Besides, a C-style would allocate a single array of M*N slots and then calculate 2d offsets into that single array. :-P -tkc From dihedral88888 at googlemail.com Wed Sep 26 18:53:40 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 26 Sep 2012 15:53:40 -0700 (PDT) Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: References: <7x7grgtq75.fsf@ruckus.brouhaha.com> <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> Message-ID: <37c60fca-449c-49d4-b64b-3a50e10b5007@googlegroups.com> Tim Chase? 2012?9?27????UTC+8??6?44?42???? > On 09/26/12 17:28, 88888 Dihedral wrote: > > > 88888 Dihedral? 2012?9?27????UTC+8??6?07?35???? > > >>>> In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" > > >>>> without this behavior? > > >>> >>> a = [[0]*3 for i in xrange(2)] > > >>> >>> a[0][0]=2 > > >>> >>> a > > >>> [[2, 0, 0], [0, 0, 0]] > > > > > > def zeros(m,n): > > > a=[] > > > for i in xrange(m): > > > a.append([0]*n) > > > return a > > > > > > If one wants to tranlate to C, this is the style. > > > > But this is Python, so why the heck would anybody want to emulate > > *C* style? It could also be written in an assembly-language style, > > COBOL style, or a Fortran style...none of which are particularly > > valuable. > > > > Besides, a C-style would allocate a single array of M*N slots and > > then calculate 2d offsets into that single array. :-P > > > > -tkc I don't think a lot programmers can write assembly programs well for different instruction sets of cpus. Of course if GCC was not supportd in manny platforms free of charge, then I won't recommend this style of programming in python. From dihedral88888 at googlemail.com Wed Sep 26 18:53:40 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 26 Sep 2012 15:53:40 -0700 (PDT) Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: References: <7x7grgtq75.fsf@ruckus.brouhaha.com> <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> Message-ID: <37c60fca-449c-49d4-b64b-3a50e10b5007@googlegroups.com> Tim Chase? 2012?9?27????UTC+8??6?44?42???? > On 09/26/12 17:28, 88888 Dihedral wrote: > > > 88888 Dihedral? 2012?9?27????UTC+8??6?07?35???? > > >>>> In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" > > >>>> without this behavior? > > >>> >>> a = [[0]*3 for i in xrange(2)] > > >>> >>> a[0][0]=2 > > >>> >>> a > > >>> [[2, 0, 0], [0, 0, 0]] > > > > > > def zeros(m,n): > > > a=[] > > > for i in xrange(m): > > > a.append([0]*n) > > > return a > > > > > > If one wants to tranlate to C, this is the style. > > > > But this is Python, so why the heck would anybody want to emulate > > *C* style? It could also be written in an assembly-language style, > > COBOL style, or a Fortran style...none of which are particularly > > valuable. > > > > Besides, a C-style would allocate a single array of M*N slots and > > then calculate 2d offsets into that single array. :-P > > > > -tkc I don't think a lot programmers can write assembly programs well for different instruction sets of cpus. Of course if GCC was not supportd in manny platforms free of charge, then I won't recommend this style of programming in python. From tjreedy at udel.edu Wed Sep 26 19:24:11 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 26 Sep 2012 19:24:11 -0400 Subject: Article on the future of Python In-Reply-To: References: Message-ID: On 9/26/2012 8:19 AM, wxjmfauth at gmail.com wrote: > You are always selling the same argument. Because you keep repeating the same insane argument against 3.3. > Py3.3 is the only computer language I'm aware of which > is maltreating Unicode in such a way. You have it backwards. 3.3 fixes maltreatment of unicode, such as also exists in other languages. re will also run better with 3.3. You have not shown any new bugs. Many other languages do not handle extended plane characters properly. > After all, if replacing a Nabla operator in a string take > 10 times more times in Py33 than in Python32, it takes 10 > times more . There is nothing more to say. On the contrary, there is lots more to say. You have picked out the one thing that 3.3 does not do as well and ignored all the things 3.3 does better. I and others have already explained many of them. Included is that fact that 3.3 does one operation 10, 100, 1000,... times faster than 3.2. -- Terry Jan Reedy From tjreedy at udel.edu Wed Sep 26 19:29:49 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 26 Sep 2012 19:29:49 -0400 Subject: Fwd: Re: Article on the future of Python In-Reply-To: References: Message-ID: On 9/26/2012 2:58 PM, Ian Kelly wrote: > You know, usually when I see software decried as America-centric, it's > because it doesn't support Unicode. This must be the first time I've > seen that label applied to software that dares to *fully* support Unicode. What is truly bizarre is the idea came from and much or most of the implementation was done by Europeans, not Americans. -- Terry Jan Reedy From rosuav at gmail.com Wed Sep 26 19:42:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Sep 2012 09:42:14 +1000 Subject: Fwd: Re: Article on the future of Python In-Reply-To: References: Message-ID: On Thu, Sep 27, 2012 at 9:29 AM, Terry Reedy wrote: > On 9/26/2012 2:58 PM, Ian Kelly wrote: > >> You know, usually when I see software decried as America-centric, it's >> because it doesn't support Unicode. This must be the first time I've >> seen that label applied to software that dares to *fully* support Unicode. > > > What is truly bizarre is the idea came from and much or most of the > implementation was done by Europeans, not Americans. I suppose that a system that supports only Latin-1 is therefore Italy-centric? ChrisA From wuwei23 at gmail.com Wed Sep 26 20:14:44 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 26 Sep 2012 17:14:44 -0700 (PDT) Subject: Article on the future of Python References: <04e6e8dd-1549-4792-9bf2-4190b8874925@googlegroups.com> Message-ID: On Sep 26, 10:17?pm, wxjmfa... at gmail.com wrote: > Notice, I'm not a Unicode illiterate Any chance you could work on your usenet literacy and fix your double posts? From wuwei23 at gmail.com Wed Sep 26 20:17:37 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 26 Sep 2012 17:17:37 -0700 (PDT) Subject: templating performance References: Message-ID: On Sep 27, 7:50?am, Gelonida N wrote: > http://mindref.blogspot.fr/2012/07/python-fastest-template.html This is already being discussed on the list. See the thread "Fastest template engine". From wuwei23 at gmail.com Wed Sep 26 20:28:47 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 26 Sep 2012 17:28:47 -0700 (PDT) Subject: PIL questions: still supported? Problems on 2.7 for win? alternatives? References: Message-ID: <01772b51-733a-4cf1-917c-181c3f5d61ef@ro10g2000pbc.googlegroups.com> On Sep 27, 7:44?am, Gelonida N wrote: > This is what is confusing me. > if I start with a new python and I just install Pillow, then pillow is > imported via > import PIL > so it does not seem to have a separate name space > > If I had PIL and pillow installed, then I wouldn't even know how to > choose which one to import. Ah, I'm so sorry, I totally thought pillow had moved into its own namespace (but of course that makes no sense if it's to be a drop-in replacement for PIL). To be honest, I never rely on the system install of Python to provide anything, and prefer to use buildout/setup.py to guarantee the development/installation environment is correct. I suspect (and hopefully someone with more virtualenv experience will speak up here) that you'll have to modify your PYTHONPATH within the virtualenv to point to your local install of pillow before the site packages. From wuwei23 at gmail.com Wed Sep 26 20:30:31 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 26 Sep 2012 17:30:31 -0700 (PDT) Subject: new-style class or old-style class? References: <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com> Message-ID: On Sep 27, 6:15?am, wxjmfa... at gmail.com wrote: > The interesting point or my question. > Why a Python beginner arrives here and should ask about this? Would you prefer that they'd instead make some kind of false assumption and then post endless screeds condemning it? From wuwei23 at gmail.com Wed Sep 26 20:31:17 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 26 Sep 2012 17:31:17 -0700 (PDT) Subject: FirePlus References: <0151ce62-c926-476b-9307-9688cc9d72fa@googlegroups.com> Message-ID: <9174ef9a-9857-4414-b56f-2467a955490a@wm7g2000pbc.googlegroups.com> On Sep 27, 5:19?am, php... at gmail.com wrote: > http://bin.phpyjs.com/firen.zip > > by WatchMan Context? Description? Virus propagation? From wuwei23 at gmail.com Wed Sep 26 20:33:24 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 26 Sep 2012 17:33:24 -0700 (PDT) Subject: Fastest template engine References: Message-ID: <5c56c39b-96de-40a0-987c-be8037e9b68e@q9g2000pbo.googlegroups.com> On Sep 27, 2:12?am, Jean-Michel Pichavant wrote: > Kindly ignore my post, I don't know why, I read web framework instead of template engine. Possibly because there's a parallel thread by Andriy on that topic :) From steve+comp.lang.python at pearwood.info Wed Sep 26 20:36:09 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Sep 2012 00:36:09 GMT Subject: Article on the future of Python References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> Message-ID: <50639f78$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 26 Sep 2012 07:19:56 -0700, wxjmfauth wrote: > No, I'm comparing Py33 with Py32 narrow build [*]. And I am not a Python > newbie. Others in a previous discussion have pointed "bad" numbers and > even TR wrote something like "I'm baffled (?) by these numbers". jmf, some time ago I said to you that if you want your claims to be taken seriously, you should come up with a test suite that exercises the FULL range of string operations and still demonstrates a significant slowdown. Have you do this? I would be interested to run your test suite. We know that if the only thing you do is repeatedly create strings, then throw them away, then create more strings, then throw them away, Python 3.3 will be a little slower than Python 3.2. You say "ten times" slower, but nobody else has been able to confirm this. Others are reporting that, at worst, string handling is twice as slow and sometimes twice as fast, depending on what operations you do, and what operating system you have. (Since creating strings depends on allocating, and moving, blocks of memory, the speed of creating strings is highly dependent on the operating system's memory management.) If all you want to do is complain and whinge and feel morally superior that you are the only one that cares that "Python is slower" (allegedly), please take it to your blog because we don't care. But if you genuinely want to determine whether or not this slowdown is meaningful in practice, and if so help optimise it so that it is faster, then stop with the propaganda about Python destroying Unicode and start writing a test suite. -- Steven From steve+comp.lang.python at pearwood.info Wed Sep 26 20:40:16 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Sep 2012 00:40:16 GMT Subject: Article on the future of Python References: <5062AC20.6060904@stoneleaf.us> Message-ID: <5063a070$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 26 Sep 2012 10:01:11 +0100, Mark Lawrence wrote: > You remind me of the opening to the song Plaistow Patricia by Ian Dury > and the Blockheads. While I always appreciate a good reference to Ian Dury, please stop feeding D.H.'s ego by responding to his taunts. -- Steven From wuwei23 at gmail.com Wed Sep 26 20:40:38 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 26 Sep 2012 17:40:38 -0700 (PDT) Subject: Stop feeding the trolls (Was: which a is used?) References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> <20120925095327.aa0d222bad8678f6c0339fbf@druid.net> Message-ID: <66323e0b-228b-44c1-96e3-eecb7cc3cd84@n7g2000pbj.googlegroups.com> On Sep 26, 5:06?pm, Dwight Hutto wrote: > You can "Plonk" my dick bitches. You do understand that when you have so many people react badly to how you phrase things, that the problem most likely lies with you and not them? That the only person who actually reacts favourably to this garbage coming from you is *you*? There is no place for racist or sexist speech here. Reply personally to whomever you want with whatever invective you choose, that's your right (just as it is their right to flag your emails as spam, as I have). But this is a place for public discussion and, again, we do not need you driving away people who might actually contribute positively simply because you're unable or unwilling to always do so. From steve+comp.lang.python at pearwood.info Wed Sep 26 20:44:41 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Sep 2012 00:44:41 GMT Subject: Article on the future of Python References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 26 Sep 2012 09:30:19 -0400, Kevin Walzer wrote: > On 9/25/12 11:35 AM, Steven D'Aprano wrote: >> IronPython in C#. Jython is written in Java. CLPython is written in >> Lisp. Berp and HoPe are written in Haskell. Nuitka is written in C++. >> Skulpt is written in Javascript. Vyper is written in Ocaml. PyPy is >> written in RPython. >> >> Some of those Python compilers are obsolete, unmaintained or >> experimental. Others are not. But either way, it is certainly not true >> that Python is written in C. One specific Python compiler happens to be >> written in C, that is all. > > Apart from IronPython, what constituency do these alternative > implementations of Python have that would raise them above the level of > interesting experiments? The "Big Four" are CPython, Jython, IronPython and PyPy. Possibly "Big Five" if you include Stackless, although I'm not quite sure just how big (popular) Stackless actually is. It's certainly old and venerable, and actively maintained. If you've played EVE Online, you've seen Stackless in action. Jython has a big constituency in Java shops. I can't tell you much about that because I don't use Java. PyPy is, well, PyPy is amazing, if you have the hardware to run it. It is an optimizing Python JIT compiler, and it can consistently demonstrate speeds of about 10 times the speed of CPython, which puts it in the same ballpark as native code generated by Java compilers. For some (admittedly artificially narrow) tasks it can beat optimized C code. It's fast enough for real time video processing, depending on the algorithm used. While PyPy is still a work in progress, and is not anywhere near as mature as (say) gcc or clang, it should be considered production-ready. I expect that, within the decade, PyPy will become "the" standard Python compiler and CPython will be relegated to "merely" the reference implementation. -- Steven From d at davea.name Wed Sep 26 20:51:49 2012 From: d at davea.name (Dave Angel) Date: Wed, 26 Sep 2012 20:51:49 -0400 Subject: FirePlus In-Reply-To: <9174ef9a-9857-4414-b56f-2467a955490a@wm7g2000pbc.googlegroups.com> References: <0151ce62-c926-476b-9307-9688cc9d72fa@googlegroups.com> <9174ef9a-9857-4414-b56f-2467a955490a@wm7g2000pbc.googlegroups.com> Message-ID: <5063A325.3020305@davea.name> On 09/26/2012 08:31 PM, alex23 wrote: > On Sep 27, 5:19 am, php... at gmail.com wrote: >> http://bin.xxxxxxxxx.yyy/ppppp.zip >> >> by WatchMan > Context? Description? Virus propagation? Why would you propagate that link? When I saw the original, I just deleted it immediately from the local folder. -- DaveA From wayne at waynewerner.com Wed Sep 26 21:03:39 2012 From: wayne at waynewerner.com (Wayne Werner) Date: Wed, 26 Sep 2012 20:03:39 -0500 (CDT) Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> Message-ID: On Sat, 22 Sep 2012, ????? ?????? wrote: > > Okey i'll ask this to the officila joomla forum, one last thing though. > > Is there a way to somehow embed(or utilize) python code, for example my python counter code script you have seen last week inside my Joomla/WordPress cms sites? > > For example: > > http://superhost.gr/ is my main website utilizing python counter script. > > http://superhost.gr/html/?show=log is my own way(i prefer it over awstats - don't ask why) for viewing my visitors. > > in my other sites which are CMS sites, like > > http://varsa.gr > and > http://thessalonik.wordpress.com/ > > is there a possible way to embed(if thats the term) my python counter script there too? > > so i can keep track of visitors info for each page i have there? Sure, but why create a counter (ugh) when you can use something like Google Analytics for free and get much more interesting and useful metrics? -Wayne From wayne at waynewerner.com Wed Sep 26 21:06:44 2012 From: wayne at waynewerner.com (Wayne Werner) Date: Wed, 26 Sep 2012 20:06:44 -0500 (CDT) Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> <505e8ada$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 23 Sep 2012, Dwight Hutto wrote: > We're the borg. Oh, so you *are* a robot. That does explain your posts ;) From breamoreboy at yahoo.co.uk Wed Sep 26 21:10:16 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 27 Sep 2012 02:10:16 +0100 Subject: Article on the future of Python In-Reply-To: <5063a070$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <5062AC20.6060904@stoneleaf.us> <5063a070$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27/09/2012 01:40, Steven D'Aprano wrote: > On Wed, 26 Sep 2012 10:01:11 +0100, Mark Lawrence wrote: > >> You remind me of the opening to the song Plaistow Patricia by Ian Dury >> and the Blockheads. > > While I always appreciate a good reference to Ian Dury, please stop > feeding D.H.'s ego by responding to his taunts. > > Good point as he's had so much rope that he's hung himself several times over. Thanks for helping me get my feet back on the ground. -- Cheers. Mark Lawrence. From wuwei23 at gmail.com Wed Sep 26 21:19:30 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 26 Sep 2012 18:19:30 -0700 (PDT) Subject: FirePlus References: <0151ce62-c926-476b-9307-9688cc9d72fa@googlegroups.com> <9174ef9a-9857-4414-b56f-2467a955490a@wm7g2000pbc.googlegroups.com> Message-ID: <7e8a9aeb-869d-4fc4-8ee3-9c5088158641@r2g2000pbk.googlegroups.com> On Sep 27, 10:52?am, Dave Angel wrote: > Why would you propagate that link? ?When I saw the original, I just > deleted it immediately from the local folder. It's sometimes difficult to tell the difference between malicious and incompetent. My apologies, though, I should've realised that others are apparently unable to decide for themselves whether to click on random links or not. From emile at fenx.com Wed Sep 26 21:33:26 2012 From: emile at fenx.com (Emile van Sebille) Date: Wed, 26 Sep 2012 18:33:26 -0700 Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> <505e8ada$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/26/2012 6:06 PM Wayne Werner said... > On Sun, 23 Sep 2012, Dwight Hutto wrote: > >> We're the borg. > > Oh, so you *are* a robot. That does explain your posts ;) Damn. Now I'll forever more hear Stephen Hawkin's voice as I read the repeated contexts. Maybe that'll help. EMile From wayne at waynewerner.com Wed Sep 26 21:34:51 2012 From: wayne at waynewerner.com (Wayne Werner) Date: Wed, 26 Sep 2012 20:34:51 -0500 (CDT) Subject: Who's laughing at my responses, and who's not? In-Reply-To: References: <5bc2681o43dhv5p13v71jqodtnokbq9mko@4ax.com> Message-ID: On Tue, 25 Sep 2012, Dwight Hutto wrote: > It sounds pretentious, but over the past several days, I've been > slammed on every post almost. All because of an argument over me not > posting a little context in a conversation, that seemed short and > chatty. Your being slammed has nothing to do with your lack of context, and everything to do with the fact that the way you responded to it was through ad hominem attacks, and the fact that most of your responses read like a transcript from kids I remember in junior high. It's annoying to most people - the same way pretentious teenage nitwits annoy most people who are interested in talking about Python code, and not who did what to who. -Wayne From walterhurry at lavabit.com Wed Sep 26 21:37:54 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Thu, 27 Sep 2012 01:37:54 +0000 (UTC) Subject: Article on the future of Python References: <04e6e8dd-1549-4792-9bf2-4190b8874925@googlegroups.com> Message-ID: On Wed, 26 Sep 2012 17:14:44 -0700, alex23 wrote: > On Sep 26, 10:17?pm, wxjmfa... at gmail.com wrote: >> Notice, I'm not a Unicode illiterate > > Any chance you could work on your usenet literacy and fix your double > posts? I have a better idea: Consign him to the same bin as Dwight Hutto and Dihedral. From wuwei23 at gmail.com Wed Sep 26 21:38:37 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 26 Sep 2012 18:38:37 -0700 (PDT) Subject: Article on the future of Python References: Message-ID: <98aaa5c9-d9fd-4dc9-a222-49a14635bd58@j2g2000pbg.googlegroups.com> On Sep 27, 6:27?am, Terry Reedy wrote: > On 9/26/2012 4:45 AM, Dwight Hutto wrote: > > my ego > Uh, Dwight, he was not talking to you. The irony, it is so rich :) From python at mrabarnett.plus.com Wed Sep 26 22:02:03 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 27 Sep 2012 03:02:03 +0100 Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> <505e8ada$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5063B39B.5080804@mrabarnett.plus.com> On 2012-09-27 02:06, Wayne Werner wrote: > On Sun, 23 Sep 2012, Dwight Hutto wrote: > >> We're the borg. > > Oh, so you *are* a robot. That does explain your posts ;) > The Borg are cyborgs, not robots. From steve+comp.lang.python at pearwood.info Wed Sep 26 22:25:16 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Sep 2012 02:25:16 GMT Subject: Python 3.3 and .pyo files References: Message-ID: <5063b90b$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 21 Sep 2012 11:10:07 +0200, Marco wrote: > I was trying to import a pyo module in Python 3.3, but Python does not > find it: [...] Marco, this bug is apparently now fixed: http://bugs.python.org/issue16046 Please download the latest version of Python 3.3 and try again. (Folks, this is why testing and reporting bugs to beta and rc versions is so useful. You can often get them fixed quite quickly.) -- Steven From ben+python at benfinney.id.au Wed Sep 26 23:06:54 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 27 Sep 2012 13:06:54 +1000 Subject: Stop feeding the trolls References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> <20120925095327.aa0d222bad8678f6c0339fbf@druid.net> <66323e0b-228b-44c1-96e3-eecb7cc3cd84@n7g2000pbj.googlegroups.com> Message-ID: <7wehlodv01.fsf@benfinney.id.au> alex23 writes: > On Sep 26, 5:06?pm, Dwight Hutto wrote: > > You can "Plonk" my dick bitches. > > You do understand that when you have so many people react badly to how > you phrase things, that the problem most likely lies with you and not > them? That the only person who actually reacts favourably to this > garbage coming from you is *you*? There have been ample opportunities for him to realise this. It's past time to stop feeding this troll, please. -- \ ?Alternative explanations are always welcome in science, if | `\ they are better and explain more. Alternative explanations that | _o__) explain nothing are not welcome.? ?Victor J. Stenger, 2001-11-05 | Ben Finney From rosuav at gmail.com Thu Sep 27 01:37:35 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Sep 2012 15:37:35 +1000 Subject: Article on the future of Python In-Reply-To: <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 27, 2012 at 10:44 AM, Steven D'Aprano wrote: > PyPy is, well, PyPy is amazing, if you have the hardware to run it. It is > an optimizing Python JIT compiler, and it can consistently demonstrate > speeds of about 10 times the speed of CPython, which puts it in the same > ballpark as native code generated by Java compilers. For some (admittedly > artificially narrow) tasks it can beat optimized C code. It's fast enough > for real time video processing, depending on the algorithm used. > > While PyPy is still a work in progress, and is not anywhere near as > mature as (say) gcc or clang, it should be considered production-ready. That's all very well, but unless I have my facts badly wrong, PyPy is only compatible with Python 2 - right? I'd much rather have full Unicode support etc etc etc than the coolness of Python-implemented-in-Python, even with a significant performance boost. > I expect that, within the decade, PyPy will become "the" standard Python > compiler and CPython will be relegated to "merely" the reference > implementation. Assuming it manages to catch up with Py3, which a decade makes entirely possible, this I can well believe. And while we're sounding all hopeful, maybe Python will be on popularity par with every other P in the classic LAMP stack. *That* would be a Good Thing. ChrisA From steve+comp.lang.python at pearwood.info Thu Sep 27 02:01:06 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Sep 2012 06:01:06 GMT Subject: Article on the future of Python References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> On Thu, 27 Sep 2012 15:37:35 +1000, Chris Angelico wrote: > On Thu, Sep 27, 2012 at 10:44 AM, Steven D'Aprano > wrote: >> While PyPy is still a work in progress, and is not anywhere near as >> mature as (say) gcc or clang, it should be considered production-ready. > > That's all very well, but unless I have my facts badly wrong, PyPy is > only compatible with Python 2 - right? At the moment, yes. Support for Python 3 is in active development. http://morepypy.blogspot.com/2012/09/py3k-status-update-6.html [...] > Assuming it manages to catch up with Py3, which a decade makes entirely > possible, this I can well believe. And while we're sounding all hopeful, > maybe Python will be on popularity par with every other P in the classic > LAMP stack. *That* would be a Good Thing. Given how Perl has slipped in the last decade or so, that would be a step backwards for Python :-P -- Steven From rosuav at gmail.com Thu Sep 27 02:08:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Sep 2012 16:08:41 +1000 Subject: Article on the future of Python In-Reply-To: <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 27, 2012 at 4:01 PM, Steven D'Aprano wrote: > On Thu, 27 Sep 2012 15:37:35 +1000, Chris Angelico wrote: >> Assuming it manages to catch up with Py3, which a decade makes entirely >> possible, this I can well believe. And while we're sounding all hopeful, >> maybe Python will be on popularity par with every other P in the classic >> LAMP stack. *That* would be a Good Thing. > > Given how Perl has slipped in the last decade or so, that would be a step > backwards for Python :-P LAMP usually means PHP these days. There's a lot of that around. ChrisA From steve+comp.lang.python at pearwood.info Thu Sep 27 02:13:10 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Sep 2012 06:13:10 GMT Subject: Article on the future of Python References: Message-ID: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Sep 2012 09:15:00 +0100, Mark Lawrence wrote: > Hi all, > > I though this might be of interest. > > http://www.ironfroggy.com/software/i-am-worried-about-the-future-of- python And a response: http://data.geek.nz/python-is-doing-just-fine -- Steven From steve+comp.lang.python at pearwood.info Thu Sep 27 02:13:32 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Sep 2012 06:13:32 GMT Subject: #python archives? Message-ID: <5063ee8b$0$29997$c3e8da3$5496439d@news.astraweb.com> My google-foo is failing me. Is the #python chatroom on freenode archived anywhere on the web? -- Steven From redstone-cold at 163.com Thu Sep 27 02:26:30 2012 From: redstone-cold at 163.com (iMath) Date: Wed, 26 Sep 2012 23:26:30 -0700 (PDT) Subject: Does os.getcwd() and os.curdir have the same effect ? In-Reply-To: References: <12b64802-d598-441b-b3cd-87ec17bba514@googlegroups.com> Message-ID: <15bbb5f2-2242-44db-b97d-ba15cb8843b3@googlegroups.com> On Sunday, September 9, 2012 9:39:28 PM UTC+8, Thomas Jollans wrote: > On 09/09/2012 03:22 PM, iMath wrote: > Does os.getcwd() and os.curdir have the same effect ? > Python 3.2.3 (default, May 3 2012, 15:51:42) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.getcwd() '/home/tjol' >>> os.curdir '.' >>> No. Both refer to the current directory, but os.curdir is not an absolute path, so you can't chdir() to it later and expect to land it the original directory. get it ,thanks From redstone-cold at 163.com Thu Sep 27 02:26:30 2012 From: redstone-cold at 163.com (iMath) Date: Wed, 26 Sep 2012 23:26:30 -0700 (PDT) Subject: Does os.getcwd() and os.curdir have the same effect ? In-Reply-To: References: <12b64802-d598-441b-b3cd-87ec17bba514@googlegroups.com> Message-ID: <15bbb5f2-2242-44db-b97d-ba15cb8843b3@googlegroups.com> On Sunday, September 9, 2012 9:39:28 PM UTC+8, Thomas Jollans wrote: > On 09/09/2012 03:22 PM, iMath wrote: > Does os.getcwd() and os.curdir have the same effect ? > Python 3.2.3 (default, May 3 2012, 15:51:42) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.getcwd() '/home/tjol' >>> os.curdir '.' >>> No. Both refer to the current directory, but os.curdir is not an absolute path, so you can't chdir() to it later and expect to land it the original directory. get it ,thanks From dieter at handshake.de Thu Sep 27 02:55:20 2012 From: dieter at handshake.de (Dieter Maurer) Date: Thu, 27 Sep 2012 08:55:20 +0200 Subject: python application file format References: <5062F9D6.2060402@abzinc.com> Message-ID: <87obksrm3r.fsf@handshake.de> Benjamin Jessup writes: > ... > What do people recommend for a file format for a python desktop > application? Data is complex with 100s/1000s of class instances, which > reference each other. > > ... > Use cPickle with a module/class whitelist? (Can't easily port, not > entirely safe, compact enough, expandable) This is the approach used by the ZODB (Zope Object DataBase). I like the ZODB. It is really quite easy to get data persisted. It uses an elaborate caching scheme to speed up database interaction and has transaction control to ensure persistent data consistency in case of errors. Maybe not so relevant in your context, it does not require locking to safely access persistent data in a multi thread environment. > ... From info at egenix.com Thu Sep 27 03:23:58 2012 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Thu, 27 Sep 2012 09:23:58 +0200 Subject: ANN: eGenix PyRun - One file Python Runtime 1.1.0 Message-ID: <5063FF0E.9010503@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix PyRun - One file Python Runtime Version 1.1.0 An easy-to-use single file relocatable Python run-time - available for Windows, Mac OS X and Unix platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-PyRun-1.1.0.html ________________________________________________________________________ INTRODUCTION Our new eGenix PyRun combines a Python interpreter with an almost complete Python standard library into a single easy-to-use executable, that does not require a system wide installation and is fully relocatable. eGenix PyRun's executable only needs 11MB, but still supports most Python application and scripts - and it can be further compressed to 3-4MB using gzexe or upx. Compared to a regular Python installation of typically 100MB on disk, this makes eGenix PyRun ideal for applications and scripts that need to be distributed to many target machines, client installations or customers. It makes "installing" Python on a Unix based system as simple as copying a single file. We have been using the product internally in our mxODBC Connect Server since 2008 with great success and have now extracted it into a stand-alone open-source product. We provide both the source archive to build your own eGenix PyRun, as well as pre-compiled binaries for Linux, FreeBSD and Mac OS X, as 32- and 64-bit versions. Please see the product page for more details: http://www.egenix.com/products/python/PyRun/ ________________________________________________________________________ NEWS This is a new minor release of eGenix PyRun, which contains a few important fixes and enhancement based on the user feedback we received. Simplified Installation ----------------------- The new release includes a new script called install-pyrun, which greatly simplifies installation of eGenix PyRun, which works much like the virtualenv shell script used for creating new virtual environments (except that there's nothing virtual about PyRun environments :-)). Using the script, the eGenix PyRun installation is as simple as running: install-pyrun targetdir New Features ------------ * Added new simple end-to-end test for the PyRun build process: make test-distribution. * Added support to import top-level frozen modules via -m. For packages this still fails due to bugs in Python itself. * Added a new easy to use pyrun installation shell script: install-pyrun. * install-pyrun will now default to eGenix PyRun 1.1.0. * install-pyrun now has a new --pyrun-distribution option to manually direct the script to a distribution file. This comes in handy when testing your own eGenix PyRun distributions. Enhanced Integration -------------------- * Optional readline module included in our binary builds now links against readline version 6 instead of 5. This should resolve readline issues on modern Linux installations. * Resolved an issue related to sys.argv[0] that prevented installation of e.g. numpy and lxml with pyrun. We've tested PyRun installation with numpy, lxml, Cython, Django, Trac and several other popular packages. They should all install fine now. * PyRun now reads scripts from stdin when used as filter or when providing '-' as script name. Other Changes ------------- * Documented that setuptools/distribute and pip are not designed to be relocatable - unlike PyRun itself. * Most references to the pyrun build directory are now replaced with "". This reduces the pyrun binary size and also avoids confusion when looking at tracebacks. * Backported a patch to have Python 2.5 compile on systems that have a more recent version of svnversion installed. * Overall, we've managed to push the size down from 12MB in 1.0.0 to 11MB in this new release. Thanks go to Pavlos Christoforou for providing lots of good feedback, which triggered many of the above enhancements. Presentation at PyCon UK 2012 ----------------------------- Marc-Andr?, CEO of eGenix, will be giving a presentation about eGenix PyRun at PyCon UK 2012 in Coventry, UK on Saturday, Sept 29th in the Room Python/CC1.8. He will also be available during the conference to answer questions. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the product can be found at: http://www.egenix.com/products/python/PyRun/ _______________________________________________________________________ SUPPORT Commercial support for these packages is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. ________________________________________________________________________ MORE INFORMATION For more information about eGenix PyRun, licensing and download instructions, please visit our web-site or write to sales at egenix.com. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 27 2012) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2012-10-29: PyCon DE 2012, Leipzig, Germany ... 32 days to go 2012-10-23: Python Meeting Duesseldorf ... 26 days to go 2012-09-26: Released mxODBC.Connect 2.0.1 ... http://egenix.com/go34 2012-09-25: Released mxODBC 3.2.1 ... http://egenix.com/go33 eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From bryanjugglercryptographer at yahoo.com Thu Sep 27 04:00:51 2012 From: bryanjugglercryptographer at yahoo.com (bryanjugglercryptographer at yahoo.com) Date: Thu, 27 Sep 2012 01:00:51 -0700 (PDT) Subject: Memory usage per top 10x usage per heapy In-Reply-To: References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5060EB2C.6080508@tim.thechases.com> Message-ID: MrsEntity wrote: > Based on heapy, a db based solution would be serious overkill. I've embraced overkill and my life is better for it. Don't confuse overkill with cost. Overkill is your friend. The facts of the case: You need to save some derived strings for each of 2M input lines. Even half the input runs over the 2GB RAM in your (virtual) machine. You're using Ubuntu 12.04 in Virtualbox on Win7/64, Python 2.7/64. That screams "sqlite3". It's overkill, in a good way. It's already there for the importing. Other approaches? You could try to keep everything in RAM, but use less. Tim Chase pointed out the memory-efficiency of named tuples. You could save some more by switching to Win7/32, Python 2.7/32; VirtualBox makes trying such alternatives quick and easy. Or you could add memory. Compared to good old 32-bit, 64-bit operation consumes significantly more memory and supports vastly more memory. There's a bit of a mis-match in a 64-bit system with just 2GB of RAM. I know, sounds weird, "just" two billion bytes of RAM. I'll rephrase: just ten dollars worth of RAM. Less if you buy it where I do. I don't know why the memory profiling tools are misleading you. I can think of plausible explanations, but they'd just be guesses. There's nothing all that surprising in running out of RAM, given what you've explained. A couple K per line is easy to burn. -Bryan From bryanjugglercryptographer at yahoo.com Thu Sep 27 04:00:51 2012 From: bryanjugglercryptographer at yahoo.com (bryanjugglercryptographer at yahoo.com) Date: Thu, 27 Sep 2012 01:00:51 -0700 (PDT) Subject: Memory usage per top 10x usage per heapy In-Reply-To: References: <983c532f-3ff6-4bd2-bb48-07cf4d065a4b@googlegroups.com> <5060EB2C.6080508@tim.thechases.com> Message-ID: MrsEntity wrote: > Based on heapy, a db based solution would be serious overkill. I've embraced overkill and my life is better for it. Don't confuse overkill with cost. Overkill is your friend. The facts of the case: You need to save some derived strings for each of 2M input lines. Even half the input runs over the 2GB RAM in your (virtual) machine. You're using Ubuntu 12.04 in Virtualbox on Win7/64, Python 2.7/64. That screams "sqlite3". It's overkill, in a good way. It's already there for the importing. Other approaches? You could try to keep everything in RAM, but use less. Tim Chase pointed out the memory-efficiency of named tuples. You could save some more by switching to Win7/32, Python 2.7/32; VirtualBox makes trying such alternatives quick and easy. Or you could add memory. Compared to good old 32-bit, 64-bit operation consumes significantly more memory and supports vastly more memory. There's a bit of a mis-match in a 64-bit system with just 2GB of RAM. I know, sounds weird, "just" two billion bytes of RAM. I'll rephrase: just ten dollars worth of RAM. Less if you buy it where I do. I don't know why the memory profiling tools are misleading you. I can think of plausible explanations, but they'd just be guesses. There's nothing all that surprising in running out of RAM, given what you've explained. A couple K per line is easy to burn. -Bryan From gandalf at shopzeus.com Thu Sep 27 05:00:36 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 27 Sep 2012 11:00:36 +0200 Subject: Module baldy compiled to pyc? Message-ID: <506415B4.7090100@shopzeus.com> Today I had a strange experience. I have copied some updated py files (modules) to a directory on a remote server, overwritting the old ones. The pyc files on the server were older. Many programs are importing these modules, and most of them are started as background jobs (from cron). They started to throw all kinds of errors. I checked the py files, and they did have class definitions inside. However when I tried to use them I got AttributeError exceptions. Telling that those things are not in the module. I checked their contents by importing them, and they were not defined indeed. Finally I have checked the module.__file__ attributes to see that they are imported from the right place. The __file__ contained the path to the compiled pyc file, but the path was correct. So finally I have deleted all pyc files, and suddenly every program was working again. (Starting the interpreter again and importing the modules again did not solve the problem.) I suspect that there were two (or more) programs starting at the same time, writting the same pyc file at the same time. It happened with two modules today. Over the years, I have always copied files to this server, and let background programs compile the pyc files as needed. I have never experienced anything like this before, and I cannot reproduce the error. The question is this: do you think this could happen? Is it possible that something else caused the problem? What else could it be? What are the chances that it will happen again, and how can I prevent it? Thanks, Laszlo From storchaka at gmail.com Thu Sep 27 05:20:51 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 27 Sep 2012 12:20:51 +0300 Subject: Article on the future of Python In-Reply-To: References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27.09.12 09:08, Chris Angelico wrote: > LAMP usually means PHP these days. There's a lot of that around. And Cyrillic ? means Ruby. :-P From steve+comp.lang.python at pearwood.info Thu Sep 27 05:33:34 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Sep 2012 09:33:34 GMT Subject: Article on the future of Python References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> Message-ID: <50641d6d$0$29997$c3e8da3$5496439d@news.astraweb.com> On Wed, 26 Sep 2012 08:45:30 -0700, wxjmfauth wrote: > Sorry guys, I'm "only" able to see this (with the Python versions an end > user can download): [snip timeit results] While you have been all doom and gloom and negativity that Python has "destroyed" Unicode, I've actually done some testing. It seems that, possibly, there is a performance regression in the "replace" method. This is on Debian squeeze, using the latest rc version of 3.3, 3.3.0rc3: py> timeit.repeat("('b'*1000).replace('b', 'a')") [28.308280900120735, 29.012173799797893, 28.834429003298283] Notice that Unicode doesn't come into it, they are pure ASCII strings. Here's the same thing using 3.2.2: py> timeit.repeat("('b'*1000).replace('b', 'a')") [3.4444618225097656, 3.147739887237549, 3.132185935974121] That's a factor of 9 slowdown in 3.3, and no Unicode. Obviously Python has "destroyed ASCII". (I get similar slowdowns for Unicode strings too, so clearly Python hates all strings, not just ASCII.) Now, for irrelevant reasons, here I swapped to Centos. [steve at ando ~]$ python2.7 -m timeit "'b'*1000" 1000000 loops, best of 3: 0.48 usec per loop [steve at ando ~]$ python3.2 -m timeit "'b'*1000" 1000000 loops, best of 3: 1.3 usec per loop [steve at ando ~]$ python3.3 -m timeit "'b'*1000" 1000000 loops, best of 3: 0.397 usec per loop Clearly 3.3 is the fastest at string multiplication, at least for this trivial example. Just to prove that the result also applies to Unicode: [steve at ando ~]$ python3.3 -m timeit "('?'*1000)" 1000000 loops, best of 3: 1.38 usec per loop Almost identical to 3.2. And the reason it is slower than the 3.3 test using 'b' above is almost certainly because the string uses four times more memory: [steve at ando ~]$ python3.3 -m timeit "('abcd'*1000)" 1000000 loops, best of 3: 0.919 usec per loop So a little slower that the pure-ASCII version for the same amount of memory, but not significantly so. But add a call to replace, and things are very different: [steve at ando ~]$ python2.7 -m timeit -s "s = 'b'*1000" "s.replace('b', 'a')" 100000 loops, best of 3: 9.3 usec per loop [steve at ando ~]$ python3.2 -m timeit -s "s = 'b'*1000" "s.replace('b', 'a')" 100000 loops, best of 3: 5.43 usec per loop [steve at ando ~]$ python3.3 -m timeit -s "s = 'b'*1000" "s.replace('b', 'a')" 100000 loops, best of 3: 18.3 usec per loop Three times slower, even for pure-ASCII strings. I get comparable results for Unicode. Notice how slow Python 2.7 is: [steve at ando ~]$ python2.7 -m timeit -s "s = u'?'*1000" "s.replace(u'?', u'a')" 10000 loops, best of 3: 65.6 usec per loop [steve at ando ~]$ python3.2 -m timeit -s "s = '?'*1000" "s.replace('?', 'a')" 100000 loops, best of 3: 2.79 usec per loop [steve at ando ~]$ python3.3 -m timeit -s "s = '?'*1000" "s.replace('?', 'a')" 10000 loops, best of 3: 23.7 usec per loop Even with the performance regression, it is still over twice as fast as Python 2.7. Nevertheless, I think there is something here. The consequences are nowhere near as dramatic as jmf claims, but it does seem that replace() has taken a serious performance hit. Perhaps it is unavoidable, but perhaps not. If anyone else can confirm similar results, I think this should be raised as a performance regression. -- Steven From andriy.kornatskyy at live.com Thu Sep 27 05:44:42 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Thu, 27 Sep 2012 12:44:42 +0300 Subject: Fastest web framework In-Reply-To: References: , Message-ID: CherryPy is in the list now. http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html Thanks. Andriy ---------------------------------------- > From: andriy.kornatskyy at live.com > To: python-list at python.org > Subject: RE: Fastest web framework > Date: Tue, 25 Sep 2012 13:52:25 +0300 > > > The post has been updated with two more frameworks (per community request): tornado and web2py. > > Comments or suggestions are welcome. > > Thanks. > > Andriy Kornatskyy > > > ---------------------------------------- > > From: andriy.kornatskyy at live.com > > To: python-list at python.org > > Subject: Fastest web framework > > Date: Sun, 23 Sep 2012 12:19:16 +0300 > > > > > > I have run recently a benchmark of a trivial 'hello world' application for various python web frameworks (bottle, django, flask, pyramid, web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find it interesting: > > > > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > > > > Comments or suggestions are welcome. > > > > Thanks. > > > > Andriy Kornatskyy > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > -- > http://mail.python.org/mailman/listinfo/python-list From sscc at mweb.co.za Thu Sep 27 06:43:44 2012 From: sscc at mweb.co.za (Alex Strickland) Date: Thu, 27 Sep 2012 12:43:44 +0200 Subject: Article on the future of Python In-Reply-To: <50641d6d$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> <50641d6d$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50642DE0.8030102@mweb.co.za> Hi >> Sorry guys, I'm "only" able to see this (with the Python versions an end >> user can download): > > [snip timeit results] > > While you have been all doom and gloom and negativity that Python has > "destroyed" Unicode, I thought that jmf's concerns were solely concerned with the selection of latin1 as the 1 byte set. My impression was that if some set of characters was chosen that included all characters commonly used in French then all would be well with the world. But now I'm confused because latin1 seems to cater for French quite well: http://en.wikipedia.org/wiki/ISO/IEC_8859-1 -- Regards Alex From steve+comp.lang.python at pearwood.info Thu Sep 27 07:13:04 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Sep 2012 11:13:04 GMT Subject: Module baldy compiled to pyc? References: Message-ID: <506434bf$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 27 Sep 2012 11:00:36 +0200, Laszlo Nagy wrote: > Today I had a strange experience. I have copied some updated py files > (modules) to a directory on a remote server, overwritting the old ones. > The pyc files on the server were older. Many programs are importing > these modules, and most of them are started as background jobs (from > cron). They started to throw all kinds of errors. I checked the py > files, and they did have class definitions inside. However when I tried > to use them I got AttributeError exceptions. Telling that those things > are not in the module. It sounds to me like the timestamps on the .py files were messed up when you copied them, causing Python to prefer old, broken .pyc files instead of the newer .py files. > I suspect that there were two (or more) programs starting at the same > time, writting the same pyc file at the same time. I suppose that's not impossible, although you would need to check the Python source code to be sure. But I would expect that each process writes the .pyc file atomically, so even if two processes both try to create the .pyc file, one will harmlessly overwrite the other's output. I would be surprised if it were possible for two processes to simultaneously write to the same file -- that would require the Python compiler to explicitly open the .pyc file in shared writable mode, and why would it do that? Far more likely is a file system error. I recommend you run a disk check on the file server and see if it comes up with any errors. -- Steven From dihedral88888 at googlemail.com Thu Sep 27 07:15:55 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 27 Sep 2012 04:15:55 -0700 (PDT) Subject: Algorithms using Python? In-Reply-To: References: Message-ID: <293744c6-55a6-450e-99b6-8a506c146b52@googlegroups.com> Wayne Werner? 2012?9?27????UTC+8??12?05?31???? > On Fri, 21 Sep 2012, Dennis Lee Bieber wrote: > > > > > On Fri, 21 Sep 2012 14:26:04 +0530, Mayuresh Kathe > > > declaimed the following in gmane.comp.python.general: > > > > > >> Is there a good book on foundational as well as advanced algorithms > > >> using Python? > > >> > > > Depends on what you mean by "foundational"... > > > > > > Since Python has dynamic lists and dictionaries, I suspect you won't > > > find any textbook focusing on linked-list or hashed lookup algorithms > > > using Python. > > > > > > You can probably implement them, but they're not going to be very > > > efficient. (And never "remove" an element from the linked-list > > > implementation because Python would shift all the other elements, hence > > > your "links" become invalid). > > > > It's quite inefficient, but it would be fairly trivial to create a LL > > implementation like this: > > > > class Link: > > def __init__(self): > > self.next = None > > self.value = None > > > > class LinkedList: > > def __init__(self): > > self.head = None > > > > def add(self, value): > > node = Link() > > node.value = value > > self.append(node) > > > > def append(self, node): > > # Write some code > > > > It's fairly easy to use reference types as one would use pointers in > > . > > > > But it might actually require understanding pointers and such in the first > > place... > > > > I'm not really aware of any algorithm that's impossible/harder to > > implement in Python - Python just makes most things a lot easier so you > > never have to deal with the lower level algorithms. Which makes *me* happy > > :) > > > > -Wayne In python long integers of varried lengths of precesions, doubles, complex numbers, immutable tuples, modifiable lists, modifiable dictionaries, and functions and classes are all name resolved basic built in types. It is more interesting to implement a binary tree in python from a dictionary. Also the set part can be implemented by long integers or dictionaries. The symbolic computation part as in sympy is also a good example of high level programmings in python. But this also means a lot kids will finish their calculous homeworks trivially by machines instead of reasoning and learning in person. From dihedral88888 at googlemail.com Thu Sep 27 07:15:55 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 27 Sep 2012 04:15:55 -0700 (PDT) Subject: Algorithms using Python? In-Reply-To: References: Message-ID: <293744c6-55a6-450e-99b6-8a506c146b52@googlegroups.com> Wayne Werner? 2012?9?27????UTC+8??12?05?31???? > On Fri, 21 Sep 2012, Dennis Lee Bieber wrote: > > > > > On Fri, 21 Sep 2012 14:26:04 +0530, Mayuresh Kathe > > > declaimed the following in gmane.comp.python.general: > > > > > >> Is there a good book on foundational as well as advanced algorithms > > >> using Python? > > >> > > > Depends on what you mean by "foundational"... > > > > > > Since Python has dynamic lists and dictionaries, I suspect you won't > > > find any textbook focusing on linked-list or hashed lookup algorithms > > > using Python. > > > > > > You can probably implement them, but they're not going to be very > > > efficient. (And never "remove" an element from the linked-list > > > implementation because Python would shift all the other elements, hence > > > your "links" become invalid). > > > > It's quite inefficient, but it would be fairly trivial to create a LL > > implementation like this: > > > > class Link: > > def __init__(self): > > self.next = None > > self.value = None > > > > class LinkedList: > > def __init__(self): > > self.head = None > > > > def add(self, value): > > node = Link() > > node.value = value > > self.append(node) > > > > def append(self, node): > > # Write some code > > > > It's fairly easy to use reference types as one would use pointers in > > . > > > > But it might actually require understanding pointers and such in the first > > place... > > > > I'm not really aware of any algorithm that's impossible/harder to > > implement in Python - Python just makes most things a lot easier so you > > never have to deal with the lower level algorithms. Which makes *me* happy > > :) > > > > -Wayne In python long integers of varried lengths of precesions, doubles, complex numbers, immutable tuples, modifiable lists, modifiable dictionaries, and functions and classes are all name resolved basic built in types. It is more interesting to implement a binary tree in python from a dictionary. Also the set part can be implemented by long integers or dictionaries. The symbolic computation part as in sympy is also a good example of high level programmings in python. But this also means a lot kids will finish their calculous homeworks trivially by machines instead of reasoning and learning in person. From jeanpierreda at gmail.com Thu Sep 27 08:11:13 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 27 Sep 2012 08:11:13 -0400 Subject: Article on the future of Python In-Reply-To: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 27, 2012 at 2:13 AM, Steven D'Aprano wrote: > On Tue, 25 Sep 2012 09:15:00 +0100, Mark Lawrence wrote: > And a response: > > http://data.geek.nz/python-is-doing-just-fine Summary of that article: "Sure, you have all these legitimate concerns, but look, cake!" -- Devin From storchaka at gmail.com Thu Sep 27 08:46:13 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 27 Sep 2012 15:46:13 +0300 Subject: Article on the future of Python In-Reply-To: <50641d6d$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> <50641d6d$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27.09.12 12:33, Steven D'Aprano wrote: > Nevertheless, I think there is something here. The consequences are nowhere > near as dramatic as jmf claims, but it does seem that replace() has taken a > serious performance hit. Perhaps it is unavoidable, but perhaps not. > > If anyone else can confirm similar results, I think this should be raised as > a performance regression. Yes, I confirm, it's a performance regression. It should be avoidable. Almost any PEP393 performance regression can be avoided. At least for such corner case. Just no one has yet optimized this case. From invalid at invalid.invalid Thu Sep 27 09:59:17 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 27 Sep 2012 13:59:17 +0000 (UTC) Subject: Article on the future of Python References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-09-27, Chris Angelico wrote: > On Thu, Sep 27, 2012 at 4:01 PM, Steven D'Aprano wrote: > >> Given how Perl has slipped in the last decade or so, that would be a step >> backwards for Python :-P > > LAMP usually means PHP these days. There's a lot of that around. Yea, unfortunately. What a mess of a language. I recently had to learn enough PHP to make some changes to a web site we had done by an outside contractor. PHP feels like it was designed by taking a half-dozen other languages, chopping them into bits and then pulling random features/syntax/semantics at random from the various different piles. Those bits where then stuck together with duct tape and bubble gum and called PHP... As one of the contractors who wrote some of the PHP said: "PHP is like the worst parts of shell, Perl, and Java all combined into one language!" -- Grant Edwards grant.b.edwards Yow! Did something bad at happen or am I in a gmail.com drive-in movie?? From steve+comp.lang.python at pearwood.info Thu Sep 27 10:25:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Sep 2012 14:25:01 GMT Subject: Article on the future of Python References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <506461bc$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 27 Sep 2012 08:11:13 -0400, Devin Jeanpierre wrote: > On Thu, Sep 27, 2012 at 2:13 AM, Steven D'Aprano > wrote: >> On Tue, 25 Sep 2012 09:15:00 +0100, Mark Lawrence wrote: And a >> response: >> >> http://data.geek.nz/python-is-doing-just-fine > > Summary of that article: > > "Sure, you have all these legitimate concerns, but look, cake!" Did you read the article or just make up a witty response? If so, you half succeeded. It's more like, "Well, maybe, your concerns *might* be legitimate, but I don't think so because..." and then he gives half a dozen or more reasons why Python is in no danger. None of which involve cake, although one of them did involve Raspberry Pi. An easy mistake to make. -- Steven From rosuav at gmail.com Thu Sep 27 10:32:58 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Sep 2012 00:32:58 +1000 Subject: Article on the future of Python In-Reply-To: References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 27, 2012 at 11:59 PM, Grant Edwards wrote: > On 2012-09-27, Chris Angelico wrote: >> On Thu, Sep 27, 2012 at 4:01 PM, Steven D'Aprano wrote: >> >>> Given how Perl has slipped in the last decade or so, that would be a step >>> backwards for Python :-P >> >> LAMP usually means PHP these days. There's a lot of that around. > > Yea, unfortunately. What a mess of a language. I recently had to > learn enough PHP to make some changes to a web site we had done by an > outside contractor. PHP feels like it was designed by taking a > half-dozen other languages, chopping them into bits and then pulling > random features/syntax/semantics at random from the various different > piles. Those bits where then stuck together with duct tape and bubble > gum and called PHP... > > As one of the contractors who wrote some of the PHP said: "PHP is like > the worst parts of shell, Perl, and Java all combined into one > language!" I can't remember where I read it, and I definitely don't know if it's accurate to current thinking, but the other day I found a quote purporting to be from the creator of PHP saying that he didn't care about memory leaks, just restart Apache periodically. It's definitely true of most PHP scripts that they're unconcerned about resource leakage, on the assumption that everything'll get cleared out at the end of a page render. PHP seems to encourage sloppiness. ChrisA From klausem at gmail.com Thu Sep 27 10:44:56 2012 From: klausem at gmail.com (Klaus) Date: Thu, 27 Sep 2012 07:44:56 -0700 (PDT) Subject: ERROR:root:code for hash md5 was not found In-Reply-To: References: Message-ID: <914056ab-0c00-4b51-bb35-52b73a5f3ba7@googlegroups.com> I had that problem after moving my Python installation into another directory. Reinstalling Python helped. From ian.g.kelly at gmail.com Thu Sep 27 11:06:06 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 27 Sep 2012 09:06:06 -0600 Subject: Article on the future of Python In-Reply-To: <50642DE0.8030102@mweb.co.za> References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> <50641d6d$0$29997$c3e8da3$5496439d@news.astraweb.com> <50642DE0.8030102@mweb.co.za> Message-ID: On Thu, Sep 27, 2012 at 4:43 AM, Alex Strickland wrote: > I thought that jmf's concerns were solely concerned with the selection of > latin1 as the 1 byte set. My impression was that if some set of characters > was chosen that included all characters commonly used in French then all > would be well with the world. > > But now I'm confused because latin1 seems to cater for French quite well: > > http://en.wikipedia.org/wiki/ISO/IEC_8859-1 I understand ISO 8859-15 (Latin-9) to be the preferred Latin character set for French, as it includes the Euro sign as well as a few characters that are not in Latin-1 but are nonetheless infrequently found in French. From ramdevtech.netinc at gmail.com Thu Sep 27 11:08:15 2012 From: ramdevtech.netinc at gmail.com (ram dev) Date: Thu, 27 Sep 2012 08:08:15 -0700 (PDT) Subject: Client Needs Sr. Java Developer, Sacramento, CA Message-ID: Good Day, We have an urgent Contract Opening in Sr.Java Developer Looking forward to submit your resume for below mentioned Requirement? If you are interested, Please forward your latest resume along with location and pay rate details to ram at tech-netinc.com asked at the bottom of mail Job Title: Sr. Java Developer Location: Sacramento, CA Duration: 12+ Months Required Skills: ? J2EE ? SOA ? Web services(Strong, i.e., 3-4 years) ? Oracle pl/sql ? UNIX platform ? Full Name: ? Current Location: ? Pay Rate : ? Contact Details: ? Email: ? Availability: ? Visa Status: ? Relocation to : ? Last 4-digits of SSN: ? References: ? Ready for Telephonic discussion during office hours Thanks, ============================ Ram Dev Recruiter Tech-Net Inc. Tel: 916-458-4390 Ext 102 Email: ram at tech-netinc.com From jeanpierreda at gmail.com Thu Sep 27 11:40:21 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 27 Sep 2012 11:40:21 -0400 Subject: #python archives? In-Reply-To: <5063ee8b$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <5063ee8b$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 27, 2012 at 2:13 AM, Steven D'Aprano wrote: > My google-foo is failing me. Is the #python chatroom on freenode archived > anywhere on the web? #python doesn't have a policy against quiet bots that log channel interaction, but AFAIK there are no up-to-date public logs. As evidence to this, a certain anti-logging freenode user hasn't pestered #python ever since the last logging bot was banned (because of unrelated reasons). Is there any particular reason you want the logs? -- Devin From python.list at tim.thechases.com Thu Sep 27 11:59:06 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 27 Sep 2012 10:59:06 -0500 Subject: Ordering of mailbox.mbox contents? Message-ID: <506477CA.3010209@tim.thechases.com> Reading through the docs[1] and the source, I'm trying to discern if there's any guarantee that the contents of a mbox file remain in a consistent ordering across add/delete calls. As best I can tell from the source, it _looks_ like the code keeps an existing file in the same order, deletions remove without changing the order, and additions append at the end of the file in the order they're added. That's what I'd expect. Is this accurate, or have I missed anything? Thanks, -tkc [1] http://docs.python.org/library/mailbox.html#mbox From breamoreboy at yahoo.co.uk Thu Sep 27 12:03:30 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 27 Sep 2012 17:03:30 +0100 Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> <50641d6d$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27/09/2012 13:46, Serhiy Storchaka wrote: > On 27.09.12 12:33, Steven D'Aprano wrote: >> Nevertheless, I think there is something here. The consequences are >> nowhere >> near as dramatic as jmf claims, but it does seem that replace() has >> taken a >> serious performance hit. Perhaps it is unavoidable, but perhaps not. >> >> If anyone else can confirm similar results, I think this should be >> raised as >> a performance regression. > > Yes, I confirm, it's a performance regression. It should be avoidable. > Almost any PEP393 performance regression can be avoided. At least for > such corner case. Just no one has yet optimized this case. > > I have taken a liberty and raised this on the bug tracker quoting Steven D'Aprano's original figures and your response above. -- Cheers. Mark Lawrence. From jeanpierreda at gmail.com Thu Sep 27 12:16:38 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 27 Sep 2012 12:16:38 -0400 Subject: Article on the future of Python In-Reply-To: <506461bc$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> <506461bc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 27, 2012 at 10:25 AM, Steven D'Aprano wrote: > On Thu, 27 Sep 2012 08:11:13 -0400, Devin Jeanpierre wrote: > >> On Thu, Sep 27, 2012 at 2:13 AM, Steven D'Aprano >> wrote: >>> On Tue, 25 Sep 2012 09:15:00 +0100, Mark Lawrence wrote: And a >>> response: >>> >>> http://data.geek.nz/python-is-doing-just-fine >> >> Summary of that article: >> >> "Sure, you have all these legitimate concerns, but look, cake!" > > Did you read the article or just make up a witty response? If so, you > half succeeded. > > It's more like, "Well, maybe, your concerns *might* be legitimate, but I > don't think so because..." and then he gives half a dozen or more reasons > why Python is in no danger. None of which involve cake, although one of > them did involve Raspberry Pi. An easy mistake to make. Haha! :) Well, I don't agree. But let me explain. If we're going to have a serious discussion about the problems Python faces in the future, then the topics that Calvin brings up are relevant. These are problems that, ideally, we would overcome. And I think, to some degree, we are working towards a future where these problems are solved. (Except perhaps the game development one, which is a rather tough problem in a lot of ways.) As people have noted, we do have Kivy, we do have PyPy, we do have PyJS and other such things. The future has possibilities for the problems Calvin mentions to be solved, even if they are problems today. The article that was linked, the response, it doesn't talk about this. When Calvin says that Python has problems with mobile, the article doesn't even say "but Kivy does mobile" -- it says "but Science people love Python!" When Calvin says that Python has problems being done on the web, the article doesn't even say "but PyJS!" (regardless of the problems of relying on a hijacked project), it says "education loves Python!" When Calvin says that Python has failed for game development, the article doesn't try to explain any way that Python is moving to success here, or any way that Calvin's assessment is wrong. Instead, it says, "But The Web loves Python!" There is a pattern here. The pattern is that the article does not actually directly respond to anything Calvin said. It doesn't try to carry a dialogue about concerns about problem areas Python has. It ignores Python's problems, and focuses on its strengths. Charitably, maybe we'd call this a way of encouraging people who are discouraged by the bleaker tone of Calvin's post. And that's valid, if we're worried about morale. Definitely Calvin's post could be -- and has been -- taken the wrong way. It could be taken as a way of saying, "Python is doomed!", even though that isn't something Calvin ever wrote (he appears, from my reading, to be more worried about a stagnating community than a failed language). Under that interpretation, we would want other, more encouraging voices around, talking about ways in which Python is good and will survive. Uncharitably, it's just a way of hiding one's head in the sand, ignoring any problems Python has by focusing on what problems it doesn't have. So that's why I said that the summary is, "but look, cake!". Instead of being a dialogue about improving Python, it's a distraction from the issues Calvin brought up. It brings up strengths, which are also part of Python, but don't have much at all to do with Python's weaknesses, or with what Calvin was talking about. -- Devin From breamoreboy at yahoo.co.uk Thu Sep 27 12:45:03 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 27 Sep 2012 17:45:03 +0100 Subject: Article on the future of Python In-Reply-To: References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> <506461bc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27/09/2012 17:16, Devin Jeanpierre wrote: > On Thu, Sep 27, 2012 at 10:25 AM, Steven D'Aprano > wrote: >> On Thu, 27 Sep 2012 08:11:13 -0400, Devin Jeanpierre wrote: >> >>> On Thu, Sep 27, 2012 at 2:13 AM, Steven D'Aprano >>> wrote: >>>> On Tue, 25 Sep 2012 09:15:00 +0100, Mark Lawrence wrote: And a >>>> response: >>>> >>>> http://data.geek.nz/python-is-doing-just-fine >>> >>> Summary of that article: >>> >>> "Sure, you have all these legitimate concerns, but look, cake!" >> >> Did you read the article or just make up a witty response? If so, you >> half succeeded. >> >> It's more like, "Well, maybe, your concerns *might* be legitimate, but I >> don't think so because..." and then he gives half a dozen or more reasons >> why Python is in no danger. None of which involve cake, although one of >> them did involve Raspberry Pi. An easy mistake to make. > > Haha! :) > > Well, I don't agree. But let me explain. > [snipped] > -- Devin > The article Steven D'Aprano referred to is not a direct response to the article I referred to, yet your words are written as if it were. May I ask why? Or have I missed something? -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Thu Sep 27 12:47:08 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 27 Sep 2012 17:47:08 +0100 Subject: Article on the future of Python In-Reply-To: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27/09/2012 07:13, Steven D'Aprano wrote: > On Tue, 25 Sep 2012 09:15:00 +0100, Mark Lawrence wrote: > >> Hi all, >> >> I though this might be of interest. >> >> http://www.ironfroggy.com/software/i-am-worried-about-the-future-of- > python > > > And a response: > > http://data.geek.nz/python-is-doing-just-fine > > > Well there's definite proof that the PyPy people are all completely incompetent in a response on the above link, this is how easy it is "But ... why does the runtime environment have to be so limiting? Operations involving primitives could be easily compiled (on the fly - JIT) to machine code and more advanced objects exist as plug-ins. Oh, and it would be nice to be able to write such objects quickly and easily - not the convoluted mess that it is currently." Simples :) -- Cheers. Mark Lawrence. From rosuav at gmail.com Thu Sep 27 12:49:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Sep 2012 02:49:41 +1000 Subject: Article on the future of Python In-Reply-To: References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> <506461bc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 28, 2012 at 2:45 AM, Mark Lawrence wrote: > The article Steven D'Aprano referred to is not a direct response to the > article I referred to, yet your words are written as if it were. May I ask > why? Or have I missed something? Steven cited it with the words "And a response". ChrisA From jeanpierreda at gmail.com Thu Sep 27 12:50:43 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 27 Sep 2012 12:50:43 -0400 Subject: Article on the future of Python In-Reply-To: References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> <506461bc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 27, 2012 at 12:45 PM, Mark Lawrence wrote: > The article Steven D'Aprano referred to is not a direct response to the > article I referred to, yet your words are written as if it were. May I ask > why? Or have I missed something? Post hoc ergo propter hoc :( -- Devin From ethan at stoneleaf.us Thu Sep 27 12:53:31 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 27 Sep 2012 09:53:31 -0700 Subject: Article on the future of Python In-Reply-To: References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> <506461bc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5064848B.2000509@stoneleaf.us> Mark Lawrence wrote: > On 27/09/2012 17:16, Devin Jeanpierre wrote: >> On Thu, Sep 27, 2012 at 10:25 AM, Steven D'Aprano wrote: >>> On Thu, 27 Sep 2012 08:11:13 -0400, Devin Jeanpierre wrote: >>>> Summary of that article: >>>> >>>> "Sure, you have all these legitimate concerns, but look, cake!" >>> >>> Did you read the article or just make up a witty response? If so, you >>> half succeeded. >>> >>> It's more like, "Well, maybe, your concerns *might* be legitimate, but I >>> don't think so because..." and then he gives half a dozen or more >>> reasons >>> why Python is in no danger. None of which involve cake, although one of >>> them did involve Raspberry Pi. An easy mistake to make. >> >> Haha! :) >> >> Well, I don't agree. But let me explain. >> > > [snipped] > > The article Steven D'Aprano referred to is not a direct response to the > article I referred to, yet your words are written as if it were. May I > ask why? Or have I missed something? The second article didn't reference the first directly, but was aimed at that general type of article. At any rate, Steven wrote as if it were a direct response. ~Ethan~ From breamoreboy at yahoo.co.uk Thu Sep 27 12:58:19 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 27 Sep 2012 17:58:19 +0100 Subject: Article on the future of Python In-Reply-To: References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> <506461bc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27/09/2012 17:49, Chris Angelico wrote: > On Fri, Sep 28, 2012 at 2:45 AM, Mark Lawrence wrote: >> The article Steven D'Aprano referred to is not a direct response to the >> article I referred to, yet your words are written as if it were. May I ask >> why? Or have I missed something? > > Steven cited it with the words "And a response". > > ChrisA > Fair enough, we'll blame Steven on the grounds that he's Antipodean :) -- Cheers. Mark Lawrence. From ramit.prasad at jpmorgan.com Thu Sep 27 12:58:45 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 27 Sep 2012 16:58:45 +0000 Subject: How to limit CPU usage in Python In-Reply-To: <7xpq5d7j5e.fsf@ruckus.brouhaha.com> References: <7xpq5d7j5e.fsf@ruckus.brouhaha.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474166CAA91@SCACMX008.exchad.jpmchase.net> Paul Rubin wrote: > Rolando Ca?er Roblejo writes: > > Is it possible for me to put a limit in the amount of processor usage > > (% CPU) that my current python script is using? Is there any module > > useful for this task? > > One way is check your cpu usage once in a while, compare with elapsed > time, and if your % usage is above what you want, sleep for a suitable > interval before proceeding. > > Tim Roberts: reasons to want to do this might involve a shared host > where excessive cpu usage affects other users; or a computer with > limited power consumption, where prolonged high cpu activity causes > thermal or other problems. The problem is that checking the CPU usage is fairly misleading if you are worried about contention. If your process takes up 100% of CPU and nothing else needs the resource, does it matter? I would not want to sleep *unless* something else needs the resource. Of course, there might be a good/easy way of checking usage + contention, but I am unaware of any off the top of my head. On *nix you should just set the appropriate nice-ness and then let the OS handle CPU scheduling. Not sure what you would do for Windows--I assume OS X is the same as *nix for this context. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Thu Sep 27 13:06:28 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 27 Sep 2012 17:06:28 +0000 Subject: One of my joomla webpages has been hacked. Please help. In-Reply-To: <2c8e16fe-5c02-4288-a364-ca596c46b92e@googlegroups.com> References: <079f4b21-93f4-450b-9112-21b2faa19ed3@googlegroups.com> <505db890$0$29981$c3e8da3$5496439d@news.astraweb.com> <73e59160-13b4-48c0-899f-53fc7517b21a@googlegroups.com> <505e8ada$0$29981$c3e8da3$5496439d@news.astraweb.com> <2c8e16fe-5c02-4288-a364-ca596c46b92e@googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474166CAADB@SCACMX008.exchad.jpmchase.net> ????? G??ee? wrote: > I shouldn't have asked about Joomla here, or even about Python embedding > within Joomla cms. I was under the impression that the latter was relevant to > ask here but it seems it isnt. > > My bad, let's just close this thread so i don't waste anyone's time. Now when/if you get Joomla to run Python code and have a problem with *Python* code/coding, feel free to come back and ask questions on that. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From malaclypse2 at gmail.com Thu Sep 27 13:07:56 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Thu, 27 Sep 2012 13:07:56 -0400 Subject: How to limit CPU usage in Python In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474166CAA91@SCACMX008.exchad.jpmchase.net> References: <7xpq5d7j5e.fsf@ruckus.brouhaha.com> <5B80DD153D7D744689F57F4FB69AF474166CAA91@SCACMX008.exchad.jpmchase.net> Message-ID: On Thu, Sep 27, 2012 at 12:58 PM, Prasad, Ramit wrote: > On *nix you should just set the appropriate nice-ness and then > let the OS handle CPU scheduling. Not sure what you would do > for Windows--I assume OS X is the same as *nix for this context. On windows, you can also set the priority of a process, though it's a little different from the *nix niceness level. See http://code.activestate.com/recipes/496767/ for a recipe using pywin32. I believe the psutil module handles this too, but I don't think it manages to abstract away the platform differences. -- Jerry From ramit.prasad at jpmorgan.com Thu Sep 27 13:09:05 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 27 Sep 2012 17:09:05 +0000 Subject: Redirecting STDOUT to a Python Variable In-Reply-To: <505ebc65$0$6891$e4fe514c@news2.news.xs4all.nl> References: <7e934b64-ec84-48c8-a4bb-a2272f1449a4@u26g2000yqu.googlegroups.com> <4c206409$0$14147$c3e8da3@news.astraweb.com> <8cabc9bb-5ae0-41fa-86b6-0a184192e601@googlegroups.com> <505ebc65$0$6891$e4fe514c@news2.news.xs4all.nl> Message-ID: <5B80DD153D7D744689F57F4FB69AF474166CAAF1@SCACMX008.exchad.jpmchase.net> Hans Mulder wrote: > On 22/09/12 23:57:52, ross.marsden at gmail.com wrote: > > To capture the traceback, so to put it in a log, I use this > > > > import traceback > > > > def get_traceback(): # obtain and return the traceback > > exc_type, exc_value, exc_traceback = sys.exc_info() > > return ''.join(traceback.format_exception(exc_type, exc_value, > exc_traceback)) > > This could be coded more succinctly as > > import sys, traceback > > def get_traceback(): # obtain and return the traceback > return ''.join(traceback.format_exception(*sys.exc_info())) Why not just use? return traceback.format_exc() > > > Suppose I have a script run by the scheduler, this captures the traceback > form any problems and emails them. > > > > if __name__ == '__main__': > > try: > > Runs_unattended() > > except: > > send_mail(send_from = yourEmailAddress, > > send_to = [ yourEmailAddress ], subject = 'Runs_unattended', > > text = '%s' % get_traceback(), > > files = [], server=yourLocalSMTP) > > Errhm, '%s' % get_traceback() is equiavalent to get_traceback() > How about: > > if __name__ == '__main__': > try: > Runs_unattended() > except: > send_mail(send_from = yourEmailAddress, > send_to = [ yourEmailAddress ], > subject = 'Runs_unattended', > text = get_traceback(), > files = [], > server=yourLocalSMTP) > This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From storchaka at gmail.com Thu Sep 27 13:17:31 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 27 Sep 2012 20:17:31 +0300 Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> <50641d6d$0$29997$c3e8da3$5496439d@news.astraweb.com> <50642DE0.8030102@mweb.co.za> Message-ID: On 27.09.12 18:06, Ian Kelly wrote: > I understand ISO 8859-15 (Latin-9) to be the preferred Latin character > set for French, as it includes the Euro sign as well as a few > characters that are not in Latin-1 but are nonetheless infrequently > found in French. Even for Latin-9 Python 3.3 can be a little faster 3.2. $ ./python -m timeit -s "s=bytes(range(256))*100" "s.decode('latin1')" Python 2.7: 105 usec Python 3.2: 20.4 usec Python 3.3: 4.98 usec $ ./python -m timeit -s "s=bytes(range(256))*100" "s.decode('latin9')" Python 2.7: 700 usec Python 3.2: 94.6 usec Python 3.3: 93.2 usec From ramit.prasad at jpmorgan.com Thu Sep 27 13:20:03 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 27 Sep 2012 17:20:03 +0000 Subject: Capitalization for variable that holds a class In-Reply-To: <5efu58paorg84u94l9ca1ibh7901dcjugm@invalid.netcom.com> References: <5efu58paorg84u94l9ca1ibh7901dcjugm@invalid.netcom.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474166CAB5C@SCACMX008.exchad.jpmchase.net> Dennis Lee Bieber wrote: > Sent: Sunday, September 23, 2012 11:53 AM > To: python-list at python.org > Subject: Re: Capitalization for variable that holds a class > > On Sun, 23 Sep 2012 16:48:38 +0100, Joshua Landau > declaimed the following in > gmane.comp.python.general: > > > Simple question: > > > > [myClass() for myClass in myClasses] > > vs > > [MyClass() for MyClass in myClasses] > > > > The recommended naming scheme for Python is that class DEFINITIONS > begin capitalized. Instances, methods/attributes, functions begin > lowercase. > > I abstain from the argument about camel-case vs _ (Ada "pretty > printers" automatically capitalize at _, so _ is common in Ada) > > class MyClass(object): > def myMethod(self): Are you (the OP) using Python 2 or 3? In python 2 list comprehensions leak; if you use MyClass as the list comprehension variable name it will overwrite the MyClass class definition (if it exists). >>> class MyClass(object): ... pass ... >>> print MyClass >>> _ = [ MyClass for MyClass in xrange( 5 ) ] >>> print MyClass 4 Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From jtim.arnold at gmail.com Thu Sep 27 13:30:25 2012 From: jtim.arnold at gmail.com (Tim) Date: Thu, 27 Sep 2012 10:30:25 -0700 (PDT) Subject: web access to configuration database Message-ID: <69720900-008d-4b6c-95fa-b914f9320090@googlegroups.com> I want to make some configuration data available via a web service (bottle) that returns JSON data to a client which may be a python app or a jqgrid-based web page ui. The data structure is a list of dicts with strings, other dicts, and lists. It doesn't fit the relational database scheme; it looks like a nested key-value store. I want to handle get/post for crud operations. Any thoughts as to the best way to store the data? The magic solution would be a json-based database supporting get/post I guess. I've been looking at MongoDB, Redis, CouchDB, and ZODB. (apache thrift?) Currently learning Redis. thanks, --Tim From ramit.prasad at jpmorgan.com Thu Sep 27 13:34:45 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 27 Sep 2012 17:34:45 +0000 Subject: For Counter Variable In-Reply-To: <505F9B59.6040909@tim.thechases.com> References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <505f9311$0$1612$c3e8da3$76491128@news.astraweb.com> <505F9B59.6040909@tim.thechases.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474166CAC0C@SCACMX008.exchad.jpmchase.net> Tim Chase wrote: > [snip] though I'm minorly miffed that > enumerate()'s starting-offset wasn't back-ported into earlier 2.x > versions and have had to code around it for 1-based indexing; either > extra "+1"s or whip up my own simple enumerate() generator). Starting offset is in Python 2.6, unless you meant earlier than 2.6. >>> for idx, x in enumerate( xrange(5), 10 ): ... print idx, x ... 10 0 11 1 12 2 13 3 14 4 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Thu Sep 27 13:53:15 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 27 Sep 2012 17:53:15 +0000 Subject: Fastest web framework In-Reply-To: References: , <1348515720.16099.4.camel@stretch> Message-ID: <5B80DD153D7D744689F57F4FB69AF474166CACC4@SCACMX008.exchad.jpmchase.net> Andriy Kornatskyy wrote: > Try to see 'Hello World' benchmark as an answer to the question how effective > is the framework inside... > > If computer X boots faster than Y, it means it is more effective in this > particular area. > > If a sportsman runs a distance 1 second faster than other, he got a medal (it > is not quite adequate to say if I load?sportsman?with 50 kilo bag he will not > run that fast... just try split the concerns). > > Thanks. > > Andriy > Not really, it depends on what each computer is doing during boot. To switch to the sportsman analogy, if sportsman A has to run 1 mile and along the way pick up 1 lb/kg every .1 mile while sportsman B has to pick up all the weight at the start. It is conceivable that sportsman A runs completes the run in 10 minutes while sportsman B runs the time in 9 minutes. Sportsman A might run the first .1 miles faster (sportsman A "boots" faster, but that is most likely less important than the overall long-term/real-world time to complete the task. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Thu Sep 27 13:58:21 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 27 Sep 2012 17:58:21 +0000 Subject: A little morning puzzle In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF474166CACF4@SCACMX008.exchad.jpmchase.net> Dwight Hutto wrote: > > Ergo: 'enumerate()' is the correct suggestion over manually > > maintaining your own index, despite it ostensibly being "more" code > > due to its implementation. > > But, therefore, that doesn't mean that the coder can just USE a > function, and not be able to design it themselves. So 'correct > suggestion' is a moot point. > Can you rephrase your first sentence? I am not sure what you mean. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From bv8bv8bv8 at gmail.com Thu Sep 27 14:44:03 2012 From: bv8bv8bv8 at gmail.com (BV BV) Date: Thu, 27 Sep 2012 11:44:03 -0700 (PDT) Subject: Did you know that about Islam? Message-ID: <487fa2b1-d8a2-4b00-aff2-cd4a05dba0fa@b19g2000vbt.googlegroups.com> Did you know that about Islam? http://www.youtube.com/v/e5-gmD-jUsc?rel=0 thank you From tyler at tysdomain.com Thu Sep 27 15:05:11 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Thu, 27 Sep 2012 13:05:11 -0600 Subject: teventlet: a light-weight method for handling events Message-ID: <5064A367.9040802@tysdomain.com> Hello all: This was my first PyPi project to create. I'd like some feedback as to whether or not something like this is even moderately useful, and what I could do better with it. The blog article that details some of this is: http://tds-solutions.net/blog/?p=137 And the PyPi page: http://pypi.python.org/pypi/teventlet Essentially, Teventlet is just a handler that allows the registration of multiple callbacks; when something calls invoke, it dispatches all arguments to each individual callback. It's pretty small, and probably something anyone who is reasonably skilled could have written in a few minutes, but I wanted to put it out there anyway. Any ideas, suggestions/etc would be welcome. -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From tjreedy at udel.edu Thu Sep 27 15:08:50 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 27 Sep 2012 15:08:50 -0400 Subject: Article on the future of Python In-Reply-To: <50641d6d$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> <50641d6d$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/27/2012 5:33 AM, Steven D'Aprano wrote: > Nevertheless, I think there is something here. The consequences are nowhere > near as dramatic as jmf claims, but it does seem that replace() has taken a > serious performance hit. Perhaps it is unavoidable, but perhaps not. > > If anyone else can confirm similar results, I already did, about a month ago, for windows. I think the actual problem is with find, not replace (which does a find before the replace). When I asked on pydev, Victor Stinner had no explanation, but said he might look into it eventually. Others thought it not terribly important since 7 times blazingly fast is still fast (in your example, 29 versus 3 microseconds per operation. jmf wrapping a possible real issue with anti-3.3 crud did not help in getting attention to the regression. I also reported results of running stringbench.py on both 3.2 and 3.3 on windows. Overall, Unicode is nearly as fast as bytes and 3.3 as fast as 3.2. Find/replace is the notable exception in stringbench, so it is an anomaly. Other things are faster in 3.3. > I think this should be raised as a performance regression. I agree, and Mark did it. -- Terry Jan Reedy From wxjmfauth at gmail.com Thu Sep 27 15:09:37 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 27 Sep 2012 12:09:37 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> <50641d6d$0$29997$c3e8da3$5496439d@news.astraweb.com> <50642DE0.8030102@mweb.co.za> Message-ID: <051dde5c-5293-4a9a-85c8-aa6714db4f69@googlegroups.com> This flexible string representation is wrong by design. Expecting to divide "Unicode" in chunks and to gain something is an illusion. It has been created by a computer scientist who thinks "bytes" when on that field one has to think "bytes" and usage of the characters at the same time. The latin-1 chunk illustrates this wonderfully. jmf From wxjmfauth at gmail.com Thu Sep 27 15:09:37 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 27 Sep 2012 12:09:37 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> <50641d6d$0$29997$c3e8da3$5496439d@news.astraweb.com> <50642DE0.8030102@mweb.co.za> Message-ID: <051dde5c-5293-4a9a-85c8-aa6714db4f69@googlegroups.com> This flexible string representation is wrong by design. Expecting to divide "Unicode" in chunks and to gain something is an illusion. It has been created by a computer scientist who thinks "bytes" when on that field one has to think "bytes" and usage of the characters at the same time. The latin-1 chunk illustrates this wonderfully. jmf From tjreedy at udel.edu Thu Sep 27 15:32:20 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 27 Sep 2012 15:32:20 -0400 Subject: Article on the future of Python In-Reply-To: References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> <506461bc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/27/2012 12:16 PM, Devin Jeanpierre wrote: > Charitably, maybe we'd call this a way of encouraging people who are > discouraged by the bleaker tone of Calvin's post. And that's valid, if > we're worried about morale. Definitely Calvin's post could be -- and > has been -- taken the wrong way. It could be taken as a way of saying, > "Python is doomed!", even though that isn't something Calvin ever > wrote (he appears, from my reading, to be more worried about a > stagnating community than a failed language). The title was "i-am-worried-about-the-future-of-python" (as in 'I am afraid Python will not have one'), not 'python has problems in some application areas'. Given the doom-y title and the tone of the article, excuse me for thinking doom was the topic. As for community: Calvin is worried that all the hot new people in these particular areas will not use and contribute to Python and the community. > Under that > interpretation, we would want other, more encouraging voices around, > talking about ways in which Python is good and will survive. And that is what the second article was about. It turns out that there are hot new people in other growing areas where Python is growing. Computing for science, megadata, and education are not going away. Being a glue language for numerical computing was Python's first killer application nearly two decades ago, and it still is an important one. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Thu Sep 27 16:16:14 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 27 Sep 2012 21:16:14 +0100 Subject: Article on the future of Python In-Reply-To: <051dde5c-5293-4a9a-85c8-aa6714db4f69@googlegroups.com> References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> <50641d6d$0$29997$c3e8da3$5496439d@news.astraweb.com> <50642DE0.8030102@mweb.co.za> <051dde5c-5293-4a9a-85c8-aa6714db4f69@googlegroups.com> Message-ID: On 27/09/2012 20:09, wxjmfauth at gmail.com wrote: > This flexible string representation is wrong by design. Please state who agrees with this and why. > Expecting to divide "Unicode" in chunks and to gain something > is an illusion. Please provide the benchmarks to support your claim. > It has been created by a computer scientist who thinks "bytes" > when on that field one has to think "bytes" and usage of the > characters at the same time. Please name this computer scientist so everybody knows to whom you are referring. > The latin-1 chunk illustrates this wonderfully. I understand from an earlier post that latin-9 meets your needs completely for all French language characters plus the Euro sign, why don't you simply use that and stop rabitting on about latin-1. > > jmf > Would you please be so kind as to stand up as your voice is rather muffled. -- Cheers. Mark Lawrence. From dihedral88888 at googlemail.com Thu Sep 27 17:24:00 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 27 Sep 2012 14:24:00 -0700 (PDT) Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: References: <7x7grgtq75.fsf@ruckus.brouhaha.com> <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> Message-ID: <19af87b0-1e0e-4931-9d0e-7461303d2304@googlegroups.com> Tim Chase? 2012?9?27????UTC+8??6?44?42???? > On 09/26/12 17:28, 88888 Dihedral wrote: > > > 88888 Dihedral? 2012?9?27????UTC+8??6?07?35???? > > >>>> In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" > > >>>> without this behavior? > > >>> >>> a = [[0]*3 for i in xrange(2)] > > >>> >>> a[0][0]=2 > > >>> >>> a > > >>> [[2, 0, 0], [0, 0, 0]] > > > > > > def zeros(m,n): > > > a=[] > > > for i in xrange(m): > > > a.append([0]*n) > > > return a > > > > > > If one wants to tranlate to C, this is the style. > > > > But this is Python, so why the heck would anybody want to emulate > > *C* style? It could also be written in an assembly-language style, > > COBOL style, or a Fortran style...none of which are particularly > > valuable. > > > > Besides, a C-style would allocate a single array of M*N slots and > > then calculate 2d offsets into that single array. :-P > > > > -tkc a=[1, 2,3] b=[a]*4 print b a[1]=4 print b I thnik this is very clear about the situation in entangled references. From dihedral88888 at googlemail.com Thu Sep 27 17:24:00 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 27 Sep 2012 14:24:00 -0700 (PDT) Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: References: <7x7grgtq75.fsf@ruckus.brouhaha.com> <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> Message-ID: <19af87b0-1e0e-4931-9d0e-7461303d2304@googlegroups.com> Tim Chase? 2012?9?27????UTC+8??6?44?42???? > On 09/26/12 17:28, 88888 Dihedral wrote: > > > 88888 Dihedral? 2012?9?27????UTC+8??6?07?35???? > > >>>> In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" > > >>>> without this behavior? > > >>> >>> a = [[0]*3 for i in xrange(2)] > > >>> >>> a[0][0]=2 > > >>> >>> a > > >>> [[2, 0, 0], [0, 0, 0]] > > > > > > def zeros(m,n): > > > a=[] > > > for i in xrange(m): > > > a.append([0]*n) > > > return a > > > > > > If one wants to tranlate to C, this is the style. > > > > But this is Python, so why the heck would anybody want to emulate > > *C* style? It could also be written in an assembly-language style, > > COBOL style, or a Fortran style...none of which are particularly > > valuable. > > > > Besides, a C-style would allocate a single array of M*N slots and > > then calculate 2d offsets into that single array. :-P > > > > -tkc a=[1, 2,3] b=[a]*4 print b a[1]=4 print b I thnik this is very clear about the situation in entangled references. From rsnrm1 at gmail.com Thu Sep 27 17:28:43 2012 From: rsnrm1 at gmail.com (ForeverYoung) Date: Thu, 27 Sep 2012 14:28:43 -0700 (PDT) Subject: test Message-ID: <8ad96ff3-7d17-42b2-b2fe-e14e54d1d816@googlegroups.com> Please ignore this post. I am testing to see if I can post successfully. From jeanpierreda at gmail.com Thu Sep 27 17:36:57 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 27 Sep 2012 17:36:57 -0400 Subject: test In-Reply-To: <8ad96ff3-7d17-42b2-b2fe-e14e54d1d816@googlegroups.com> References: <8ad96ff3-7d17-42b2-b2fe-e14e54d1d816@googlegroups.com> Message-ID: On Thu, Sep 27, 2012 at 5:28 PM, ForeverYoung wrote: > Please ignore this post. > I am testing to see if I can post successfully. Is there a reason you can't wait until you have something to say / ask to see if it works? You're spamming a large number of inboxes with nothing. -- Devin From gelonida at gmail.com Thu Sep 27 17:43:45 2012 From: gelonida at gmail.com (Gelonida N) Date: Thu, 27 Sep 2012 23:43:45 +0200 Subject: templating performance In-Reply-To: References: Message-ID: On 09/27/2012 02:17 AM, alex23 wrote: > On Sep 27, 7:50 am, Gelonida N wrote: >> http://mindref.blogspot.fr/2012/07/python-fastest-template.html > > This is already being discussed on the list. See the thread "Fastest > template engine". Apologies everybody, I wanted to 'bookkmark' (forward this article to myself) and posted it accidentally once more to this group. (Can happen if not paying attention with Thunderbird :-( ) From joshua.landau.ws at gmail.com Thu Sep 27 17:53:13 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Thu, 27 Sep 2012 22:53:13 +0100 Subject: Capitalization for variable that holds a class In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474166CAB5C@SCACMX008.exchad.jpmchase.net> References: <5efu58paorg84u94l9ca1ibh7901dcjugm@invalid.netcom.com> <5B80DD153D7D744689F57F4FB69AF474166CAB5C@SCACMX008.exchad.jpmchase.net> Message-ID: On 27 September 2012 18:20, Prasad, Ramit wrote: > Dennis Lee Bieber wrote: > > Sent: Sunday, September 23, 2012 11:53 AM > > To: python-list at python.org > > Subject: Re: Capitalization for variable that holds a class > > > > On Sun, 23 Sep 2012 16:48:38 +0100, Joshua Landau > > declaimed the following in > > gmane.comp.python.general: > > > > > Simple question: > > > > > > [myClass() for myClass in myClasses] > > > vs > > > [MyClass() for MyClass in myClasses] > > > > > > > The recommended naming scheme for Python is that class DEFINITIONS > > begin capitalized. Instances, methods/attributes, functions begin > > lowercase. > > > > I abstain from the argument about camel-case vs _ (Ada "pretty > > printers" automatically capitalize at _, so _ is common in Ada) > > > > class MyClass(object): > > def myMethod(self): > > Are you (the OP) using Python 2 or 3? In python 2 list > comprehensions leak; if you use MyClass as the list > comprehension variable name it will overwrite the > MyClass class definition (if it exists). > > >>> class MyClass(object): > ... pass > ... > >>> print MyClass > > >>> _ = [ MyClass for MyClass in xrange( 5 ) ] > >>> print MyClass > 4 > Don't worry, not only am I using Python 3 but I would be certain to use GenericUnusedClassName anyway ;) -------------- next part -------------- An HTML attachment was scrubbed... URL: From skunkworks at rikishi42.net Thu Sep 27 17:57:00 2012 From: skunkworks at rikishi42.net (Rikishi42) Date: Thu, 27 Sep 2012 23:57:00 +0200 Subject: Reducing cache/buffer for faster display Message-ID: I have these 2 scripts that are very heavy on the file i/o, consume a very reasonable amount of cpu and output their counters at a - very - relaxed pace to the console. The output is very simply done using something like: print "files:", nFiles, "\r", Yet alltough there is no real reason for it, even a pace of a print every 10-30 secs will be cached, only to actually show an output update every 1-2 min or so. When I run the scripts with "python -u myscript.py", the output is complete, very speedy and without any kind of impact on the actual work being one. Can this option be called from within the script? Or is there another option to make the display "a bit" speedier ? Runnning Python 2.7.3, but it seems to me I've allready had this problem a long, long time ago with other releases. -- When in doubt, use brute force. -- Ken Thompson From skunkworks at rikishi42.net Thu Sep 27 17:58:52 2012 From: skunkworks at rikishi42.net (Rikishi42) Date: Thu, 27 Sep 2012 23:58:52 +0200 Subject: test References: <8ad96ff3-7d17-42b2-b2fe-e14e54d1d816@googlegroups.com> Message-ID: On 2012-09-27, Devin Jeanpierre wrote: > On Thu, Sep 27, 2012 at 5:28 PM, ForeverYoung wrote: >> Please ignore this post. >> I am testing to see if I can post successfully. > > Is there a reason you can't wait until you have something to say / ask > to see if it works? You're spamming a large number of inboxes with > nothing. Inboxes? What is this, usenet or email ? -- When in doubt, use brute force. -- Ken Thompson From rosuav at gmail.com Thu Sep 27 18:00:16 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Sep 2012 08:00:16 +1000 Subject: Article on the future of Python In-Reply-To: <051dde5c-5293-4a9a-85c8-aa6714db4f69@googlegroups.com> References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> <50641d6d$0$29997$c3e8da3$5496439d@news.astraweb.com> <50642DE0.8030102@mweb.co.za> <051dde5c-5293-4a9a-85c8-aa6714db4f69@googlegroups.com> Message-ID: You're posting to both comp.lang.python and python-list, are you aware that that's redundant? On Fri, Sep 28, 2012 at 5:09 AM, wrote: > This flexible string representation is wrong by design. > Expecting to divide "Unicode" in chunks and to gain something > is an illusion. > It has been created by a computer scientist who thinks "bytes" > when on that field one has to think "bytes" and usage of the > characters at the same time. There's another range of numbers that, in some languages, is divided for efficiency's sake: Integers below 1<<[bit size]. In Python 2, such numbers were an entirely different data type (int vs long); other languages let you use the same data type for both, but "(1<<5)+1" will be executed much faster than "(1<<500)+1". (And far as I know, a conforming Python 3 implementation should be allowed to do that; 3.2 on Windows doesn't seem to, though.) That's all PEP 393 is; it's a performance improvement for a particular subset of values that happens to fit conveniently into the underlying machine's data storage. If Python were implemented on a 9-bit computer, I wouldn't be surprised if the PEP 393 optimizations were applied differently. It's nothing to do with Latin-1, except insofar as the narrowest form of string _happens_ to contain everything that's in Latin-1. Go blame the Unicode consortium for picking that. > The latin-1 chunk illustrates this wonderfully. Aside from replace(), as mentioned in this thread, are there any other ways that this is so wonderfully illustrated? Or is it "wonderfully" as in "I wonder if people will believe me if I keep spouting unsubstantiated claims"? ChrisA From tyler at tysdomain.com Thu Sep 27 18:09:29 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Thu, 27 Sep 2012 16:09:29 -0600 Subject: test In-Reply-To: References: <8ad96ff3-7d17-42b2-b2fe-e14e54d1d816@googlegroups.com> Message-ID: <5064CE99.8090202@tysdomain.com> On 9/27/2012 3:36 PM, Devin Jeanpierre wrote: > On Thu, Sep 27, 2012 at 5:28 PM, ForeverYoung wrote: >> Please ignore this post. >> I am testing to see if I can post successfully. > Is there a reason you can't wait until you have something to say / ask > to see if it works? You're spamming a large number of inboxes with > nothing. I'm kind of thinking complaints about it are just doubling the spam to a large number of inboxes. You could've just doubled the spam in the OP's inbox and that would've been that. -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From rosuav at gmail.com Thu Sep 27 18:09:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Sep 2012 08:09:59 +1000 Subject: Reducing cache/buffer for faster display In-Reply-To: References: Message-ID: On Fri, Sep 28, 2012 at 7:57 AM, Rikishi42 wrote: > I have these 2 scripts that are very heavy on the file i/o, consume a very > reasonable amount of cpu and output their counters at a - very - relaxed > pace to the console. The output is very simply done using something like: > > print "files:", nFiles, "\r", > > > Yet alltough there is no real reason for it, even a pace of a print every > 10-30 secs will be cached, only to actually show an output update every 1-2 > min or so. Yup! Just add a call to sys.stdout.flush() after each print. ChrisA From gordon at panix.com Thu Sep 27 18:25:39 2012 From: gordon at panix.com (John Gordon) Date: Thu, 27 Sep 2012 22:25:39 +0000 (UTC) Subject: Reducing cache/buffer for faster display References: Message-ID: In Chris Angelico writes: > On Fri, Sep 28, 2012 at 7:57 AM, Rikishi42 wrote: > > I have these 2 scripts that are very heavy on the file i/o, consume a very > > reasonable amount of cpu and output their counters at a - very - relaxed > > pace to the console. The output is very simply done using something like: > > > > print "files:", nFiles, "\r", > > > > > > Yet alltough there is no real reason for it, even a pace of a print every > > 10-30 secs will be cached, only to actually show an output update every 1-2 > > min or so. > Yup! Just add a call to sys.stdout.flush() after each print. Isn't terminal output line-buffered? I don't understand why there would be an output delay. (Unless the "\r" is messing things up...) -- 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 rosuav at gmail.com Thu Sep 27 18:38:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Sep 2012 08:38:29 +1000 Subject: Reducing cache/buffer for faster display In-Reply-To: References: Message-ID: On Fri, Sep 28, 2012 at 8:25 AM, John Gordon wrote: > Isn't terminal output line-buffered? I don't understand why there would > be an output delay. (Unless the "\r" is messing things up...) This is a classic progress-indication case, which does indeed mess up line-buffering. The carriage return (and no line feed, done in the Python 2 style of a trailing comma) puts the cursor back to the beginning of the line, ready to overwrite, and ripe for one of those old favorite incomplete overwrite errors - if nFiles monotonically increases, it's fine, but if it decreases, the display can get ugly. ChrisA From emile at fenx.com Thu Sep 27 19:14:59 2012 From: emile at fenx.com (Emile van Sebille) Date: Thu, 27 Sep 2012 16:14:59 -0700 Subject: test In-Reply-To: References: <8ad96ff3-7d17-42b2-b2fe-e14e54d1d816@googlegroups.com> Message-ID: On 9/27/2012 2:58 PM Rikishi42 said... > > Inboxes? > > What is this, usenet or email ? > Yes. Both. Emile From vasudevram at gmail.com Thu Sep 27 19:51:27 2012 From: vasudevram at gmail.com (vasudevram) Date: Thu, 27 Sep 2012 16:51:27 -0700 (PDT) Subject: Using PipeController (v0.2) to run a pipe incrementally Message-ID: <31a45c61-7b4f-4180-b948-c076bf633d00@googlegroups.com> I've released v0.2 of PipeController, my experimental tool to simulate pipes in Python. It can be downloaded here: http://dancingbison.com/pipe_controller-v0.2.zip Changes in v0.2: - module name changed to avoid clashes with pipes module in the standard Python library; the module is now called pipe_controller.py instead of pipes.py; - you can now pass input and output filename arguments on the command in your program that calls PipeController, instead of having to use I/O redirection; - you can now import class PipeController from the module, with: from pipe_controller import PipeController - you can now run a PipeController pipe incrementally, i.e., run the pipe in a loop, adding a pipe component (a Python function) in each iteration, and it can save the intermediate outputs resulting from each iteration, to separate output files; the program test_pipe_controller_03.py in the download package shows how to do this. This feature can be useful to debug your pipe's logic, and also to save the intermediate computation results in case they are of use in their own right. Blog post about using PipeController v0.2 to run a pipe incrementally: http://jugad2.blogspot.in/2012/09/using-pipecontroller-to-run-pipe.html - Vasudev Ram www.dancingbison.com jugad2.blogspot.com twitter.com/vasudevram From steve+comp.lang.python at pearwood.info Thu Sep 27 20:05:03 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Sep 2012 00:05:03 GMT Subject: test References: <8ad96ff3-7d17-42b2-b2fe-e14e54d1d816@googlegroups.com> Message-ID: <5064e9af$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 27 Sep 2012 17:36:57 -0400, Devin Jeanpierre wrote: > On Thu, Sep 27, 2012 at 5:28 PM, ForeverYoung wrote: >> Please ignore this post. >> I am testing to see if I can post successfully. > > Is there a reason you can't wait until you have something to say / ask > to see if it works? You're spamming a large number of inboxes with > nothing. It is perfectly legitimate to send a test message to Usenet to check that you can post. But it's not really appropriate to send it *here* unless you think that you have a specific problem with this newsgroup, comp.lang.python. Otherwise you should send test posts to dedicated testing newsgroups like alabama.test, alt.binaries.test or be.test. -- Steven From skunkworks at rikishi42.net Thu Sep 27 20:05:58 2012 From: skunkworks at rikishi42.net (Rikishi42) Date: Fri, 28 Sep 2012 02:05:58 +0200 Subject: Reducing cache/buffer for faster display References: Message-ID: <686fj9-aql.ln1@murmur.very.softly> On 2012-09-27, Chris Angelico wrote: > On Fri, Sep 28, 2012 at 8:25 AM, John Gordon wrote: >> Isn't terminal output line-buffered? I don't understand why there would >> be an output delay. (Unless the "\r" is messing things up...) > > This is a classic progress-indication case, which does indeed mess up > line-buffering. The carriage return (and no line feed, done in the > Python 2 style of a trailing comma) puts the cursor back to the > beginning of the line, ready to overwrite, and ripe for one of those > old favorite incomplete overwrite errors - if nFiles monotonically > increases, it's fine, but if it decreases, the display can get ugly. True, but that wasn't the problem here. The updates where. Thanks for the given answer, I'll try it. The scripts in question only increase numbers. But should that not be the case, solutions are simple enough. The numbers can be formatted to have a fixed size. In the case of random line contents (a list of filesnames, say) it's enough to create an output function that is aware of the length of the previously printed line, and add enough spaces to the current one to wipe exess content. Thanks again for the suggestion. -- When in doubt, use brute force. -- Ken Thompson From skunkworks at rikishi42.net Thu Sep 27 20:15:25 2012 From: skunkworks at rikishi42.net (Rikishi42) Date: Fri, 28 Sep 2012 02:15:25 +0200 Subject: Reducing cache/buffer for faster display References: Message-ID: On 2012-09-27, Chris Angelico wrote: > On Fri, Sep 28, 2012 at 7:57 AM, Rikishi42 wrote: >> I have these 2 scripts that are very heavy on the file i/o, consume a very >> reasonable amount of cpu and output their counters at a - very - relaxed >> pace to the console. The output is very simply done using something like: >> >> print "files:", nFiles, "\r", >> >> >> Yet alltough there is no real reason for it, even a pace of a print every >> 10-30 secs will be cached, only to actually show an output update every 1-2 >> min or so. > > Yup! Just add a call to sys.stdout.flush() after each print. Update: tried it, ran it, I love it. Thanks ! -- When in doubt, use brute force. -- Ken Thompson From wuwei23 at gmail.com Thu Sep 27 20:59:20 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 27 Sep 2012 17:59:20 -0700 (PDT) Subject: Article on the future of Python References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sep 28, 2:47?am, Mark Lawrence wrote: > "... why does the runtime environment have to be so limiting? Operations > involving primitives could be easily compiled (on the fly - JIT) to > machine code and more advanced objects exist as plug-ins. Oh, and it > would be nice to be able to write such objects quickly and easily - not > the convoluted mess that it is currently." > > Simples :) You should see how awesome _my_ imaginary implementation is! From wuwei23 at gmail.com Thu Sep 27 20:59:39 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 27 Sep 2012 17:59:39 -0700 (PDT) Subject: Article on the future of Python References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> <506461bc$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0ac0d6c8-3fda-4b4c-afd6-01cc36019aaa@lo4g2000pbb.googlegroups.com> On Sep 28, 2:17?am, Devin Jeanpierre wrote: > Uncharitably, it's just a way of hiding one's head in the sand, > ignoring any problems Python has by focusing on what problems it > doesn't have. But isn't that what counterpoint is all about? Calvin's article highlighted what he felt were areas that Python isn't successful, while Tim McNamara's pointed out areas it was. Just because Python isn't used much in commercial video games doesn't undermine the point that it's heavily used in education and research. Does Python _have_ to be a go-to tool in gaming for it to not be on its death march? Or more to the point: rather than just complain about it... It's not like there aren't active communities that _are_ working in this area: PyGame, pyglet, Kivy are all projects that can be contributed to. I love using Python and will endeavour to do so wherever I can, but it's always going to be the case that a language has strengths & weaknesses that other languages lack. From walterhurry at lavabit.com Thu Sep 27 21:22:44 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Fri, 28 Sep 2012 01:22:44 +0000 (UTC) Subject: Article on the future of Python References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 28 Sep 2012 00:32:58 +1000, Chris Angelico wrote: > On Thu, Sep 27, 2012 at 11:59 PM, Grant Edwards > wrote: >> On 2012-09-27, Chris Angelico wrote: >>> On Thu, Sep 27, 2012 at 4:01 PM, Steven D'Aprano >>> wrote: >>> >>>> Given how Perl has slipped in the last decade or so, that would be a >>>> step backwards for Python :-P >>> >>> LAMP usually means PHP these days. There's a lot of that around. >> >> Yea, unfortunately. What a mess of a language. I recently had to >> learn enough PHP to make some changes to a web site we had done by an >> outside contractor. PHP feels like it was designed by taking a >> half-dozen other languages, chopping them into bits and then pulling >> random features/syntax/semantics at random from the various different >> piles. Those bits where then stuck together with duct tape and bubble >> gum and called PHP... >> >> As one of the contractors who wrote some of the PHP said: "PHP is like >> the worst parts of shell, Perl, and Java all combined into one >> language!" > > I can't remember where I read it, and I definitely don't know if it's > accurate to current thinking, but the other day I found a quote > purporting to be from the creator of PHP saying that he didn't care > about memory leaks, just restart Apache periodically. It's definitely > true of most PHP scripts that they're unconcerned about resource > leakage, on the assumption that everything'll get cleared out at the end > of a page render. PHP seems to encourage sloppiness. Fair enough, but it's the M in the LAMP stack I object to. I'd much rather have P. From jason at powerpull.net Thu Sep 27 23:05:25 2012 From: jason at powerpull.net (Jason Friedman) Date: Thu, 27 Sep 2012 21:05:25 -0600 Subject: Article on the future of Python In-Reply-To: References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Fair enough, but it's the M in the LAMP stack I object to. I'd much > rather have P. +1 From tyler at tysdomain.com Thu Sep 27 23:14:00 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Thu, 27 Sep 2012 21:14:00 -0600 Subject: Article on the future of Python In-Reply-To: References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <506515F8.9020606@tysdomain.com> On 9/27/2012 9:05 PM, Jason Friedman wrote: >> Fair enough, but it's the M in the LAMP stack I object to. I'd much >> rather have P. > +1 I know this isn't the list for database discussions, but I've never gotten a decent answer. I don't know much about either, so I'm kind of curious why postgresql over mysql? -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From wayne at waynewerner.com Thu Sep 27 23:37:36 2012 From: wayne at waynewerner.com (Wayne Werner) Date: Thu, 27 Sep 2012 22:37:36 -0500 (CDT) Subject: Article on the future of Python In-Reply-To: <506515F8.9020606@tysdomain.com> References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> <506515F8.9020606@tysdomain.com> Message-ID: > On 9/27/2012 9:05 PM, Jason Friedman wrote: >>> Fair enough, but it's the M in the LAMP stack I object to. I'd much >>> rather have P. >> +1 > > > I know this isn't the list for database discussions, but I've never gotten a > decent answer. I don't know much about either, so I'm kind of curious why > postgresql over mysql? I'll try not to get too OT... I had previously just used MySQL (and SQLite), but have been reaading some PostGres stuff lately. I took a look around and basically... you and I won't know or notice a difference probably ever. There's all sorts of crazy tweaks you can get for reliability, speed, and backups depending on what you use. So the only advice I can give on that is just learn to use both. And even better yet, just use SQLAlchemy if you're ever touching a database from Python because it handles all the mucky SQL for you - you just define the ORM. (Hey look! A Python module!) My $0.02 -Wayne From dwightdhutto at gmail.com Thu Sep 27 23:39:32 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Thu, 27 Sep 2012 23:39:32 -0400 Subject: Stop feeding the trolls In-Reply-To: <7wehlodv01.fsf@benfinney.id.au> References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> <20120925095327.aa0d222bad8678f6c0339fbf@druid.net> <66323e0b-228b-44c1-96e3-eecb7cc3cd84@n7g2000pbj.googlegroups.com> <7wehlodv01.fsf@benfinney.id.au> Message-ID: It's past > time to stop feeding this troll, please. You mean like the post above you sent....bitch please, I'm eatin good right now. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Thu Sep 27 23:47:56 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Thu, 27 Sep 2012 23:47:56 -0400 Subject: Stop feeding the trolls (Was: which a is used?) In-Reply-To: <66323e0b-228b-44c1-96e3-eecb7cc3cd84@n7g2000pbj.googlegroups.com> References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> <20120925095327.aa0d222bad8678f6c0339fbf@druid.net> <66323e0b-228b-44c1-96e3-eecb7cc3cd84@n7g2000pbj.googlegroups.com> Message-ID: On Wed, Sep 26, 2012 at 8:40 PM, alex23 wrote: > On Sep 26, 5:06 pm, Dwight Hutto wrote: >> You can "Plonk" my dick bitches. > > You do understand that when you have so many people react badly to how > you phrase things, that the problem most likely lies with you and not > them? Depends on the demographic. That the only person who actually reacts favourably to this > garbage coming from you is *you*? Yeah...I'm egotistical. > > There is no place for racist or sexist speech here. \ There never was any from me Reply personally > to whomever you want with whatever invective you choose, that's your > right (just as it is their right to flag your emails as spam, as I > have). Yeah, hit the mute button if you don't like me. That's a brilliant fucking idea...buddy. But this is a place for public discussion and, again, we do not > need you driving away people who might actually contribute positively > simply because you're unable or unwilling to always do so. Uhm, I do post appropriately, unless you're trolling the board, with a few other avatars, and buddies in order to stomp a flame war someone else started...IMHO. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From gdonald at gmail.com Thu Sep 27 23:50:19 2012 From: gdonald at gmail.com (Greg Donald) Date: Thu, 27 Sep 2012 22:50:19 -0500 Subject: Article on the future of Python In-Reply-To: <506515F8.9020606@tysdomain.com> References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> <506515F8.9020606@tysdomain.com> Message-ID: On Thu, Sep 27, 2012 at 10:14 PM, Littlefield, Tyler wrote: > I know this isn't the list for database discussions, but I've never gotten a > decent answer. I don't know much about either, so I'm kind of curious why > postgresql over mysql? MySQL is an open-source PRODUCT owned by a for-profit company. PostgreSQL is an open-source PROJECT and is unowned. A lot of the major technical differences are outlined here: http://www.wikivs.com/wiki/MySQL_vs_PostgreSQL -- Greg Donald From gdonald at gmail.com Fri Sep 28 00:12:27 2012 From: gdonald at gmail.com (Greg Donald) Date: Thu, 27 Sep 2012 23:12:27 -0500 Subject: Article on the future of Python In-Reply-To: References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> <506515F8.9020606@tysdomain.com> Message-ID: On Thu, Sep 27, 2012 at 10:37 PM, Wayne Werner wrote: > the only advice I can give on that is > just learn to use both. I find there's little to lose in having experience with both. Most every good web framework out there supports lots of different databases through generic ORM layers.. so flipping back and forth to see which database is better for your particular app and workload is trivial. -- Greg Donald From rosuav at gmail.com Fri Sep 28 00:37:21 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Sep 2012 14:37:21 +1000 Subject: Article on the future of Python In-Reply-To: References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> <506515F8.9020606@tysdomain.com> Message-ID: On Fri, Sep 28, 2012 at 2:12 PM, Greg Donald wrote: > On Thu, Sep 27, 2012 at 10:37 PM, Wayne Werner wrote: >> the only advice I can give on that is >> just learn to use both. > > I find there's little to lose in having experience with both. > > Most every good web framework out there supports lots of different > databases through generic ORM layers.. so flipping back and forth to > see which database is better for your particular app and workload is > trivial. Learning both is good, if for no reason than that learning more tends to be advantageous. As Greg said in his other post, PGSQL is a completely open source project. That's a significant point imho. Other points to consider: * MySQL is designed for dynamic web sites, with lots of reading and not too much writing. Its row and table locking system is pretty rudimentary, and it's quite easy for performance to suffer really badly if you don't think about it. But if your needs are simple, MySQL is probably enough. PostgreSQL uses MVCC to avoid locks in many cases. You can happily read from a row while it's being updated; you'll be unaware of the update until it's committed. * Postgres has solid support for advanced features like replication. I don't know how good MySQL's replication is, never tried it. Can't say. This might be completely insignificant. * The default MySQL engine, MyISAM, doesn't do proper transaction logging etc. InnoDB is better for this, but the internal tables (where your database *structure* is maintained) are MyISAM. This imposes a definite risk. * Both engines have good support in popular languages, including (dragging this back on topic, kicking and screaming) Python. For further details, poke around on the web; I'm sure you'll find plenty of good blog posts etc. But as for me and my house, we will have Postgres serve us. ChrisA From rosuav at gmail.com Fri Sep 28 00:40:34 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Sep 2012 14:40:34 +1000 Subject: Stop feeding the trolls (Was: which a is used?) In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> <20120925095327.aa0d222bad8678f6c0339fbf@druid.net> <66323e0b-228b-44c1-96e3-eecb7cc3cd84@n7g2000pbj.googlegroups.com> Message-ID: On Fri, Sep 28, 2012 at 1:47 PM, Dwight Hutto wrote: > [ lots of screed that demonstrates that Dwight hasn't grokked the hacker culture ] Dwight, have a read of these documents. They may help you to understand how the python-list community operates, and perhaps more so, why most of the regulars here think the way they do. Actually, this may be of interest to quite a few people, so I'll post it on-list. http://catb.org/~esr/faqs/ ChrisA From ryclbac9rh at gmail.com Fri Sep 28 00:42:31 2012 From: ryclbac9rh at gmail.com (ryclbac9rh at gmail.com) Date: Thu, 27 Sep 2012 21:42:31 -0700 (PDT) Subject: iPhone App To Help You Learn Spanish Faster By Using Flashcards With Pictures Message-ID: <2cd93413-db34-421f-b60a-cc9efa2f2e7f@googlegroups.com> http://goo.gl/CRhLz - "Spanish Flashcards with Pictures" is an iPhone app that will help you learn Spanish faster by using flashcards with pictures (learn over 300 most commonly used words in the English / Spanish language from A to Z), thanks. From dwightdhutto at gmail.com Fri Sep 28 00:50:50 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 28 Sep 2012 00:50:50 -0400 Subject: Stop feeding the trolls (Was: which a is used?) In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> <20120925095327.aa0d222bad8678f6c0339fbf@druid.net> <66323e0b-228b-44c1-96e3-eecb7cc3cd84@n7g2000pbj.googlegroups.com> Message-ID: On Fri, Sep 28, 2012 at 12:40 AM, Chris Angelico wrote: > On Fri, Sep 28, 2012 at 1:47 PM, Dwight Hutto wrote: >> [ lots of screed that demonstrates that Dwight hasn't grokked the hacker culture ] Don't hack, but could very well if necessary. > > Dwight, have a read of these documents. They may help you to > understand how the python-list community operates, and perhaps more > so, why most of the regulars here think the way they do. They have double digit I.Q.'s ? Actually, > this may be of interest to quite a few people, so I'll post it > on-list. Go right ahead....buddy. > > http://catb.org/~esr/faqs/ > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From tyler at tysdomain.com Fri Sep 28 01:12:54 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Thu, 27 Sep 2012 23:12:54 -0600 Subject: Stop feeding the trolls (Was: which a is used?) In-Reply-To: References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> <20120925095327.aa0d222bad8678f6c0339fbf@druid.net> <66323e0b-228b-44c1-96e3-eecb7cc3cd84@n7g2000pbj.googlegroups.com> Message-ID: <506531D6.9000108@tysdomain.com> On 9/27/2012 10:50 PM, Dwight Hutto wrote: > On Fri, Sep 28, 2012 at 12:40 AM, Chris Angelico wrote: >> On Fri, Sep 28, 2012 at 1:47 PM, Dwight Hutto wrote: >>> [ lots of screed that demonstrates that Dwight hasn't grokked the hacker culture ] > Don't hack, but could very well if necessary. You couldn't hack your self out of a wet paper bag, and you're fooling noone. Sorry... buddy. You should go away now; You asked who is laughing at you the other day, and at that point you had the ability to salvage (or at least attempt to salvage) your reputation with a few people. You've pretty much blown that away at this point, so a belated answer to your question is everyone. >> Dwight, have a read of these documents. They may help you to >> understand how the python-list community operates, and perhaps more >> so, why most of the regulars here think the way they do. > They have double digit I.Q.'s ? > > Actually, >> this may be of interest to quite a few people, so I'll post it >> on-list. > Go right ahead....buddy. > >> http://catb.org/~esr/faqs/ >> >> ChrisA >> -- >> http://mail.python.org/mailman/listinfo/python-list > > -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From tyler at tysdomain.com Fri Sep 28 01:20:24 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Thu, 27 Sep 2012 23:20:24 -0600 Subject: Article on the future of Python In-Reply-To: References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> <506515F8.9020606@tysdomain.com> Message-ID: <50653398.9070507@tysdomain.com> On 9/27/2012 10:37 PM, Chris Angelico wrote: > On Fri, Sep 28, 2012 at 2:12 PM, Greg Donald wrote: >> On Thu, Sep 27, 2012 at 10:37 PM, Wayne Werner wrote: >>> the only advice I can give on that is >>> just learn to use both. >> I find there's little to lose in having experience with both. >> >> Most every good web framework out there supports lots of different >> databases through generic ORM layers.. so flipping back and forth to >> see which database is better for your particular app and workload is >> trivial. I plan to do that, just so I have both. I've had the experience of mysql, so I guess postgresql is up next. I was just really curious why so many people prefered it. Perhaps off topic (actually really off topic), but if I were to dump my tables from mysql out into flat-files, does postgresql use the same basic structure? IIRC there's a sql98 standard or something like that. Learning both is good, if for no reason than that learning more tends to be advantageous. As Greg said in his other post, PGSQL is a completely open source project. That's a significant point imho. Other points to consider: * MySQL is designed for dynamic web sites, with lots of reading and not too much writing. Its row and table locking system is pretty rudimentary, and it's quite easy for performance to suffer really badly if you don't think about it. But if your needs are simple, MySQL is probably enough. PostgreSQL uses MVCC to avoid locks in many cases. You can happily read from a row while it's being updated; you'll be unaware of the update until it's committed. * Postgres has solid support for advanced features like replication. I don't know how good MySQL's replication is, never tried it. Can't say. This might be completely insignificant. * The default MySQL engine, MyISAM, doesn't do proper transaction logging etc. InnoDB is better for this, but the internal tables (where your database *structure* is maintained) are MyISAM. This imposes a definite risk. You've lost me here; there are two different engines. From what I got from your post, innoDB just essentially wraps MyIsam with some pretty (or apparently not so pretty) locking stuff to help with transactions? * Both engines have good support in popular languages, including (dragging this back on topic, kicking and screaming) Python. For further details, poke around on the web; I'm sure you'll find plenty of good blog posts etc. But as for me and my house, we will have Postgres serve us. Will do, thanks for all the feedback (both on and off list). I'm not a huge database person; I've never really played around with much of it since there's a lot more to understand and I can't just mess with it like any other language, so I was unaware of a lot, and still am in terms of performance. I've obviously seen a ton of blog posts talking about the differences, but they tend to dive into the inner mechanics, something which I don't understand all that well. PS: Someone mentioned my messages were not indented properly; is this still the case? Apparently thunderbird allows ctrl+right bracket to outdent, so I assume my messages should be the outer ones with others being indented farther. ChrisA -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Fri Sep 28 01:21:19 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 28 Sep 2012 01:21:19 -0400 Subject: Stop feeding the trolls (Was: which a is used?) In-Reply-To: <506531D6.9000108@tysdomain.com> References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <648f62d6-6f07-432c-b742-876cedfce950@wm7g2000pbc.googlegroups.com> <20120925095327.aa0d222bad8678f6c0339fbf@druid.net> <66323e0b-228b-44c1-96e3-eecb7cc3cd84@n7g2000pbj.googlegroups.com> <506531D6.9000108@tysdomain.com> Message-ID: On Fri, Sep 28, 2012 at 1:12 AM, Littlefield, Tyler wrote: > On 9/27/2012 10:50 PM, Dwight Hutto wrote: >> >> On Fri, Sep 28, 2012 at 12:40 AM, Chris Angelico wrote: >>> >>> On Fri, Sep 28, 2012 at 1:47 PM, Dwight Hutto >>> wrote: >>>> >>>> [ lots of screed that demonstrates that Dwight hasn't grokked the hacker >>>> culture ] >> >> Don't hack, but could very well if necessary. > > > You couldn't hack your self out of a wet paper bag, and you're fooling > noone. Yeah I could. Sorry... buddy. You should go away now; So you can dominate with a lame ass attempt to approach my responses with a manipulative tactic to discredit me, including such hits as racism, and sexism? You asked who is laughing at > you the other day, and at that point you had the ability to salvage (or at > least attempt to salvage) your reputation with a few people. Nobody, they're laughing at your failed attempt to discredit me in a on thread response in which I was a respondent. Please don't disguise your foolishnish with lies. You've pretty > much blown that away at this point, so a belated answer to your question is > everyone. You mean I went to sleep, woke up and responded? Nice attempt, but you can set a random seed of mine up your ass. > > >>> Dwight, have a read of these documents. They may help you to >>> understand how the python-list community operates, and perhaps more >>> so, why most of the regulars here think the way they do. >> >> They have double digit I.Q.'s ? >> >> Actually, >>> >>> this may be of interest to quite a few people, so I'll post it >>> on-list. >> >> Go right ahead....buddy. >> >>> http://catb.org/~esr/faqs/ >>> >>> ChrisA >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >> >> >> > > > -- > Take care, > Ty > http://tds-solutions.net > The aspen project: a barebones light-weight mud engine: > http://code.google.com/p/aspenmud > He that will not reason is a bigot; he that cannot reason is a fool; he that > dares not reason is a slave. > -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From alec.taylor6 at gmail.com Fri Sep 28 01:41:32 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 28 Sep 2012 15:41:32 +1000 Subject: REST code-golf: How concisely can you expose and consume services? Message-ID: web2py (7 lines): https://gist.github.com/3798093 Includes creation of models, validator, controllers and urls. Rules: - Must have [at least] the same functionality as my 7-line example - Imports are allowed and not taken into line count, on the condition that everything remains generic. I.e.: one can change model and controller names &etc without modifying imported libraries - Can't import/take the code from web2py (e.g.: https://github.com/web2py/web2py/blob/master/gluon/tools.py#L4098) (feel free to write them in reply to this email and/or as gist comments =]) Good luck! From gairehari at gmail.com Fri Sep 28 01:51:11 2012 From: gairehari at gmail.com (gairehari at gmail.com) Date: Thu, 27 Sep 2012 22:51:11 -0700 (PDT) Subject: py2exe deal with python command line inside a program In-Reply-To: <8de9116a-0b09-4919-aec2-a9c41e37e177@y12g2000yqh.googlegroups.com> References: <16c80c55-f06d-4682-9e7d-594471561f46@b10g2000yqa.googlegroups.com> <8de9116a-0b09-4919-aec2-a9c41e37e177@y12g2000yqh.googlegroups.com> Message-ID: <8dbf4df9-8d8c-46be-b265-4ab2d5055a19@googlegroups.com> Hi, have you been able to solve this problem ?? From rustompmody at gmail.com Fri Sep 28 01:51:57 2012 From: rustompmody at gmail.com (rusi) Date: Thu, 27 Sep 2012 22:51:57 -0700 (PDT) Subject: Stop feeding the trolls (Was: which a is used?) References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <20120925095327.aa0d222bad8678f6c0339fbf@druid.net> <66323e0b-228b-44c1-96e3-eecb7cc3cd84@n7g2000pbj.googlegroups.com> <506531D6.9000108@tysdomain.com> Message-ID: <5b7694f7-474c-41dd-8de3-7ad1b6a96210@s9g2000pbh.googlegroups.com> On Sep 28, 10:21?am, Dwight Hutto wrote: > On Fri, Sep 28, 2012 at 1:12 AM, Littlefield, Tyler wrote: > > On 9/27/2012 10:50 PM, Dwight Hutto wrote: > > >> On Fri, Sep 28, 2012 at 12:40 AM, Chris Angelico wrote: > > >>> On Fri, Sep 28, 2012 at 1:47 PM, Dwight Hutto > >>> wrote: > > >>>> [ lots of screed that demonstrates that Dwight hasn't grokked the hacker > >>>> culture ] > > >> Don't hack, but could very well if necessary. > > > You couldn't hack your self out of a wet paper bag, and you're fooling > > noone. > > Yeah I could. > > ?Sorry... buddy. You should go away now; > > So you can dominate with a lame ass attempt to approach my responses > with a manipulative tactic to discredit me, including such hits as > racism, and sexism? > > You asked who is laughing at > > > you the other day, and at that point you had the ability to salvage (or at > > least attempt to salvage) your reputation with a few people. > > Nobody, they're laughing at your failed attempt to discredit me in a > on thread response in which I was a respondent. > > Please don't disguise your foolishnish with lies. > > ?You've pretty > > > much blown that away at this point, so a belated answer to your question is > > everyone. > > You mean I went to sleep, woke up and responded? Nice attempt, but you > can set a random seed of mine up your ass. > > > > > > > > > > > > >>> Dwight, have a read of these documents. They may help you to > >>> understand how the python-list community operates, and perhaps more > >>> so, why most of the regulars here think the way they do. > > >> They have double digit I.Q.'s ? > > >> Actually, > > >>> this may be of interest to quite a few people, so I'll post it > >>> on-list. > > >> Go right ahead....buddy. > > >>>http://catb.org/~esr/faqs/ > > >>> ChrisA > >>> -- > >>>http://mail.python.org/mailman/listinfo/python-list > > > -- > > Take care, > > Ty > >http://tds-solutions.net > > The aspen project: a barebones light-weight mud engine: > >http://code.google.com/p/aspenmud > > He that will not reason is a bigot; he that cannot reason is a fool; he that > > dares not reason is a slave. Some facts that are well-known enough but somehow seem relevant to this discussion. Technology is called a great enabler -- A little less gushingly its a great multiplier. When we look a little impartially at it we see that as technology increases in scope/power the corresponding human involvement gets more and more passive. Coming to the specific technology-stack -- mailing-lists atop the internet -- we see the following: When I hit the send button Ive no idea who will read what I send. Likewise what I end up reading may not be something I specifically wish to read. Specifically, Ive no idea what is the size of the python-list readership -- surely in hundreds, more likely thousands. So when I feel like making a response to one or two people which has more heat than (python-related) light, it would help to consider the thousand(s) who will read it who are not involved/interested in the fracas. A more physical analogy: Lets say I am driving along happily on the freeway and someone does something to me that generates severe justifiable road-rage. So I stop the car, get down and do my schtick -- shout, shoot, mow-him-down, whatever -- and in the process create a jam of a hundred vehicles all around. However justifiable my rage, I would be lucky to get anyone's support! A more personal point. I find that anger is usually a thin cover for depression. And depression inversely correlates with amount of sunshine I see. So before hitting the send button, it may be a good idea to sleep over and see if the rising sun changes my mood. Coming to threads like this one: We've seen an old member of this list scolded for stretching the drinking jokes a bit too far. And another old member who posted a youtube link which had nothing to do with python even though the subject said 'OT' So? Staying withing python-related discussions and using courteous language is the general rule for all. If you follow that you should be ok From dwightdhutto at gmail.com Fri Sep 28 02:20:11 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 28 Sep 2012 02:20:11 -0400 Subject: Stop feeding the trolls (Was: which a is used?) In-Reply-To: <5b7694f7-474c-41dd-8de3-7ad1b6a96210@s9g2000pbh.googlegroups.com> References: <95e88ca6-36ad-4820-8ecc-c9a788517430@googlegroups.com> <20120925095327.aa0d222bad8678f6c0339fbf@druid.net> <66323e0b-228b-44c1-96e3-eecb7cc3cd84@n7g2000pbj.googlegroups.com> <506531D6.9000108@tysdomain.com> <5b7694f7-474c-41dd-8de3-7ad1b6a96210@s9g2000pbh.googlegroups.com> Message-ID: On Fri, Sep 28, 2012 at 1:51 AM, rusi wrote: > On Sep 28, 10:21 am, Dwight Hutto wrote: >> On Fri, Sep 28, 2012 at 1:12 AM, Littlefield, Tyler wrote: >> > On 9/27/2012 10:50 PM, Dwight Hutto wrote: >> >> >> On Fri, Sep 28, 2012 at 12:40 AM, Chris Angelico wrote: >> >> >>> On Fri, Sep 28, 2012 at 1:47 PM, Dwight Hutto >> >>> wrote: >> >> >>>> [ lots of screed that demonstrates that Dwight hasn't grokked the hacker >> >>>> culture ] >> >> >> Don't hack, but could very well if necessary. >> >> > You couldn't hack your self out of a wet paper bag, and you're fooling >> > noone. >> >> Yeah I could. >> >> Sorry... buddy. You should go away now; >> >> So you can dominate with a lame ass attempt to approach my responses >> with a manipulative tactic to discredit me, including such hits as >> racism, and sexism? >> >> You asked who is laughing at >> >> > you the other day, and at that point you had the ability to salvage (or at >> > least attempt to salvage) your reputation with a few people. >> >> Nobody, they're laughing at your failed attempt to discredit me in a >> on thread response in which I was a respondent. >> >> Please don't disguise your foolishnish with lies. >> >> You've pretty >> >> > much blown that away at this point, so a belated answer to your question is >> > everyone. >> >> You mean I went to sleep, woke up and responded? Nice attempt, but you >> can set a random seed of mine up your ass. >> >> >> >> >> >> >> >> >> >> >> >> >>> Dwight, have a read of these documents. They may help you to >> >>> understand how the python-list community operates, and perhaps more >> >>> so, why most of the regulars here think the way they do. >> >> >> They have double digit I.Q.'s ? >> >> >> Actually, >> >> >>> this may be of interest to quite a few people, so I'll post it >> >>> on-list. >> >> >> Go right ahead....buddy. >> >> >>>http://catb.org/~esr/faqs/ >> >> >>> ChrisA >> >>> -- >> >>>http://mail.python.org/mailman/listinfo/python-list >> >> > -- >> > Take care, >> > Ty >> >http://tds-solutions.net >> > The aspen project: a barebones light-weight mud engine: >> >http://code.google.com/p/aspenmud >> > He that will not reason is a bigot; he that cannot reason is a fool; he that >> > dares not reason is a slave. > > Some facts that are well-known enough but somehow seem relevant to > this discussion. > Technology is called a great enabler -- A little less gushingly its a > great multiplier. > When we look a little impartially at it we see that as technology > increases in scope/power the corresponding human involvement gets more > and more passive. > But technology should be engaged by many different view points, in order to insure that the output of technology is within the, not only the grasp of outsiders, but the scope of those who wish to debate it's usage in many different areas in order to have stability of the society(societies) that produce the output. > Coming to the specific technology-stack -- mailing-lists atop the > internet -- we see the following: > When I hit the send button Ive no idea who will read what I send. > Likewise what I end up reading may not be something I specifically > wish to read. That's common on mailing lists, and the discussions they maintain, as well as the usage membership. > > Specifically, Ive no idea what is the size of the python-list > readership -- surely in hundreds, more likely thousands. > Then it's part of, but the only side of, your public persona. > So when I feel like making a response to one or two people which has > more heat than (python-related) light, it would help to consider the > thousand(s) who will read it who are not involved/interested in the > fracas. Don't be a little bitch, and respond. Instead you're whining about it. > > A more physical analogy: Lets say I am driving along happily on the > freeway and someone does something to me that generates severe > justifiable road-rage. So I stop the car, get down and do my schtick > -- shout, shoot, mow-him-down, whatever -- and in the process create a > jam of a hundred vehicles all around. However justifiable my rage, I > would be lucky to get anyone's support! It's called information overload, and temporary insanity...go ask a lawyer list. > > A more personal point. I find that anger is usually a thin cover for > depression. A medical condition which can be cause by many different factors, and all legal. And depression inversely correlates with amount of > sunshine I see. This is more seasonal depression, and human biological adjustment to circadian rhythm in nature that appears in several areas. So before hitting the send button, it may be a good > idea to sleep over and see if the rising sun changes my mood. It always does, it's biological in nature for this to happen. > > Coming to threads like this one: > We've seen an old member of this list scolded for stretching the > drinking jokes a bit too far. Probably me, and you have no idea what I'm not saying when if not drinking I have severe nerve damage...that would probably blow your own little itty bitty mind, so deal with average intelligence on your own. > And another old member who posted a youtube link which had nothing to > do with python even though the subject said 'OT' > > So? Staying withing python-related discussions and using courteous > language is the general rule for all. If you follow that you should be > ok Open mindedness is what the internet is about, if you can't be free with emotions and internal vectors of molecular thought freedom, then you might want ot move out of the way of the New World Order. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From bob.martin at excite.com Fri Sep 28 08:06:13 2012 From: bob.martin at excite.com (Bob Martin) Date: Fri, 28 Sep 2012 08:06:13 BST Subject: Article on the future of Python References: Message-ID: in 681910 20120927 131113 Devin Jeanpierre wrote: >On Thu, Sep 27, 2012 at 2:13 AM, Steven D'Aprano > wrote: >> On Tue, 25 Sep 2012 09:15:00 +0100, Mark Lawrence wrote: >> And a response: >> >> http://data.geek.nz/python-is-doing-just-fine > >Summary of that article: > >"Sure, you have all these legitimate concerns, but look, cake!" Quote : "This piece argues that Python is an easy-to-learn language that where you can be almost immediately productive in." From dwightdhutto at gmail.com Fri Sep 28 03:22:48 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Fri, 28 Sep 2012 03:22:48 -0400 Subject: Article on the future of Python In-Reply-To: References: Message-ID: >>Summary of that article: >> >>"Sure, you have all these legitimate concerns, but look, cake!" > > Quote : "This piece argues that Python is an easy-to-learn > language that where you can be almost immediately productive in." It is, but so is every other language. "hello world" is the standard... follow the syntax, import/include the appropriate library functions, and create your own to use them. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From rosuav at gmail.com Fri Sep 28 03:39:08 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Sep 2012 17:39:08 +1000 Subject: REST code-golf: How concisely can you expose and consume services? In-Reply-To: References: Message-ID: On Fri, Sep 28, 2012 at 3:41 PM, Alec Taylor wrote: > web2py (7 lines): https://gist.github.com/3798093 I love the idea, even though I shan't be entering. Code golf is awesome fun! My latest golf game involved importing code comments and text-file annotations into autodoc markup... with two one-liners. And it only needed two because I did it in two parts (wasn't even aware of the text file until I'd done the code comments). Of course, a real RESTful API is likely to have rather more guts in it, but it's cool how little you need of structure! ChrisA From ye.youqun at eisoo.com Fri Sep 28 03:45:58 2012 From: ye.youqun at eisoo.com (=?UTF-8?B?5Y+25L2R576k?=) Date: Fri, 28 Sep 2012 15:45:58 +0800 Subject: how to run shell command like "< Hi, all, I have the shell command like this: sfdisk -uM /dev/sdb << EOT ,1000,83 ,,83 EOT I have tried subprocess.Popen, pexpect.spawn and os.popen, but none of these works, but when I type this shell command in shell, it is works fine. I wonder how to emulate this type of behavior in python , and if someone can figure out the reason why? The sample code of subprocess.Popen is: command = ["sfdisk", "-uM", target, "< From rosuav at gmail.com Fri Sep 28 04:08:58 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Sep 2012 18:08:58 +1000 Subject: Reducing cache/buffer for faster display In-Reply-To: <686fj9-aql.ln1@murmur.very.softly> References: <686fj9-aql.ln1@murmur.very.softly> Message-ID: On Fri, Sep 28, 2012 at 10:05 AM, Rikishi42 wrote: > The scripts in question only increase numbers. But should that not be the > case, solutions are simple enough. The numbers can be formatted to have a > fixed size. In the case of random line contents (a list of filesnames, say) > it's enough to create an output function that is aware of the length of the > previously printed line, and add enough spaces to the current one to wipe > exess content. Yep, that's a pretty effective way to do it. One simple method to it is to format the whole string as a single whole, then left justify it in a field of (say) 79 characters, and output that: msg = "Progress: %d%% (%d/%d)... %s" % (done*100/total, done, total, current_file) print msg.ljust(79)+"\r", sys.stdout.flush() ChrisA From kushal.kumaran+python at gmail.com Fri Sep 28 04:16:10 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Fri, 28 Sep 2012 13:46:10 +0530 Subject: how to run shell command like "< References: <506555B6.5040406@eisoo.com> Message-ID: On Fri, Sep 28, 2012 at 1:15 PM, ??? wrote: > Hi, all, > > I have the shell command like this: > > sfdisk -uM /dev/sdb << EOT > ,1000,83 > ,,83 > EOT > > > I have tried subprocess.Popen, pexpect.spawn and os.popen, but none of > these works, but when I type this shell command in shell, it is works fine. > I wonder how to emulate this type of behavior in python , and if someone can > figure out the reason why? > > The sample code of subprocess.Popen is: > > command = ["sfdisk", "-uM", target, "< ",", 1000, ",", "83", "\r\n", > ",", ",", "83", "\r\n", "EOT", "\r\n"] > > pobj = subprocess.Popen (command, bufsize=1, \ > stderr=subprocess.PIPE, stdout=subprocess.PIPE) > > res = pobj.stderr.readline () > if res is not None and pobj.returncode != 0: > observer.ShowProgress (u"??? %s ?????" % target) > return False > The "< and pexpect code is: > > child = pexpect.spawn ("sfdisk -uM /dev/sdb < child.sendline (....) > child.sendline (....) > child.sendline (....) > > and os.popen like this: > > os.popen ("sfdisk -uM /dev/sdb < > I tried "\r\n", and it doesn't work either. > -- regards, kushal From breamoreboy at yahoo.co.uk Fri Sep 28 05:16:15 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 28 Sep 2012 10:16:15 +0100 Subject: Article on the future of Python In-Reply-To: References: <5062ad83$0$29997$c3e8da3$5496439d@news.astraweb.com> <693ac61b-b1d3-4192-9e50-5166fd119278@googlegroups.com> <447851a9-bc63-4711-a4e6-bff565e28f1f@googlegroups.com> <2b2d20f5-2807-4a61-b284-8075e900db22@googlegroups.com> <50641d6d$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27/09/2012 20:08, Terry Reedy wrote: > On 9/27/2012 5:33 AM, Steven D'Aprano wrote: > >> Nevertheless, I think there is something here. The consequences are >> nowhere >> near as dramatic as jmf claims, but it does seem that replace() has >> taken a >> serious performance hit. Perhaps it is unavoidable, but perhaps not. >> >> If anyone else can confirm similar results, > > I already did, about a month ago, for windows. I think the actual > problem is with find, not replace (which does a find before the > replace). When I asked on pydev, Victor Stinner had no explanation, but > said he might look into it eventually. Others thought it not terribly > important since 7 times blazingly fast is still fast (in your example, > 29 versus 3 microseconds per operation. > > jmf wrapping a possible real issue with anti-3.3 crud did not help in > getting attention to the regression. > > I also reported results of running stringbench.py on both 3.2 and 3.3 on > windows. Overall, Unicode is nearly as fast as bytes and 3.3 as fast as > 3.2. Find/replace is the notable exception in stringbench, so it is an > anomaly. Other things are faster in 3.3. > >> I think this should be raised as a performance regression. > > I agree, and Mark did it. > http://bugs.python.org/issue16061 and you should read it. I've tried to really muddy the waters by opening this issue, and the python devs are giving out facts, how dare they!!! It's just not my day is it? :( -- Cheers. Mark Lawrence. From nospam at nospam.com Fri Sep 28 06:32:49 2012 From: nospam at nospam.com (Gilles) Date: Fri, 28 Sep 2012 12:32:49 +0200 Subject: "#!/usr/bin/env python" vs. "#!/usr/bin/python"? Message-ID: <34va6856ocuas7jpueujscf3kdt7k44mfl@4ax.com> Hello I've seen both shebang lines to run a Python script on a *nix host: #!/usr/bin/env python #!/usr/bin/python What's the difference? Thank you. From sahnov.m at gmail.com Fri Sep 28 06:39:55 2012 From: sahnov.m at gmail.com (=?KOI8-R?B?88HIzs/XIO3JyMHJzA==?=) Date: Fri, 28 Sep 2012 14:39:55 +0400 Subject: "#!/usr/bin/env python" vs. "#!/usr/bin/python"? In-Reply-To: <34va6856ocuas7jpueujscf3kdt7k44mfl@4ax.com> References: <34va6856ocuas7jpueujscf3kdt7k44mfl@4ax.com> Message-ID: When you use frst one, you'll get the system-wide default interpreter. When you use second one, you'll get concrete interpreter (or error, if path to interpreter is invalid) 2012/9/28 Gilles > Hello > > I've seen both shebang lines to run a Python script on a *nix host: > > #!/usr/bin/env python > #!/usr/bin/python > > What's the difference? > > Thank you. > -- > http://mail.python.org/mailman/listinfo/python-list > -- ? ?????????, ?????? ??????. -- ICQ:#7499099 JID:soider at jabber.ru -------------- next part -------------- An HTML attachment was scrubbed... URL: From jpiitula at ling.helsinki.fi Fri Sep 28 06:49:07 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 28 Sep 2012 13:49:07 +0300 Subject: "#!/usr/bin/env python" vs. "#!/usr/bin/python"? References: <34va6856ocuas7jpueujscf3kdt7k44mfl@4ax.com> Message-ID: Gilles writes: > #!/usr/bin/env python > #!/usr/bin/python > > What's the difference? Not much if your python is /usr/bin/python: env looks for python and finds the same executable. When python is not /usr/bin/python but something else that is still found by your system, /usr/bin/env still finds it. For example, in a server where I work, python3 is installed as something like /opt/python/3.2.2-gcc/bin/python3. There is no /usr/bin/python3 at all, but "#! /usr/bin/env python3" works. From roy at panix.com Fri Sep 28 06:57:28 2012 From: roy at panix.com (Roy Smith) Date: Fri, 28 Sep 2012 06:57:28 -0400 Subject: "#!/usr/bin/env python" vs. "#!/usr/bin/python"? References: <34va6856ocuas7jpueujscf3kdt7k44mfl@4ax.com> Message-ID: In article <34va6856ocuas7jpueujscf3kdt7k44mfl at 4ax.com>, Gilles wrote: > Hello > > I've seen both shebang lines to run a Python script on a *nix host: > > #!/usr/bin/env python > #!/usr/bin/python > > What's the difference? The first one looks through your PATH to find the right python interpreter to run. The second one is hard-wired to run /usr/bin/python. If you only have a single copy of python installed, it doesn't really matter which you use. But, you might as well get into the habit of using the /usr/bin/env flavor because it's more flexible. I'm working on a number of different python projects. For each one, I set up a new virtual environment using virtualenv. This lets me run different versions of python in different projects, with different collections of installed packages (and possibly different versions). I can only do this because I use the /usr/bin/env line in all my scripts. From nospam at nospam.com Fri Sep 28 07:34:48 2012 From: nospam at nospam.com (Gilles) Date: Fri, 28 Sep 2012 13:34:48 +0200 Subject: "#!/usr/bin/env python" vs. "#!/usr/bin/python"? References: <34va6856ocuas7jpueujscf3kdt7k44mfl@4ax.com> Message-ID: On Fri, 28 Sep 2012 06:57:28 -0400, Roy Smith wrote: >The first one looks through your PATH to find the right python >interpreter to run. The second one is hard-wired to run /usr/bin/python. > >If you only have a single copy of python installed, it doesn't really >matter which you use. But, you might as well get into the habit of >using the /usr/bin/env flavor because it's more flexible. Thanks guys. I suspected that's what the difference was. From nospam at nospam.com Fri Sep 28 07:37:36 2012 From: nospam at nospam.com (Gilles) Date: Fri, 28 Sep 2012 13:37:36 +0200 Subject: How to investigate web script not running? Message-ID: Hello I'm trying to run my very first FastCGI script on an Apache shared host that relies on mod_fcgid: ============== #!/usr/bin/python from fcgi import WSGIServer import cgitb # enable debugging cgitb.enable() def myapp(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return ['Hello World!\n'] WSGIServer(myapp).run() ============== After following a tutorial, Apache complains with the following when I call my script: ============== Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. ============== Generally speaking, what tools are available to investigate issues when running a Python web app? Thank you. From jayden.shui at gmail.com Fri Sep 28 07:57:13 2012 From: jayden.shui at gmail.com (Jayden) Date: Fri, 28 Sep 2012 04:57:13 -0700 (PDT) Subject: Python source code easy to hack? Message-ID: <0023d73b-00f6-4d82-b68b-eb28f4587ab1@googlegroups.com> Dear All, I have a concern in developing commercial code with Python. Someone told me that its program can be easily hacked to get its source code. Is it really the case? Any way to protect your source code? Thanks a lot! Jayden From rustompmody at gmail.com Fri Sep 28 08:08:24 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 28 Sep 2012 05:08:24 -0700 (PDT) Subject: Article on the future of Python References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sep 27, 5:11?pm, Devin Jeanpierre wrote: > On Thu, Sep 27, 2012 at 2:13 AM, Steven D'Aprano > > wrote: > > On Tue, 25 Sep 2012 09:15:00 +0100, Mark Lawrence wrote: > > And a response: > > >http://data.geek.nz/python-is-doing-just-fine > > Summary of that article: > > "Sure, you have all these legitimate concerns, but look, cake!" > > -- Devin My summary of the first (worried about python) article: Python is about to miss the Bell's law bus: http://en.wikipedia.org/wiki/Bell%27s_Law_of_Computer_Classes From nospam at nospam.com Fri Sep 28 08:13:51 2012 From: nospam at nospam.com (Gilles) Date: Fri, 28 Sep 2012 14:13:51 +0200 Subject: How to investigate web script not running? References: Message-ID: On Fri, 28 Sep 2012 13:37:36 +0200, Gilles wrote: >============== >Internal Server Error > >The server encountered an internal error or misconfiguration and was >unable to complete your request. >============== Looks like fcgi.py doesn't support WSGI: Traceback (most recent call last): File "hello.fcgi", line 2, in ? from fcgi import WSGIServer ImportError: cannot import name WSGIServer From gmx at ross.cx Fri Sep 28 08:16:22 2012 From: gmx at ross.cx (Michael Ross) Date: Fri, 28 Sep 2012 14:16:22 +0200 Subject: How to investigate web script not running? In-Reply-To: References: Message-ID: On Fri, 28 Sep 2012 13:37:36 +0200, Gilles wrote: > Hello > > I'm trying to run my very first FastCGI script on an Apache shared > host that relies on mod_fcgid: > ============== > #!/usr/bin/python > from fcgi import WSGIServer > import cgitb > > # enable debugging > cgitb.enable() > > def myapp(environ, start_response): > start_response('200 OK', [('Content-Type', 'text/plain')]) > return ['Hello World!\n'] > > WSGIServer(myapp).run() > ============== > > After following a tutorial, Apache complains with the following when I > call my script: > ============== > Internal Server Error > > The server encountered an internal error or misconfiguration and was > unable to complete your request. > ============== Do it the other way around: # cgitb before anything else import cgitb cgitb.enable() # so this error will be caught from fcgi import WSGIServer Regards, Michael From breamoreboy at yahoo.co.uk Fri Sep 28 08:17:26 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 28 Sep 2012 13:17:26 +0100 Subject: Python source code easy to hack? In-Reply-To: <0023d73b-00f6-4d82-b68b-eb28f4587ab1@googlegroups.com> References: <0023d73b-00f6-4d82-b68b-eb28f4587ab1@googlegroups.com> Message-ID: On 28/09/2012 12:57, Jayden wrote: > Dear All, > > I have a concern in developing commercial code with Python. Someone told me that its program can be easily hacked to get its source code. Is it really the case? Any way to protect your source code? > > Thanks a lot! > > Jayden > This question has been asked on numerous occasions so if you search the archives you're sure to get loads of answers. -- Cheers. Mark Lawrence. From zig-zag at yahoo.com Fri Sep 28 08:30:32 2012 From: zig-zag at yahoo.com (zig-zag) Date: Fri, 28 Sep 2012 14:30:32 +0200 Subject: Python source code easy to hack? In-Reply-To: References: <0023d73b-00f6-4d82-b68b-eb28f4587ab1@googlegroups.com> Message-ID: On 09/28/2012 02:17 PM, Mark Lawrence wrote: > On 28/09/2012 12:57, Jayden wrote: >> Dear All, >> >> I have a concern in developing commercial code with Python. Someone >> told me that its program can be easily hacked to get its source code. >> Is it really the case? Any way to protect your source code? >> >> Thanks a lot! >> >> Jayden >> > > This question has been asked on numerous occasions so if you search the > archives you're sure to get loads of answers. > http://stackoverflow.com/questions/261638/how-do-i-protect-python-code http://stackoverflow.com/questions/164137/how-do-i-deploy-a-python-desktop-application From miki.tebeka at gmail.com Fri Sep 28 08:54:06 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 28 Sep 2012 05:54:06 -0700 (PDT) Subject: py2exe deal with python command line inside a program In-Reply-To: References: Message-ID: > sys.executable was printed out as ''C:\\Python25\\python.exe'', how > can I make this work in executable package through py2exe? Does http://www.py2exe.org/index.cgi/WhereAmI help? From steve+comp.lang.python at pearwood.info Fri Sep 28 08:54:55 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Sep 2012 12:54:55 GMT Subject: Article on the future of Python References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50659e1f$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 28 Sep 2012 05:08:24 -0700, rusi wrote: > On Sep 27, 5:11?pm, Devin Jeanpierre wrote: >> On Thu, Sep 27, 2012 at 2:13 AM, Steven D'Aprano >> >> wrote: >> > On Tue, 25 Sep 2012 09:15:00 +0100, Mark Lawrence wrote: And a >> > response: >> >> >http://data.geek.nz/python-is-doing-just-fine >> >> Summary of that article: >> >> "Sure, you have all these legitimate concerns, but look, cake!" >> >> -- Devin > > My summary of the first (worried about python) article: Python is about > to miss the Bell's law bus: > > http://en.wikipedia.org/wiki/Bell%27s_Law_of_Computer_Classes Except that very concept is stupid. Mainframes have not be replaced. There are more mainframes around today than fifty years ago. Minicomputers too, only we don't call them minicomputers, we call them "servers". In ten years time, there will be more desktop PCs around than now. Most of them will be in the 90% of the world that isn't America. And most of them will be laptops. But they'll be used as desktops too. Not everybody wants to read email on a device smaller than your hand, clumsily poking at a tiny virtual keyboard. And anybody who thinks that Python can't run on tablets or smartphones hasn't been paying attention. -- Steven From chenwei.address at gmail.com Fri Sep 28 09:12:35 2012 From: chenwei.address at gmail.com (=?UTF-8?B?6ZmI5Lyf?=) Date: Fri, 28 Sep 2012 06:12:35 -0700 (PDT) Subject: what is the difference between st_ctime and st_mtime one is the time of last change and the other is the time of last modification, but i can not understand what is the difference between 'change' and 'modification'. Message-ID: From rustompmody at gmail.com Fri Sep 28 09:14:32 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 28 Sep 2012 06:14:32 -0700 (PDT) Subject: Article on the future of Python References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> <50659e1f$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sep 28, 5:54?pm, Steven D'Aprano wrote: > On Fri, 28 Sep 2012 05:08:24 -0700, rusi wrote: > > On Sep 27, 5:11?pm, Devin Jeanpierre wrote: > >> On Thu, Sep 27, 2012 at 2:13 AM, Steven D'Aprano > > >> wrote: > >> > On Tue, 25 Sep 2012 09:15:00 +0100, Mark Lawrence wrote: And a > >> > response: > > >> >http://data.geek.nz/python-is-doing-just-fine > > >> Summary of that article: > > >> "Sure, you have all these legitimate concerns, but look, cake!" > > >> -- Devin > > > My summary of the first (worried about python) article: Python is about > > to miss the Bell's law bus: > > >http://en.wikipedia.org/wiki/Bell%27s_Law_of_Computer_Classes > > Except that very concept is stupid. Mainframes have not be replaced. > There are more mainframes around today than fifty years ago. > Minicomputers too, only we don't call them minicomputers, we call them > "servers". > > In ten years time, there will be more desktop PCs around than now. Most > of them will be in the 90% of the world that isn't America. And most of > them will be laptops. But they'll be used as desktops too. Not everybody > wants to read email on a device smaller than your hand, clumsily poking > at a tiny virtual keyboard. > > And anybody who thinks that Python can't run on tablets or smartphones > hasn't been paying attention. > > -- > Steven It would be good to pay attention before calling others to pay attention. http://litmus.com/blog/email-client-market-share-stats-infographic-june-2012/email-client-market-share-june-2012 From nospam at nospam.com Fri Sep 28 09:15:40 2012 From: nospam at nospam.com (Gilles) Date: Fri, 28 Sep 2012 15:15:40 +0200 Subject: How to investigate web script not running? References: Message-ID: <8h7b68lk4lakmgijhqeo918e01gh7pg7d2@4ax.com> On Fri, 28 Sep 2012 14:16:22 +0200, "Michael Ross" wrote: >Do it the other way around: > ># cgitb before anything else >import cgitb >cgitb.enable() > ># so this error will be caught > from fcgi import WSGIServer Thanks much for the tip. The error isn't displayed when calling the script from a web browser but it is when running the script on a shell account. It looks like that newer version of fcgi.py doesn't include support for WSGI, and I need some extra (Flup?) software to sit between mod_fcgid and a WSGI Python application. Definitely not plug 'n play :-/ From darcy at druid.net Fri Sep 28 09:19:54 2012 From: darcy at druid.net (D'Arcy Cain) Date: Fri, 28 Sep 2012 09:19:54 -0400 Subject: "#!/usr/bin/env python" vs. "#!/usr/bin/python"? In-Reply-To: References: <34va6856ocuas7jpueujscf3kdt7k44mfl@4ax.com> Message-ID: <20120928091954.d0d883f3cb6d993ac793d543@druid.net> On Fri, 28 Sep 2012 06:57:28 -0400 Roy Smith wrote: > > I've seen both shebang lines to run a Python script on a *nix host: > > > > #!/usr/bin/env python > > #!/usr/bin/python > > > > What's the difference? > > The first one looks through your PATH to find the right python > interpreter to run. The second one is hard-wired to run /usr/bin/python. > > If you only have a single copy of python installed, it doesn't really > matter which you use. But, you might as well get into the habit of > using the /usr/bin/env flavor because it's more flexible. Not just flexible but portable. On various systems I have Python in /usr/bin, /usr/local/bin and /usr/pkg/bin. "#!/usr/bin/env python" finds it in each case so I only need one version of the script. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From nospam at nospam.com Fri Sep 28 09:22:16 2012 From: nospam at nospam.com (Gilles) Date: Fri, 28 Sep 2012 15:22:16 +0200 Subject: "#!/usr/bin/env python" vs. "#!/usr/bin/python"? References: <34va6856ocuas7jpueujscf3kdt7k44mfl@4ax.com> Message-ID: <049b685demsr20e29qn3v2b0hpjmsv9rdh@4ax.com> On Fri, 28 Sep 2012 09:19:54 -0400, D'Arcy Cain wrote: >Not just flexible but portable. On various systems I have Python >in /usr/bin, /usr/local/bin and /usr/pkg/bin. "#!/usr/bin/env python" >finds it in each case so I only need one version of the script. Good to know. From demianbrecht at gmail.com Fri Sep 28 09:58:43 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Fri, 28 Sep 2012 06:58:43 -0700 Subject: "#!/usr/bin/env python" vs. "#!/usr/bin/python"? In-Reply-To: <20120928091954.d0d883f3cb6d993ac793d543@druid.net> References: <34va6856ocuas7jpueujscf3kdt7k44mfl@4ax.com> <20120928091954.d0d883f3cb6d993ac793d543@druid.net> Message-ID: <5065AD13.70108@gmail.com> On 12-09-28 06:19 AM, D'Arcy Cain wrote: > Not just flexible but portable. On various systems I have Python > in /usr/bin, /usr/local/bin and /usr/pkg/bin. "#!/usr/bin/env python" > finds it in each case so I only need one version of the script. > +1. This also resolves correctly on Cygwin, even if Python is installed via Windows installers (as long as it's on system PATH). Tremendously useful if you're bouncing between *nix and Windows regularly. -- Demian Brecht @demianbrecht http://demianbrecht.github.com From demianbrecht at gmail.com Fri Sep 28 10:17:15 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Fri, 28 Sep 2012 07:17:15 -0700 Subject: REST code-golf: How concisely can you expose and consume services? In-Reply-To: References: Message-ID: <5065B16B.5030405@gmail.com> (A little OT so my apologies up front) On 12-09-28 12:39 AM, Chris Angelico wrote: > I love the idea, even though I shan't be entering. Code golf is awesome fun! Code golf is indeed awesome fun and I usually enjoy taking part as well. However, I'm not a fan of code golf such as this, that uses a framework and then defines a rule that you *can't* hack on the same framework. In the framework/external module spirit, I *could* write a module that does *all* of this for me (in Pyramid, Django, web2py, etc) and then enter with a simple method call in another module. Done. One liner. I win ;) I much prefer code golf that tests algorithmic/core language feature knowledge. Of course, that's entirely only my opinion. -- Demian Brecht @demianbrecht http://demianbrecht.github.com From sturla at molden.no Fri Sep 28 10:18:36 2012 From: sturla at molden.no (sturla at molden.no) Date: Fri, 28 Sep 2012 07:18:36 -0700 (PDT) Subject: Python source code easy to hack? In-Reply-To: <0023d73b-00f6-4d82-b68b-eb28f4587ab1@googlegroups.com> References: <0023d73b-00f6-4d82-b68b-eb28f4587ab1@googlegroups.com> Message-ID: kl. 13:57:14 UTC+2 fredag 28. september 2012 skrev Jayden f?lgende: > Dear All, I have a concern in developing commercial code with Python. Someone told me that its program can be easily hacked to get its source code. Is it really the case? Any way to protect your source code? Thanks a lot! Jayden Python bytecode is not easier to hack than Java or .NET bytecodes. You don't have to distribute your source code. Dropbox and BitTorrent are written in Python. I don't think "hacking the source" is a major problem. You also have the option of compiling parts of the source code to native C DLLs using Cython. If you are very paranoid about protecting your sources, perhaps you shouldn't distribute it at all, but provide a web application? Sturla From malaclypse2 at gmail.com Fri Sep 28 10:38:00 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Fri, 28 Sep 2012 10:38:00 -0400 Subject: Python source code easy to hack? In-Reply-To: References: <0023d73b-00f6-4d82-b68b-eb28f4587ab1@googlegroups.com> Message-ID: On Fri, Sep 28, 2012 at 10:18 AM, wrote: > Python bytecode is not easier to hack than Java or .NET bytecodes. This is true, but both java and .net are also relatively easy to decompile. In general though, why does it matter? What are you trying to protect yourself against? If you're including secrets in your code like encryption keys or bank account numbers, there's no way to keep them out of the hands of a determined attacker that has access to your file, no matter what language it may be written in. If you must keep anyone from ever seeing how your code works, the only way to do that is to keep all the sensitive bits running on a machine that you control. Typically, you would do that by distributing a client portion of your application, and also running a web service. Then you can have your client connect to the web service, request that the sensitive calculations, or money transfer, or whatever, be done on the server, and just pass back the results. -- Jerry From ndbecker2 at gmail.com Fri Sep 28 10:39:32 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 28 Sep 2012 10:39:32 -0400 Subject: howto handle nested for Message-ID: I know this should be a fairly basic question, but I'm drawing a blank. I have code that looks like: for s0 in xrange (n_syms): for s1 in xrange (n_syms): for s2 in xrange (n_syms): for s3 in xrange (n_syms): for s4 in range (n_syms): for s5 in range (n_syms): Now I need the level of nesting to vary dynamically. (e.g., maybe I need to add for s6 in range (n_syms)) Smells like a candidate for recursion. Also sounds like a use for yield. Any suggestions? From alister.ware at ntlworld.com Fri Sep 28 10:42:20 2012 From: alister.ware at ntlworld.com (Alister) Date: Fri, 28 Sep 2012 14:42:20 GMT Subject: howto handle nested for References: Message-ID: On Fri, 28 Sep 2012 10:39:32 -0400, Neal Becker wrote: > I know this should be a fairly basic question, but I'm drawing a blank. > > I have code that looks like: > > for s0 in xrange (n_syms): > for s1 in xrange (n_syms): > for s2 in xrange (n_syms): > for s3 in xrange (n_syms): > for s4 in range (n_syms): > for s5 in range (n_syms): > > Now I need the level of nesting to vary dynamically. (e.g., maybe I > need to add for s6 in range (n_syms)) > > Smells like a candidate for recursion. Also sounds like a use for > yield. Any suggestions? It definitely looks like for is the wrong way to go for this without more information on the reason why it is difficult to say what the correct approach would be -- Calm down, it's *____only* ones and zeroes. From decyk at nospam.poczta.fm Fri Sep 28 10:51:07 2012 From: decyk at nospam.poczta.fm (Wojtek) Date: Fri, 28 Sep 2012 16:51:07 +0200 Subject: howto handle nested for In-Reply-To: References: Message-ID: <5065b96c$0$1213$65785112@news.neostrada.pl> W dniu 2012-09-28 16:42, Alister pisze: > On Fri, 28 Sep 2012 10:39:32 -0400, Neal Becker wrote: > >> I know this should be a fairly basic question, but I'm drawing a blank. >> >> I have code that looks like: >> >> for s0 in xrange (n_syms): >> for s1 in xrange (n_syms): >> for s2 in xrange (n_syms): >> for s3 in xrange (n_syms): >> for s4 in range (n_syms): >> for s5 in range (n_syms): >> >> Now I need the level of nesting to vary dynamically. (e.g., maybe I >> need to add for s6 in range (n_syms)) >> >> Smells like a candidate for recursion. Also sounds like a use for >> yield. Any suggestions? > > It definitely looks like for is the wrong way to go for this > without more information on the reason why it is difficult to say what > the correct approach would be > > > it's well described in head first: python book ;) check this sources from this book http://www.headfirstlabs.com/books/hfpython/code/chapter1.zip hope it helps, regards From rosuav at gmail.com Fri Sep 28 10:58:51 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Sep 2012 00:58:51 +1000 Subject: Article on the future of Python In-Reply-To: References: <506515F8.9020606@tysdomain.com> Message-ID: On Sat, Sep 29, 2012 at 12:31 AM, Dennis Lee Bieber wrote: > On Fri, 28 Sep 2012 14:37:21 +1000, Chris Angelico > declaimed the following in gmane.comp.python.general: > > >> For further details, poke around on the web; I'm sure you'll find >> plenty of good blog posts etc. But as for me and my house, we will >> have Postgres serve us. >> > > Please, at least use the proper name... "Postgres" is a non-SQL > database inspired by Ingres. "PostgreSQL" is Postgres with an SQL query > engine. http://www.postgresql.org/docs/9.1/static/history.html "Many people continue to refer to PostgreSQL as "Postgres" (now rarely in all capital letters) because of tradition or because it is easier to pronounce. This usage is widely accepted as a nickname or alias." There's lots of internal documentation that references "Postgres". I don't see it as that big a deal. > On my side... I have MySQL running on my desktop. When I started, > MySQL had a native build that would run on Win9X; PostgreSQL at the time > required installing a Cygwin environment. > > MySQL v5 has improved a lot from those days (v3)... It now supports > stored procedures, triggers, a form of views, and prepared statements > (though MySQLdb is still pre v5 and sends completely formatted string > queries). They've even added GIS capabilities. (And then there is the > "drop-in" replacement for MySQL -- MariaDB: > http://kb.askmonty.org/en/mariadb-vs-mysql-compatibility/ ) Yes, MySQL has definitely improved. There was a time when its unreliability applied to all your data too, but now you can just click in InnoDB and have mostly-real transaction support etc. But there's still a lot of work that by requirement happens outside of transactions - MySQL doesn't let you roll back DDL, for instance. ChrisA From gandalf at shopzeus.com Fri Sep 28 11:04:38 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 28 Sep 2012 17:04:38 +0200 Subject: howto handle nested for In-Reply-To: References: Message-ID: <5065BC86.90708@shopzeus.com> On 2012-09-28 16:39, Neal Becker wrote: > I know this should be a fairly basic question, but I'm drawing a blank. > > I have code that looks like: > > for s0 in xrange (n_syms): > for s1 in xrange (n_syms): > for s2 in xrange (n_syms): > for s3 in xrange (n_syms): > for s4 in range (n_syms): > for s5 in range (n_syms): > > Now I need the level of nesting to vary dynamically. (e.g., maybe I need to add > for s6 in range (n_syms)) > > Smells like a candidate for recursion. Also sounds like a use for yield. Any > suggestions? > In your example, it seem that the iterable of the for loop is always the same: range(n_sysms). It seems to be a number. Is that true? If that is so, then here is something useful: import copy class MultiLevelIterator(object): def __init__(self,levels,n): assert(levels>0) assert(n>0) self.levels = levels self.values = [0]*levels self.n = n def __iter__(self): return self def next(self): res = copy.copy(self.values) idx = self.levels-1 while idx>=0: self.values[idx]+=1 if self.values[idx]>=self.n: self.values[idx] = 0 idx-=1 else: return res raise StopIteration i = MultiLevelIterator(2,3) for values in i: print values This will print: [0, 0] [0, 1] [0, 2] [1, 0] [1, 1] [1, 2] [2, 0] [2, 1] From rosuav at gmail.com Fri Sep 28 11:07:15 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Sep 2012 01:07:15 +1000 Subject: what is the difference between st_ctime and st_mtime one is the time of last change and the other is the time of last modification, but i can not understand what is the difference between 'change' and 'modification'. In-Reply-To: References: Message-ID: On Fri, Sep 28, 2012 at 11:12 PM, ?? wrote: > > -- > http://mail.python.org/mailman/listinfo/python-list In future, can you put the body of your message into the body please? :) ctime is creation time, not change time. mtime is modification time, as you have. But I can understand where the confusion comes from; Google tells me there've been documentation bugs involving this very thing (and Google, being extremely Lawful Neutral, would have happily told you the same thing if you'd asked). ChrisA From ian.g.kelly at gmail.com Fri Sep 28 11:14:56 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 28 Sep 2012 09:14:56 -0600 Subject: Article on the future of Python In-Reply-To: References: <506515F8.9020606@tysdomain.com> Message-ID: On Fri, Sep 28, 2012 at 8:58 AM, Chris Angelico wrote: > Yes, MySQL has definitely improved. There was a time when its > unreliability applied to all your data too, but now you can just click > in InnoDB and have mostly-real transaction support etc. But there's > still a lot of work that by requirement happens outside of > transactions - MySQL doesn't let you roll back DDL, for instance. Neither does Oracle, for that matter. I don't really see any reason why DDL *should* be transactional in nature. If your web app is issuing DDL statements, then you're probably doing something wrong. From christian at python.org Fri Sep 28 11:18:28 2012 From: christian at python.org (Christian Heimes) Date: Fri, 28 Sep 2012 17:18:28 +0200 Subject: what is the difference between st_ctime and st_mtime one is the time of last change and the other is the time of last modification, but i can not understand what is the difference between 'change' and 'modification'. In-Reply-To: References: Message-ID: Am 28.09.2012 17:07, schrieb Chris Angelico: > On Fri, Sep 28, 2012 at 11:12 PM, ?? wrote: >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > > In future, can you put the body of your message into the body please? :) > > ctime is creation time, not change time. mtime is modification time, > as you have. But I can understand where the confusion comes from; > Google tells me there've been documentation bugs involving this very > thing (and Google, being extremely Lawful Neutral, would have happily > told you the same thing if you'd asked). In the future please read the manual before replying! ;) You are wrong, ctime is *not* the creation time. It's the change time of the inode. It's updated whenever the inode is modified, e.g. metadata modifications like permission changes, link/unlink of hard links etc. Christian From sturla at molden.no Fri Sep 28 11:19:54 2012 From: sturla at molden.no (sturla at molden.no) Date: Fri, 28 Sep 2012 08:19:54 -0700 (PDT) Subject: Python source code easy to hack? In-Reply-To: References: <0023d73b-00f6-4d82-b68b-eb28f4587ab1@googlegroups.com> Message-ID: <04a311f6-9162-40d6-8fc7-acc0b0128bc8@googlegroups.com> kl. 16:38:10 UTC+2 fredag 28. september 2012 skrev Jerry Hill f?lgende: > This is true, but both java and .net are also relatively easy to decompile. Neither of them are very "obfuscated". > In general though, why does it matter? Paranoia among managers? > What are you trying to protect yourself against? Embarassment? Patent trolls? Unauthorized access to priviledged features? Industrial espionage? > If you must keep anyone from ever seeing how your code works, the only way to do that is to keep all the sensitive bits running on a machine that you control. Indeed :) Sturla From sturla at molden.no Fri Sep 28 11:19:54 2012 From: sturla at molden.no (sturla at molden.no) Date: Fri, 28 Sep 2012 08:19:54 -0700 (PDT) Subject: Python source code easy to hack? In-Reply-To: References: <0023d73b-00f6-4d82-b68b-eb28f4587ab1@googlegroups.com> Message-ID: <04a311f6-9162-40d6-8fc7-acc0b0128bc8@googlegroups.com> kl. 16:38:10 UTC+2 fredag 28. september 2012 skrev Jerry Hill f?lgende: > This is true, but both java and .net are also relatively easy to decompile. Neither of them are very "obfuscated". > In general though, why does it matter? Paranoia among managers? > What are you trying to protect yourself against? Embarassment? Patent trolls? Unauthorized access to priviledged features? Industrial espionage? > If you must keep anyone from ever seeing how your code works, the only way to do that is to keep all the sensitive bits running on a machine that you control. Indeed :) Sturla From rosuav at gmail.com Fri Sep 28 11:20:45 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Sep 2012 01:20:45 +1000 Subject: Article on the future of Python In-Reply-To: References: <506515F8.9020606@tysdomain.com> Message-ID: On Sat, Sep 29, 2012 at 1:14 AM, Ian Kelly wrote: > On Fri, Sep 28, 2012 at 8:58 AM, Chris Angelico wrote: >> Yes, MySQL has definitely improved. There was a time when its >> unreliability applied to all your data too, but now you can just click >> in InnoDB and have mostly-real transaction support etc. But there's >> still a lot of work that by requirement happens outside of >> transactions - MySQL doesn't let you roll back DDL, for instance. > > Neither does Oracle, for that matter. I don't really see any reason > why DDL *should* be transactional in nature. If your web app is > issuing DDL statements, then you're probably doing something wrong. I have an auto-update script that ensures that our database is at the correct patchlevel. It's fairly straight-forward: switch on patchlevel, execute the statements required to get up to the next one, at the bottom record the patchlevel in the database. (This relieves us of issues of schema changes done in development that didn't get pushed to production, for instance; our source code repository has _everything_ needed.) If anything goes wrong, Postgres will roll the transaction back. It doesn't matter if the first statement added a column to a table and the second does an INSERT... SELECT; they both get rolled back (as would any change to the patchlevel field, though that happens at the very end so it's not significant here). I can guarantee that the patch has either been completely applied or completely rolled back - exactly what transactions are for. ChrisA From rosuav at gmail.com Fri Sep 28 11:25:18 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Sep 2012 01:25:18 +1000 Subject: what is the difference between st_ctime and st_mtime one is the time of last change and the other is the time of last modification, but i can not understand what is the difference between 'change' and 'modification'. In-Reply-To: References: Message-ID: On Sat, Sep 29, 2012 at 1:18 AM, Christian Heimes wrote: > Am 28.09.2012 17:07, schrieb Chris Angelico: > In the future please read the manual before replying! ;) You are wrong, > ctime is *not* the creation time. It's the change time of the inode. > It's updated whenever the inode is modified, e.g. metadata modifications > like permission changes, link/unlink of hard links etc. Whoops, my bad! Sorry. I was remembering some other APIs with similar terminology. Lesson: Check the docs, they're more reliable. ChrisA From python.list at tim.thechases.com Fri Sep 28 11:28:21 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 28 Sep 2012 10:28:21 -0500 Subject: howto handle nested for In-Reply-To: References: Message-ID: <5065C215.9010303@tim.thechases.com> On 09/28/12 09:39, Neal Becker wrote: > I know this should be a fairly basic question, but I'm drawing a blank. > > I have code that looks like: > > for s0 in xrange (n_syms): > for s1 in xrange (n_syms): > for s2 in xrange (n_syms): > for s3 in xrange (n_syms): > for s4 in range (n_syms): > for s5 in range (n_syms): > > Now I need the level of nesting to vary dynamically. (e.g., maybe I need to add > for s6 in range (n_syms)) > > Smells like a candidate for recursion. Also sounds like a use for yield. Any > suggestions? There was a good discussion on this back in 2008 that might be worth reading over. For some reason the mail.python.org archives[1] seem to have broken threading on this topic (Andrew Reedick's reply using exec() is waaay down in the archive, disassociated from the thread), so here it is archived somewhere else where the 2 pages of threading seems more manageable/accurate: http://www.velocityreviews.com/forums/t585147-creating-unique-combinations-from-lists.html -tkc [1] http://mail.python.org/pipermail/python-list/2008-January/487851.html From ian.g.kelly at gmail.com Fri Sep 28 11:49:36 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 28 Sep 2012 09:49:36 -0600 Subject: howto handle nested for In-Reply-To: References: Message-ID: On Fri, Sep 28, 2012 at 8:39 AM, Neal Becker wrote: > I know this should be a fairly basic question, but I'm drawing a blank. > > I have code that looks like: > > for s0 in xrange (n_syms): > for s1 in xrange (n_syms): > for s2 in xrange (n_syms): > for s3 in xrange (n_syms): > for s4 in range (n_syms): > for s5 in range (n_syms): > > Now I need the level of nesting to vary dynamically. (e.g., maybe I need to add > for s6 in range (n_syms)) > > Smells like a candidate for recursion. Also sounds like a use for yield. Any > suggestions? levels = 6 for combination in itertools.product(xrange(n_syms), levels): # do stuff Cheers, Ian From ndbecker2 at gmail.com Fri Sep 28 11:52:36 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 28 Sep 2012 11:52:36 -0400 Subject: howto handle nested for References: Message-ID: Neal Becker wrote: > I know this should be a fairly basic question, but I'm drawing a blank. > > I have code that looks like: > > for s0 in xrange (n_syms): > for s1 in xrange (n_syms): > for s2 in xrange (n_syms): > for s3 in xrange (n_syms): > for s4 in range (n_syms): > for s5 in range (n_syms): > > Now I need the level of nesting to vary dynamically. (e.g., maybe I need to > add > for s6 in range (n_syms)) > > Smells like a candidate for recursion. Also sounds like a use for yield. Any > suggestions? Thanks for the suggestions: I found itertools.product is just great for this. From rurpy at yahoo.com Fri Sep 28 11:52:45 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 28 Sep 2012 08:52:45 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> <506515F8.9020606@tysdomain.com> Message-ID: <7bac7f07-8f54-4e53-aa59-3aae472e6c23@googlegroups.com> On 09/27/2012 10:37 PM, Chris Angelico wrote:>[...] > * MySQL is designed for dynamic web sites, with lots of reading and > not too much writing. Its row and table locking system is pretty > rudimentary, and it's quite easy for performance to suffer really > badly if you don't think about it. But if your needs are simple, MySQL > is probably enough. PostgreSQL uses MVCC to avoid locks in many cases. > You can happily read from a row while it's being updated; you'll be > unaware of the update until it's committed. MVCC comes with a cost though, as anyone who has ever needed to do a SELECT COUNT(*) on a large Postgresql table knows. >[...] > * Both engines have good support in popular languages, including > (dragging this back on topic, kicking and screaming) Python. Maybe things are different now but a few years ago I was trying to choose between Postgresql and Mysql about the time Python 2.4 (I think) was released. After waiting for over a year for the Python mysql dbi module to be released for the then current version of Python (I needed a binary for Windows) I finally gave up and decided to go with Postgresql (the psycopg2 module was available a very short time after the new Python was.) From rurpy at yahoo.com Fri Sep 28 11:52:45 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 28 Sep 2012 08:52:45 -0700 (PDT) Subject: Article on the future of Python In-Reply-To: References: <5061cf25$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063a179$0$29981$c3e8da3$5496439d@news.astraweb.com> <5063eba2$0$29997$c3e8da3$5496439d@news.astraweb.com> <506515F8.9020606@tysdomain.com> Message-ID: <7bac7f07-8f54-4e53-aa59-3aae472e6c23@googlegroups.com> On 09/27/2012 10:37 PM, Chris Angelico wrote:>[...] > * MySQL is designed for dynamic web sites, with lots of reading and > not too much writing. Its row and table locking system is pretty > rudimentary, and it's quite easy for performance to suffer really > badly if you don't think about it. But if your needs are simple, MySQL > is probably enough. PostgreSQL uses MVCC to avoid locks in many cases. > You can happily read from a row while it's being updated; you'll be > unaware of the update until it's committed. MVCC comes with a cost though, as anyone who has ever needed to do a SELECT COUNT(*) on a large Postgresql table knows. >[...] > * Both engines have good support in popular languages, including > (dragging this back on topic, kicking and screaming) Python. Maybe things are different now but a few years ago I was trying to choose between Postgresql and Mysql about the time Python 2.4 (I think) was released. After waiting for over a year for the Python mysql dbi module to be released for the then current version of Python (I needed a binary for Windows) I finally gave up and decided to go with Postgresql (the psycopg2 module was available a very short time after the new Python was.) From __peter__ at web.de Fri Sep 28 11:53:54 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 28 Sep 2012 17:53:54 +0200 Subject: howto handle nested for References: Message-ID: Neal Becker wrote: > I know this should be a fairly basic question, but I'm drawing a blank. > > I have code that looks like: > > for s0 in xrange (n_syms): > for s1 in xrange (n_syms): > for s2 in xrange (n_syms): > for s3 in xrange (n_syms): > for s4 in range (n_syms): > for s5 in range (n_syms): > > Now I need the level of nesting to vary dynamically. (e.g., maybe I need > to add > for s6 in range (n_syms)) > > Smells like a candidate for recursion. Also sounds like a use for yield. > Any suggestions? for s in itertools.product(range(n_syms), repeat=6): print s From tyler at tysdomain.com Fri Sep 28 11:56:30 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Fri, 28 Sep 2012 09:56:30 -0600 Subject: Python source code easy to hack? In-Reply-To: <04a311f6-9162-40d6-8fc7-acc0b0128bc8@googlegroups.com> References: <0023d73b-00f6-4d82-b68b-eb28f4587ab1@googlegroups.com> <04a311f6-9162-40d6-8fc7-acc0b0128bc8@googlegroups.com> Message-ID: <5065C8AE.1070709@tysdomain.com> On 9/28/2012 9:19 AM, sturla at molden.no wrote: > kl. 16:38:10 UTC+2 fredag 28. september 2012 skrev Jerry Hill f?lgende: > >> This is true, but both java and .net are also relatively easy to decompile. > Neither of them are very "obfuscated". > > >> In general though, why does it matter? > Paranoia among managers? > > >> What are you trying to protect yourself against? Embarassment? Patent trolls? Unauthorized access to priviledged features? Industrial espionage? Sounds like a web solution is the best way. Use a thin client and run your NSA-level code on a server. It's worth pointing out though that even c/c++ isn't free. If someone wants to decompile or disassemble your code bad enough, it's going to happen. >> If you must keep anyone from ever seeing how your code works, the only way to do that is to keep all the sensitive bits running on a machine that you control. > Indeed :) > > > > Sturla -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From ian.g.kelly at gmail.com Fri Sep 28 12:00:02 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 28 Sep 2012 10:00:02 -0600 Subject: howto handle nested for In-Reply-To: References: Message-ID: On Sep 28, 2012 9:49 AM, "Ian Kelly" wrote: > levels = 6 > for combination in itertools.product(xrange(n_syms), levels): > # do stuff Sorry, that should have read "product(xrange(n_syms), repeat=levels)". The repeat argument is keyword-only. -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Fri Sep 28 12:25:31 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 29 Sep 2012 02:25:31 +1000 Subject: REST code-golf: How concisely can you expose and consume services? In-Reply-To: <5065B16B.5030405@gmail.com> References: <5065B16B.5030405@gmail.com> Message-ID: On Sat, Sep 29, 2012 at 12:17 AM, Demian Brecht wrote: > (A little OT so my apologies up front) > > > On 12-09-28 12:39 AM, Chris Angelico wrote: >> >> I love the idea, even though I shan't be entering. Code golf is awesome >> fun! > > > Code golf is indeed awesome fun and I usually enjoy taking part as well. > However, I'm not a fan of code golf such as this, that uses a framework and > then defines a rule that you *can't* hack on the same framework. > > In the framework/external module spirit, I *could* write a module that does > *all* of this for me (in Pyramid, Django, web2py, etc) and then enter with a > simple method call in another module. > > Done. One liner. I win ;) > > I much prefer code golf that tests algorithmic/core language feature > knowledge. Of course, that's entirely only my opinion. > > -- > Demian Brecht > @demianbrecht > http://demianbrecht.github.com > -- > http://mail.python.org/mailman/listinfo/python-list Well I suppose I could lax that same requirement. I.e.: if you can get these decorators (also working with RBAC) in, for example: Django; then it still satisfied the rules :) From rolando.caner at gmail.com Fri Sep 28 12:26:02 2012 From: rolando.caner at gmail.com (=?ISO-8859-1?Q?Rolando_Ca=F1er_Roblejo?=) Date: Fri, 28 Sep 2012 12:26:02 -0400 Subject: How to get progress in python script. Message-ID: <5065CF9A.6090303@gmail.com> Hi all, Please, I need you suggest me a way to get statistics about a progress of my python script. My python script could take a lot of time processing a file, so I need a way that an external program check the progress of the script. My first idea was that the python script write a temp file showing the progress and the external program can check that file, but I think might happen file read/write locking issues. Thanks. From steve+comp.lang.python at pearwood.info Fri Sep 28 12:33:06 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Sep 2012 16:33:06 GMT Subject: Article on the future of Python References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> <50659e1f$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5065d142$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 28 Sep 2012 06:14:32 -0700, rusi wrote: > It would be good to pay attention before calling others to pay > attention. > > http://litmus.com/blog/email-client-market-share-stats-infographic- june-2012/email-client-market-share-june-2012 Oh my, that's hilarious. It's a big, flashy "infographic" with lots of graphics and absolutely no meaningful information. As pure a case of "garbage in, garbage out" as you can hope to see. Hidden in the fine print: "Data for some email clients and mobiles may be over- and under- represented due to image blocking." You think? I would have thought that the whole Thunderbird-doesn't-get-a-mention might have given you a clue that the data there was rubbish. Or that they think more people use Yahoo than Gmail. Riiiight. 1% of email users are on AOL? Pull the other one, it has bells on. Three years ago, there were about 2 billion active email users worldwide. 1% of that is 20 million. There are fewer than 4 million AOL subscribers, or about 0.2% (or less, given that total email users are increasing and AOL subscribers are not). The only thing that link is good for is determining which mail clients have crap privacy policies. Thank you for sharing this, it is a great example of the use of bogus statistics. -- Steven From gordon at panix.com Fri Sep 28 12:36:52 2012 From: gordon at panix.com (John Gordon) Date: Fri, 28 Sep 2012 16:36:52 +0000 (UTC) Subject: How to get progress in python script. References: Message-ID: In =?ISO-8859-1?Q?Rolando_Ca=F1er_Roblejo?= writes: > Hi all, > Please, I need you suggest me a way to get statistics about a progress > of my python script. My python script could take a lot of time > processing a file, so I need a way that an external program check the > progress of the script. My first idea was that the python script write a > temp file showing the progress and the external program can check that > file, but I think might happen file read/write locking issues. The external program should open the progress file for read only, so I wouldn't think file locking would be an issue. -- 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 jeanmichel at sequans.com Fri Sep 28 13:07:03 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 28 Sep 2012 19:07:03 +0200 (CEST) Subject: How to get progress in python script. In-Reply-To: <5065CF9A.6090303@gmail.com> Message-ID: <764362453.2823074.1348852023815.JavaMail.root@sequans.com> ----- Original Message ----- > Hi all, > > Please, I need you suggest me a way to get statistics about a > progress > of my python script. My python script could take a lot of time > processing a file, so I need a way that an external program check the > progress of the script. My first idea was that the python script > write a > temp file showing the progress and the external program can check > that > file, but I think might happen file read/write locking issues. > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > Hello, One easy way would be to use a RPC system. Pyro implements one of them. See http://packages.python.org/Pyro4/tutorials.html This could be achieved in very few lines. Your script create a thread in which it serves the remote requests. xmlrpclib is another popular RPC package. Another solution is to use a web server (sounds overkill but it isn't). A lot of python web frameworks allow you to create such server in very few lines. look at http://www.cherrypy.org/ for instance, use their 'hello word' example and replace the 'hello word' by the current script progress and you're done. JM From nobody at nowhere.com Fri Sep 28 13:22:11 2012 From: nobody at nowhere.com (Nobody) Date: Fri, 28 Sep 2012 18:22:11 +0100 Subject: what is the difference between st_ctime and st_mtime one is the time of last change and the other is the time of last modification, but i can not understand what is the difference between 'change' and 'modification'. References: Message-ID: On Fri, 28 Sep 2012 06:12:35 -0700, ?? wrote: > what is the difference between st_ctime and st_mtime one is the time of > last change and the other is the time of last modification, but i can > not understand what is the difference between 'change' and 'modification'. st_mtime is updated when the file's contents change. st_ctime is updated when the file's metadata (owner, group, permissions, link count, etc) changes. From dihedral88888 at googlemail.com Fri Sep 28 13:37:47 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 28 Sep 2012 10:37:47 -0700 (PDT) Subject: Python source code easy to hack? In-Reply-To: <0023d73b-00f6-4d82-b68b-eb28f4587ab1@googlegroups.com> References: <0023d73b-00f6-4d82-b68b-eb28f4587ab1@googlegroups.com> Message-ID: <50c0e16d-91c6-487a-bfe7-330371b7ed56@googlegroups.com> Jayden? 2012?9?28????UTC+8??7?57?14???? > Dear All, > > > > I have a concern in developing commercial code with Python. Someone told me that its program can be easily hacked to get its source code. Is it really the case? Any way to protect your source code? > > > > Thanks a lot! > > > > Jayden Nowadays high priced commercial IDE software products shipped with a built in interpreter with some GUI to let users customize their own needs in designs. This also means examples in source codes to be provided, too. Anyway even compiled instructions can be iced and reverse engineered for all the flows of the software. From kwebb at teradactyl.com Fri Sep 28 13:48:23 2012 From: kwebb at teradactyl.com (Kristen J. Webb) Date: Fri, 28 Sep 2012 11:48:23 -0600 Subject: what is the difference between st_ctime and st_mtime one is the time of last change and the other is the time of last modification, but i can not understand what is the difference between 'change' and 'modification'. In-Reply-To: References: Message-ID: <5065E2E7.3020101@teradactyl.com> The Windows stat() call treats things differently, FROM: http://msdn.microsoft.com/en-us/library/14h5k7ff%28v=vs.80%29.aspx st_ctime Time of creation of file. Valid on NTFS but not on FAT formatted disk drives. I don't think that Windows has a concept of a "change time" for meta data (though that would be nice). How's that for compatibility ;) NOTE: I am a C programmer and new to python, so can anyone comment on what the st_ctime value is when os.stat() is called on Windows? Kris On 9/28/12 9:25 AM, Chris Angelico wrote: > On Sat, Sep 29, 2012 at 1:18 AM, Christian Heimes wrote: >> Am 28.09.2012 17:07, schrieb Chris Angelico: >> In the future please read the manual before replying! ;) You are wrong, >> ctime is *not* the creation time. It's the change time of the inode. >> It's updated whenever the inode is modified, e.g. metadata modifications >> like permission changes, link/unlink of hard links etc. > > Whoops, my bad! Sorry. I was remembering some other APIs with similar > terminology. > > Lesson: Check the docs, they're more reliable. > > ChrisA > -- This message is NOT encrypted -------------------------------- Mr. Kristen J. Webb Chief Technology Officer Teradactyl LLC. 2301 Yale Blvd. SE. Suite C7 Albuquerque, NM 87106 Phone: 1-505-338-6000 Email: kwebb at teradactyl.com Web: http://www.teradactyl.com Home of the True incremental Backup System -------------------------------- NOTICE TO RECIPIENTS: Any information contained in or attached to this message is intended solely for the use of the intended recipient(s). If you are not the intended recipient of this transmittal, you are hereby notified that you received this transmittal in error, and we request that you please delete and destroy all copies and attachments in your possession, notify the sender that you have received this communication in error, and note that any review or dissemination of, or the taking of any action in reliance on, this communication is expressly prohibited. Regular internet e-mail transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate, and it should not be relied upon as such. If you prefer to communicate with Teradactyl LLC. using secure (i.e., encrypted and/or digitally signed) e-mail transmission, please notify the sender. Otherwise, you will be deemed to have consented to communicate with Teradactyl via regular internet e-mail transmission. Please note that Teradactyl reserves the right to intercept, monitor, and retain all e-mail messages (including secure e-mail messages) sent to or from its systems as permitted by applicable law. From ramit.prasad at jpmorgan.com Fri Sep 28 14:02:04 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 28 Sep 2012 18:02:04 +0000 Subject: data attributes override method attributes? In-Reply-To: References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474166CCB67@SCACMX008.exchad.jpmchase.net> Terry Reedy wrote: > On 9/25/2012 4:07 PM, Ian Kelly wrote: > > On Tue, Sep 25, 2012 at 1:58 PM, Terry Reedy wrote: > >> On 9/25/2012 11:03 AM, Chris Angelico wrote: > >>> Instance attributes override (shadow) class attributes. > >> > >> > >> except for (some? all?) special methods > > > > Those names are shadowed too. If you call foo.__len__() and the name > > is bound on the instance, it will call that function preferentially. > > It's just that when the special Python machinery calls the method, it > > skips the instance and goes straight to the class. > > I added "Ian Kelly reminds me that instance.__xxx__ is only skipped by > the internal machinery and not by direct accesses in user code. In the > other hand, docs, official or otherwise, are filled with things like > 'len(a) calls a.__len__', so I think something should be said that > giving instances special method attributes does not have the effect one > might expect." > > to the issue. > Just to make sure I am following, if you call foo.__len__() it goes to the instance code while if you do len(foo) it will go to class.__len__()? If so, why? This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Fri Sep 28 14:07:57 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 28 Sep 2012 18:07:57 +0000 Subject: =?utf-8?B?UkU6IHJlZ3VsYXIgZXhwcmVzc2lvbiA6ICB0aGUgZG9sbGFyIHNpZ24gKCQp?= =?utf-8?B?IHdvcmsgd2l0aCByZS5tYXRjaCgpIG9yIHJlLnNlYXJjaCgpICDvvJ8=?= In-Reply-To: <5d913584-b5ea-4ff1-8094-f4d5b273c0b6@googlegroups.com> References: <5d913584-b5ea-4ff1-8094-f4d5b273c0b6@googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474166CCB8B@SCACMX008.exchad.jpmchase.net> iMath wrote: > Sent: Wednesday, September 26, 2012 2:39 AM > To: python-list at python.org > Subject: regular expression : the dollar sign ($) work with re.match() or re.search() ? > > I only know the dollar sign ($) will match a pattern from the > end of a string,but which method does it work with ,re.match() or re.search() ? You can try this on the interactive interpreter. >>> re.match('hi$', 'xihi') >>> re.search('hi$', 'xihi') <_sre.SRE_Match object at 0x13FF7100> Although, I think match does not work since match only starts searching at the start of the string while search looks for the pattern anywhere in the string. >>> re.match('x.hi$', 'xihi') <_sre.SRE_Match object at 0x15693BF0> I guess you can consider re.match's pattern to be prefixed with '^'. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ian.g.kelly at gmail.com Fri Sep 28 14:25:11 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 28 Sep 2012 12:25:11 -0600 Subject: data attributes override method attributes? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474166CCB67@SCACMX008.exchad.jpmchase.net> References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> <5B80DD153D7D744689F57F4FB69AF474166CCB67@SCACMX008.exchad.jpmchase.net> Message-ID: On Fri, Sep 28, 2012 at 12:02 PM, Prasad, Ramit wrote: > Just to make sure I am following, if you call > foo.__len__() it goes to the instance code while > if you do len(foo) it will go to class.__len__()? Yes: >>> class Foo(object): ... def __len__(self): ... return 42 ... >>> foo = Foo() >>> foo.__len__ = lambda: 43 >>> foo.__len__() 43 >>> len(foo) 42 > If so, why? In the first case, "foo.__len__" just does the normal attribute lookup for the class. Instance attributes shadow class attributes, so the instance attribute is returned and then called. In the second case, "len(foo)" is implemented by a method in a prescribed location: foo.__class__.__len__. It only looks in the class for efficiency and because that is what the class object is for: to define how its instances behave. From tjreedy at udel.edu Fri Sep 28 14:26:05 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 28 Sep 2012 14:26:05 -0400 Subject: data attributes override method attributes? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474166CCB67@SCACMX008.exchad.jpmchase.net> References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> <5B80DD153D7D744689F57F4FB69AF474166CCB67@SCACMX008.exchad.jpmchase.net> Message-ID: On 9/28/2012 2:02 PM, Prasad, Ramit wrote: > Just to make sure I am following, if you call > foo.__len__() it goes to the instance code while > if you do len(foo) it will go to class.__len__()? len(foo) calls someclass.__len__(foo) where someclass is foo.__class__or some superclass. > If so, why? Efficiency and perhaps simpler implementation, especially for binary ops. -- Terry Jan Reedy From ian.g.kelly at gmail.com Fri Sep 28 14:32:07 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 28 Sep 2012 12:32:07 -0600 Subject: =?UTF-8?B?UmU6IHJlZ3VsYXIgZXhwcmVzc2lvbiA6IHRoZSBkb2xsYXIgc2lnbiAoJCkgd29yayB3aQ==?= =?UTF-8?B?dGggcmUubWF0Y2goKSBvciByZS5zZWFyY2goKSDvvJ8=?= In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474166CCB8B@SCACMX008.exchad.jpmchase.net> References: <5d913584-b5ea-4ff1-8094-f4d5b273c0b6@googlegroups.com> <5B80DD153D7D744689F57F4FB69AF474166CCB8B@SCACMX008.exchad.jpmchase.net> Message-ID: On Fri, Sep 28, 2012 at 12:07 PM, Prasad, Ramit wrote: > I guess you can consider re.match's pattern to be > prefixed with '^'. You can in this case, but they're not equivalent in multi-line mode: >>> re.match('^two', 'one\ntwo', re.M) >>> re.search('^two', 'one\ntwo', re.M) <_sre.SRE_Match object at 0x0475BFA8> From franck at ditter.org Fri Sep 28 14:42:03 2012 From: franck at ditter.org (Franck Ditter) Date: Fri, 28 Sep 2012 20:42:03 +0200 Subject: print or write on a text file ? Message-ID: Hi ! Here is Python 3.3 Is it better in any way to use print(x,x,x,file='out') or out.write(x) ? Any reason to prefer any of them ? There should be a printlines, like readlines ? Thanks, franck From jeanpierreda at gmail.com Fri Sep 28 14:50:14 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 28 Sep 2012 14:50:14 -0400 Subject: Article on the future of Python In-Reply-To: <0ac0d6c8-3fda-4b4c-afd6-01cc36019aaa@lo4g2000pbb.googlegroups.com> References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> <506461bc$0$29981$c3e8da3$5496439d@news.astraweb.com> <0ac0d6c8-3fda-4b4c-afd6-01cc36019aaa@lo4g2000pbb.googlegroups.com> Message-ID: On Thu, Sep 27, 2012 at 8:59 PM, alex23 wrote: > On Sep 28, 2:17 am, Devin Jeanpierre wrote: >> Uncharitably, it's just a way of hiding one's head in the sand, >> ignoring any problems Python has by focusing on what problems it >> doesn't have. > > But isn't that what counterpoint is all about? Actually I think it's about the charitable interpretation. Nobody writes an article and says, "I'm going to stick my head in the sand". I do believe the article is trying to provide a counterweight to the gloomy mood set by the first. > Calvin's article > highlighted what he felt were areas that Python isn't successful, > while Tim McNamara's pointed out areas it was. Just because Python > isn't used much in commercial video games doesn't undermine the point > that it's heavily used in education and research. Absolutely. But also, vice versa -- just because Python is a wonderful language for education and research does not mean that its problems in commercial video games are not worth looking at. > Does Python _have_ to be a go-to tool in gaming for it to not be on > its death march? I don't think anyone is arguing it's on a death march, just that there are issues that we downplay but should address to keep a vibrant and diverse community. Or something. I'm pretty sure nobody thinks Python is on a death march. > Or more to the point: rather than just complain about it... It's not > like there aren't active communities that _are_ working in this area: > PyGame, pyglet, Kivy are all projects that can be contributed to. Haha, I wouldn't phrase it as "complaining". Of these, I have mixed feelings. For example, Calvin has concerns that Python isn't so good on mobile because battery usage (or some such thing). I have no experience on mobile development, so no comment there. I intend to use Kivy this weekend actually, so... Maybe this one is very promising! You didn't mention it, but for the browser issue there is PyJS... but we've all heard the issues that project has. Not sure if there are sane alternatives. Perhaps Silverlight? In all cases you end up with output that's rather large. I'm not sure how practical it is, in the end, to use Python. It may just be that the difference in productivity for common web tasks, is tiny enough that the difficulty of setting up an efficient python->JS toolchain is overwhelming. As for pygame and pyglet, and game development, well, those are things. That's a sort of frustrating response for a number of reasons, but I'll keep it to just one: Those have been around for a very long time, and are very stable (to the point where the infrequency of updates sometimes leads to questions as to whether they're even maintained (I think they are)). The situation for using Python for game development is virtually unchanged in the past several years, and it's been failing for the past several years, so these two projects can't fix it. If these are the best we have, barring additional argument we are going nowhere on this front. For what it's worth, I think there are much larger problems in the game development world than how well Python is faring. Open source projects for game development are few and of not-so-amazing quality. > I love using Python and will endeavour to do so wherever I can, but > it's always going to be the case that a language has strengths & > weaknesses that other languages lack. Absolutely! Python will never be perfect. There will always be paths we can take to improve it. And we should always seek to improve it, as long as we stand behind it as a good and useful language compared to the alternatives. On the other hand, I will not use Python "wherever I can". I will use it wherever it makes the most sense to use it. For example, I would write a first person shooter game in C# and Unity 3D, and I would write my AJAX website in Javascript. It's just easier for me that way. Why use Python if it makes my job harder? -- Devin From ramit.prasad at jpmorgan.com Fri Sep 28 16:34:25 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 28 Sep 2012 20:34:25 +0000 Subject: [python-list] python application file format In-Reply-To: <5062F9D6.2060402@abzinc.com> References: <5062F9D6.2060402@abzinc.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474166CCE39@SCACMX008.exchad.jpmchase.net> Benjamin Jessup wrote: > Hello all, > > What do people recommend for a file format for a python desktop > application? Data is complex with 100s/1000s of class instances, which > reference each other. > > Write the file with struct module? (Rebuild object pointers, safe, > compact, portable, not expandable without reserved space) > > Use cPickle with a module/class whitelist? (Can't easily port, not > entirely safe, compact enough, expandable) > > Use JSON or similar? (Rebuild object pointers, portable, expandable, size?) > > Any advice is greatly appreciated! I would think your options are pickle, json or database (either sqlite or something like Postgres). I am unfamiliar with the struct module so I cannot comment on its applicability. I would guess that your data would be best saved by using a sqlite database. Your biggest problem might be how the different classes are referencing each other. If you are using identifiers then any of these options will probably work. If you are using aggregation then I know that pickle will work (at least for built-in types). JSON will keep the structure but duplicate elements. >>> a = [ 1,2,3 ] >>> b = [ 'a', 'b', 'c' ] >>> a.append( b ) >>> e = [ a,b ] >>> s = json.dumps( e ) >>> eret = json.loads( s ) >>> id(eret[0][3]), id(eret[1]) # Same result for json and simplejson (329443808, 327677272) >>> eret[0][3].append( 'o') >>> eret[0][3], eret[1] ([u'a', u'b', u'c', 'o'], [u'a', u'b', u'c']) So pickle will be your easiest option, but I am not sure how well it will scale with a large number items. Using sqlite/db should scale well but it will take you longer/more effort to create a system for converting your objects to and from the DB. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From neilc at norwich.edu Fri Sep 28 16:38:56 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 28 Sep 2012 20:38:56 GMT Subject: howto handle nested for References: Message-ID: On 2012-09-28, Laszlo Nagy wrote: > In your example, it seem that the iterable of the for loop is > always the same: range(n_sysms). It seems to be a number. Is > that true? If that is so, then here is something useful: > > import copy > > class MultiLevelIterator(object): > def __init__(self,levels,n): > assert(levels>0) > assert(n>0) > self.levels = levels > self.values = [0]*levels > self.n = n > > def __iter__(self): > return self > > def next(self): > res = copy.copy(self.values) > idx = self.levels-1 > while idx>=0: > self.values[idx]+=1 > if self.values[idx]>=self.n: > self.values[idx] = 0 > idx-=1 > else: > return res > raise StopIteration > > i = MultiLevelIterator(2,3) > for values in i: > print values > > This will print: > > [0, 0] > [0, 1] > [0, 2] > [1, 0] > [1, 1] > [1, 2] > [2, 0] > [2, 1] It looks like you might have missed the last one. Also, be sure to check itertools for occasionally for cool stuff like this. >>> for values in itertools.product(range(3), repeat=2): ... print(values) ... (0, 0) (0, 1) (0, 2) (1, 0) (1, 1) (1, 2) (2, 0) (2, 1) (2, 2) -- Neil Cerutti From wayne at waynewerner.com Fri Sep 28 17:33:30 2012 From: wayne at waynewerner.com (Wayne Werner) Date: Fri, 28 Sep 2012 16:33:30 -0500 (CDT) Subject: print or write on a text file ? In-Reply-To: References: Message-ID: On Fri, 28 Sep 2012, Franck Ditter wrote: > Hi ! > Here is Python 3.3 > Is it better in any way to use print(x,x,x,file='out') > or out.write(x) ? Any reason to prefer any of them ? > There should be a printlines, like readlines ? > Thanks, The print function automatically appends newlines to the end of what it prints. So if you had text = 'Hello!' and you did: print(text, file=outfile) then outfile would contain 'Hello!\n' In contrast, outfile.write(text) would only write 'Hello!'. No newline. There are lots of other handy things you can do with the print function: values = [1,2,3,4] print(*values, sep='\n', file=outfile) I'll leave it to you to experiment. HTH, Wayne From thudfoo at gmail.com Fri Sep 28 17:55:07 2012 From: thudfoo at gmail.com (xDog Walker) Date: Fri, 28 Sep 2012 14:55:07 -0700 Subject: How to pass FILE * Message-ID: <201209281455.07702.thudfoo@gmail.com> The function I am trying to call wants a FILE *: dlg_progressbox(const char *title, const char *cprompt, int height, int width, int pauseopt, FILE *fp) I can open the file to be referenced: fp = os.fdopen(self.pipefds[0], 'r') Every thing I've tried ends with ctypes raising a TypeError. -- Yonder nor sorghum stenches shut ladle gulls stopper torque wet strainers. ------------------------------------------------------- -- Yonder nor sorghum stenches shut ladle gulls stopper torque wet strainers. From nospam at nospam.com Fri Sep 28 17:57:14 2012 From: nospam at nospam.com (Gilles) Date: Fri, 28 Sep 2012 23:57:14 +0200 Subject: [fcgi.py] Force cache upgrade? Message-ID: Hello Does someone know if something must be done after editing a FastCGI + WSGI script so that the changes will show in the browser immediately instead of having to wait X minutes? =========== #!/usr/bin/env python2.6 def myapp(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return ['I CHANGED THIS\n'] if __name__ == '__main__': from flup.server.fcgi import WSGIServer WSGIServer(myapp).run() =========== I guess the FastCGI server (Flup) only updates its cache every so often. Do I need to type a command to force Flup to recompile the Python script? Thank you. From davidreynon at gmail.com Fri Sep 28 19:39:33 2012 From: davidreynon at gmail.com (dave) Date: Fri, 28 Sep 2012 16:39:33 -0700 (PDT) Subject: creating an artificial "last element" in sort list Message-ID: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> a = ['a', 'b', x] b = sorted(a) What does x need to be to always be last on an ascending sort no matter what 'a' and 'b' are.... within reason... I am expecting 'a' and 'b' will be not longer than 10 char's long.... I tried making x = 'zzzzzzzzzzzzzzzz' and believe it or not, this appears FIRST on the sort!!! From demianbrecht at gmail.com Fri Sep 28 19:41:58 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Fri, 28 Sep 2012 16:41:58 -0700 Subject: [fcgi.py] Force cache upgrade? In-Reply-To: References: Message-ID: If you don't have access to restart Apache (or `x` server), then touch fcgi.py *should* work. On Fri, Sep 28, 2012 at 2:57 PM, Gilles wrote: > Hello > > Does someone know if something must be done after editing a FastCGI + > WSGI script so that the changes will show in the browser immediately > instead of having to wait X minutes? > > =========== > #!/usr/bin/env python2.6 > > def myapp(environ, start_response): > start_response('200 OK', [('Content-Type', 'text/plain')]) > return ['I CHANGED THIS\n'] > > if __name__ == '__main__': > from flup.server.fcgi import WSGIServer > WSGIServer(myapp).run() > =========== > > I guess the FastCGI server (Flup) only updates its cache every so > often. Do I need to type a command to force Flup to recompile the > Python script? > > Thank you. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Fri Sep 28 19:45:43 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 28 Sep 2012 17:45:43 -0600 Subject: creating an artificial "last element" in sort list In-Reply-To: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> References: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> Message-ID: On Fri, Sep 28, 2012 at 5:39 PM, dave wrote: > a = ['a', 'b', x] > > b = sorted(a) > > What does x need to be to always be last on an ascending sort no matter what 'a' and 'b' are.... within reason... I am expecting 'a' and 'b' will be not longer than 10 char's long.... I tried making x = 'zzzzzzzzzzzzzzzz' and believe it or not, this appears FIRST on the sort!!! It appears last when I run the code. To answer your question, though, if you want to force x to be last, then I suggest removing it from the list and then appending it to the end. From davidreynon at gmail.com Fri Sep 28 19:51:10 2012 From: davidreynon at gmail.com (dave) Date: Fri, 28 Sep 2012 16:51:10 -0700 (PDT) Subject: creating an artificial "last element" in sort list In-Reply-To: References: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> Message-ID: more clearer, this is a more realistic use case: ['awefawef', 'awefawfsf', 'awefsdf', 'zzzzzzzzzzzzzz', 'zzzzzzzzzzzzzz', 'zzzzzzzzzzzzzz'] and the quantity of ''zzzzzzzzzzzzzz'' would be dynamic. On Friday, September 28, 2012 4:46:15 PM UTC-7, Ian wrote: > > > a = ['a', 'b', x] > > > > > > b = sorted(a) > > > > > > What does x need to be to always be last on an ascending sort no matter what 'a' and 'b' are.... within reason... I am expecting 'a' and 'b' will be not longer than 10 char's long.... I tried making x = 'zzzzzzzzzzzzzzzz' and believe it or not, this appears FIRST on the sort!!! > > > > It appears last when I run the code. > > > > To answer your question, though, if you want to force x to be last, > > then I suggest removing it from the list and then appending it to the > > end. From davidreynon at gmail.com Fri Sep 28 19:51:10 2012 From: davidreynon at gmail.com (dave) Date: Fri, 28 Sep 2012 16:51:10 -0700 (PDT) Subject: creating an artificial "last element" in sort list In-Reply-To: References: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> Message-ID: more clearer, this is a more realistic use case: ['awefawef', 'awefawfsf', 'awefsdf', 'zzzzzzzzzzzzzz', 'zzzzzzzzzzzzzz', 'zzzzzzzzzzzzzz'] and the quantity of ''zzzzzzzzzzzzzz'' would be dynamic. On Friday, September 28, 2012 4:46:15 PM UTC-7, Ian wrote: > > > a = ['a', 'b', x] > > > > > > b = sorted(a) > > > > > > What does x need to be to always be last on an ascending sort no matter what 'a' and 'b' are.... within reason... I am expecting 'a' and 'b' will be not longer than 10 char's long.... I tried making x = 'zzzzzzzzzzzzzzzz' and believe it or not, this appears FIRST on the sort!!! > > > > It appears last when I run the code. > > > > To answer your question, though, if you want to force x to be last, > > then I suggest removing it from the list and then appending it to the > > end. From demianbrecht at gmail.com Fri Sep 28 20:19:22 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Fri, 28 Sep 2012 17:19:22 -0700 Subject: creating an artificial "last element" in sort list In-Reply-To: References: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> Message-ID: Maybe l = filter(a, lambda v: v == a[-1]) sorted(a[:-len(l)]) + l ? On Fri, Sep 28, 2012 at 4:51 PM, dave wrote: > more clearer, this is a more realistic use case: > > ['awefawef', 'awefawfsf', 'awefsdf', 'zzzzzzzzzzzzzz', 'zzzzzzzzzzzzzz', > 'zzzzzzzzzzzzzz'] > > and the quantity of ''zzzzzzzzzzzzzz'' would be dynamic. > > On Friday, September 28, 2012 4:46:15 PM UTC-7, Ian wrote: > > > > > > a = ['a', 'b', x] > > > > > > > > > > b = sorted(a) > > > > > > > > > > What does x need to be to always be last on an ascending sort no > matter what 'a' and 'b' are.... within reason... I am expecting 'a' and 'b' > will be not longer than 10 char's long.... I tried making x = > 'zzzzzzzzzzzzzzzz' and believe it or not, this appears FIRST on the sort!!! > > > > > > > > It appears last when I run the code. > > > > > > > > To answer your question, though, if you want to force x to be last, > > > > then I suggest removing it from the list and then appending it to the > > > > end. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From skunkworks at rikishi42.net Fri Sep 28 20:20:50 2012 From: skunkworks at rikishi42.net (Rikishi42) Date: Sat, 29 Sep 2012 02:20:50 +0200 Subject: Reducing cache/buffer for faster display References: Message-ID: <2grhj9-ofn.ln1@murmur.very.softly> On 2012-09-28, Dennis Lee Bieber wrote: > On Thu, 27 Sep 2012 22:25:39 +0000 (UTC), John Gordon > declaimed the following in gmane.comp.python.general: > >> >> Isn't terminal output line-buffered? I don't understand why there would >> be an output delay. (Unless the "\r" is messing things up...) > > It's the trailing , The \r is being used to reset to the > beginning of the console line, but the comma "says" more output for > /this/ line will be coming... So no output until explicitly flushed, or > a new-line is issued. Well, the \r seems to be the problem, allright. But output was not completely blocked, just delayed a very long time. So perhaps flushing and a sending a newline aren't the only triggers for output. Perhaps there's a maximum delay or a maximum cumulated size, and the output is flushed when such a limit is reached. Anyway, that's mainly academic. I doubt there will be a correction to that behaviour. -- When in doubt, use brute force. -- Ken Thompson From nospam at nospam.com Fri Sep 28 20:21:53 2012 From: nospam at nospam.com (Gilles) Date: Sat, 29 Sep 2012 02:21:53 +0200 Subject: [fcgi.py] Force cache upgrade? References: Message-ID: <1nfc68di85mfuaqm2gggura2bsio7gg4ke@4ax.com> On Fri, 28 Sep 2012 23:57:14 +0200, Gilles wrote: >I guess the FastCGI server (Flup) only updates its cache every so >often. Do I need to type a command to force Flup to recompile the >Python script? Turns out that, yes, mod_fcgid is configured to reload a script only after some time or some number of hits, and yes, mod_fcgid settings are off-limit on a shared host. From dihedral88888 at googlemail.com Fri Sep 28 20:24:59 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 28 Sep 2012 17:24:59 -0700 (PDT) Subject: creating an artificial "last element" in sort list In-Reply-To: References: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> Message-ID: <6646e40a-bb2a-468b-87ab-767b2e6b42d0@googlegroups.com> dave? 2012?9?29????UTC+8??7?51?10???? > more clearer, this is a more realistic use case: > > > > ['awefawef', 'awefawfsf', 'awefsdf', 'zzzzzzzzzzzzzz', 'zzzzzzzzzzzzzz', 'zzzzzzzzzzzzzz'] > > > > and the quantity of ''zzzzzzzzzzzzzz'' would be dynamic. > > > > On Friday, September 28, 2012 4:46:15 PM UTC-7, Ian wrote: > > > > > > > > > a = ['a', 'b', x] > > > > > > > > > > > > > > b = sorted(a) > > > > > > > > > > > > > > What does x need to be to always be last on an ascending sort no matter what 'a' and 'b' are.... within reason... I am expecting 'a' and 'b' will be not longer than 10 char's long.... I tried making x = 'zzzzzzzzzzzzzzzz' and believe it or not, this appears FIRST on the sort!!! > > > > > > > > > > > > It appears last when I run the code. > > > > > > > > > > > > To answer your question, though, if you want to force x to be last, > > > > > > then I suggest removing it from the list and then appending it to the > > > > > > end. I am thinking if it is helpful to preprocess an arbitrary list first into some set of unique ordered elements before a sort. Anyway lists are passed by references to functions in python. From dihedral88888 at googlemail.com Fri Sep 28 20:24:59 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 28 Sep 2012 17:24:59 -0700 (PDT) Subject: creating an artificial "last element" in sort list In-Reply-To: References: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> Message-ID: <6646e40a-bb2a-468b-87ab-767b2e6b42d0@googlegroups.com> dave? 2012?9?29????UTC+8??7?51?10???? > more clearer, this is a more realistic use case: > > > > ['awefawef', 'awefawfsf', 'awefsdf', 'zzzzzzzzzzzzzz', 'zzzzzzzzzzzzzz', 'zzzzzzzzzzzzzz'] > > > > and the quantity of ''zzzzzzzzzzzzzz'' would be dynamic. > > > > On Friday, September 28, 2012 4:46:15 PM UTC-7, Ian wrote: > > > > > > > > > a = ['a', 'b', x] > > > > > > > > > > > > > > b = sorted(a) > > > > > > > > > > > > > > What does x need to be to always be last on an ascending sort no matter what 'a' and 'b' are.... within reason... I am expecting 'a' and 'b' will be not longer than 10 char's long.... I tried making x = 'zzzzzzzzzzzzzzzz' and believe it or not, this appears FIRST on the sort!!! > > > > > > > > > > > > It appears last when I run the code. > > > > > > > > > > > > To answer your question, though, if you want to force x to be last, > > > > > > then I suggest removing it from the list and then appending it to the > > > > > > end. I am thinking if it is helpful to preprocess an arbitrary list first into some set of unique ordered elements before a sort. Anyway lists are passed by references to functions in python. From skunkworks at rikishi42.net Fri Sep 28 20:31:33 2012 From: skunkworks at rikishi42.net (Rikishi42) Date: Sat, 29 Sep 2012 02:31:33 +0200 Subject: Reducing cache/buffer for faster display References: <686fj9-aql.ln1@murmur.very.softly> Message-ID: <54shj9-ofn.ln1@murmur.very.softly> On 2012-09-28, Chris Angelico wrote: > On Fri, Sep 28, 2012 at 10:05 AM, Rikishi42 wrote: >> The scripts in question only increase numbers. But should that not be the >> case, solutions are simple enough. The numbers can be formatted to have a >> fixed size. In the case of random line contents (a list of filesnames, say) >> it's enough to create an output function that is aware of the length of the >> previously printed line, and add enough spaces to the current one to wipe >> exess content. > > Yep, that's a pretty effective way to do it. One simple method to it > is to format the whole string as a single whole, then left justify it > in a field of (say) 79 characters, and output that: > > msg = "Progress: %d%% (%d/%d)... %s" % (done*100/total, done, total, > current_file) > print msg.ljust(79)+"\r", > sys.stdout.flush() Mmm, I allmost went for that. It's elegant, simple and clear. But there's one drawback: I usually reduce the terminal's window to take up less desktop surface during those long runs. So fixing it to 79 chars won't do. And I'm not even tempted to go for a detection of the width of the terminal from within the script. The idea is after all to keep the scripts simple (syntax) and light (execution). Well, good night everyone. -- When in doubt, use brute force. -- Ken Thompson From redstone-cold at 163.com Fri Sep 28 20:31:40 2012 From: redstone-cold at 163.com (iMath) Date: Fri, 28 Sep 2012 17:31:40 -0700 (PDT) Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. Message-ID: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. From demianbrecht at gmail.com Fri Sep 28 20:32:17 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Fri, 28 Sep 2012 17:32:17 -0700 Subject: creating an artificial "last element" in sort list In-Reply-To: References: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> Message-ID: <50664191.3050108@gmail.com> Apparently gmail hates me and my last response didn't get through: a = ['awefawef', 'awefawfsf', 'awefsdf', 'zzzzzzzzzzzzzz', 'zzzzzzzzzzzzzz', 'zzzzzzzzzzzzzz'] f = filter(lambda s: s == a[-1], a) l = sorted(lst[:-len(f)]) + f Now, not 100% sure about efficiency over large sizes of a, but that's a naive stab at it anyway. -- Demian Brecht @demianbrecht http://demianbrecht.github.com From ye.youqun at eisoo.com Fri Sep 28 20:34:04 2012 From: ye.youqun at eisoo.com (=?UTF-8?B?5Y+25L2R576k?=) Date: Sat, 29 Sep 2012 08:34:04 +0800 Subject: how to run shell command like "< References: <506555B6.5040406@eisoo.com> Message-ID: <506641FC.7020607@eisoo.com> ? 2012-9-28 16:16, Kushal Kumaran ??: > On Fri, Sep 28, 2012 at 1:15 PM, ??? wrote: >> Hi, all, >> >> I have the shell command like this: >> >> sfdisk -uM /dev/sdb<< EOT >> ,1000,83 >> ,,83 >> EOT >> >> >> I have tried subprocess.Popen, pexpect.spawn and os.popen, but none of >> these works, but when I type this shell command in shell, it is works fine. >> I wonder how to emulate this type of behavior in python , and if someone can >> figure out the reason why? >> >> The sample code of subprocess.Popen is: >> >> command = ["sfdisk", "-uM", target, "<> ",", 1000, ",", "83", "\r\n", >> ",", ",", "83", "\r\n", "EOT", "\r\n"] >> >> pobj = subprocess.Popen (command, bufsize=1, \ >> stderr=subprocess.PIPE, stdout=subprocess.PIPE) >> >> res = pobj.stderr.readline () >> if res is not None and pobj.returncode != 0: >> observer.ShowProgress (u"??? %s ?????" % target) >> return False >> > The "< command. If you use the communicate method, you can provide input as > an argument: > > command = ["sfdisk", "-uM", target ] > instructions = """ > ,1000,83 > ,,83 > """ > pobj = subprocess.Popen(command, stdin=subprocess.PIPE, > stdout=subprocess.PIPE, stderr=subprocess.PIPE) > (output, errors) = pobj.communicate(instructions) If I want to read the output line by line and not put all output to memory buffer in one time, how to write the code? >> and pexpect code is: >> >> child = pexpect.spawn ("sfdisk -uM /dev/sdb<> child.sendline (....) >> child.sendline (....) >> child.sendline (....) >> >> and os.popen like this: >> >> os.popen ("sfdisk -uM /dev/sdb<> >> I tried "\r\n", and it doesn't work either. >> From tjreedy at udel.edu Fri Sep 28 20:41:38 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 28 Sep 2012 20:41:38 -0400 Subject: print or write on a text file ? In-Reply-To: References: Message-ID: On 9/28/2012 2:42 PM, Franck Ditter wrote: > Hi ! > Here is Python 3.3 > Is it better in any way to use print(x,x,x,file='out') > or out.write(x) ? Any reason to prefer any of them ? print converts objects to strings and adds separators and terminators. If you have a string s and want to output it as is, out.write(s) is perhaps faster. It is 6 chars shorted than print(s, file=out). > There should be a printlines, like readlines ? No, now that files are iterators, I believe readlines is somewhat obsolete. file.readlines() == list(file) The only reason not to deprecate it is for the hint parameter to limit the bytes read. That is little harder to do with the iterator. If you have any iterator of lines, for line in lines: line.print() is quite sufficient. There is little or no need for output limitation. -- Terry Jan Reedy From ye.youqun at eisoo.com Fri Sep 28 20:48:03 2012 From: ye.youqun at eisoo.com (=?UTF-8?B?5Y+25L2R576k?=) Date: Sat, 29 Sep 2012 08:48:03 +0800 Subject: how to run shell command like "< References: <506555B6.5040406@eisoo.com> Message-ID: <50664543.1050809@eisoo.com> ? 2012-9-28 16:16, Kushal Kumaran ??: > On Fri, Sep 28, 2012 at 1:15 PM, ??? wrote: >> Hi, all, >> >> I have the shell command like this: >> >> sfdisk -uM /dev/sdb<< EOT >> ,1000,83 >> ,,83 >> EOT >> >> >> I have tried subprocess.Popen, pexpect.spawn and os.popen, but none of >> these works, but when I type this shell command in shell, it is works fine. >> I wonder how to emulate this type of behavior in python , and if someone can >> figure out the reason why? >> >> The sample code of subprocess.Popen is: >> >> command = ["sfdisk", "-uM", target, "<> ",", 1000, ",", "83", "\r\n", >> ",", ",", "83", "\r\n", "EOT", "\r\n"] >> >> pobj = subprocess.Popen (command, bufsize=1, \ >> stderr=subprocess.PIPE, stdout=subprocess.PIPE) >> >> res = pobj.stderr.readline () >> if res is not None and pobj.returncode != 0: >> observer.ShowProgress (u"??? %s ?????" % target) >> return False >> > The "< command. If you use the communicate method, you can provide input as > an argument: > > command = ["sfdisk", "-uM", target ] > instructions = """ > ,1000,83 > ,,83 > """ > pobj = subprocess.Popen(command, stdin=subprocess.PIPE, > stdout=subprocess.PIPE, stderr=subprocess.PIPE) > (output, errors) = pobj.communicate(instructions) I tried this, but it is still not work. > >> and pexpect code is: >> >> child = pexpect.spawn ("sfdisk -uM /dev/sdb<> child.sendline (....) >> child.sendline (....) >> child.sendline (....) >> >> and os.popen like this: >> >> os.popen ("sfdisk -uM /dev/sdb<> >> I tried "\r\n", and it doesn't work either. >> From demianbrecht at gmail.com Fri Sep 28 20:59:48 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Fri, 28 Sep 2012 17:59:48 -0700 (PDT) Subject: creating an artificial "last element" in sort list In-Reply-To: References: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> Message-ID: <16506499-9803-4f68-8269-f201863574c9@googlegroups.com> > f = filter(lambda s: s == a[-1], a) That line's assuming that the last element may also be found in arbitrary locations in the list. If it's guaranteed that they're all contiguous at the upper bounds, I'd just walk the list backwards until I found one that wasn't matching rather than filtering. From demianbrecht at gmail.com Fri Sep 28 20:59:48 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Fri, 28 Sep 2012 17:59:48 -0700 (PDT) Subject: creating an artificial "last element" in sort list In-Reply-To: References: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> Message-ID: <16506499-9803-4f68-8269-f201863574c9@googlegroups.com> > f = filter(lambda s: s == a[-1], a) That line's assuming that the last element may also be found in arbitrary locations in the list. If it's guaranteed that they're all contiguous at the upper bounds, I'd just walk the list backwards until I found one that wasn't matching rather than filtering. From ppearson at nowhere.invalid Fri Sep 28 21:15:24 2012 From: ppearson at nowhere.invalid (Peter Pearson) Date: 29 Sep 2012 01:15:24 GMT Subject: howto handle nested for References: Message-ID: On Fri, 28 Sep 2012 09:49:36 -0600, Ian Kelly wrote: > > levels = 6 > for combination in itertools.product(xrange(n_syms), levels): > # do stuff >>> n_syms = 3 >>> levels = 6 >>> for combination in itertools.product(xrange(n_syms), levels): ... print combination ... Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not iterable -- To email me, substitute nowhere->spamcop, invalid->net. From buzzard at invalid.invalid Fri Sep 28 21:19:35 2012 From: buzzard at invalid.invalid (duncan smith) Date: Sat, 29 Sep 2012 02:19:35 +0100 Subject: creating an artificial "last element" in sort list In-Reply-To: References: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> Message-ID: <50664122$0$7414$a8266bb1@newsreader.readnews.com> On 29/09/12 00:51, dave wrote: > more clearer, this is a more realistic use case: > > ['awefawef', 'awefawfsf', 'awefsdf', 'zzzzzzzzzzzzzz', 'zzzzzzzzzzzzzz', 'zzzzzzzzzzzzzz'] > > and the quantity of ''zzzzzzzzzzzzzz'' would be dynamic. > Maybe, class Greatest: def __lt__(self, other): return False def __eq__(self, other): return type(other) == type(self) etc. Duncan From python.list at tim.thechases.com Fri Sep 28 21:35:41 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 28 Sep 2012 20:35:41 -0500 Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. In-Reply-To: References: Message-ID: <5066506D.4020702@tim.thechases.com> On 09/28/12 19:31, iMath wrote: > write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. Okay, that was pretty easy. Thanks for the challenge :-) -tkc From no.email at nospam.invalid Fri Sep 28 21:42:27 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 28 Sep 2012 18:42:27 -0700 Subject: creating an artificial "last element" in sort list References: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> Message-ID: <7xlift8v0c.fsf@ruckus.brouhaha.com> dave writes: > What does x need to be to always be last on an ascending sort no > matter what 'a' and 'b' are.... within reason... Why are you trying to do that? It sounds ugly. Just sort the list with the a's and b's. If you absolutely have to, you could make a class with comparison methods that put all the x's at the bottom, but look for something cleaner. From no.email at nospam.invalid Fri Sep 28 21:42:44 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 28 Sep 2012 18:42:44 -0700 Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. References: Message-ID: <7xhaqh8uzv.fsf@ruckus.brouhaha.com> iMath writes: > write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. And then you have two problems. From breamoreboy at yahoo.co.uk Fri Sep 28 21:58:51 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 29 Sep 2012 02:58:51 +0100 Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. In-Reply-To: <5066506D.4020702@tim.thechases.com> References: <5066506D.4020702@tim.thechases.com> Message-ID: On 29/09/2012 02:35, Tim Chase wrote: > On 09/28/12 19:31, iMath wrote: >> write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. > > Okay, that was pretty easy. Thanks for the challenge :-) > > -tkc > What's the run time speed like? How much memory does it use? Shouldn't you be using the regex module from pypi instead of the standard library re? Guess who's borrowed the time machine? -- Cheers. Mark Lawrence. From missive at hotmail.com Fri Sep 28 22:04:00 2012 From: missive at hotmail.com (Lee Harr) Date: Sat, 29 Sep 2012 06:34:00 +0430 Subject: QThread.terminate in Python 3 Message-ID: >> I understand that use of QThread.terminate is discouraged, >> but it has worked well previously and I would like to continue >> this use if possible. >> > ? ? ? And now you've encountered the reason it is discouraged. Ok. Point taken. What I hear you saying is that once I use .terminate anything following that is indeterminate. It might work on my system and nowhere else. Even though it was working for me?before, it was likely causing trouble elsewhere. So, I need another approach. The problem I am facing is that I want to run arbitrary (user-supplied) code in the other thread and need to be able to stop it at any time. This is for a python turtle-graphics application: http://pynguin.googlecode.com/ I found another possible approach here: http://tomerfiliba.com/recipes/Thread2/ It uses ctypes to raise an exception in the other thread. For the simple test case, at least, it works (for me). Is this any safer or more reliable than .terminate ? Is it portable? ie, if I build this in to my actual application and it works for me, is it likely to work for everyone? Thanks for any insight. From steve+comp.lang.python at pearwood.info Fri Sep 28 22:05:15 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Sep 2012 02:05:15 GMT Subject: creating an artificial "last element" in sort list References: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> Message-ID: <5066575b$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 28 Sep 2012 16:39:33 -0700, dave wrote: > a = ['a', 'b', x] > b = sorted(a) > > What does x need to be to always be last on an ascending sort no matter > what 'a' and 'b' are.... within reason... How about this? a = ['a', 'b'] b = sorted(a) + ['whatever you want'] You could also do this: x = max(a) a.append(x) b = sorted(a) > I am expecting 'a' and 'b' > will be not longer than 10 char's long.... I tried making x = > 'zzzzzzzzzzzzzzzz' and believe it or not, this appears FIRST on the > sort!!! I think you are mistaken. py> sorted(['a', 'b', 'zzzzzzzzzzzzzzzz']) ['a', 'b', 'zzzzzzzzzzzzzzzz'] But really, I don't understand what problem you are trying to solve. Perhaps if you explain the purpose of this, we can suggest a solution. -- Steven From python.list at tim.thechases.com Fri Sep 28 22:17:07 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 28 Sep 2012 21:17:07 -0500 Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. In-Reply-To: References: <5066506D.4020702@tim.thechases.com> Message-ID: <50665A23.1060300@tim.thechases.com> On 09/28/12 20:58, Mark Lawrence wrote: > On 29/09/2012 02:35, Tim Chase wrote: >> On 09/28/12 19:31, iMath wrote: >>> write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. >> >> Okay, that was pretty easy. Thanks for the challenge :-) > > What's the run time speed like? O(1) r = re.compile( "800-555-1212|" "555-1212|" r"\(800\) 555-1212" ) (okay, so I also have one that solves the OP's underqualified problem, but without the OP at least *trying* to code up an answer and asking for help with it, I've give the snarky solution :-) > How much memory does it use? Insignificant. > Shouldn't you be using the regex module from pypi instead of the > standard library re? Only if the OP requested it ;-) > Guess who's borrowed the time machine? Neutrino! -tkc From fpesposito at gmail.com Fri Sep 28 22:39:32 2012 From: fpesposito at gmail.com (FPEFPE) Date: Fri, 28 Sep 2012 19:39:32 -0700 (PDT) Subject: Missing library path (WIndows) Message-ID: <8cab2c34-7594-471a-80e9-47206bd3ea32@googlegroups.com> Hello -- I am running python from an application, starting it with a call to the python31.dll I think I am missing something in my path -- any help would be appreciated -- thanks Here is the script and the output --- # this is a test import sys print('hello from python') print('Number of arguments:', len(sys.argv), 'arguments.') print('Argument List:', str(sys.argv)) #--------------------------------------------------# # o u t p u t # #--------------------------------------------------# Argument List: hello from python Number of arguments: 5 arguments. Traceback (most recent call last): File "", line 1, in File "C:/DOCUME~1/Frank/LOCALS~1/Temp/foo.py", line 10, in print('Argument List:', str(sys.argv)) File "C:\Python32\Lib\encodings\cp437.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode characters in position 2-18: character maps to From steve+comp.lang.python at pearwood.info Fri Sep 28 23:07:21 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Sep 2012 03:07:21 GMT Subject: Article on the future of Python References: <5063ee76$0$29997$c3e8da3$5496439d@news.astraweb.com> <506461bc$0$29981$c3e8da3$5496439d@news.astraweb.com> <0ac0d6c8-3fda-4b4c-afd6-01cc36019aaa@lo4g2000pbb.googlegroups.com> Message-ID: <506665e8$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 28 Sep 2012 14:50:14 -0400, Devin Jeanpierre wrote: > I'm pretty sure nobody thinks Python is on a death march. Don't be so sure. There's always *someone* complaining about something, and they're usually convinced that (Language X) is on it's last legs because (feature Y) is missing or (event Z) happened. Seriously. If you believe the haters and the complainers, Python will never be taken seriously as a language because: - it has significant whitespace. - it doesn't have braces. - it doesn't have static typing. - Python is too slow. - it has lost momentum to Ruby on RAILS. - it has lost momentum to Javascript. - it doesn't have a real garbage collector that can collect cycles. - oh, Python has had one of those for a decade? I meant a garbage collector that can collect cycles involving objects with __del__ methods. - threads aren't exactly like threads in some other language. - Python only uses a single core of the CPU. - I mean CPython. IronPython and Jython don't count. - I mean ordinary Python code, using multiprocessing doesn't count. - Neither do C extensions or numpy. - Python changes too fast. People can't keep up. Python should be an ISO standard managed by a committee, like C, with a guarantee that 30 year old code will run in the latest version. - Python changes too slow. People can't use all these great new features. It has gotten too big and the developers care too much about backward compatibility and aren't willing to delete cruft from the language. - you can't compile to native machine code. No language can possibly be successful with byte-code running in a virtual machine. - it isn't a pure object-oriented language exactly like Java. - you can't hide your source code from the end user. People will STEEEAAAAAL MY INTELLECTUUUUUUUALLLLLL PROPERTY!!! - oh, you can? Yeah, but it's too hard, and besides they might decompile the .pyc files. - Python 3 is a failure and has split the community. I think I've got all the most common reasons for dismissing Python. "Python has lost ground to Flash" is a new one for me, as is "Python ate my mobile phone's batteries". In a way, it's quite unfortunate that you can't write a blog post discussing weaknesses of a language (as opposed to strengths) without turning it into fuel for the haters: http://news.ycombinator.com/item?id=4567023 But when you give a blog post an inflammatory title like "I am worried about the future of Python", what do you expect? -- Steven From steve+comp.lang.python at pearwood.info Fri Sep 28 23:20:19 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Sep 2012 03:20:19 GMT Subject: data attributes override method attributes? References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Message-ID: <506668f3$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 28 Sep 2012 18:02:04 +0000, Prasad, Ramit wrote: > Just to make sure I am following, if you call foo.__len__() it goes to > the instance code while if you do len(foo) it will go to > class.__len__()? If you call foo.__len__, the attribute lookup of __len__ will use the exact same search path as foo.spam would use: 1) does __getattribute__ exist and intercept the call? 2) if not, does a instance attribute exist? 3) if not, does a class attribute exist? 4) if not, does a superclass attribute exist? 5) if not, does __getattr__ exist and intercept the call? Using len(foo) bypasses steps 1) and 2) as a speed optimization. For the common case where an instance's class directly defines a __len__ method, that saves about 10-15% of the overhead of calling a special method, compared to old-style classes. -- Steven From ian.g.kelly at gmail.com Fri Sep 28 23:25:35 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 28 Sep 2012 21:25:35 -0600 Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. In-Reply-To: <50665A23.1060300@tim.thechases.com> References: <5066506D.4020702@tim.thechases.com> <50665A23.1060300@tim.thechases.com> Message-ID: On Fri, Sep 28, 2012 at 8:17 PM, Tim Chase wrote: > On 09/28/12 20:58, Mark Lawrence wrote: >> On 29/09/2012 02:35, Tim Chase wrote: >>> On 09/28/12 19:31, iMath wrote: >>>> write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. >>> >>> Okay, that was pretty easy. Thanks for the challenge :-) >> >> What's the run time speed like? > > O(1) > > r = re.compile( > "800-555-1212|" > "555-1212|" > r"\(800\) 555-1212" > ) Mine is simpler and faster. r = re.compile("") From ian.g.kelly at gmail.com Fri Sep 28 23:29:53 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 28 Sep 2012 21:29:53 -0600 Subject: creating an artificial "last element" in sort list In-Reply-To: <16506499-9803-4f68-8269-f201863574c9@googlegroups.com> References: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> <16506499-9803-4f68-8269-f201863574c9@googlegroups.com> Message-ID: On Fri, Sep 28, 2012 at 6:59 PM, Demian Brecht wrote: >> f = filter(lambda s: s == a[-1], a) > > That line's assuming that the last element may also be found in arbitrary locations in the list. If it's guaranteed that they're all contiguous at the upper bounds, I'd just walk the list backwards until I found one that wasn't matching rather than filtering. The slicing operation in the second line assumes that they're all collected at the end of the list anyway. From steve+comp.lang.python at pearwood.info Fri Sep 28 23:30:17 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Sep 2012 03:30:17 GMT Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. References: <5066506D.4020702@tim.thechases.com> <50665A23.1060300@tim.thechases.com> Message-ID: <50666b49$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 28 Sep 2012 21:25:35 -0600, Ian Kelly wrote: > Mine is simpler and faster. > > r = re.compile("") The OP doesn't say that you have to compile it, so just: '' wins. -- Steven From python.list at tim.thechases.com Fri Sep 28 23:42:23 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 28 Sep 2012 22:42:23 -0500 Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. In-Reply-To: References: <5066506D.4020702@tim.thechases.com> <50665A23.1060300@tim.thechases.com> Message-ID: <50666E1F.2010908@tim.thechases.com> On 09/28/12 22:25, Ian Kelly wrote: > On Fri, Sep 28, 2012 at 8:17 PM, Tim Chase >>>> On 09/28/12 19:31, iMath wrote: >>>>> write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. >> >> r = re.compile( >> "800-555-1212|" >> "555-1212|" >> r"\(800\) 555-1212" >> ) > > Mine is simpler and faster. > > r = re.compile("") doh! ?smacks forehead? Yours is FAR more efficient, and much more readable than mine. iMath's teacher will be pleased :-) -tkc From python.list at tim.thechases.com Fri Sep 28 23:50:10 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 28 Sep 2012 22:50:10 -0500 Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. In-Reply-To: <50666b49$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <5066506D.4020702@tim.thechases.com> <50665A23.1060300@tim.thechases.com> <50666b49$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50666FF2.6040507@tim.thechases.com> On 09/28/12 22:30, Steven D'Aprano wrote: > On Fri, 28 Sep 2012 21:25:35 -0600, Ian Kelly wrote: > >> Mine is simpler and faster. >> >> r = re.compile("") > > The OP doesn't say that you have to compile it, so just: > > '' > > wins. OP doesn't say it even has to be a string, so I guess wins. :-P It's-too-late-on-a-Friday-night'ly yers, -tkc From demianbrecht at gmail.com Sat Sep 29 00:21:01 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Fri, 28 Sep 2012 21:21:01 -0700 Subject: creating an artificial "last element" in sort list In-Reply-To: References: <7cd170ac-bb14-4baa-93ea-530c569d3985@googlegroups.com> <16506499-9803-4f68-8269-f201863574c9@googlegroups.com> Message-ID: On Fri, Sep 28, 2012 at 8:29 PM, Ian Kelly wrote: > The slicing operation in the second line assumes that they're all > collected at the end of the list anyway. > True enough. Hadn't considered otherwise when I first whipped that off with the first example (thinking/trying it out *before* posting would likely be a good idea ;)). >>> a = ['z'*5, 'b', 'a', 'c', 'z'*5] >>> b = filter(lambda n: n == a[-1], a) >>> c = filter(lambda n: n != a[-1], a) >>> d = sorted(c) + b ['a', 'b', 'c', 'zzzzz', 'zzzzz'] It does the trick for what he was asking in the original question, although there are likely more optimal solutions for a sufficiently large a. As Steven noted, it definitely would help to get a little more information about the specific problem. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fgnu32 at yahoo.com Sat Sep 29 00:25:26 2012 From: fgnu32 at yahoo.com (Fg Nu) Date: Fri, 28 Sep 2012 21:25:26 -0700 (PDT) Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. In-Reply-To: <50666E1F.2010908@tim.thechases.com> References: <5066506D.4020702@tim.thechases.com> <50665A23.1060300@tim.thechases.com> <50666E1F.2010908@tim.thechases.com> Message-ID: <1348892726.87964.YahooMailNeo@web122401.mail.ne1.yahoo.com> ----- Original Message ----- From: Tim Chase To: Ian Kelly Cc: Python Sent: Saturday, September 29, 2012 9:12 AM Subject: Re: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. On 09/28/12 22:25, Ian Kelly wrote: > On Fri, Sep 28, 2012 at 8:17 PM, Tim Chase >>>> On 09/28/12 19:31, iMath wrote: >>>>> write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. >> >> r = re.compile( >>? ? "800-555-1212|" >>? ? "555-1212|" >>? ? r"\(800\) 555-1212" >>? ? ) > > Mine is simpler and faster. > > r = re.compile("") doh!? ?smacks forehead?? Yours is FAR more efficient, and much more readable than mine.? iMath's teacher will be pleased :-) -tkc lulz. -- http://mail.python.org/mailman/listinfo/python-list From jeanpierreda at gmail.com Sat Sep 29 00:25:50 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 29 Sep 2012 00:25:50 -0400 Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. In-Reply-To: References: <5066506D.4020702@tim.thechases.com> Message-ID: On Fri, Sep 28, 2012 at 9:58 PM, Mark Lawrence wrote: > What's the run time speed like? How much memory does it use? Shouldn't you > be using the regex module from pypi instead of the standard library re? > Guess who's borrowed the time machine? O(n), O(1), and I used RE2. -- Devin From clp2 at rebertia.com Sat Sep 29 00:27:13 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 28 Sep 2012 21:27:13 -0700 Subject: How to pass FILE * In-Reply-To: <201209281455.07702.thudfoo@gmail.com> References: <201209281455.07702.thudfoo@gmail.com> Message-ID: On Fri, Sep 28, 2012 at 2:55 PM, xDog Walker wrote: > > The function I am trying to call wants a FILE *: > > dlg_progressbox(const char *title, > const char *cprompt, > int height, > int width, > int pauseopt, > FILE *fp) > > I can open the file to be referenced: > > fp = os.fdopen(self.pipefds[0], 'r') > > Every thing I've tried ends with ctypes raising a TypeError. What specifically did you try? A tiny bit of googling suggests the following approach: http://stackoverflow.com/questions/3794309/python-ctypes-python-file-object-c-file/3794401#3794401 Related POSIX docs: http://pubs.opengroup.org/onlinepubs/009695399/functions/fdopen.html Cheers, Chris From kwpolska at gmail.com Sat Sep 29 04:01:26 2012 From: kwpolska at gmail.com (Kwpolska) Date: Sat, 29 Sep 2012 10:01:26 +0200 Subject: Missing library path (WIndows) In-Reply-To: <8cab2c34-7594-471a-80e9-47206bd3ea32@googlegroups.com> References: <8cab2c34-7594-471a-80e9-47206bd3ea32@googlegroups.com> Message-ID: On Sat, Sep 29, 2012 at 4:39 AM, FPEFPE wrote: > Hello -- I am running python from an application, starting it with a call to the python31.dll > > I think I am missing something in my path -- any help would be appreciated -- thanks Nope, you are not. > File "C:\Python32\Lib\encodings\cp437.py", line 19, in encode > > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > > UnicodeEncodeError: 'charmap' codec can't encode characters in position 2-18: character maps to > -- > http://mail.python.org/mailman/listinfo/python-list Python has problems with encoding the arguments to look properly with the crappy Windows cmd.exe encodings. They cannot be encoded for some reason. You may need magic, but I?m not quite sure what in Py3k (bytestrings?) -- Kwpolska stop html mail | always bottom-post www.asciiribbon.org | www.netmeister.org/news/learn2quote.html GPG KEY: 5EAAEA16 From thudfoo at gmail.com Sat Sep 29 04:45:19 2012 From: thudfoo at gmail.com (xDog Walker) Date: Sat, 29 Sep 2012 01:45:19 -0700 Subject: How to pass FILE * In-Reply-To: References: <201209281455.07702.thudfoo@gmail.com> Message-ID: <201209290145.19962.thudfoo@gmail.com> On Friday 2012 September 28 21:27, you wrote: > A tiny bit of googling suggests the following approach: > http://stackoverflow.com/questions/3794309/python-ctypes-python-file-object >-c-file/3794401#3794401 Thanks for your response. My "tiny bit of Googling" brought no joy but I did try successfully the same method suggested by Alex Martelli: use libc's fdopen to get a FILE * for ctypes. I would have posted a reply to my own post but it didn't show up. -- Yonder nor sorghum stenches shut ladle gulls stopper torque wet strainers. From andriy.kornatskyy at live.com Sat Sep 29 05:18:32 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Sat, 29 Sep 2012 12:18:32 +0300 Subject: Fastest web framework In-Reply-To: <5062CDC6.40703@ziade.org> References: , <50604907.6060405@ziade.org> , <5062C603.90905@ziade.org> , <5062CDC6.40703@ziade.org> Message-ID: Tarek, My response inline to your: > You are not getting my point. What happens to weezhy or XXX framework > when you are running it in a given stack, under heavy load ? let me correct you, it is wheezy.web (not `weezhy`). Tell me your definition of web framework heavy load. If you have one, we can try benchmark it. > There are many interactions that may impact the behavior of the stack - > most of them are in the web server itself, but they can be things in the > framework too, depending on the architectural choice. The reason I choose uWSGI is due to minimal possible impact that application server may cause. Since this component `equally influence` productivity of each framework it can be to some degree ignored. > And you will not know it with an hello world app. To put it more > bluntly, your benchmark is going to join the big pile of hello worlds > benchmarks that are completely meaningless. Can not agree. This is just simple thing. Simple things should run fast, no doubt. If you can provide a better idea as to which framework calls to put into benchmark,?I will be happy extend the benchmark case. > If you want to prove that weezhy is faster than another py framework, > because, I dunno, the number of function calls are smaller ? then you > need to isolate this and > do a different kind of bench. > > Have a look at http://plope.com/pyroptimization , it's a good example The numbers provided in that article are incorrect. They didn't match results from the file they provide (result.txt in each framework dir) at the time? of writing. I have used that idea to re-run things (isolated benchmark; report with? total time, total number of calls and number of distinct functions used). See here: https://bitbucket.org/akorn/helloworld/src/tip/benchmark.py I will update original post a bit later (to let you comment on this). > Same thing for the raw speed of your templating engine - isolation is > required. Improved bigtable benchmark report by adding total number of calls and number distinct functions used: https://bitbucket.org/akorn/wheezy.template/src/tip/demos/bigtable/bigtable.py Original post not updated yet. > One good read: > http://blog.ianbicking.org/2010/03/16/web-server-benchmarking-we-need/ Sounds not so bad. It points to some specific workloads. Any attempt to prioritize and/or practically implement them? Thanks. Andriy ---------------------------------------- > Date: Wed, 26 Sep 2012 11:41:26 +0200 > From: tarek at ziade.org > To: andriy.kornatskyy at live.com > CC: python-list at python.org > Subject: Re: Fastest web framework > > On 9/26/12 11:26 AM, Andriy Kornatskyy wrote: > > Tarek, > > > > Thank you for the response back. Yes, your idea is pretty clear to me. The point is that higher workload you put in your application business logic, repository, backend, whatever... less you will see in final results comparison. This is obvious and we, as technical people, very well understand this (somebody even laugh). > > I am happy somebody got a good laugh, I had a myself a good coffee :) > > > The reality is that not all web applications do heavy CPU computations and/or experience IO delays (due to response from database running a query over table that has no index, let say), some use caches, some split jobs to be run in background, some parallel them... I have to state that simple things must perform really fast to give more room for one that are not so. That in turn makes your infrastructure more effective. Some prefer to add a box, some see that a likely to be a problem further it goes. The good thing - you have a choice, you are not locked, and as result you are responsible for the effectiveness of the system you build today and definitely next one. > > > > Take care. > > > > Andriy > > You are not getting my point. What happens to weezhy or XXX framework > when you are running it in a given stack, under heavy load ? > > There are many interactions that may impact the behavior of the stack - > most of them are in the web server itself, but they can be things in the > framework too, depending on the architectural choice. > > And you will not know it with an hello world app. To put it more > bluntly, your benchmark is going to join the big pile of hello worlds > benchmarks that are completely meaningless. > > If you want to prove that weezhy is faster than another py framework, > because, I dunno, the number of function calls are smaller ? then you > need to isolate this and > do a different kind of bench. > > Have a look at http://plope.com/pyroptimization , it's a good example > > Same thing for the raw speed of your templating engine - isolation is > required. > > One good read: > http://blog.ianbicking.org/2010/03/16/web-server-benchmarking-we-need/ > > > Cheers > Tarek > > > > > > > ---------------------------------------- > >> Date: Wed, 26 Sep 2012 11:08:19 +0200 > >> From: tarek at ziade.org > >> To: andriy.kornatskyy at live.com > >> CC: python-list at python.org > >> Subject: Re: Fastest web framework > >> > >> On 9/25/12 3:21 PM, Andriy Kornatskyy wrote: > >>> Tarek, > >>> > >>> With all respect, running benchmark on something that has sleeps, etc is pretty far from real world use case. So I went a little bit different way. > >> That's not a good summary of what the function does. It does not just > >> sleep. It does some I/O and CPU bound tasks. The sleep is here to > >> simulate a blocking I/O call, besides the DB calls. > >> > >> The whole function tries to simulate a real application, unlike printing > >> 'Hello World' - to put the stack under realistic conditions. > >> > >> The multiplication is cached by the processor, but will still push some > >> CPU work on every call. > >> > >>> Here is a live demo (a semi real world web application) that comes with wheezy.web framework as a template: > >>> > >>> http://wheezy.pythonanywhere.com/ > >>> > >>> I have implemented it in a way that it uses one web framework (wheezy.web) and various template engines (jinja2, mako, tenjin, wheezy.template and wheezy.template with preprocessor)... Please see the following post under `Real World Example` section: > >>> > >>> http://mindref.blogspot.com/2012/07/python-fastest-template.html > >>> > >>> Source code here: > >>> > >>> https://bitbucket.org/akorn/wheezy.web/src/tip/demos/template > >>> > >>> The real world example shows the difference between template engines implementing the same things. The same applies to web frameworks (more or less depending on your choice). > >>> > >>> Thanks. > >> Great, thanks for the update ! -- that's cool to bench the template > >> engines, but this is still not what I had in mind. > >> > >> What I had in mind was to try each one of the framework with an > >> application that does things, and see how the whole stack reacts on high > >> load. > >> > >> But I guess we have different goals - wheezy seems really fast, congrats. > >> > >> > >> Cheers > >> Tarek > >> > >>> Andriy > >>> > >>> > >>> ---------------------------------------- > >>>> Date: Mon, 24 Sep 2012 13:50:31 +0200 > >>>> From: tarek at ziade.org > >>>> To: python-list at python.org > >>>> Subject: Re: Fastest web framework > >>>> > >>>> On 9/23/12 11:19 AM, Andriy Kornatskyy wrote: > >>>>> I have run recently a benchmark of a trivial 'hello world' application for various python web frameworks (bottle, django, flask, pyramid, web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find it interesting: > >>>>> > >>>>> http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > >>>>> > >>>>> Comments or suggestions are welcome. > >>>>> > >>>>> Thanks. > >>>>> > >>>>> Andriy Kornatskyy > >>>>> > >>>> I would try this with a web app that does more than 'Hello World' > >>>> > >>>> You may argue that you're just trying the server stack, but that's not > >>>> realistic because you don't really measure how the server behaves with a > >>>> real app. > >>>> > >>>> Have a look at > >>>> https://github.com/mozilla-services/chaussette/blob/master/chaussette/util.py#L188 > >>>> > >>>> (setup_bench and teardow_bench have to be run on startup and tear down > >>>> of the server) > >>>> > >>>> I would be curious to see how things goes then > >>>> > >>>> Cheers > >>>> Tarek > >>>> -- > >>>> http://mail.python.org/mailman/listinfo/python-list > > > From stefan_ml at behnel.de Sat Sep 29 05:19:51 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 29 Sep 2012 11:19:51 +0200 Subject: How to pass FILE * In-Reply-To: <201209290145.19962.thudfoo@gmail.com> References: <201209281455.07702.thudfoo@gmail.com> <201209290145.19962.thudfoo@gmail.com> Message-ID: xDog Walker, 29.09.2012 10:45: > On Friday 2012 September 28 21:27, you wrote: >> A tiny bit of googling suggests the following approach: >> http://stackoverflow.com/questions/3794309/python-ctypes-python-file-object >> -c-file/3794401#3794401 > > Thanks for your response. > > My "tiny bit of Googling" brought no joy but I did try successfully the same > method suggested by Alex Martelli: use libc's fdopen to get a FILE * for > ctypes. I would have posted a reply to my own post but it didn't show up. Given your second post on stackoverflow, you may also consider switching from ctypes to Cython. It makes these things a bit more straight forward. Stefan From breamoreboy at yahoo.co.uk Sat Sep 29 05:38:17 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 29 Sep 2012 10:38:17 +0100 Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. In-Reply-To: <50666b49$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <5066506D.4020702@tim.thechases.com> <50665A23.1060300@tim.thechases.com> <50666b49$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29/09/2012 04:30, Steven D'Aprano wrote: > On Fri, 28 Sep 2012 21:25:35 -0600, Ian Kelly wrote: > >> Mine is simpler and faster. >> >> r = re.compile("") > > The OP doesn't say that you have to compile it, so just: > > '' > > wins. > > > My understanding is that Python 3.3 has regressed the performance of ''. Surely the Python devs can speed the performance back up and, just for us, use less memory at the same time? -- Cheers. Mark Lawrence. From rosuav at gmail.com Sat Sep 29 06:05:33 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Sep 2012 20:05:33 +1000 Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. In-Reply-To: References: <5066506D.4020702@tim.thechases.com> <50665A23.1060300@tim.thechases.com> <50666b49$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 29, 2012 at 7:38 PM, Mark Lawrence wrote: > > My understanding is that Python 3.3 has regressed the performance of ''. > Surely the Python devs can speed the performance back up and, just for us, > use less memory at the same time? Yes, but to do that we'd have to make Python more Australia-focused instead of US-centric. As of Python 3.4, the empty string will be lazily evaluated and be delimited by redback spiders instead of quotes. That will give a 25% speed and 50% memory usage improvement, but you'll need to be careful you don't get bitten. ChrisA From breamoreboy at yahoo.co.uk Sat Sep 29 06:50:04 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 29 Sep 2012 11:50:04 +0100 Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. In-Reply-To: References: <5066506D.4020702@tim.thechases.com> <50665A23.1060300@tim.thechases.com> <50666b49$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29/09/2012 11:05, Chris Angelico wrote: > On Sat, Sep 29, 2012 at 7:38 PM, Mark Lawrence wrote: >> >> My understanding is that Python 3.3 has regressed the performance of ''. >> Surely the Python devs can speed the performance back up and, just for us, >> use less memory at the same time? > > Yes, but to do that we'd have to make Python more Australia-focused > instead of US-centric. As of Python 3.4, the empty string will be > lazily evaluated and be delimited by redback spiders instead of > quotes. That will give a 25% speed and 50% memory usage improvement, > but you'll need to be careful you don't get bitten. > > ChrisA > I'll happily admit that I don't like the way this is going. Do you (plural) think we should take this across to python ideas? -- Cheers. Mark Lawrence. From kushal.kumaran+python at gmail.com Sat Sep 29 07:53:31 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Sat, 29 Sep 2012 17:23:31 +0530 Subject: how to run shell command like "< References: <506555B6.5040406@eisoo.com> <50664543.1050809@eisoo.com> Message-ID: On Sat, Sep 29, 2012 at 6:18 AM, ??? wrote: > ? 2012-9-28 16:16, Kushal Kumaran ??: >> >> On Fri, Sep 28, 2012 at 1:15 PM, ??? wrote: >> >>> Hi, all, >>> >>> I have the shell command like this: >>> >>> sfdisk -uM /dev/sdb<< EOT >>> ,1000,83 >>> ,,83 >>> EOT >>> >>> >>> I have tried subprocess.Popen, pexpect.spawn and os.popen, but none >>> of >>> these works, but when I type this shell command in shell, it is works >>> fine. >>> I wonder how to emulate this type of behavior in python , and if someone >>> can >>> figure out the reason why? >>> >>> The sample code of subprocess.Popen is: >>> >>> command = ["sfdisk", "-uM", target, "<>> ",", 1000, ",", "83", "\r\n", >>> ",", ",", "83", "\r\n", "EOT", "\r\n"] >>> >>> pobj = subprocess.Popen (command, bufsize=1, \ >>> stderr=subprocess.PIPE, stdout=subprocess.PIPE) >>> >>> res = pobj.stderr.readline () >>> if res is not None and pobj.returncode != 0: >>> observer.ShowProgress (u"??? %s ?????" % target) >>> return False >>> >> The "<> command. If you use the communicate method, you can provide input as >> an argument: >> >> command = ["sfdisk", "-uM", target ] >> instructions = """ >> ,1000,83 >> ,,83 >> """ >> pobj = subprocess.Popen(command, stdin=subprocess.PIPE, >> stdout=subprocess.PIPE, stderr=subprocess.PIPE) >> (output, errors) = pobj.communicate(instructions) > > I tried this, but it is still not work. > What do you mean by "not work"? - If you get an exception, copy the entire traceback into an email - If you do not get an exception, print out the value of the "errors" variable to see why the command failed. You can also check pobj.returncode for the exit status of the subprocess. A possibility is that you have to replace "sfdisk" with the full path to the binary, if it cannot be located on the PATH. So you will replace it with "/usr/sbin/sfdisk", or "/sbin/sfdisk", or wherever the file actually is. > If I want to read the output line by line and not put all output to memory buffer in one > time, how to write the code? You can read line by line by calling pobj.stdout.readline() and pobj.stderr.readline(). You can send input to the process by calling pobj.stdin.write(). If you manage this interaction "by hand", you should not call communicate(). Also, you should be aware of the problem mentioned in the subprocess documentation: "Use communicate() rather than .stdin.write, .stdout.read or .stderr.read to avoid deadlocks due to any of the other OS pipe buffers filling up and blocking the child process." Is there any reason why you need to read line-by-line? You could use communicate(), and then call stdout.splitlines() to get a list of lines, if that's all you need. -- regards, kushal From georg at python.org Sat Sep 29 08:18:54 2012 From: georg at python.org (Georg Brandl) Date: Sat, 29 Sep 2012 14:18:54 +0200 Subject: [RELEASED] Python 3.3.0 Message-ID: <5066E72E.2010100@python.org> On behalf of the Python development team, I'm delighted to announce the Python 3.3.0 final release. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. Major new features and changes in the 3.3 release series are: * PEP 380, syntax for delegating to a subgenerator ("yield from") * PEP 393, flexible string representation (doing away with the distinction between "wide" and "narrow" Unicode builds) * A C implementation of the "decimal" module, with up to 120x speedup for decimal-heavy applications * The import system (__import__) now based on importlib by default * The new "lzma" module with LZMA/XZ support * PEP 397, a Python launcher for Windows * PEP 405, virtual environment support in core * PEP 420, namespace package support * PEP 3151, reworking the OS and IO exception hierarchy * PEP 3155, qualified name for classes and functions * PEP 409, suppressing exception context * PEP 414, explicit Unicode literals to help with porting * PEP 418, extended platform-independent clocks in the "time" module * PEP 412, a new key-sharing dictionary implementation that significantly saves memory for object-oriented code * PEP 362, the function-signature object * The new "faulthandler" module that helps diagnosing crashes * The new "unittest.mock" module * The new "ipaddress" module * The "sys.implementation" attribute * A policy framework for the email package, with a provisional (see PEP 411) policy that adds much improved unicode support for email header parsing * A "collections.ChainMap" class for linking mappings to a single unit * Wrappers for many more POSIX functions in the "os" and "signal" modules, as well as other useful functions such as "sendfile()" * Hash randomization, introduced in earlier bugfix releases, is now switched on by default In total, almost 500 API items are new or improved in Python 3.3. For a more extensive list of changes in 3.3.0, see http://docs.python.org/3.3/whatsnew/3.3.html To download Python 3.3.0 visit: http://www.python.org/download/releases/3.3.0/ This is a production release, please report any bugs to http://bugs.python.org/ Enjoy! -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) From amitsaha.in at gmail.com Sat Sep 29 08:23:49 2012 From: amitsaha.in at gmail.com (Amit Saha) Date: Sat, 29 Sep 2012 22:23:49 +1000 Subject: [Python-Dev] [RELEASED] Python 3.3.0 In-Reply-To: <5066E72E.2010100@python.org> References: <5066E72E.2010100@python.org> Message-ID: On Sat, Sep 29, 2012 at 10:18 PM, Georg Brandl wrote: > On behalf of the Python development team, I'm delighted to announce the > Python 3.3.0 final release. > > Python 3.3 includes a range of improvements of the 3.x series, as well > as easier porting between 2.x and 3.x. Major new features and changes > in the 3.3 release series are: > > * PEP 380, syntax for delegating to a subgenerator ("yield from") > * PEP 393, flexible string representation (doing away with the > distinction between "wide" and "narrow" Unicode builds) > * A C implementation of the "decimal" module, with up to 120x speedup > for decimal-heavy applications > * The import system (__import__) now based on importlib by default > * The new "lzma" module with LZMA/XZ support > * PEP 397, a Python launcher for Windows > * PEP 405, virtual environment support in core > * PEP 420, namespace package support > * PEP 3151, reworking the OS and IO exception hierarchy > * PEP 3155, qualified name for classes and functions > * PEP 409, suppressing exception context > * PEP 414, explicit Unicode literals to help with porting > * PEP 418, extended platform-independent clocks in the "time" module > * PEP 412, a new key-sharing dictionary implementation that > significantly saves memory for object-oriented code > * PEP 362, the function-signature object > * The new "faulthandler" module that helps diagnosing crashes > * The new "unittest.mock" module > * The new "ipaddress" module > * The "sys.implementation" attribute > * A policy framework for the email package, with a provisional (see > PEP 411) policy that adds much improved unicode support for email > header parsing > * A "collections.ChainMap" class for linking mappings to a single unit > * Wrappers for many more POSIX functions in the "os" and "signal" > modules, as well as other useful functions such as "sendfile()" > * Hash randomization, introduced in earlier bugfix releases, is now > switched on by default > > In total, almost 500 API items are new or improved in Python 3.3. > For a more extensive list of changes in 3.3.0, see > > http://docs.python.org/3.3/whatsnew/3.3.html Redirects to http://docs.python.org/py3k/whatsnew/3.3.html: 404 Not Found. Cheers, Amit. -- http://echorand.me From hansmu at xs4all.nl Sat Sep 29 08:32:21 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 29 Sep 2012 14:32:21 +0200 Subject: Reducing cache/buffer for faster display In-Reply-To: <2grhj9-ofn.ln1@murmur.very.softly> References: <2grhj9-ofn.ln1@murmur.very.softly> Message-ID: <5066ea55$0$6914$e4fe514c@news2.news.xs4all.nl> On 29/09/12 02:20:50, Rikishi42 wrote: > On 2012-09-28, Dennis Lee Bieber wrote: >> On Thu, 27 Sep 2012 22:25:39 +0000 (UTC), John Gordon >> declaimed the following in gmane.comp.python.general: >> >>> >>> Isn't terminal output line-buffered? I don't understand why there would >>> be an output delay. (Unless the "\r" is messing things up...) >> >> It's the trailing , The \r is being used to reset to the >> beginning of the console line, but the comma "says" more output for >> /this/ line will be coming... So no output until explicitly flushed, or >> a new-line is issued. > > Well, the \r seems to be the problem, allright. > But output was not completely blocked, just delayed a very long time. > > So perhaps flushing and a sending a newline aren't the only triggers for > output. Perhaps there's a maximum delay or a maximum cumulated size, and > the output is flushed when such a limit is reached. There's a maximum cumulated size; it's called the buffer size. Output goes into a buffer, and when the buffer is full, it's printed all at once. One way to avoid it, is to use an unbuffered stream. Another, more efficient, way to avoid it, is to invoke the stream's .flush() method after writing to it. > Anyway, that's mainly academic. I doubt there will be a correction to > that behaviour. It's an optimization. When it was invented, 40 years ago, it was a really necessary to do this, to get something resembling performance. The performance of a system without stream buffering would probably be tolerable on modern hardware. But the people maintaining Python are unlikely to cut out buffering, because few people would benefit (yours is pretty much the only use case where buffereing hurts) and some would suffer (those who write many short strings to a disk file). Hope this helps, -- HansM From d at davea.name Sat Sep 29 08:37:16 2012 From: d at davea.name (Dave Angel) Date: Sat, 29 Sep 2012 08:37:16 -0400 Subject: [Python-Dev] [RELEASED] Python 3.3.0 In-Reply-To: References: <5066E72E.2010100@python.org> Message-ID: <5066EB7C.10407@davea.name> On 09/29/2012 08:23 AM, Amit Saha wrote: > On Sat, Sep 29, 2012 at 10:18 PM, Georg Brandl wrote: >> >> >> For a more extensive list of changes in 3.3.0, see >> >> http://docs.python.org/3.3/whatsnew/3.3.html > Redirects to http://docs.python.org/py3k/whatsnew/3.3.html: 404 Not Found. > > Works for me. Perhaps a momentary glitch. -- DaveA From hansmu at xs4all.nl Sat Sep 29 08:41:40 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 29 Sep 2012 14:41:40 +0200 Subject: howto handle nested for In-Reply-To: References: Message-ID: <5066ec85$0$6970$e4fe514c@news2.news.xs4all.nl> On 29/09/12 03:15:24, Peter Pearson wrote: > On Fri, 28 Sep 2012 09:49:36 -0600, Ian Kelly wrote: >> >> levels = 6 >> for combination in itertools.product(xrange(n_syms), levels): >> # do stuff > >>>> n_syms = 3 >>>> levels = 6 >>>> for combination in itertools.product(xrange(n_syms), levels): > ... print combination > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: 'int' object is not iterable >>> n_syms = 3 >>> levels = 6 >>> for combination in itertools.product(xrange(n_syms), repeat=levels): ... print combination ... (0, 0, 0, 0, 0, 0) (0, 0, 0, 0, 0, 1) (0, 0, 0, 0, 0, 2) (0, 0, 0, 0, 1, 0) (0, 0, 0, 0, 1, 1) (0, 0, 0, 0, 1, 2) (0, 0, 0, 0, 2, 0) (0, 0, 0, 0, 2, 1) (0, 0, 0, 0, 2, 2) (0, 0, 0, 1, 0, 0) etc. Hope this helps, -- HansM From amitsaha.in at gmail.com Sat Sep 29 08:45:45 2012 From: amitsaha.in at gmail.com (Amit Saha) Date: Sat, 29 Sep 2012 22:45:45 +1000 Subject: [Python-Dev] [RELEASED] Python 3.3.0 In-Reply-To: <5066EB7C.10407@davea.name> References: <5066E72E.2010100@python.org> <5066EB7C.10407@davea.name> Message-ID: On Sat, Sep 29, 2012 at 10:37 PM, Dave Angel wrote: > On 09/29/2012 08:23 AM, Amit Saha wrote: >> On Sat, Sep 29, 2012 at 10:18 PM, Georg Brandl wrote: >>> >>> >>> For a more extensive list of changes in 3.3.0, see >>> >>> http://docs.python.org/3.3/whatsnew/3.3.html >> Redirects to http://docs.python.org/py3k/whatsnew/3.3.html: 404 Not Found. >> >> > Works for me. Perhaps a momentary glitch. Yes, I clicked too soon, i guess.. -Amit. -- http://echorand.me From hansmu at xs4all.nl Sat Sep 29 09:02:06 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 29 Sep 2012 15:02:06 +0200 Subject: [Python-Dev] [RELEASED] Python 3.3.0 In-Reply-To: References: <5066E72E.2010100@python.org> Message-ID: <5066f14e$0$6985$e4fe514c@news2.news.xs4all.nl> On 29/09/12 14:23:49, Amit Saha wrote: > On Sat, Sep 29, 2012 at 10:18 PM, Georg Brandl wrote: >> On behalf of the Python development team, I'm delighted to announce the >> Python 3.3.0 final release. Thank you!!! >> For a more extensive list of changes in 3.3.0, see >> >> http://docs.python.org/3.3/whatsnew/3.3.html > > Redirects to http://docs.python.org/py3k/whatsnew/3.3.html: 404 Not Found. Somebody has fixed it. -- HansM From eliben at gmail.com Sat Sep 29 09:24:46 2012 From: eliben at gmail.com (Eli Bendersky) Date: Sat, 29 Sep 2012 06:24:46 -0700 Subject: [Python-Dev] [RELEASED] Python 3.3.0 In-Reply-To: <5066E72E.2010100@python.org> References: <5066E72E.2010100@python.org> Message-ID: On Sat, Sep 29, 2012 at 5:18 AM, Georg Brandl wrote: > On behalf of the Python development team, I'm delighted to announce the > Python 3.3.0 final release. > Yay :) From maniandram01 at gmail.com Sat Sep 29 09:27:47 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 29 Sep 2012 06:27:47 -0700 (PDT) Subject: Should one always add super().__init__() to the __init__? Message-ID: Should one always add super().__init__() to the __init__? The reason for this is the possibility of changing base classes (and forgetting to update the __init__). From maniandram01 at gmail.com Sat Sep 29 09:28:04 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 29 Sep 2012 06:28:04 -0700 (PDT) Subject: [Python-Dev] [RELEASED] Python 3.3.0 In-Reply-To: References: <5066E72E.2010100@python.org> Message-ID: <3401f5bb-216d-4bca-8860-d5138249815c@googlegroups.com> On Saturday, 29 September 2012 18:55:36 UTC+5:30, eliben wrote: > On Sat, Sep 29, 2012 at 5:18 AM, Georg Brandl wrote: > > > On behalf of the Python development team, I'm delighted to announce the > > > Python 3.3.0 final release. > > > > > > > Yay :) +1 From maniandram01 at gmail.com Sat Sep 29 09:28:04 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 29 Sep 2012 06:28:04 -0700 (PDT) Subject: [Python-Dev] [RELEASED] Python 3.3.0 In-Reply-To: References: <5066E72E.2010100@python.org> Message-ID: <3401f5bb-216d-4bca-8860-d5138249815c@googlegroups.com> On Saturday, 29 September 2012 18:55:36 UTC+5:30, eliben wrote: > On Sat, Sep 29, 2012 at 5:18 AM, Georg Brandl wrote: > > > On behalf of the Python development team, I'm delighted to announce the > > > Python 3.3.0 final release. > > > > > > > Yay :) +1 From maniandram01 at gmail.com Sat Sep 29 09:28:52 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 29 Sep 2012 06:28:52 -0700 (PDT) Subject: Should one always add super().__init__() to the __init__? In-Reply-To: References: Message-ID: <403a13e6-a118-4620-bf3d-827644987d81@googlegroups.com> On Saturday, 29 September 2012 18:57:48 UTC+5:30, Ramchandra Apte wrote: > Should one always add super().__init__() to the __init__? The reason for this is the possibility of changing base classes (and forgetting to update the __init__). This is my first post so I may be breaching nettique. From maniandram01 at gmail.com Sat Sep 29 09:35:02 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 29 Sep 2012 06:35:02 -0700 (PDT) Subject: [python-list] python application file format In-Reply-To: References: <5062F9D6.2060402@abzinc.com> Message-ID: On Saturday, 29 September 2012 02:05:07 UTC+5:30, Prasad, Ramit wrote: > Benjamin Jessup wrote: > > > Hello all, > > > > > > What do people recommend for a file format for a python desktop > > > application? Data is complex with 100s/1000s of class instances, which > > > reference each other. > > > > > > Write the file with struct module? (Rebuild object pointers, safe, > > > compact, portable, not expandable without reserved space) > > > > > > Use cPickle with a module/class whitelist? (Can't easily port, not > > > entirely safe, compact enough, expandable) > > > > > > Use JSON or similar? (Rebuild object pointers, portable, expandable, size?) > > > > > > Any advice is greatly appreciated! > > > > I would think your options are pickle, json or database (either sqlite or > > something like Postgres). I am unfamiliar with the struct module so I > > cannot comment on its applicability. > > > > I would guess that your data would be best saved by using a sqlite > > database. Your biggest problem might be how the different classes are > > referencing each other. If you are using identifiers then any of these > > options will probably work. If you are using aggregation then I know > > that pickle will work (at least for built-in types). JSON will > > keep the structure but duplicate elements. > > > > > > >>> a = [ 1,2,3 ] > > >>> b = [ 'a', 'b', 'c' ] > > >>> a.append( b ) > > >>> e = [ a,b ] > > >>> s = json.dumps( e ) > > >>> eret = json.loads( s ) > > >>> id(eret[0][3]), id(eret[1]) # Same result for json and simplejson > > (329443808, 327677272) > > >>> eret[0][3].append( 'o') > > >>> eret[0][3], eret[1] > > ([u'a', u'b', u'c', 'o'], [u'a', u'b', u'c']) > > > > So pickle will be your easiest option, but I am not sure how well it > > will scale with a large number items. Using sqlite/db should scale well > > but it will take you longer/more effort to create a system for converting > > your objects to and from the DB. > > > > > > > > This email is confidential and subject to important disclaimers and > > conditions including on offers for the purchase or sale of > > securities, accuracy and completeness of information, viruses, > > confidentiality, legal privilege, and legal entity disclaimers, > > available at http://www.jpmorgan.com/pages/disclosures/email. Guess I shouldn't read or rely your posts (virus'es could be in them) :-D From maniandram01 at gmail.com Sat Sep 29 09:35:02 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 29 Sep 2012 06:35:02 -0700 (PDT) Subject: [python-list] python application file format In-Reply-To: References: <5062F9D6.2060402@abzinc.com> Message-ID: On Saturday, 29 September 2012 02:05:07 UTC+5:30, Prasad, Ramit wrote: > Benjamin Jessup wrote: > > > Hello all, > > > > > > What do people recommend for a file format for a python desktop > > > application? Data is complex with 100s/1000s of class instances, which > > > reference each other. > > > > > > Write the file with struct module? (Rebuild object pointers, safe, > > > compact, portable, not expandable without reserved space) > > > > > > Use cPickle with a module/class whitelist? (Can't easily port, not > > > entirely safe, compact enough, expandable) > > > > > > Use JSON or similar? (Rebuild object pointers, portable, expandable, size?) > > > > > > Any advice is greatly appreciated! > > > > I would think your options are pickle, json or database (either sqlite or > > something like Postgres). I am unfamiliar with the struct module so I > > cannot comment on its applicability. > > > > I would guess that your data would be best saved by using a sqlite > > database. Your biggest problem might be how the different classes are > > referencing each other. If you are using identifiers then any of these > > options will probably work. If you are using aggregation then I know > > that pickle will work (at least for built-in types). JSON will > > keep the structure but duplicate elements. > > > > > > >>> a = [ 1,2,3 ] > > >>> b = [ 'a', 'b', 'c' ] > > >>> a.append( b ) > > >>> e = [ a,b ] > > >>> s = json.dumps( e ) > > >>> eret = json.loads( s ) > > >>> id(eret[0][3]), id(eret[1]) # Same result for json and simplejson > > (329443808, 327677272) > > >>> eret[0][3].append( 'o') > > >>> eret[0][3], eret[1] > > ([u'a', u'b', u'c', 'o'], [u'a', u'b', u'c']) > > > > So pickle will be your easiest option, but I am not sure how well it > > will scale with a large number items. Using sqlite/db should scale well > > but it will take you longer/more effort to create a system for converting > > your objects to and from the DB. > > > > > > > > This email is confidential and subject to important disclaimers and > > conditions including on offers for the purchase or sale of > > securities, accuracy and completeness of information, viruses, > > confidentiality, legal privilege, and legal entity disclaimers, > > available at http://www.jpmorgan.com/pages/disclosures/email. Guess I shouldn't read or rely your posts (virus'es could be in them) :-D From stefan_ml at behnel.de Sat Sep 29 09:37:45 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 29 Sep 2012 15:37:45 +0200 Subject: [RELEASED] Python 3.3.0 In-Reply-To: <5066E72E.2010100@python.org> References: <5066E72E.2010100@python.org> Message-ID: Georg Brandl, 29.09.2012 14:18: > On behalf of the Python development team, I'm delighted to announce the > Python 3.3.0 final release. > [...] > * PEP 380, syntax for delegating to a subgenerator ("yield from") Ah, you're so late! Cython has shipped its implementation almost a month ago! ;) Stefan From maniandram01 at gmail.com Sat Sep 29 09:41:48 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 29 Sep 2012 06:41:48 -0700 (PDT) Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> Message-ID: <0bed7b23-856c-41d0-b5ed-98ab4108cec1@googlegroups.com> On Tuesday, 25 September 2012 05:48:22 UTC+5:30, David Hutto wrote: > > Is the animated GIF on your website under 60MB yet? > > yeah a command line called convert, and taking out a few jpegs used to > > convert, and I can reduce it to any size, what's the fucking point of > > that question other than ignorant rhetoric, that you know is easily > > fixable? > > > > > > -- > > Best Regards, > > David Hutto > > CEO: http://www.hitwebdevelopment.com There are children (such as me) here! From maniandram01 at gmail.com Sat Sep 29 09:41:48 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 29 Sep 2012 06:41:48 -0700 (PDT) Subject: For Counter Variable In-Reply-To: References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <5060DA00.10801@stoneleaf.us> <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> Message-ID: <0bed7b23-856c-41d0-b5ed-98ab4108cec1@googlegroups.com> On Tuesday, 25 September 2012 05:48:22 UTC+5:30, David Hutto wrote: > > Is the animated GIF on your website under 60MB yet? > > yeah a command line called convert, and taking out a few jpegs used to > > convert, and I can reduce it to any size, what's the fucking point of > > that question other than ignorant rhetoric, that you know is easily > > fixable? > > > > > > -- > > Best Regards, > > David Hutto > > CEO: http://www.hitwebdevelopment.com There are children (such as me) here! From andriy.kornatskyy at live.com Sat Sep 29 09:42:09 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Sat, 29 Sep 2012 16:42:09 +0300 Subject: [RELEASED] Python 3.3.0 In-Reply-To: <5066E72E.2010100@python.org> References: <5066E72E.2010100@python.org> Message-ID: The following doctest fails with python3.3 (it is okay for python2.4-2.7, 3.2). class adict(dict): ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? """ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? >>> d = adict(a=1, b=2) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? >>> d ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {'a': 1, 'b': 2} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? """ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if __name__ == "__main__": ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? import doctest ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? doctest.testmod()? Please advise if that is something known. Andriy ---------------------------------------- > Date: Sat, 29 Sep 2012 14:18:54 +0200 > From: georg at python.org > To: python-announce at python.org; python-dev at python.org; python-list at python.org > Subject: [RELEASED] Python 3.3.0 > > On behalf of the Python development team, I'm delighted to announce the > Python 3.3.0 final release. > > Python 3.3 includes a range of improvements of the 3.x series, as well > as easier porting between 2.x and 3.x. Major new features and changes > in the 3.3 release series are: > > * PEP 380, syntax for delegating to a subgenerator ("yield from") > * PEP 393, flexible string representation (doing away with the > distinction between "wide" and "narrow" Unicode builds) > * A C implementation of the "decimal" module, with up to 120x speedup > for decimal-heavy applications > * The import system (__import__) now based on importlib by default > * The new "lzma" module with LZMA/XZ support > * PEP 397, a Python launcher for Windows > * PEP 405, virtual environment support in core > * PEP 420, namespace package support > * PEP 3151, reworking the OS and IO exception hierarchy > * PEP 3155, qualified name for classes and functions > * PEP 409, suppressing exception context > * PEP 414, explicit Unicode literals to help with porting > * PEP 418, extended platform-independent clocks in the "time" module > * PEP 412, a new key-sharing dictionary implementation that > significantly saves memory for object-oriented code > * PEP 362, the function-signature object > * The new "faulthandler" module that helps diagnosing crashes > * The new "unittest.mock" module > * The new "ipaddress" module > * The "sys.implementation" attribute > * A policy framework for the email package, with a provisional (see > PEP 411) policy that adds much improved unicode support for email > header parsing > * A "collections.ChainMap" class for linking mappings to a single unit > * Wrappers for many more POSIX functions in the "os" and "signal" > modules, as well as other useful functions such as "sendfile()" > * Hash randomization, introduced in earlier bugfix releases, is now > switched on by default > > In total, almost 500 API items are new or improved in Python 3.3. > For a more extensive list of changes in 3.3.0, see > > http://docs.python.org/3.3/whatsnew/3.3.html > > To download Python 3.3.0 visit: > > http://www.python.org/download/releases/3.3.0/ > > This is a production release, please report any bugs to > > http://bugs.python.org/ > > > Enjoy! > > -- > Georg Brandl, Release Manager > georg at python.org > (on behalf of the entire python-dev team and 3.3's contributors) > -- > http://mail.python.org/mailman/listinfo/python-list From maniandram01 at gmail.com Sat Sep 29 09:43:14 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 29 Sep 2012 06:43:14 -0700 (PDT) Subject: [RELEASED] Python 3.3.0 In-Reply-To: References: <5066E72E.2010100@python.org> Message-ID: On Saturday, 29 September 2012 19:08:25 UTC+5:30, Stefan Behnel wrote: > Georg Brandl, 29.09.2012 14:18: > > > On behalf of the Python development team, I'm delighted to announce the > > > Python 3.3.0 final release. > > > [...] > > > * PEP 380, syntax for delegating to a subgenerator ("yield from") > > > > Ah, you're so late! Cython has shipped its implementation almost a month > > ago! ;) > > > > Stefan Where did Cython get shipped to? LOL From maniandram01 at gmail.com Sat Sep 29 09:43:14 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 29 Sep 2012 06:43:14 -0700 (PDT) Subject: [RELEASED] Python 3.3.0 In-Reply-To: References: <5066E72E.2010100@python.org> Message-ID: On Saturday, 29 September 2012 19:08:25 UTC+5:30, Stefan Behnel wrote: > Georg Brandl, 29.09.2012 14:18: > > > On behalf of the Python development team, I'm delighted to announce the > > > Python 3.3.0 final release. > > > [...] > > > * PEP 380, syntax for delegating to a subgenerator ("yield from") > > > > Ah, you're so late! Cython has shipped its implementation almost a month > > ago! ;) > > > > Stefan Where did Cython get shipped to? LOL From maniandram01 at gmail.com Sat Sep 29 09:46:22 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 29 Sep 2012 06:46:22 -0700 (PDT) Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: References: <7x7grgtq75.fsf@ruckus.brouhaha.com> <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> Message-ID: <98034dee-0108-4099-bbdd-82f90e96d383@googlegroups.com> On Thursday, 27 September 2012 04:14:42 UTC+5:30, Tim Chase wrote: > On 09/26/12 17:28, 88888 Dihedral wrote: > > > 88888 Dihedral? 2012?9?27????UTC+8??6?07?35???? > > >>>> In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" > > >>>> without this behavior? > > >>> >>> a = [[0]*3 for i in xrange(2)] > > >>> >>> a[0][0]=2 > > >>> >>> a > > >>> [[2, 0, 0], [0, 0, 0]] > > > > > > def zeros(m,n): > > > a=[] > > > for i in xrange(m): > > > a.append([0]*n) > > > return a > > > > > > If one wants to tranlate to C, this is the style. > > > > But this is Python, so why the heck would anybody want to emulate > > *C* style? It could also be written in an assembly-language style, > > COBOL style, or a Fortran style...none of which are particularly > > valuable. > > > > Besides, a C-style would allocate a single array of M*N slots and > > then calculate 2d offsets into that single array. :-P > > > > -tkc 88888 Dihedral is a bot. From maniandram01 at gmail.com Sat Sep 29 09:46:22 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 29 Sep 2012 06:46:22 -0700 (PDT) Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: References: <7x7grgtq75.fsf@ruckus.brouhaha.com> <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> Message-ID: <98034dee-0108-4099-bbdd-82f90e96d383@googlegroups.com> On Thursday, 27 September 2012 04:14:42 UTC+5:30, Tim Chase wrote: > On 09/26/12 17:28, 88888 Dihedral wrote: > > > 88888 Dihedral? 2012?9?27????UTC+8??6?07?35???? > > >>>> In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" > > >>>> without this behavior? > > >>> >>> a = [[0]*3 for i in xrange(2)] > > >>> >>> a[0][0]=2 > > >>> >>> a > > >>> [[2, 0, 0], [0, 0, 0]] > > > > > > def zeros(m,n): > > > a=[] > > > for i in xrange(m): > > > a.append([0]*n) > > > return a > > > > > > If one wants to tranlate to C, this is the style. > > > > But this is Python, so why the heck would anybody want to emulate > > *C* style? It could also be written in an assembly-language style, > > COBOL style, or a Fortran style...none of which are particularly > > valuable. > > > > Besides, a C-style would allocate a single array of M*N slots and > > then calculate 2d offsets into that single array. :-P > > > > -tkc 88888 Dihedral is a bot. From p.f.moore at gmail.com Sat Sep 29 09:51:28 2012 From: p.f.moore at gmail.com (Paul Moore) Date: Sat, 29 Sep 2012 14:51:28 +0100 Subject: [Python-Dev] [RELEASED] Python 3.3.0 In-Reply-To: References: <5066E72E.2010100@python.org> Message-ID: On 29 September 2012 14:24, Eli Bendersky wrote: > On Sat, Sep 29, 2012 at 5:18 AM, Georg Brandl wrote: >> On behalf of the Python development team, I'm delighted to announce the >> Python 3.3.0 final release. >> > > Yay :) Agreed - this is a really nice release, thanks to all who put it together. Paul From christian at python.org Sat Sep 29 10:06:10 2012 From: christian at python.org (Christian Heimes) Date: Sat, 29 Sep 2012 16:06:10 +0200 Subject: [RELEASED] Python 3.3.0 In-Reply-To: References: <5066E72E.2010100@python.org> Message-ID: Am 29.09.2012 15:42, schrieb Andriy Kornatskyy: > > The following doctest fails with python3.3 (it is okay for python2.4-2.7, 3.2). > > class adict(dict): > """ > >>> d = adict(a=1, b=2) > >>> d > {'a': 1, 'b': 2} > """ > > if __name__ == "__main__": > import doctest > doctest.testmod() > > Please advise if that is something known. Yes, it's caused by the hash randomization. From now on you can't rely on the order of an unordered type like dict or set. You could replace d with sorted(d.items()). Christian From stefan_ml at behnel.de Sat Sep 29 10:17:51 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 29 Sep 2012 16:17:51 +0200 Subject: [RELEASED] Python 3.3.0 In-Reply-To: References: <5066E72E.2010100@python.org> Message-ID: Christian Heimes, 29.09.2012 16:06: > From now on you can't rely > on the order of an unordered type like dict or set. Tautologies tend to be true even without a temporal qualification. Stefan From alexis.lopezgarcia at gmail.com Sat Sep 29 10:19:09 2012 From: alexis.lopezgarcia at gmail.com (Alexis Lopez-Garcia) Date: Sat, 29 Sep 2012 16:19:09 +0200 Subject: unexpected error from Python 3.3.0 Message-ID: Hi. I installed Python3.3.0 with python-3.3.0.amd64.msi on a win7 machine. While using this funcion (see below) from a script called by double clicking on the .py file I get a "invalid variable "right" referenced before assignment" error. The weird thing is that launching the script from a cmd windows does no give the error and if you repeactedly double click on the .py file sometimes the error does not reproduce so I concluded it was a timing issue between win7 and python. So by trial and error I ended up fixing it by inserting a time.sleep(0.5) on the function and now it works 100% of the time. These error did not show in Python3.2.3 and thus I don't know if I just found a new bug or what. I write it here so that more knowledgeable people could: 1. explains to me why the errors is happening 2. deems it a bug and maybe reports it on the Python site. below is the particular function giving the error with the fix line, which is not in the original version def console_resize(width=80, height=24, buffer_height=600): '''Sets up the console size and buffer height. @param width {int} Width of console in column value. @param height {int} Height of console in row value. @param buffer_height {int} Buffer console height in row value. ''' from ctypes import windll, byref, create_string_buffer from ctypes.wintypes import SMALL_RECT, _COORD # Active console screen buffer # STD_OUTPUT_HANDLE -> -11, STD_ERROR_HANDLE -> -12) STDERR = -12 # SMALL_RECT input LEFT = 0 TOP = 0 RIGHT = width - 1 BOTTOM = height - 1 # handle hdl = windll.kernel32.GetStdHandle(STDERR) csbi = create_string_buffer(22) time.sleep(0.5) # <--- FIX IS THIS LINE res = windll.kernel32.GetConsoleScreenBufferInfo(hdl, csbi) if res: import struct (bufx, bufy, curx, cury, wattr, left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw) current_width = right - left + 1 current_height = bottom - top + 1 current_buffer_height = bufy if buffer_height < height: buffer_height = height # order of resizing avoiding some problems if current_buffer_height > buffer_height: rect = SMALL_RECT(LEFT, TOP, RIGHT, BOTTOM) # (left, top, right, bottom) windll.kernel32.SetConsoleWindowInfo(hdl, True, byref(rect)) bufsize = _COORD(width, buffer_height) # columns, rows windll.kernel32.SetConsoleScreenBufferSize(hdl, bufsize) else: bufsize = _COORD(width, buffer_height) # columns, rows windll.kernel32.SetConsoleScreenBufferSize(hdl, bufsize) rect = SMALL_RECT(LEFT, TOP, RIGHT, BOTTOM) # (left, top, right, bottom) windll.kernel32.SetConsoleWindowInfo(hdl, True, byref(rect)) -- There are more things in heaven and earth, Horatio, Than are dreamt of in your philosophy. Alexis Lopez-Garcia alexis.lopezgarcia at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Sep 29 10:25:02 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Sep 2012 00:25:02 +1000 Subject: [RELEASED] Python 3.3.0 In-Reply-To: References: <5066E72E.2010100@python.org> Message-ID: On Sun, Sep 30, 2012 at 12:17 AM, Stefan Behnel wrote: > Christian Heimes, 29.09.2012 16:06: >> From now on you can't rely >> on the order of an unordered type like dict or set. > > Tautologies tend to be true even without a temporal qualification. Technically people shouldn't ever have relied on the order, but until hash randomization came in, the order in CPython was actually predictable - for a given set of dictionary operations, the internal structure was determinate, and the consequent iteration order would be consistent. Now that that's no longer the case, "unordered" really means "unordered", and the order can change from one run of a program to another. So it may be a tautology in theory, but not in practice..... until now. Truth has become true. ChrisA From python at bdurham.com Sat Sep 29 11:14:18 2012 From: python at bdurham.com (python at bdurham.com) Date: Sat, 29 Sep 2012 11:14:18 -0400 Subject: [Python-Dev] [RELEASED] Python 3.3.0 In-Reply-To: References: <5066E72E.2010100@python.org> Message-ID: <1348931658.18629.140661134295829.195F63B3@webmail.messagingengine.com> > Agreed - this is a really nice release, thanks to all who put it together. +1 Thank you! Malcolm From thbach at students.uni-mainz.de Sat Sep 29 12:14:38 2012 From: thbach at students.uni-mainz.de (Thomas Bach) Date: Sat, 29 Sep 2012 18:14:38 +0200 Subject: Slicing iterables in sub-generators without loosing elements Message-ID: <20120929161437.GA8832@taris.box> Hi, say we have the following: >>> data = [('foo', 1), ('foo', 2), ('bar', 3), ('bar', 2)] is there a way to code a function iter_in_blocks such that >>> result = [ list(block) for block in iter_in_blocks(data) ] evaluates to >>> result = [ [('foo', 1), ('foo', 2)], [('bar', 3), ('bar', 2)] ] by _only_ _iterating_ over the list (caching all the elements sharing the same first element doesn't count)? I came up with the following def iter_in_blocks(iterable): my_iter = iter(iterable) while True: first = next(my_iter) pred = lambda entry: entry[0] == first[0] def block_iter(): yield first for entry in itertools.takewhile(pred, my_iter): yield entry yield block_iter() which does not work as itertools.takewhile consumes the first entry not fulfilling the pred. I currently have the intuition that the problem is not solvable without using e.g. a global to pass something back to iter_in_blocks from block_iter. Any other suggestions? Regards, Thomas Bach. From no.email at nospam.invalid Sat Sep 29 12:26:00 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 29 Sep 2012 09:26:00 -0700 Subject: Slicing iterables in sub-generators without loosing elements References: Message-ID: <7xpq54u76v.fsf@ruckus.brouhaha.com> Thomas Bach writes: >>>> result = [ [('foo', 1), ('foo', 2)], [('bar', 3), ('bar', 2)] ] > by _only_ _iterating_ over the list (caching all the elements sharing > the same first element doesn't count)? itertools.groupby(data, lambda (x,y) : x) is basically what you want. From d at davea.name Sat Sep 29 12:29:59 2012 From: d at davea.name (Dave Angel) Date: Sat, 29 Sep 2012 12:29:59 -0400 Subject: unexpected error from Python 3.3.0 In-Reply-To: References: Message-ID: <50672207.7060406@davea.name> On 09/29/2012 10:19 AM, Alexis Lopez-Garcia wrote: > Hi. > > I installed Python3.3.0 with python-3.3.0.amd64.msi on a win7 machine. > > While using this funcion (see below) from a script called by double > clicking on the .py file I get a "invalid variable "right" referenced > before assignment" error. You forgot to include the whole, actual error trace. > The weird thing is that launching the script from a cmd windows does no > give the error and if you repeactedly double click on the .py file > sometimes the error does not reproduce so I concluded it was a timing issue > between win7 and python. > So by trial and error I ended up fixing it by inserting a time.sleep(0.5) > on the function and now it works 100% of the time. > > These error did not show in Python3.2.3 and thus I don't know if I just > found a new bug or what. > I write it here so that more knowledgeable people could: > > 1. explains to me why the errors is happening see below. > 2. deems it a bug and maybe reports it on the Python site. Sure, report it to Microsoft. For whatever reason, your call to GetConsoleScreenBufferInfo() is returning false (or something equivalent, like 0). What does the Windows 7 documentation say about not attaching a console for a while? > below is the particular function giving the error with the fix line, which > is not in the original version > > def console_resize(width=80, height=24, buffer_height=600): > '''Sets up the console size and buffer height. > > @param width {int} Width of console in column value. > @param height {int} Height of console in row value. > @param buffer_height {int} Buffer console height in row value. > ''' > from ctypes import windll, byref, create_string_buffer > from ctypes.wintypes import SMALL_RECT, _COORD > # Active console screen buffer > # STD_OUTPUT_HANDLE -> -11, STD_ERROR_HANDLE -> -12) > STDERR = -12 > # SMALL_RECT input > LEFT = 0 > TOP = 0 > RIGHT = width - 1 > BOTTOM = height - 1 > # handle > hdl = windll.kernel32.GetStdHandle(STDERR) > csbi = create_string_buffer(22) > > time.sleep(0.5) # <--- FIX IS THIS LINE > > res = windll.kernel32.GetConsoleScreenBufferInfo(hdl, csbi) > > if res: > import struct > (bufx, bufy, curx, cury, wattr, > left, top, right, bottom, > maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw) Your problem is you don't have an else clause. How did you expect bufs, bufy, etc. to be initialized without executing that code. So if the rest of the function doesn't make sense without a console, you should be skipping it, or throwing an exception, or returning, or something. > > current_width = right - left + 1 This happens to be the first time you tried to use one of those non-variables. Naturally, it fails. > current_height = bottom - top + 1 > current_buffer_height = bufy > > if buffer_height < height: > buffer_height = height > # order of resizing avoiding some problems > if current_buffer_height > buffer_height: > rect = SMALL_RECT(LEFT, TOP, RIGHT, BOTTOM) # (left, top, right, > bottom) > windll.kernel32.SetConsoleWindowInfo(hdl, True, byref(rect)) > > bufsize = _COORD(width, buffer_height) # columns, rows > windll.kernel32.SetConsoleScreenBufferSize(hdl, bufsize) > else: > bufsize = _COORD(width, buffer_height) # columns, rows > windll.kernel32.SetConsoleScreenBufferSize(hdl, bufsize) > > rect = SMALL_RECT(LEFT, TOP, RIGHT, BOTTOM) # (left, top, right, > bottom) > windll.kernel32.SetConsoleWindowInfo(hdl, True, byref(rect)) > > > -- DaveA From ian.g.kelly at gmail.com Sat Sep 29 12:36:39 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 29 Sep 2012 10:36:39 -0600 Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: <20120929161437.GA8832@taris.box> References: <20120929161437.GA8832@taris.box> Message-ID: On Sat, Sep 29, 2012 at 10:14 AM, Thomas Bach wrote: > Hi, > > say we have the following: > >>>> data = [('foo', 1), ('foo', 2), ('bar', 3), ('bar', 2)] > > is there a way to code a function iter_in_blocks such that > >>>> result = [ list(block) for block in iter_in_blocks(data) ] > > evaluates to > >>>> result = [ [('foo', 1), ('foo', 2)], [('bar', 3), ('bar', 2)] ] > > by _only_ _iterating_ over the list (caching all the elements sharing > the same first element doesn't count)? Am I correct in understanding that the intent is that the "blocks" are groups that share the same first item? Is it guaranteed that the blocks will be contiguous? If so, you could use itertools.groupby: from itertools import groupby, imap from operator import itemgetter def iter_in_blocks(data): return imap(itemgetter(1), groupby(data, itemgetter(0))) If there is no such guarantee, then the list would need to be sorted first. From thbach at students.uni-mainz.de Sat Sep 29 12:44:51 2012 From: thbach at students.uni-mainz.de (Thomas Bach) Date: Sat, 29 Sep 2012 18:44:51 +0200 Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: <7xpq54u76v.fsf@ruckus.brouhaha.com> References: <7xpq54u76v.fsf@ruckus.brouhaha.com> Message-ID: <20120929164451.GB8832@taris.box> On Sat, Sep 29, 2012 at 09:26:00AM -0700, Paul Rubin wrote: > Thomas Bach writes: > > itertools.groupby(data, lambda (x,y) : x) > > is basically what you want. True! Thanks, Thomas Bach From ian.g.kelly at gmail.com Sat Sep 29 12:59:16 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 29 Sep 2012 10:59:16 -0600 Subject: Should one always add super().__init__() to the __init__? In-Reply-To: References: Message-ID: On Sat, Sep 29, 2012 at 7:27 AM, Ramchandra Apte wrote: > Should one always add super().__init__() to the __init__? The reason for this is the possibility of changing base classes (and forgetting to update the __init__). As long as the class and its subclasses only use single inheritance, it makes little difference, so if you think it will reduce the maintenance burden, I would say go for it. From dihedral88888 at googlemail.com Sat Sep 29 13:01:30 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 29 Sep 2012 10:01:30 -0700 (PDT) Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: <98034dee-0108-4099-bbdd-82f90e96d383@googlegroups.com> References: <7x7grgtq75.fsf@ruckus.brouhaha.com> <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> <98034dee-0108-4099-bbdd-82f90e96d383@googlegroups.com> Message-ID: On Saturday, September 29, 2012 9:46:22 PM UTC+8, Ramchandra Apte wrote: > On Thursday, 27 September 2012 04:14:42 UTC+5:30, Tim Chase wrote: > > > On 09/26/12 17:28, 88888 Dihedral wrote: > > > > > > > 88888 Dihedral? 2012?9?27????UTC+8??6?07?35???? > > > > > > >>>> In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" > > > > > > >>>> without this behavior? > > > > > > >>> >>> a = [[0]*3 for i in xrange(2)] > > > > > > >>> >>> a[0][0]=2 > > > > > > >>> >>> a > > > > > > >>> [[2, 0, 0], [0, 0, 0]] > > > > > > > > > > > > > > def zeros(m,n): > > > > > > > a=[] > > > > > > > for i in xrange(m): > > > > > > > a.append([0]*n) > > > > > > > return a > > > > > > > > > > > > > > If one wants to tranlate to C, this is the style. > > > > > > > > > > > > But this is Python, so why the heck would anybody want to emulate > > > > > > *C* style? It could also be written in an assembly-language style, > > > > > > COBOL style, or a Fortran style...none of which are particularly > > > > > > valuable. > > > > > > > > > > > > Besides, a C-style would allocate a single array of M*N slots and > > > > > > then calculate 2d offsets into that single array. :-P > > > > > > > > > > > > -tkc > > > > 88888 Dihedral is a bot. Don't you get it why I avoided the lambda one liner as a functon. I prefer the def way with a name chosen. From dihedral88888 at googlemail.com Sat Sep 29 13:01:30 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 29 Sep 2012 10:01:30 -0700 (PDT) Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: <98034dee-0108-4099-bbdd-82f90e96d383@googlegroups.com> References: <7x7grgtq75.fsf@ruckus.brouhaha.com> <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> <98034dee-0108-4099-bbdd-82f90e96d383@googlegroups.com> Message-ID: On Saturday, September 29, 2012 9:46:22 PM UTC+8, Ramchandra Apte wrote: > On Thursday, 27 September 2012 04:14:42 UTC+5:30, Tim Chase wrote: > > > On 09/26/12 17:28, 88888 Dihedral wrote: > > > > > > > 88888 Dihedral? 2012?9?27????UTC+8??6?07?35???? > > > > > > >>>> In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" > > > > > > >>>> without this behavior? > > > > > > >>> >>> a = [[0]*3 for i in xrange(2)] > > > > > > >>> >>> a[0][0]=2 > > > > > > >>> >>> a > > > > > > >>> [[2, 0, 0], [0, 0, 0]] > > > > > > > > > > > > > > def zeros(m,n): > > > > > > > a=[] > > > > > > > for i in xrange(m): > > > > > > > a.append([0]*n) > > > > > > > return a > > > > > > > > > > > > > > If one wants to tranlate to C, this is the style. > > > > > > > > > > > > But this is Python, so why the heck would anybody want to emulate > > > > > > *C* style? It could also be written in an assembly-language style, > > > > > > COBOL style, or a Fortran style...none of which are particularly > > > > > > valuable. > > > > > > > > > > > > Besides, a C-style would allocate a single array of M*N slots and > > > > > > then calculate 2d offsets into that single array. :-P > > > > > > > > > > > > -tkc > > > > 88888 Dihedral is a bot. Don't you get it why I avoided the lambda one liner as a functon. I prefer the def way with a name chosen. From ian.g.kelly at gmail.com Sat Sep 29 13:04:55 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 29 Sep 2012 11:04:55 -0600 Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. In-Reply-To: References: <5066506D.4020702@tim.thechases.com> <50665A23.1060300@tim.thechases.com> <50666b49$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 29, 2012 at 3:38 AM, Mark Lawrence wrote: > My understanding is that Python 3.3 has regressed the performance of ''. > Surely the Python devs can speed the performance back up and, just for us, > use less memory at the same time? At least it will be stored as a Latin-1 '' for efficiency and not a bloated UCS-4 ''. From maniandram01 at gmail.com Sat Sep 29 13:05:25 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 29 Sep 2012 10:05:25 -0700 (PDT) Subject: How to investigate web script not running? In-Reply-To: <8h7b68lk4lakmgijhqeo918e01gh7pg7d2@4ax.com> References: <8h7b68lk4lakmgijhqeo918e01gh7pg7d2@4ax.com> Message-ID: <7f6dc32a-1052-486a-9b5f-140e2297395d@googlegroups.com> On Friday, 28 September 2012 18:45:41 UTC+5:30, Gilles wrote: > On Fri, 28 Sep 2012 14:16:22 +0200, "Michael Ross" > > wrote: > > >Do it the other way around: > > > > > ># cgitb before anything else > > >import cgitb > > >cgitb.enable() > > > > > ># so this error will be caught > > > from fcgi import WSGIServer > > > > Thanks much for the tip. The error isn't displayed when calling the > > script from a web browser but it is when running the script on a shell > > account. > > > > It looks like that newer version of fcgi.py doesn't include support > > for WSGI, and I need some extra (Flup?) software to sit between > > mod_fcgid and a WSGI Python application. > > > > Definitely not plug 'n play :-/ Well the plug and play standard is superseded by USB practically. From peterfarrell66 at gmail.com Sat Sep 29 13:14:51 2012 From: peterfarrell66 at gmail.com (peterfarrell66 at gmail.com) Date: Sat, 29 Sep 2012 10:14:51 -0700 (PDT) Subject: Editing in IDLE Message-ID: <13cba669-3640-4e7b-8fee-c84c7bafb67c@googlegroups.com> Hello to the group! I'm a new Python user and so far I'm enjoying it. One of the many newbie problems I'm having is I can't edit my code in IDLE once it's run or there's an error message. I can only copy the code so far, paste at the bottom and continue coding. Is there something simple I'm missing, or should I be using a different editor? Thanks in advance! Peter Farrell From steve+comp.lang.python at pearwood.info Sat Sep 29 13:17:20 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Sep 2012 17:17:20 GMT Subject: Should one always add super().__init__() to the __init__? References: Message-ID: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 29 Sep 2012 06:27:47 -0700, Ramchandra Apte wrote: > Should one always add super().__init__() to the __init__? The reason for > this is the possibility of changing base classes (and forgetting to > update the __init__). No. Only add code that works and that you need. Arbitrarily adding calls to the superclasses "just in case" may not work: py> class Spam(object): ... def __init__(self, x): ... self.x = x ... super(Spam, self).__init__(x) ... py> x = Spam(1) Traceback (most recent call last): File "", line 1, in File "", line 4, in __init__ TypeError: object.__init__() takes no parameters -- Steven From ian.g.kelly at gmail.com Sat Sep 29 13:18:48 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 29 Sep 2012 11:18:48 -0600 Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: References: <7x7grgtq75.fsf@ruckus.brouhaha.com> <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> <98034dee-0108-4099-bbdd-82f90e96d383@googlegroups.com> Message-ID: On Sat, Sep 29, 2012 at 11:01 AM, 88888 Dihedral wrote: > > Don't you get it why I avoided the lambda one liner as a functon. > > I prefer the def way with a name chosen. Certainly, but the Bresenham line algorithm is O(n), which is why it is so superior to quicksort that is O(n log n). Of course you might try the Capo Ferro optimization, but I find that Thibault cancels out Capo Ferro, don't you? From rosuav at gmail.com Sat Sep 29 13:41:04 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Sep 2012 03:41:04 +1000 Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: References: <7x7grgtq75.fsf@ruckus.brouhaha.com> <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> <98034dee-0108-4099-bbdd-82f90e96d383@googlegroups.com> Message-ID: On Sun, Sep 30, 2012 at 3:18 AM, Ian Kelly wrote: > On Sat, Sep 29, 2012 at 11:01 AM, 88888 Dihedral > wrote: >> >> Don't you get it why I avoided the lambda one liner as a functon. >> >> I prefer the def way with a name chosen. > > Certainly, but the Bresenham line algorithm is O(n), which is why it > is so superior to quicksort that is O(n log n). Of course you might > try the Capo Ferro optimization, but I find that Thibault cancels out > Capo Ferro, don't you? Unless ... class Agrippa(object): students = [] def __init__(self): students.append(self) enemy = Agrippa() ChrisA (maybe I'm pushing this a bit too far) From alexis.lopezgarcia at gmail.com Sat Sep 29 13:41:09 2012 From: alexis.lopezgarcia at gmail.com (Alexis Lopez-Garcia) Date: Sat, 29 Sep 2012 19:41:09 +0200 Subject: unexpected error from Python 3.3.0 In-Reply-To: <50672207.7060406@davea.name> References: <50672207.7060406@davea.name> Message-ID: Thanks for pointing me to the right direction. It seems that GetConsoleScreenBufferInfo() is indeed returning 0 and further investigation points to the error code 6 (ERROR_INVALID_HANDLE). No idea why this is so but just doing a while loop until the call gets a non-zero value seem to work as a fix. On Sat, Sep 29, 2012 at 6:29 PM, Dave Angel wrote: > On 09/29/2012 10:19 AM, Alexis Lopez-Garcia wrote: > > Hi. > > > > I installed Python3.3.0 with python-3.3.0.amd64.msi on a win7 machine. > > > > While using this funcion (see below) from a script called by double > > clicking on the .py file I get a "invalid variable "right" referenced > > before assignment" error. > > You forgot to include the whole, actual error trace. > > > The weird thing is that launching the script from a cmd windows does no > > give the error and if you repeactedly double click on the .py file > > sometimes the error does not reproduce so I concluded it was a timing > issue > > between win7 and python. > > So by trial and error I ended up fixing it by inserting a time.sleep(0.5) > > on the function and now it works 100% of the time. > > > > These error did not show in Python3.2.3 and thus I don't know if I just > > found a new bug or what. > > I write it here so that more knowledgeable people could: > > > > 1. explains to me why the errors is happening > see below. > > 2. deems it a bug and maybe reports it on the Python site. > > Sure, report it to Microsoft. For whatever reason, your call to > > GetConsoleScreenBufferInfo() is returning false (or something equivalent, > like 0). What does the Windows 7 documentation say about not attaching a > console for a while? > > > > below is the particular function giving the error with the fix line, > which > > is not in the original version > > > > def console_resize(width=80, height=24, buffer_height=600): > > '''Sets up the console size and buffer height. > > > > @param width {int} Width of console in column value. > > @param height {int} Height of console in row value. > > @param buffer_height {int} Buffer console height in row value. > > ''' > > from ctypes import windll, byref, create_string_buffer > > from ctypes.wintypes import SMALL_RECT, _COORD > > # Active console screen buffer > > # STD_OUTPUT_HANDLE -> -11, STD_ERROR_HANDLE -> -12) > > STDERR = -12 > > # SMALL_RECT input > > LEFT = 0 > > TOP = 0 > > RIGHT = width - 1 > > BOTTOM = height - 1 > > # handle > > hdl = windll.kernel32.GetStdHandle(STDERR) > > csbi = create_string_buffer(22) > > > > time.sleep(0.5) # <--- FIX IS THIS LINE > > > > res = windll.kernel32.GetConsoleScreenBufferInfo(hdl, csbi) > > > > if res: > > import struct > > (bufx, bufy, curx, cury, wattr, > > left, top, right, bottom, > > maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw) > > Your problem is you don't have an else clause. How did you expect bufs, > bufy, etc. to be initialized without executing that code. So if the > rest of the function doesn't make sense without a console, you should be > skipping it, or throwing an exception, or returning, or something. > > > > > > > current_width = right - left + 1 > > This happens to be the first time you tried to use one of those > non-variables. Naturally, it fails. > > > current_height = bottom - top + 1 > > current_buffer_height = bufy > > > > if buffer_height < height: > > buffer_height = height > > # order of resizing avoiding some problems > > if current_buffer_height > buffer_height: > > rect = SMALL_RECT(LEFT, TOP, RIGHT, BOTTOM) # (left, top, right, > > bottom) > > windll.kernel32.SetConsoleWindowInfo(hdl, True, byref(rect)) > > > > bufsize = _COORD(width, buffer_height) # columns, rows > > windll.kernel32.SetConsoleScreenBufferSize(hdl, bufsize) > > else: > > bufsize = _COORD(width, buffer_height) # columns, rows > > windll.kernel32.SetConsoleScreenBufferSize(hdl, bufsize) > > > > rect = SMALL_RECT(LEFT, TOP, RIGHT, BOTTOM) # (left, top, right, > > bottom) > > windll.kernel32.SetConsoleWindowInfo(hdl, True, byref(rect)) > > > > > > > -- > > DaveA > > -- There are more things in heaven and earth, Horatio, Than are dreamt of in your philosophy. Alexis Lopez-Garcia alexis.lopezgarcia at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Sep 29 13:52:59 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 29 Sep 2012 13:52:59 -0400 Subject: Editing in IDLE In-Reply-To: <13cba669-3640-4e7b-8fee-c84c7bafb67c@googlegroups.com> References: <13cba669-3640-4e7b-8fee-c84c7bafb67c@googlegroups.com> Message-ID: On 9/29/2012 1:14 PM, peterfarrell66 at gmail.com wrote: > Hello to the group! > > I'm a new Python user and so far I'm enjoying it. One of the many > newbie problems I'm having is I can't edit my code in IDLE once it's > run or there's an error message. I can only copy the code so far, > paste at the bottom and continue coding. Is there something simple > I'm missing, or should I be using a different editor? You are missing how to use IDLE. It has two kinds of windows: interactive Shell and Edit windows. The shell more or less emulates the interactive interpreter, running one statement at a time. You can put the cursor on a previous statement and hit return to make it the current statement, where you can edit it. You edit normal multi-statement code in edit windows, hit F5 to run, edit, run, edit, run. -- Terry Jan Reedy From jeanpierreda at gmail.com Sat Sep 29 14:18:03 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 29 Sep 2012 14:18:03 -0400 Subject: Should one always add super().__init__() to the __init__? In-Reply-To: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 29, 2012 at 1:17 PM, Steven D'Aprano wrote: > No. Only add code that works and that you need. Arbitrarily adding calls > to the superclasses "just in case" may not work: > > > > py> class Spam(object): > ... def __init__(self, x): > ... self.x = x > ... super(Spam, self).__init__(x) > ... > py> x = Spam(1) > Traceback (most recent call last): > File "", line 1, in > File "", line 4, in __init__ > TypeError: object.__init__() takes no parameters That's a good thing. We've gone from code that doesn't call the initializer and leaves the object in a potentially invalid state (silently!), to code that calls the initializer and then fails (loudly). -- Devin From rosuav at gmail.com Sat Sep 29 14:31:48 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Sep 2012 04:31:48 +1000 Subject: Should one always add super().__init__() to the __init__? In-Reply-To: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 30, 2012 at 3:17 AM, Steven D'Aprano wrote: > No. Only add code that works and that you need. Arbitrarily adding calls > to the superclasses "just in case" may not work: > > py> class Spam(object): > ... def __init__(self, x): > ... self.x = x > ... super(Spam, self).__init__(x) > ... > py> x = Spam(1) > Traceback (most recent call last): > File "", line 1, in > File "", line 4, in __init__ > TypeError: object.__init__() takes no parameters That's because you're subclassing something that doesn't take parameters and giving it parameters. Of course that won't work. The normal and logical thing to do is to pass on only the parameters that you know the parent class expects... but that implies knowing the parent, so it's kinda moot. ChrisA From rosuav at gmail.com Sat Sep 29 14:35:02 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Sep 2012 04:35:02 +1000 Subject: Editing in IDLE In-Reply-To: <13cba669-3640-4e7b-8fee-c84c7bafb67c@googlegroups.com> References: <13cba669-3640-4e7b-8fee-c84c7bafb67c@googlegroups.com> Message-ID: On Sun, Sep 30, 2012 at 3:14 AM, wrote: > Hello to the group! > > I'm a new Python user and so far I'm enjoying it. One of the many newbie problems I'm having is I can't edit my code in IDLE once it's run or there's an error message. I can only copy the code so far, paste at the bottom and continue coding. Is there something simple I'm missing, or should I be using a different editor? I only ever use IDLE in its interactive mode (at which, imho, it's rather better than the default Python interactive mode, as it auto-indents). In that mode, you can retrieve previous commands with Alt-P - at least, that's the keystroke on Windows, not sure if it's different on other platforms. For editing code that's to be saved in a .py file, I use SciTE, but a lot of people do use IDLE for that too. It's a matter of personal preference. ChrisA From dihedral88888 at googlemail.com Sat Sep 29 14:50:52 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 29 Sep 2012 11:50:52 -0700 (PDT) Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: References: <7x7grgtq75.fsf@ruckus.brouhaha.com> <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> <98034dee-0108-4099-bbdd-82f90e96d383@googlegroups.com> Message-ID: On Sunday, September 30, 2012 1:19:22 AM UTC+8, Ian wrote: > On Sat, Sep 29, 2012 at 11:01 AM, 88888 Dihedral > > wrote: > > > > > > Don't you get it why I avoided the lambda one liner as a functon. > > > > > > I prefer the def way with a name chosen. > > > > Certainly, but the Bresenham line algorithm is O(n), which is why it > > is so superior to quicksort that is O(n log n). Of course you might > > try the Capo Ferro optimization, but I find that Thibault cancels out > > Capo Ferro, don't you? OK! I'll illustrate the lazy aspect of the python interpreter furthermore. a=[1,2,3] b=[a]*4 # different from a sliced copy as [list(a)]*4 print b a[1]=4 print b #----- a=666 # type morphed print b From dihedral88888 at googlemail.com Sat Sep 29 14:50:52 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 29 Sep 2012 11:50:52 -0700 (PDT) Subject: using "*" to make a list of lists with repeated (and independent) elements In-Reply-To: References: <7x7grgtq75.fsf@ruckus.brouhaha.com> <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> <98034dee-0108-4099-bbdd-82f90e96d383@googlegroups.com> Message-ID: On Sunday, September 30, 2012 1:19:22 AM UTC+8, Ian wrote: > On Sat, Sep 29, 2012 at 11:01 AM, 88888 Dihedral > > wrote: > > > > > > Don't you get it why I avoided the lambda one liner as a functon. > > > > > > I prefer the def way with a name chosen. > > > > Certainly, but the Bresenham line algorithm is O(n), which is why it > > is so superior to quicksort that is O(n log n). Of course you might > > try the Capo Ferro optimization, but I find that Thibault cancels out > > Capo Ferro, don't you? OK! I'll illustrate the lazy aspect of the python interpreter furthermore. a=[1,2,3] b=[a]*4 # different from a sliced copy as [list(a)]*4 print b a[1]=4 print b #----- a=666 # type morphed print b From nobody at nowhere.com Sat Sep 29 15:24:14 2012 From: nobody at nowhere.com (Nobody) Date: Sat, 29 Sep 2012 20:24:14 +0100 Subject: what is the difference between st_ctime and st_mtime one is the time of last change and the other is the time of last modification, but i can not understand what is the difference between 'change' and 'modification'. References: Message-ID: On Fri, 28 Sep 2012 11:48:23 -0600, Kristen J. Webb wrote: > NOTE: I am a C programmer and new to python, so can anyone comment > on what the st_ctime value is when os.stat() is called on Windows? The documentation[1] says: st_ctime - platform dependent; time of most recent metadata change on Unix, or the time of creation on Windows) [1] http://docs.python.org/library/os#os.stat From davidedillard at gmail.com Sat Sep 29 16:03:41 2012 From: davidedillard at gmail.com (David Dillard) Date: Sat, 29 Sep 2012 13:03:41 -0700 (PDT) Subject: EOL for Python 3.2? Message-ID: With the release of Python 3.3.0 does that mean the 3.2.x line is now end of life? I've looked for some sort of end of life policy on python.org, but was unable to find one. From bahamutzero8825 at gmail.com Sat Sep 29 16:26:15 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 29 Sep 2012 15:26:15 -0500 Subject: EOL for Python 3.2? In-Reply-To: References: Message-ID: <50675967.2020902@gmail.com> On 2012.09.29 15:03, David Dillard wrote: > With the release of Python 3.3.0 does that mean the 3.2.x line is now end of life? No. Old releases get security fixes for years. > I've looked for some sort of end of life policy on python.org, but was unable to find one. http://www.python.org/download/releases/ If you go to a version, it will tell you the status. For example, 3.1.x and 2.6.x still get security fixes, but 2.5.6 is the absolute last release of 2.5 - it will NOT receive updates of any kind. Unless the page states otherwise, it is pretty safe to assume that the release is maintained. -- CPython 3.3.0 | Windows NT 6.1.7601.17835 From fpesposito at gmail.com Sat Sep 29 16:32:27 2012 From: fpesposito at gmail.com (FPEFPE) Date: Sat, 29 Sep 2012 13:32:27 -0700 (PDT) Subject: Missing library path (WIndows) In-Reply-To: References: <8cab2c34-7594-471a-80e9-47206bd3ea32@googlegroups.com> Message-ID: <21e6fb32-ee1e-429d-ba6f-276c8208ca78@googlegroups.com> On Saturday, September 29, 2012 4:02:13 AM UTC-4, Kwpolska wrote: > On Sat, Sep 29, 2012 at 4:39 AM, FPEFPE wrote: > > > Hello -- I am running python from an application, starting it with a call to the python31.dll > > > > > > I think I am missing something in my path -- any help would be appreciated -- thanks > > > > Nope, you are not. > > > > > File "C:\Python32\Lib\encodings\cp437.py", line 19, in encode > > > > > > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > > > > > > UnicodeEncodeError: 'charmap' codec can't encode characters in position 2-18: character maps to > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > Python has problems with encoding the arguments to look properly with > > the crappy Windows cmd.exe encodings. They cannot be encoded for some > > reason. You may need magic, but I?m not quite sure what in Py3k > > (bytestrings?) > > > > -- > > Kwpolska > > stop html mail | always bottom-post > > www.asciiribbon.org | www.netmeister.org/news/learn2quote.html > > GPG KEY: 5EAAEA16 Hello -- thanks for the reply ... is "magic" a debugging tool? From fpesposito at gmail.com Sat Sep 29 16:32:27 2012 From: fpesposito at gmail.com (FPEFPE) Date: Sat, 29 Sep 2012 13:32:27 -0700 (PDT) Subject: Missing library path (WIndows) In-Reply-To: References: <8cab2c34-7594-471a-80e9-47206bd3ea32@googlegroups.com> Message-ID: <21e6fb32-ee1e-429d-ba6f-276c8208ca78@googlegroups.com> On Saturday, September 29, 2012 4:02:13 AM UTC-4, Kwpolska wrote: > On Sat, Sep 29, 2012 at 4:39 AM, FPEFPE wrote: > > > Hello -- I am running python from an application, starting it with a call to the python31.dll > > > > > > I think I am missing something in my path -- any help would be appreciated -- thanks > > > > Nope, you are not. > > > > > File "C:\Python32\Lib\encodings\cp437.py", line 19, in encode > > > > > > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > > > > > > UnicodeEncodeError: 'charmap' codec can't encode characters in position 2-18: character maps to > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > Python has problems with encoding the arguments to look properly with > > the crappy Windows cmd.exe encodings. They cannot be encoded for some > > reason. You may need magic, but I?m not quite sure what in Py3k > > (bytestrings?) > > > > -- > > Kwpolska > > stop html mail | always bottom-post > > www.asciiribbon.org | www.netmeister.org/news/learn2quote.html > > GPG KEY: 5EAAEA16 Hello -- thanks for the reply ... is "magic" a debugging tool? From timothy.c.delaney at gmail.com Sat Sep 29 16:51:31 2012 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Sun, 30 Sep 2012 06:51:31 +1000 Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. In-Reply-To: References: <5066506D.4020702@tim.thechases.com> <50665A23.1060300@tim.thechases.com> <50666b49$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29 September 2012 20:05, Chris Angelico wrote: > On Sat, Sep 29, 2012 at 7:38 PM, Mark Lawrence > wrote: > > > > My understanding is that Python 3.3 has regressed the performance of ''. > > Surely the Python devs can speed the performance back up and, just for > us, > > use less memory at the same time? > > Yes, but to do that we'd have to make Python more Australia-focused > instead of US-centric. As of Python 3.4, the empty string will be > lazily evaluated and be delimited by redback spiders instead of > quotes. That will give a 25% speed and 50% memory usage improvement, > but you'll need to be careful you don't get bitten > Look - the worst that will happen is nausea and painful swelling and maybe death if you're a very young child. Personally I voted for the Fierce Snake[1][2] as the delimiter, but it was voted down as "not Pythonic" enough. I'm sure they were using that as a euphamism for "Python*ish*" though. [1] https://en.wikipedia.org/wiki/Inland_Taipan [2] It's is so pretty: https://upload.wikimedia.org/wikipedia/commons/f/fe/Fierce_Snake-Oxyuranus_microlepidotus.jpg Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From piet at vanoostrum.org Sat Sep 29 17:51:29 2012 From: piet at vanoostrum.org (Piet van Oostrum) Date: Sat, 29 Sep 2012 17:51:29 -0400 Subject: Should one always add super().__init__() to the __init__? References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico writes: > On Sun, Sep 30, 2012 at 3:17 AM, Steven D'Aprano > wrote: >> No. Only add code that works and that you need. Arbitrarily adding calls >> to the superclasses "just in case" may not work: >> >> py> class Spam(object): >> ... def __init__(self, x): >> ... self.x = x >> ... super(Spam, self).__init__(x) >> ... >> py> x = Spam(1) >> Traceback (most recent call last): >> File "", line 1, in >> File "", line 4, in __init__ >> TypeError: object.__init__() takes no parameters > > That's because you're subclassing something that doesn't take > parameters and giving it parameters. Of course that won't work. The > normal and logical thing to do is to pass on only the parameters that > you know the parent class expects... but that implies knowing the > parent, so it's kinda moot. It is not necesarily calling the parent class. It calls the initializer of the next class in the MRO order and what class that is depends on the actual multiple inheritance structure it is used in, which can depend on subclasses that you don't know yet. This makes it even worse. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From rosuav at gmail.com Sat Sep 29 19:26:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Sep 2012 09:26:20 +1000 Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. In-Reply-To: References: <5066506D.4020702@tim.thechases.com> <50665A23.1060300@tim.thechases.com> <50666b49$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 30, 2012 at 6:51 AM, Tim Delaney wrote: > Personally I voted for the Fierce Snake[1][2] as the delimiter, but it was > voted down as "not Pythonic" enough. > I'm sure they were using that as a euphamism for "Python*ish*" though. > > [1] https://en.wikipedia.org/wiki/Inland_Taipan > [2] It's is so pretty: > https://upload.wikimedia.org/wikipedia/commons/f/fe/Fierce_Snake-Oxyuranus_microlepidotus.jpg A tempting idea, but it's rather a large delimiter. We should reserve that for multi-line strings, I think. Although you may have a problem with i18n; when you take your code to the southern hemisphere, the snake will be facing the other way, so what you thought was an open-quote marker is now a close-quote marker instead. Could get awkward for naive coders. ChrisA From timothy.c.delaney at gmail.com Sat Sep 29 20:10:22 2012 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Sun, 30 Sep 2012 10:10:22 +1000 Subject: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. In-Reply-To: References: <5066506D.4020702@tim.thechases.com> <50665A23.1060300@tim.thechases.com> <50666b49$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 30 September 2012 09:26, Chris Angelico wrote: > On Sun, Sep 30, 2012 at 6:51 AM, Tim Delaney > wrote: > > Personally I voted for the Fierce Snake[1][2] as the delimiter, but it > was > > voted down as "not Pythonic" enough. > > I'm sure they were using that as a euphamism for "Python*ish*" though. > > > > [1] https://en.wikipedia.org/wiki/Inland_Taipan > > [2] It's is so pretty: > > > https://upload.wikimedia.org/wikipedia/commons/f/fe/Fierce_Snake-Oxyuranus_microlepidotus.jpg > > A tempting idea, but it's rather a large delimiter. We should reserve > that for multi-line strings, I think. Although you may have a problem > with i18n; when you take your code to the southern hemisphere, the > snake will be facing the other way, so what you thought was an > open-quote marker is now a close-quote marker instead. Could get > awkward for naive coders > You seem to have that backwards. With the Oz-centric focus, it's taking code to the northern hemisphere that's the problem. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From kevin.s.anthony at gmail.com Sat Sep 29 21:27:58 2012 From: kevin.s.anthony at gmail.com (Kevin Anthony) Date: Sat, 29 Sep 2012 21:27:58 -0400 Subject: Compairing filenames in a list Message-ID: I have a list of filenames, and i need to find files with the same name, different extensions, and split that into tuples. does anyone have any suggestions on an easy way to do this that isn't O(n^2)? -- Thanks Kevin Anthony www.NoSideRacing.com Do you use Banshee? Download the Community Extensions: http://banshee.fm/download/extensions/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Sat Sep 29 21:41:03 2012 From: d at davea.name (Dave Angel) Date: Sat, 29 Sep 2012 21:41:03 -0400 Subject: Compairing filenames in a list In-Reply-To: References: Message-ID: <5067A32F.3070600@davea.name> On 09/29/2012 09:27 PM, Kevin Anthony wrote: > I have a list of filenames, and i need to find files with the same > name, different extensions, and split that into tuples. does anyone have > any suggestions on an easy way to do this that isn't O(n^2)? > > Sure, collect them in a collections.defaultdict Use basename for the key, and a list of names as the data item. if that's not good enough, show us your code, and why it doesn't work, and tell us what version of Python you're using. -- DaveA From cjw at ncf.ca Sat Sep 29 22:10:29 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 29 Sep 2012 22:10:29 -0400 Subject: How to get progress in python script. In-Reply-To: References: Message-ID: On 28/09/2012 12:26 PM, Rolando Ca?er Roblejo wrote: > Hi all, > > Please, I need you suggest me a way to get statistics about a progress > of my python script. My python script could take a lot of time > processing a file, so I need a way that an external program check the > progress of the script. My first idea was that the python script write a > temp file showing the progress and the external program can check that > file, but I think might happen file read/write locking issues. > > Thanks. Would the Python profiler meet your need? Colin W. From maniandram01 at gmail.com Sat Sep 29 23:14:10 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 29 Sep 2012 20:14:10 -0700 (PDT) Subject: Should one always add super().__init__() to the __init__? In-Reply-To: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <46096186-8383-4990-99c9-61c87f1c5a2f@googlegroups.com> On Saturday, 29 September 2012 22:47:20 UTC+5:30, Steven D'Aprano wrote: > On Sat, 29 Sep 2012 06:27:47 -0700, Ramchandra Apte wrote: > > > > > Should one always add super().__init__() to the __init__? The reason for > > > this is the possibility of changing base classes (and forgetting to > > > update the __init__). > > > > No. Only add code that works and that you need. Arbitrarily adding calls > > to the superclasses "just in case" may not work: > > > > > > > > py> class Spam(object): > > ... def __init__(self, x): > > ... self.x = x > > ... super(Spam, self).__init__(x) > > ... > > py> x = Spam(1) > > Traceback (most recent call last): > > File "", line 1, in > > File "", line 4, in __init__ > > TypeError: object.__init__() takes no parameters > > > > > > > > -- > > Steven I forgot something: I meant super().__init__() or similar From peterfarrell66 at gmail.com Sun Sep 30 00:13:07 2012 From: peterfarrell66 at gmail.com (peterfarrell66 at gmail.com) Date: Sat, 29 Sep 2012 21:13:07 -0700 (PDT) Subject: Editing in IDLE In-Reply-To: References: <13cba669-3640-4e7b-8fee-c84c7bafb67c@googlegroups.com> Message-ID: <20e0f570-997a-4df9-b5ee-1beec6e37417@googlegroups.com> Thanks for the responses, Terry and Chris, I'll try the shell, alt-P and I'll check out SciTE! Peter On Saturday, September 29, 2012 11:35:06 AM UTC-7, Chris Angelico wrote: > On Sun, Sep 30, 2012 at 3:14 AM, wrote: > > > Hello to the group! > > > > > > I'm a new Python user and so far I'm enjoying it. One of the many newbie problems I'm having is I can't edit my code in IDLE once it's run or there's an error message. I can only copy the code so far, paste at the bottom and continue coding. Is there something simple I'm missing, or should I be using a different editor? > > > > I only ever use IDLE in its interactive mode (at which, imho, it's > > rather better than the default Python interactive mode, as it > > auto-indents). In that mode, you can retrieve previous commands with > > Alt-P - at least, that's the keystroke on Windows, not sure if it's > > different on other platforms. > > > > For editing code that's to be saved in a .py file, I use SciTE, but a > > lot of people do use IDLE for that too. It's a matter of personal > > preference. > > > > ChrisA From peterfarrell66 at gmail.com Sun Sep 30 00:13:07 2012 From: peterfarrell66 at gmail.com (peterfarrell66 at gmail.com) Date: Sat, 29 Sep 2012 21:13:07 -0700 (PDT) Subject: Editing in IDLE In-Reply-To: References: <13cba669-3640-4e7b-8fee-c84c7bafb67c@googlegroups.com> Message-ID: <20e0f570-997a-4df9-b5ee-1beec6e37417@googlegroups.com> Thanks for the responses, Terry and Chris, I'll try the shell, alt-P and I'll check out SciTE! Peter On Saturday, September 29, 2012 11:35:06 AM UTC-7, Chris Angelico wrote: > On Sun, Sep 30, 2012 at 3:14 AM, wrote: > > > Hello to the group! > > > > > > I'm a new Python user and so far I'm enjoying it. One of the many newbie problems I'm having is I can't edit my code in IDLE once it's run or there's an error message. I can only copy the code so far, paste at the bottom and continue coding. Is there something simple I'm missing, or should I be using a different editor? > > > > I only ever use IDLE in its interactive mode (at which, imho, it's > > rather better than the default Python interactive mode, as it > > auto-indents). In that mode, you can retrieve previous commands with > > Alt-P - at least, that's the keystroke on Windows, not sure if it's > > different on other platforms. > > > > For editing code that's to be saved in a .py file, I use SciTE, but a > > lot of people do use IDLE for that too. It's a matter of personal > > preference. > > > > ChrisA From steve+comp.lang.python at pearwood.info Sun Sep 30 00:23:45 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Sep 2012 04:23:45 GMT Subject: Should one always add super().__init__() to the __init__? References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> <46096186-8383-4990-99c9-61c87f1c5a2f@googlegroups.com> Message-ID: <5067c951$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 29 Sep 2012 20:14:10 -0700, Ramchandra Apte wrote: > I forgot something: > I meant super().__init__() or similar What about it? Please try to remember that we can't read your mind and don't know what you are thinking, we can only work from what you put in writing. There is no difference between super(Class, self).__init__ and super().__init__ except that the second version only works in Python 3. -- Steven From steve+comp.lang.python at pearwood.info Sun Sep 30 00:37:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Sep 2012 04:37:22 GMT Subject: Should one always add super().__init__() to the __init__? References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5067cc81$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sun, 30 Sep 2012 04:31:48 +1000, Chris Angelico wrote: > On Sun, Sep 30, 2012 at 3:17 AM, Steven D'Aprano > wrote: >> No. Only add code that works and that you need. Arbitrarily adding >> calls to the superclasses "just in case" may not work: >> >> py> class Spam(object): >> ... def __init__(self, x): >> ... self.x = x >> ... super(Spam, self).__init__(x) ... >> py> x = Spam(1) >> Traceback (most recent call last): >> File "", line 1, in >> File "", line 4, in __init__ >> TypeError: object.__init__() takes no parameters > > That's because you're subclassing something that doesn't take parameters > and giving it parameters. Of course that won't work. The normal and > logical thing to do is to pass on only the parameters that you know the > parent class expects... but that implies knowing the parent, so it's > kinda moot. Which is exactly my point -- you can't call the superclass "just in case" it changes, because you don't know what arguments the new superclass or classes expect. You have to tailor the arguments to what the parent expects, and even whether or not you have to call super at all.[1] super() is not some magic command "don't bother me with the details, just make method overriding work". You have to actually think about what you are overriding. You can't expect to take a class that inherits from dict and change it to inherit from collections.defaultdict and have super magically sort out the differences in __init__. The usual advise given for using super is: * the method being called by super() needs to exist * the caller and callee need to have a matching[2] argument signature * and every occurrence of the method needs to use super() If all three conditions apply, then yes, you should use super. Otherwise, perhaps not. For further discussion and practical examples, see: http://rhettinger.wordpress.com/2011/05/26/super-considered-super/ For a contrary argument, or at least a look at how NOT to use super, see: https://fuhm.net/super-harmful/ which makes the mistake of blaming super() for mistakes made by people who don't use it correctly. Note that the author has back-peddled from his original argument that super was actively harmful to a less provocative argument that "you can't use super" (except you actually can: if you read past the first paragraph, the author tells you exactly what you need to do to use super correctly). [1] You *should* call super, unless you have an excellent reason not to, so that your class doesn't break multiple-inheritance. But you need to do so with care making sure that the argument signatures are designed for cooperative use of super. [2] Matching in this case does not necessarily mean identical. -- Steven From steve+comp.lang.python at pearwood.info Sun Sep 30 00:40:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Sep 2012 04:40:22 GMT Subject: Should one always add super().__init__() to the __init__? References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5067cd36$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 29 Sep 2012 17:51:29 -0400, Piet van Oostrum wrote: > It is not necesarily calling the parent class. It calls the initializer > of the next class in the MRO order and what class that is depends on the > actual multiple inheritance structure it is used in, which can depend on > subclasses that you don't know yet. This makes it even worse. I don't quite follow you here. It sounds like you are saying that if you have these classes: # pre-existing classes class A(object): pass class B(object): pass # your class class C(A, B): pass and somebody subclasses A or B, the MRO of C will change. That is not actually the case as far as I can see. -- Steven From rosuav at gmail.com Sun Sep 30 00:53:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Sep 2012 14:53:09 +1000 Subject: Should one always add super().__init__() to the __init__? In-Reply-To: <5067cc81$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> <5067cc81$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 30, 2012 at 2:37 PM, Steven D'Aprano wrote: > Which is exactly my point -- you can't call the superclass "just in case" > it changes, because you don't know what arguments the new superclass or > classes expect. You have to tailor the arguments to what the parent > expects, and even whether or not you have to call super at all.[1] > > super() is not some magic command "don't bother me with the details, just > make method overriding work". You have to actually think about what you > are overriding. Yeah. Far as I'm concerned, subclassing should *always* involve knowing the parent class. You needn't concern yourself with its implementation (I can subclass dict without caring about the details of hash randomization), but you have to be aware of its interface. And if you change the base class without changing your method chaining, you'd better be changing to a new base class that's equivalent to the old one. The advantage of super() is that you can substitute a subclass of X as a new base class without changing anything. But you need to be sure that the replacement base class obeys the Liskov Substitution Principle. ChrisA From maniandram01 at gmail.com Sun Sep 30 00:55:11 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 29 Sep 2012 21:55:11 -0700 (PDT) Subject: Should one always add super().__init__() to the __init__? In-Reply-To: <5067c951$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> <46096186-8383-4990-99c9-61c87f1c5a2f@googlegroups.com> <5067c951$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <66f99af0-39c2-4ef1-8f1e-dac17924432f@googlegroups.com> On Sunday, 30 September 2012 09:53:45 UTC+5:30, Steven D'Aprano wrote: > On Sat, 29 Sep 2012 20:14:10 -0700, Ramchandra Apte wrote: > > > > > I forgot something: > > > I meant super().__init__() or similar > > > > What about it? Please try to remember that we can't read your mind and > > don't know what you are thinking, we can only work from what you put in > > writing. > > > > There is no difference between super(Class, self).__init__ and > > super().__init__ except that the second version only works in Python 3. > > > > > > > > -- > > Steven When I said "super().__init__()" it could have been "super().__init__(size+67)" or whatever arguments are needed for __init__ From tjreedy at udel.edu Sun Sep 30 01:41:12 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 30 Sep 2012 01:41:12 -0400 Subject: EOL for Python 3.2? In-Reply-To: References: Message-ID: On 9/29/2012 4:03 PM, David Dillard wrote: > With the release of Python 3.3.0 does that mean the 3.2.x line is now > end of life? The next release (3.2.4, soon) will by the last 3.2 bugfix. Then 3 years for security fixes. > I've looked for some sort of end of life policy on python.org, but > was unable to find one. Don't know where written, but last 3.x bugfix about the time of 3.(x+1).0 and 3 years security is standard. -- Terry Jan Reedy From ian.g.kelly at gmail.com Sun Sep 30 02:08:03 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 30 Sep 2012 00:08:03 -0600 Subject: Should one always add super().__init__() to the __init__? In-Reply-To: <5067cd36$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> <5067cd36$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 29, 2012 at 10:40 PM, Steven D'Aprano wrote: > On Sat, 29 Sep 2012 17:51:29 -0400, Piet van Oostrum wrote: > >> It is not necesarily calling the parent class. It calls the initializer >> of the next class in the MRO order and what class that is depends on the >> actual multiple inheritance structure it is used in, which can depend on >> subclasses that you don't know yet. This makes it even worse. > > I don't quite follow you here. It sounds like you are saying that if you > have these classes: > > # pre-existing classes > class A(object): pass > class B(object): pass > > # your class > class C(A, B): pass > > and somebody subclasses A or B, the MRO of C will change. That is not > actually the case as far as I can see. The MRO of C will not change, but the class that follows C may be different in the MRO of a subclass. From ian.g.kelly at gmail.com Sun Sep 30 02:10:08 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 30 Sep 2012 00:10:08 -0600 Subject: Should one always add super().__init__() to the __init__? In-Reply-To: <66f99af0-39c2-4ef1-8f1e-dac17924432f@googlegroups.com> References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> <46096186-8383-4990-99c9-61c87f1c5a2f@googlegroups.com> <5067c951$0$29981$c3e8da3$5496439d@news.astraweb.com> <66f99af0-39c2-4ef1-8f1e-dac17924432f@googlegroups.com> Message-ID: On Sat, Sep 29, 2012 at 10:55 PM, Ramchandra Apte wrote: > When I said "super().__init__()" it could have been "super().__init__(size+67)" or whatever arguments are needed for __init__ But if you change the base class, couldn't those arguments change? Then you would have to change the call whether super is used or not. I believe this is what Steven is getting at. From ian.g.kelly at gmail.com Sun Sep 30 03:13:16 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 30 Sep 2012 01:13:16 -0600 Subject: Should one always add super().__init__() to the __init__? In-Reply-To: <5067cc81$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> <5067cc81$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 29, 2012 at 10:37 PM, Steven D'Aprano wrote: > [1] You *should* call super, unless you have an excellent reason not to, > so that your class doesn't break multiple-inheritance. But you need to do > so with care making sure that the argument signatures are designed for > cooperative use of super. I disagree. Most classes will not ever be used for multiple inheritance, and the changes involved in "making sure that the argument signatures are designed for cooperative use of super" are not trivial. For one, it means not being able to use positional arguments in __init__ methods. For two, the receive-and-strip-off-keyword-arguments approach falls apart if you have unrelated classes that take the same arguments. For illustration, suppose you have the following two classes, both of which use a required Frobnik object to perform their functions. class A: def __init__(self, frobnik, **kwargs): super().__init__(**kwargs) self._frobnik = frobnik ... class B: def __init__(self, frobnik, **kwargs): super().__init__(**kwargs) self._frobnik = frobnik ... Even though these classes have been designed to be cooperative, they cannot be inherited together. Whichever class is first in the MRO will receive the frobnik argument and strip it off, and then the other class's __init__ method will complain of a missing required argument. There are solutions to this. For instance, you could make frobnik optional in each class, each one relying on the other to receive the frobnik argument if it is missing, but this complicates the implementations and makes it difficult to detect in a timely manner if the frobnik argument has actually not been supplied. Or you could change the name of the argument in one of the classes, but then your library users will complain of inconsistent naming. What it boils down to is that classes that are expected to be used for multiple inheritance should be designed to use super cooperatively, but the majority of classes that you write should not have to deal with these sorts of restrictions. Classes that will only ever be singly inherited should be written normally and using whatever superclass call style feels most appropriate. From steve+comp.lang.python at pearwood.info Sun Sep 30 05:34:17 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Sep 2012 09:34:17 GMT Subject: Should one always add super().__init__() to the __init__? References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> <5067cd36$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50681219$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sun, 30 Sep 2012 00:08:03 -0600, Ian Kelly wrote: > On Sat, Sep 29, 2012 at 10:40 PM, Steven D'Aprano > wrote: >> On Sat, 29 Sep 2012 17:51:29 -0400, Piet van Oostrum wrote: >> >>> It is not necesarily calling the parent class. It calls the >>> initializer of the next class in the MRO order and what class that is >>> depends on the actual multiple inheritance structure it is used in, >>> which can depend on subclasses that you don't know yet. This makes it >>> even worse. >> >> I don't quite follow you here. It sounds like you are saying that if >> you have these classes: >> >> # pre-existing classes >> class A(object): pass >> class B(object): pass >> >> # your class >> class C(A, B): pass >> >> and somebody subclasses A or B, the MRO of C will change. That is not >> actually the case as far as I can see. > > The MRO of C will not change, but the class that follows C may be > different in the MRO of a subclass. To quote a famous line from the movie Cool Hand Luke, "what we have here, is a failure to communicate." What do you mean by one class following another? Which class is it that follows C? What subclass are you talking about, and what is it subclassing? I have absolutely no idea what you are trying to get across here, why you think it is important, or whether it matches what Piet is trying to say. -- Steven From nospam at nospam.com Sun Sep 30 05:55:02 2012 From: nospam at nospam.com (Gilles) Date: Sun, 30 Sep 2012 11:55:02 +0200 Subject: How to investigate web script not running? References: <8h7b68lk4lakmgijhqeo918e01gh7pg7d2@4ax.com> <7f6dc32a-1052-486a-9b5f-140e2297395d@googlegroups.com> Message-ID: On Sat, 29 Sep 2012 10:05:25 -0700 (PDT), Ramchandra Apte wrote: >> Definitely not plug 'n play :-/ > >Well the plug and play standard is superseded by USB practically. Indeed ;-) Anyway, Support finally got back to me, and it turns out that they have Flup alreay installed on shared hosts, so I just have to provide a WSGI script. OTOH, mod_fcgid is confured to wait 5mn or so before checking if the script was edited, so I'll have to use a test host for development and only use the shared host for deployment. Thank all. From oscar.j.benjamin at gmail.com Sun Sep 30 07:44:01 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 30 Sep 2012 12:44:01 +0100 Subject: How to get progress in python script. In-Reply-To: <5065CF9A.6090303@gmail.com> References: <5065CF9A.6090303@gmail.com> Message-ID: On 28 September 2012 17:26, Rolando Ca?er Roblejo wrote: > Hi all, > > Please, I need you suggest me a way to get statistics about a progress of > my python script. My python script could take a lot of time processing a > file, so I need a way that an external program check the progress of the > script. My first idea was that the python script write a temp file showing > the progress and the external program can check that file, but I think > might happen file read/write locking issues. > Why does it need to be an external program? I often write python scripts that run in the terminal and spend a long time processing a file or list of files. The simply way to report progress in that case is to just print something out every now and again. When I'm feeling extravagant I use the progressbar library from PyPI: http://pypi.python.org/pypi/progressbar/ With progressbar you can get a very nice display of current progress, ETA, etc: ''' import os.path import sys from progressbar import ProgressBar, Percentage, Bar, ETA def start(text, size): widgets = [text + ' ', Percentage(), ' ', Bar(), ETA()] return ProgressBar(widgets=widgets, maxval=size).start() def process_file(path): pbar = start(os.path.basename(path), os.path.getsize(path)) with open(path) as fin: for line in fin: pbar.update(pbar.currval + len(line)) words = line.split() pbar.finish() for path in sys.argv[1:]: process_file(path) ''' Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From mpg at elzevir.fr Sun Sep 30 08:04:04 2012 From: mpg at elzevir.fr (Manuel =?iso-8859-1?q?P=E9gouri=E9-Gonnard?=) Date: Sun, 30 Sep 2012 14:04:04 +0200 (CEST) Subject: Should one always add super().__init__() to the __init__? References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> <5067cd36$0$29981$c3e8da3$5496439d@news.astraweb.com> <50681219$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano scripsit : > On Sun, 30 Sep 2012 00:08:03 -0600, Ian Kelly wrote: > >> On Sat, Sep 29, 2012 at 10:40 PM, Steven D'Aprano >> wrote: >>> On Sat, 29 Sep 2012 17:51:29 -0400, Piet van Oostrum wrote: >>> >>>> It is not necesarily calling the parent class. It calls the >>>> initializer of the next class in the MRO order and what class that is >>>> depends on the actual multiple inheritance structure it is used in, >>>> which can depend on subclasses that you don't know yet. This makes it >>>> even worse. >>> >>> I don't quite follow you here. It sounds like you are saying that if >>> you have these classes: >>> >>> # pre-existing classes >>> class A(object): pass >>> class B(object): pass >>> >>> # your class >>> class C(A, B): pass >>> >>> and somebody subclasses A or B, the MRO of C will change. That is not >>> actually the case as far as I can see. >> >> The MRO of C will not change, but the class that follows C may be >> different in the MRO of a subclass. > > To quote a famous line from the movie Cool Hand Luke, "what we have here, > is a failure to communicate." > > What do you mean by one class following another? Which class is it > that follows C? What subclass are you talking about, and what is it > subclassing? > I think Piet's (and Ian's) point is, you can't assume that super().__init__, written in a method of C, is always going to refer to __init__ of the parent class of C, when a subclass of C is instanciated. For example: class C: def __init__(self): print("C init, calling C's parent init?") super().__init__() # sic class NotParentOfC: def __init__(self): print("NotParentOfC init") class Sub(C, NotParentOfC): pass spam = Sub() When Sub is instantiated, the line marked "sic" calls NotParentOfC.__init, not object.__init__ (as if would if C was instantiated). -- Manuel P?gouri?-Gonnard - http://people.math.jussieu.fr/~mpg/ From kwpolska at gmail.com Sun Sep 30 08:04:54 2012 From: kwpolska at gmail.com (Kwpolska) Date: Sun, 30 Sep 2012 14:04:54 +0200 Subject: Missing library path (WIndows) In-Reply-To: <21e6fb32-ee1e-429d-ba6f-276c8208ca78@googlegroups.com> References: <8cab2c34-7594-471a-80e9-47206bd3ea32@googlegroups.com> <21e6fb32-ee1e-429d-ba6f-276c8208ca78@googlegroups.com> Message-ID: On Sat, Sep 29, 2012 at 10:32 PM, FPEFPE wrote: > On Saturday, September 29, 2012 4:02:13 AM UTC-4, Kwpolska wrote: >> >> Python has problems with encoding the arguments to look properly with >> >> the crappy Windows cmd.exe encodings. They cannot be encoded for some >> >> reason. You may need magic, but I?m not quite sure what in Py3k >> >> (bytestrings?) >> >> >> >> -- >> >> Kwpolska >> >> stop html mail | always bottom-post >> >> www.asciiribbon.org | www.netmeister.org/news/learn2quote.html >> >> GPG KEY: 5EAAEA16 > > Hello -- thanks for the reply ... is "magic" a debugging tool? > -- > http://mail.python.org/mailman/listinfo/python-list No, no, no! I meant ?do some magic with the string?. In Py2k, it would be str.decode(), but I don?t know what to do in Py3k. -- Kwpolska stop html mail | always bottom-post www.asciiribbon.org | www.netmeister.org/news/learn2quote.html GPG KEY: 5EAAEA16 From maniandram01 at gmail.com Sun Sep 30 08:50:52 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sun, 30 Sep 2012 05:50:52 -0700 (PDT) Subject: python file API In-Reply-To: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> References: <0ec1fe2e-890c-4e25-8047-4cb8bee0aa95@googlegroups.com> Message-ID: On Tuesday, 25 September 2012 03:05:16 UTC+5:30, zipher wrote: > For some time now, I've wanted to suggest a better abstraction for the type in Python. It currently uses an antiquated C-style interface for moving around in a file, with methods like tell() and seek(). But after attributes were introduced to Python, it seems it should be re-addressed. > > > > Let file-type have an attribute .pos for position. Now you can get rid of the seek() and tell() methods and manipulate the file pointer more easily with standard arithmetic operations. > > > > >>> file.pos = x0ae1 #move file pointer to an absolute address > > >>> file.pos +=1 #increment the file pointer one byte > > >>> curr_pos = file.pos #read current file pointer > > > > You've now simplified the API by the removal of two obscure legacy methods and replaced them with a more basic one called "position". > > > > Thoughts? > > > > markj +1 From tomeuari at gmail.com Sun Sep 30 08:58:40 2012 From: tomeuari at gmail.com (tcgo) Date: Sun, 30 Sep 2012 05:58:40 -0700 (PDT) Subject: Can somebody give me an advice about what to learn? Message-ID: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Hi! I'm really new to Usenet/Newsgroups, but... I'd like to learn some new programming language, because I learnt a bit of Perl though its OOP is ugly. So, after searching a bit, I found Python and Ruby, and both of they are cute. So, assuming you'll say me "learn python", why should I learn it over Ruby? Thanks! PS: I don't want to start a flame-war, I just want an advice if it's possible please! From g.brandl at gmx.net Sun Sep 30 09:19:50 2012 From: g.brandl at gmx.net (Georg Brandl) Date: Sun, 30 Sep 2012 15:19:50 +0200 Subject: [RELEASED] Python 3.3.0 In-Reply-To: <20120929185341.641ab269@pitrou.net> References: <5066E72E.2010100@python.org> <20120929185341.641ab269@pitrou.net> Message-ID: On 09/29/2012 06:53 PM, Antoine Pitrou wrote: > > Hello, > > I've created a 3.3 category on the buildbots: > http://buildbot.python.org/3.3/ > http://buildbot.python.org/3.3.stable/ > > Someone will have to update the following HTML page: > http://python.org/dev/buildbot/ Should be done now. Georg From rosuav at gmail.com Sun Sep 30 09:25:50 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Sep 2012 23:25:50 +1000 Subject: Can somebody give me an advice about what to learn? In-Reply-To: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Message-ID: On Sun, Sep 30, 2012 at 10:58 PM, tcgo wrote: > Hi! > I'm really new to Usenet/Newsgroups, but... I'd like to learn some new programming language, because I learnt a bit of Perl though its OOP is ugly. So, after searching a bit, I found Python and Ruby, and both of they are cute. > So, assuming you'll say me "learn python", why should I learn it over Ruby? > Thanks! > PS: I don't want to start a flame-war, I just want an advice if it's possible please! I'm not going to touch Ruby, partly because I don't know it, and partly to avoid a flame war, but here's some good reasons to learn Python: * It's a modern, object-oriented, high level language. * As of version 3.3 (do make sure you grab this one, there's lots of enhancements), it has absolutely correct AND efficient Unicode string handling. I know of only one other language that can store "Hello" as a five-byte string, while simultaneously allowing perfect handling of the entire Unicode range. * Python's syntax is clean and easy to handle. Be aware, though, that some things are distinctly different from C-family languages. * You get an excellent set of modules. Python has "batteries included" (the standard library is extensive) and a whole set of custom batteries on speed dial (check out PyPI). * Easy networking support. You can write servers or clients for many popular internet protocols with just a few lines of code. Simple TCP sockets are also easy. * Python is an open source project with a permissive license. * Superb community support. You can ask a question here and get a response in minutes. :) You're not going to be left hanging when you have a problem. * With very VERY few exceptions, your code will run flawlessly on any of the many platforms Python supports. Python does have some issues, though; you'll either appreciate the syntax or absolutely hate it, and there's no efficient and reliable way to change/reload code in a running application (not often an issue). I'm sure others will add to this list, and there's at least one entry that someone's likely to disagree with me on, but there's a start! ChrisA From python.list at tim.thechases.com Sun Sep 30 09:45:38 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 30 Sep 2012 08:45:38 -0500 Subject: Can somebody give me an advice about what to learn? In-Reply-To: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Message-ID: <50684D02.6030806@tim.thechases.com> On 09/30/12 07:58, tcgo wrote: > So, assuming you'll say me "learn python", why should I learn it > over Ruby? For me, most of Chris's answers apply to both Python and Ruby. Well, I can't speak regarding the Ruby community being as awesome, but it doesn't seem to scare off folks. *READABILITY* is my main reason for choosing Python, particularly over Ruby. I can come back to Python code I wrote 5+ years ago, and it takes me mere minutes to reorient myself to the code. I can't do that with most other languages, where it often takes me hours or days to unwind the code. -tkc From rodrick.brown at gmail.com Sun Sep 30 09:49:09 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Sun, 30 Sep 2012 09:49:09 -0400 Subject: Can somebody give me an advice about what to learn? In-Reply-To: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Message-ID: On Sun, Sep 30, 2012 at 8:58 AM, tcgo wrote: > Hi! > I'm really new to Usenet/Newsgroups, but... I'd like to learn some new > programming language, because I learnt a bit of Perl though its OOP is > ugly. So, after searching a bit, I found Python and Ruby, and both of they > are cute. > So, assuming you'll say me "learn python", why should I learn it over Ruby? > Thanks! > Python comes stock on most Linux distro's and many RPM based distros uses Python itself as a core scripting language unlike Ruby, that's why I choose Python over Ruby 3-4 years back when I was debating which one I should learn. PS: I don't want to start a flame-war, I just want an advice if it's > possible please! > This is a Python mailinglist so I doubt you can ignite any flamewar's between Python vs Ruby! :) > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Sun Sep 30 10:23:35 2012 From: roy at panix.com (Roy Smith) Date: Sun, 30 Sep 2012 10:23:35 -0400 Subject: Can somebody give me an advice about what to learn? References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Message-ID: In article , Chris Angelico wrote: > there's no efficient and reliable way to change/reload code in a > running application (not often an issue). What we do (largely cribbed from django's runserver) is start up a thread which once a second, looks at all the modules in sys.modules, checks to see if the modification time for their source files has changed, and if so, restarts the application. This is hugely convenient when developing any kind of long-running application. You don't need to keep restarting the application; just edit the source and changes take effect (almost) immediately. Not sure if this is what you had in mind. From rosuav at gmail.com Sun Sep 30 10:35:52 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Oct 2012 00:35:52 +1000 Subject: Can somebody give me an advice about what to learn? In-Reply-To: References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Message-ID: On Mon, Oct 1, 2012 at 12:23 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> there's no efficient and reliable way to change/reload code in a >> running application (not often an issue). > > What we do (largely cribbed from django's runserver) is start up a > thread which once a second, looks at all the modules in sys.modules, > checks to see if the modification time for their source files has > changed, and if so, restarts the application. This is hugely convenient > when developing any kind of long-running application. You don't need to > keep restarting the application; just edit the source and changes take > effect (almost) immediately. > > Not sure if this is what you had in mind. It's not an _explicit_ restart, but you have to write your application to keep all its state on disk in some way. What I'm talking about is having a single process that never terminates, never stops accepting connections, but at some point new connections begin to be served with new code - with old ones, if they're still going, continuing to be handled by the old code. I have one such process that's been going for (let me check) 115 wk 0d 21:05:21. For many types of application, restarting is perfectly viable, so this isn't a major issue with Python. ChrisA From rosuav at gmail.com Sun Sep 30 10:37:27 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Oct 2012 00:37:27 +1000 Subject: Can somebody give me an advice about what to learn? In-Reply-To: References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Message-ID: On Mon, Oct 1, 2012 at 12:35 AM, Chris Angelico wrote: > What I'm talking about is > having a single process that never terminates, never stops accepting > connections, but at some point new connections begin to be served with > new code... And to clarify, only the code that needs updating gets updated; in-memory state is retained elsewhere, and modules are permitted and welcome to use a "global state area" that doesn't get wiped on any code reload. ChrisA From roy at panix.com Sun Sep 30 11:01:10 2012 From: roy at panix.com (Roy Smith) Date: Sun, 30 Sep 2012 11:01:10 -0400 Subject: Can somebody give me an advice about what to learn? References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Message-ID: In article , Chris Angelico wrote: > On Mon, Oct 1, 2012 at 12:23 AM, Roy Smith wrote: > > In article , > > Chris Angelico wrote: > > > >> there's no efficient and reliable way to change/reload code in a > >> running application (not often an issue). > > > > What we do (largely cribbed from django's runserver) is start up a > > thread which once a second, looks at all the modules in sys.modules, > > checks to see if the modification time for their source files has > > changed, and if so, restarts the application. This is hugely convenient > > when developing any kind of long-running application. You don't need to > > keep restarting the application; just edit the source and changes take > > effect (almost) immediately. > > > > Not sure if this is what you had in mind. > > It's not an _explicit_ restart, but you have to write your application > to keep all its state on disk in some way. Well, more strictly, what you need is to keep your state somewhere else. Doesn't have to be on disk. Could be in memory, if that memory belongs to another process (memcache, redis, or any of a number of in-memory databases). > What I'm talking about is > having a single process that never terminates, never stops accepting > connections, but at some point new connections begin to be served with > new code - with old ones, if they're still going, continuing to be > handled by the old code. I have one such process that's been going for > (let me check) 115 wk 0d 21:05:21. Why does it have to be a single process? I could imagine some front-end process which accepts connections and hands them off to worker processes. When you install new code, you could do it in a different directory tree, and then signal the front end that new code exists. The front end could then {chdir, munge sys.path, whatever} to the root of the new tree and keep going. Existing connections stay up with the old code, new connections get the new code. If you didn't want to fork a new process every time, you could have a worker process pool. When a worker signaled it was done with a task, the front end could either assign it a new connection (if the code it was running was still current), or kill it off if it was running stale code. If you truly needed this to be a single process, I could imagine a customized module importer which altered the module name to include a version prefix before registering it in sys.modules. I think that could be made to work, but would be really ugly and complicated. Or elegant and nifty, depending on your attitude :-) From rustompmody at gmail.com Sun Sep 30 11:18:01 2012 From: rustompmody at gmail.com (rusi) Date: Sun, 30 Sep 2012 08:18:01 -0700 (PDT) Subject: Can somebody give me an advice about what to learn? References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Message-ID: <4806a0b7-818a-4844-8286-f1b891a3c6d4@rj6g2000pbc.googlegroups.com> On Sep 30, 5:58?pm, tcgo wrote: > Hi! > I'm really new to Usenet/Newsgroups, but... I'd like to learn some new programming language, because I learnt a bit of Perl though its OOP is ugly. So, after searching a bit, I found Python and Ruby, and both of they are cute. > So, assuming you'll say me "learn python", why should I learn it over Ruby? > Thanks! > PS: I don't want to start a flame-war, I just want an advice if it's possible please! Here's a test to help you decide: How do you respond to the word 'magic'? If positive you will like Ruby, if not you may prefer Python. Personal note: I like magic -- as long as its not in a tech area, eg I'm a fan of Harry Potter. From rosuav at gmail.com Sun Sep 30 11:37:07 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Oct 2012 01:37:07 +1000 Subject: Can somebody give me an advice about what to learn? In-Reply-To: References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Message-ID: On Mon, Oct 1, 2012 at 1:01 AM, Roy Smith wrote: > Well, more strictly, what you need is to keep your state somewhere else. > Doesn't have to be on disk. Could be in memory, if that memory belongs > to another process (memcache, redis, or any of a number of in-memory > databases). Sure. I'll generalize my statement to "Has to be external to the process". That generally precludes the direct use of complex objects, requiring some form of serialization or dump format - you can't, for instance, retain a "socket connection object" across that sort of reload. > Why does it have to be a single process? I could imagine some front-end > process which accepts connections and hands them off to worker > processes. When you install new code, you could do it in a different > directory tree, and then signal the front end that new code exists. The > front end could then {chdir, munge sys.path, whatever} to the root of > the new tree and keep going. Existing connections stay up with the old > code, new connections get the new code. That's also a good model, for situations that can use it. My situation is a MUD-like system where different clients can affect one another, so the most logical way to do it is a single process. For instance, we have a Dungeons and Dragons battle grid that uses a web browser as its display engine; you go to a particular URL, key in your login details, and it sends AJAX long polls to the server. Whenever one client moves a token on the grid, every other client gets notified. I could, of course, do this across processes, but I'd end up needing a hefty IPC system; this way, all I need is a lightweight event semaphore that the threads wait on, and they look at the process's internal structures (thread-safe, they need only read at that point). I could have done it in other ways, of course, but this is nice and straightforward. But this is getting rather off-topic :) For the bulk of usage patterns, Python's fine. Most languages don't let you reload code on the fly, and most applications are never going to be bothered by this miniscule feature lack! ChrisA From breamoreboy at yahoo.co.uk Sun Sep 30 11:47:48 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 30 Sep 2012 16:47:48 +0100 Subject: Can somebody give me an advice about what to learn? In-Reply-To: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Message-ID: On 30/09/2012 13:58, tcgo wrote: > Hi! > I'm really new to Usenet/Newsgroups, but... I'd like to learn some new programming language, because I learnt a bit of Perl though its OOP is ugly. So, after searching a bit, I found Python and Ruby, and both of they are cute. > So, assuming you'll say me "learn python", why should I learn it over Ruby? > Thanks! > PS: I don't want to start a flame-war, I just want an advice if it's possible please! > http://www.gossamer-threads.com/lists/python/python/129650?do=post_view_threaded -- Cheers. Mark Lawrence. From joshua.landau.ws at gmail.com Sun Sep 30 13:44:47 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Sun, 30 Sep 2012 18:44:47 +0100 Subject: Can somebody give me an advice about what to learn? In-Reply-To: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Message-ID: On 30 September 2012 13:58, tcgo wrote: > Hi! > I'm really new to Usenet/Newsgroups, but... I'd like to learn some new > programming language, because I learnt a bit of Perl though its OOP is > ugly. So, after searching a bit, I found Python and Ruby, and both of them > are cute. > So, assuming you'll say me "learn python", why should I learn it over Ruby? > Thanks! > PS: I don't want to start a flame-war, I just want an advice if it's > possible please! > Like the others I don't know Ruby but a 2 minute check on Google implies that Ruby doesn't have something equivalent to Cython. I *really like* Cython because it lets me optimize without learning C*. I *really dislike* C, so this is important to me. Cython may be a bit much [aka. is way too much] for someone learning a language, but it will help if you do progress that much further. Of course, Ruby lets you write C extensions, but that's another language to learn. * You still have to learn C types, but Cython has better array classes and support for Python buffers that lets you skip most of the harder types. You don't need malloc in Cython, for example, unless you really need C arrays. Python also has PyPy, which is faster than most of what Ruby has, pushing that dreaded optimization down the road. Language wise, *whilst again I cannot speak for Ruby*, Python has a very important trait: sanity. If you slow yourself down enough, Python has a miraculous ability to make the meaning of every line you write *bloody obvious*. That's pretty much the most important part of a language. *Look over code examples of both, and choose the language you can read.* -------------- next part -------------- An HTML attachment was scrubbed... URL: From eldiener at tropicsoft.invalid Sun Sep 30 15:14:17 2012 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 30 Sep 2012 15:14:17 -0400 Subject: Coexistence of Python 2.x and 3.x on same OS Message-ID: Has there been any official software that allows both the Python 2.x and 3.x releases to coexist on the same OS so that the end-user can easily switch between them when invoking Python scripts after each has been installed to their own directories/folders ? I know of some unoffical solutions, but they require lots of tweaks. Given the vagaries of the different OSs on which Python can run I am hoping for some offical solution which will work on any of the most popular OSs ( Windows, Linux, Mac ). The situation is so confusing on Windows, where the file associations, registry entries, and other internal software which allows a given Python release to work properly when invoking Python is so complicated, that I have given up on trying to install more than one Python release and finding a relaible, foolproof way of switching between them. So although I would like to use the latest 3.x series on Windows I have decide to stick with the latest 2.x series instead because much software using Python does not support 3.x yet. From chris.jerdonek at gmail.com Sun Sep 30 15:14:37 2012 From: chris.jerdonek at gmail.com (Chris Jerdonek) Date: Sun, 30 Sep 2012 12:14:37 -0700 Subject: [Python-Dev] experimental: Misc/NEWS included in docs In-Reply-To: References: Message-ID: On Sun, Sep 30, 2012 at 6:17 AM, Georg Brandl wrote: > at http://docs.python.org/3.3/whatsnew/news.html, there is now > a rendering of Misc/NEWS with tracker links and a crude filtering > capability. I thought that this will complement the "whatsnew" > documents nicely for people looking for more detail. > > Please let me know if it's useful, or what could be done to make > it *more* useful. Good idea. Some suggestions: * A note at the top explaining what this page is and how it differs from the other What's New page (including perhaps a link to the other What's New page). It might also be good if the two had more distinctive titles. They are currently "What?s New in Python" and "Python News." * It would be good if the section links could somehow be "perma-links." They will currently vary over time, e.g. http://docs.python.org/py3k/whatsnew/news.html#id3 * Lastly, I think skimming this list would be more informative to me at least if each bullet began with the name of the affected module or area (at least in the case where just one module is affected). The issue number is less meaningful as a descriptive header. Changing this would likely require changes in how we prepare Misc/NEWS though. On a separate but related note, I never know where to put the various subsections in relation to one another in Misc/NEWS (Core and Builtins, Library, Extension Modules, etc). It would be good if there was guidance on that -- even if to say it completely doesn't matter. --Chris From bahamutzero8825 at gmail.com Sun Sep 30 15:38:00 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 30 Sep 2012 14:38:00 -0500 Subject: Coexistence of Python 2.x and 3.x on same OS In-Reply-To: References: Message-ID: <50689F98.1000407@gmail.com> On 2012.09.30 14:14, Edward Diener wrote: > The situation is so confusing on Windows, where the file associations, > registry entries, and other internal software which allows a given > Python release to work properly when invoking Python is so complicated, > that I have given up on trying to install more than one Python release > and finding a relaible, foolproof way of switching between them. So > although I would like to use the latest 3.x series on Windows I have > decide to stick with the latest 2.x series instead because much software > using Python does not support 3.x yet. http://www.python.org/dev/peps/pep-0397/ Unix-based OSes should already obey the shebang line, and on Windows, there's py.exe in 3.3 that will launch the intended version based on that shebang line. While I was using the alpha/beta versions of 3.3, I had no problems invoking either 3.2 or 3.3 with the shebang line on Windows. -- CPython 3.3.0 | Windows NT 6.1.7601.17835 From peterfarrell66 at gmail.com Sun Sep 30 15:42:37 2012 From: peterfarrell66 at gmail.com (Peter Farrell) Date: Sun, 30 Sep 2012 12:42:37 -0700 (PDT) Subject: Can't import modules Message-ID: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> Hello! I'm still new to Python, so here's another easy one. After I save something I've done as a .py file, how do I import it into something else I work on? Every time I try to import something other than turtle or math, I get this error message: 'module' object is not callable What am I doing wrong? Thanks! Peter Farrell San Mateo, CA From benjamin.kaplan at case.edu Sun Sep 30 16:15:11 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 30 Sep 2012 13:15:11 -0700 Subject: Can't import modules In-Reply-To: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> Message-ID: On Sun, Sep 30, 2012 at 12:42 PM, Peter Farrell wrote: > Hello! > > I'm still new to Python, so here's another easy one. After I save something I've done as a .py file, how do I import it into something else I work on? Every time I try to import something other than turtle or math, I get this error message: > > 'module' object is not callable > > What am I doing wrong? > > Thanks! > > Peter Farrell > San Mateo, CA > -- Well, you haven't told us what you're doing, so it's hard to say what you're doing wrong. So I'm going to make a few guesses. 1. Your first (and possibly only other) language was Java. 2. You're making a class (let's say Foo) and putting it in a file of the same name (Foo.py) 3. You're doing "import Foo" and then calling "Foo()" trying to instantiate the class. Python doesn't have that "one class per file, and the file must have the same name as the class" rule as Java. The file defines a module, which is an object and can have any number of objects (including classes, because those are objects too) in it. $ cat foo.py class Foo(object): pass def add2(y) : return y + 2 bkaplan:~ bkaplan$ python Python 2.7.3 (default, Apr 23 2012, 10:06:17) [GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.58)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import foo >>> dir(foo) ['Foo', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'add2', 'x'] >>> foo() Traceback (most recent call last): File "", line 1, in TypeError: 'module' object is not callable >>> foo.Foo() >>> foo.add2(5) 7 From steve+comp.lang.python at pearwood.info Sun Sep 30 16:21:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Sep 2012 20:21:01 GMT Subject: Can't import modules References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> Message-ID: <5068a9ac$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sun, 30 Sep 2012 12:42:37 -0700, Peter Farrell wrote: > Hello! > > I'm still new to Python, so here's another easy one. After I save > something I've done as a .py file, how do I import it into something > else I work on? Every time I try to import something other than turtle > or math, I get this error message: > > 'module' object is not callable > > What am I doing wrong? I would say that the two things you are doing wrong are, firstly, not posting the ENTIRE error message, including the full traceback, and most importantly, not paying attention to what Python is trying to tell you. The full traceback gives import information. For example: py> import foo Traceback (most recent call last): File "", line 1, in ImportError: No module named 'foo' Note carefully that Python tells you the *kind* of error made: an IMPORT error, as well as a specific error message, namely that there is no module called "foo". Python will often print the actual line causing the error as well. In your case, my guess is that this is your error: py> import math py> math(123) Traceback (most recent call last): File "", line 1, in TypeError: 'module' object is not callable Notice that the import succeeds. So it is *incorrect* that you cannot import modules, but once you import them, you use them incorrectly! Python tells you exactly what went wrong, if you would only pay attention to it: * it is a TYPE error, not an import error; * modules cannot be called as if they were a function Does this solve your problem? If not, please: * show us the ACTUAL code you are using * show us the full traceback, not just the error message * and don't expect us to guess what you are doing Thank you. -- Steven From steve+comp.lang.python at pearwood.info Sun Sep 30 16:21:31 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Sep 2012 20:21:31 GMT Subject: Can't import modules References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> Message-ID: <5068a9cb$0$29982$c3e8da3$5496439d@news.astraweb.com> On Sun, 30 Sep 2012 12:42:37 -0700, Peter Farrell wrote: > Hello! > > I'm still new to Python, so here's another easy one. After I save > something I've done as a .py file, how do I import it into something > else I work on? Every time I try to import something other than turtle > or math, I get this error message: > > 'module' object is not callable > > What am I doing wrong? I would say that the two things you are doing wrong are, firstly, not posting the ENTIRE error message, including the full traceback, and most importantly, not paying attention to what Python is trying to tell you. The full traceback gives import information. For example: py> import foo Traceback (most recent call last): File "", line 1, in ImportError: No module named 'foo' Note carefully that Python tells you the *kind* of error made: an IMPORT error, as well as a specific error message, namely that there is no module called "foo". Python will often print the actual line causing the error as well. In your case, my guess is that this is your error: py> import math py> math(123) Traceback (most recent call last): File "", line 1, in TypeError: 'module' object is not callable Notice that the import succeeds. So it is *incorrect* that you cannot import modules, but once you import them, you use them incorrectly! Python tells you exactly what went wrong, if you would only pay attention to it: * it is a TYPE error, not an import error; * modules cannot be called as if they were a function Does this solve your problem? If not, please: * show us the ACTUAL code you are using * show us the full traceback, not just the error message * and don't expect us to guess what you are doing Thank you. -- Steven From hansmu at xs4all.nl Sun Sep 30 16:21:51 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sun, 30 Sep 2012 22:21:51 +0200 Subject: Can't import modules In-Reply-To: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> Message-ID: <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> On 30/09/12 21:42:37, Peter Farrell wrote: > I'm still new to Python, so here's another easy one. After I save something > I've done as a .py file, how do I import it into something else I work on? > Every time I try to import something other than turtle or math, I get this error message: > > 'module' object is not callable > > What am I doing wrong? For starters, you're not showing us any code. The error message suggests that you have successfully imported a module, and you then try to use the module as if it were a callable. That won't work: modules are not callable. My crystal ball says that you may have been a Java programmer in an earlier life. In Java, a file must define exactly one class, and the class must have the same name as the file. Python is not Java. In Python, a file may define one class, or twenty, or none at all. To avoid confusion, do not give any of your classes the same name as any of your files. Hope this helps, -- HansM From mcepl at redhat.com Sun Sep 30 17:46:27 2012 From: mcepl at redhat.com (Matej Cepl) Date: Sun, 30 Sep 2012 23:46:27 +0200 Subject: "#!/usr/bin/env python" vs. "#!/usr/bin/python"? In-Reply-To: References: <34va6856ocuas7jpueujscf3kdt7k44mfl@4ax.com> Message-ID: On 28/09/12 12:57, Roy Smith wrote: > But, you might as well get into the habit of > using the /usr/bin/env flavor because it's more flexible. In the same manner as one's freedom-fighter is another's fundamentalist terrorist, what's flexible could be also dangerous. E.g., #!/usr/bin/env python is forbidden in the core Fedora packages (https://fedoraproject.org/wiki/Features/SystemPythonExecutablesUseSystemPython), because nobody is willing to risk that by some random python binary in /usr/local/bin some core infrastructure of Fedora installations (e.g., yum) could be broken. Mat?j From arnodel at gmail.com Sun Sep 30 18:08:32 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 30 Sep 2012 23:08:32 +0100 Subject: Compairing filenames in a list In-Reply-To: References: Message-ID: On 30 September 2012 02:27, Kevin Anthony wrote: > I have a list of filenames, and i need to find files with the same name, > different extensions, and split that into tuples. does anyone have any > suggestions on an easy way to do this that isn't O(n^2)? >>> import os, itertools >>> filenames = ["foo.png", "bar.csv", "foo.html", "bar.py"] >>> dict((key, tuple(val)) for key, val in itertools.groupby(sorted(filenames), lambda f: os.path.splitext(f)[0])) {'foo': ('foo.html', 'foo.png'), 'bar': ('bar.csv', 'bar.py')} -- Arnaud From roy at panix.com Sun Sep 30 18:14:29 2012 From: roy at panix.com (Roy Smith) Date: Sun, 30 Sep 2012 18:14:29 -0400 Subject: Can somebody give me an advice about what to learn? References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Message-ID: In article , Chris Angelico wrote: > you can't, for instance, retain a "socket connection object" across > that sort of reload. Yeah, that's a problem. There's nothing fundamental about a TCP connection endpoint which precludes it being serialized and passed around. The amount of state involved is pretty small. Unless I've forgotten something, 2 IP addresses, 2 port numbers, a few bits worth of TCP protocol state, and, for open connections, 2 sequence numbers. Maybe a couple of timers, but I don't think they're strictly necessary. The problem is, most of that state is private to the kernel. On the other hand, you could do what "screen" does, and spawn a process per connection to hold the connection open :-) From roy at panix.com Sun Sep 30 18:17:17 2012 From: roy at panix.com (Roy Smith) Date: Sun, 30 Sep 2012 18:17:17 -0400 Subject: Can somebody give me an advice about what to learn? References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> <4806a0b7-818a-4844-8286-f1b891a3c6d4@rj6g2000pbc.googlegroups.com> Message-ID: In article <4806a0b7-818a-4844-8286-f1b891a3c6d4 at rj6g2000pbc.googlegroups.com>, rusi wrote: > Here's a test to help you decide: How do you respond to the word > 'magic'? If positive you will like Ruby, if not you may prefer > Python. Some might say that magic underscores a lot of the really fun stuff in Python. See http://www.rafekettler.com/magicmethods.html From rosuav at gmail.com Sun Sep 30 19:11:01 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Oct 2012 09:11:01 +1000 Subject: Can somebody give me an advice about what to learn? In-Reply-To: References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Message-ID: On Mon, Oct 1, 2012 at 8:14 AM, Roy Smith wrote: > Yeah, that's a problem. There's nothing fundamental about a TCP > connection endpoint which precludes it being serialized and passed > around. The amount of state involved is pretty small. Unless I've > forgotten something, 2 IP addresses, 2 port numbers, a few bits worth of > TCP protocol state, and, for open connections, 2 sequence numbers. > Maybe a couple of timers, but I don't think they're strictly necessary. > The problem is, most of that state is private to the kernel. And can change at a moment's notice, with no userspace interaction. The socket connection also needs to retain sent-but-not-acknowledged and received-but-not-in-order data, so those buffers need to exist. The only way would be for the kernel to export something representing a socket - which would be the file handle. And then you have to worry about any other state, eg if you're reading line by line and are retaining a partial line... not really something that can be patched in five seconds, and not IMHO worth trying to do. Easier to simply retain the process ID. Oh, and if the pid changes on a live connection, what will that do with iptables controls, which can look at the originating process's user id and such? Hrm. ChrisA From steve+comp.lang.python at pearwood.info Sun Sep 30 19:59:27 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Sep 2012 23:59:27 GMT Subject: Can somebody give me an advice about what to learn? References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> <4806a0b7-818a-4844-8286-f1b891a3c6d4@rj6g2000pbc.googlegroups.com> Message-ID: <5068dcdf$0$29997$c3e8da3$5496439d@news.astraweb.com> On Sun, 30 Sep 2012 18:17:17 -0400, Roy Smith wrote: > In article > <4806a0b7-818a-4844-8286-f1b891a3c6d4 at rj6g2000pbc.googlegroups.com>, > rusi wrote: > >> Here's a test to help you decide: How do you respond to the word >> 'magic'? If positive you will like Ruby, if not you may prefer Python. > > Some might say that magic underscores a lot of the really fun stuff in > Python. See http://www.rafekettler.com/magicmethods.html And they would be wrong. The word they want is "special", not magic. There's nothing[1] magic about double leading-and-trailing underscore methods. They are just ordinary methods that are treated specially by Python to implement syntax such as + (the __add__ and __radd__ methods), len() (the __len__ method) and similar. The article you link to starts off with this: [quote] What are magic methods? They're everything in object-oriented Python. They're special methods that you can define to add "magic" to your classes. [end quote] Being able to add two values, or get the number of items in a container, is hardly magic. They're *special*, because the compiler looks for methods of those names, but that's all. [quote] They're also not as well documented as they need to be. All of the magic methods for Python appear in the same section in the Python docs, but they're scattered about and only loosely organized. [end quote] You got that? They're all in the same section, AND they are scattered about at the same time! Now that's truly magic! *wink* Special is not magic. Magic means that the normal behaviour of the language is broken for some arbitrary cases. Here's an example in hardware of "magic": http://catb.org/jargon/html/magic-story.html Now imagine that in software: it can't possibly work, and yet it does. I dare say nearly all non-toy languages have *some* magic. But some languages have more than others: they are full of unique cases, every one different, where the same code behaves differently that you would expect. There *is* some magic in Python: * Methods and attributes that start with a double underscore, but do not end with a double underscore, have their name mangled by the compiler. So your source code says "MyClass.__method", but the method actually created is "MyClass.__MyClass_method". This is magic because __names everywhere else do not work that way, nor do names that don't start with double-underscores. * In Python 3, if you call super() with no arguments inside a class, the compiler runs some voodoo to determine the class it belongs to and the instance it is called from. Outside of a class, super() with no arguments behaves like any other function. This is magic because the normal behaviour of a function with two required arguments is to fail if you don't provide the arguments. But super() can, somehow, determine the arguments itself, partially at compile-time and partially at run-time. * The relationship between built-ins type() and object() is magic. object is a type. But type is itself an object. You can't define object until type exists, and you can't define type until object exists. But the compiler magically bootstraps them into existence. This is magic because it is impossible[2] for pure Python code to bootstrap such mutually-defined types into existence. Off the top of my head, I can't really think of anything else that is magic in Python. Note that individual uses of magic are generally done for good reasons, or at least what seems like a good reason. For example, super's magic class detection is useful and prevents bugs. But *in general* magic is a bad thing, because it makes the language incomprehensible and code surprising. Languages with a lot of magic tend towards code which is hard to maintain and debug. Note also that "magic" is different from "deep magic" and "black magic": http://catb.org/jargon/html/M/magic.html [1] Perhaps not quite *nothing*, arguably there is a *tiny* bit of magic in that Python bypasses the instance when looking up __dunder__ methods as a speed optimization. But that's more like a sprinkle of fairy dust than real magic. [2] Or at least tricky and messy. -- Steven From jason at powerpull.net Sun Sep 30 20:11:09 2012 From: jason at powerpull.net (Jason Friedman) Date: Sun, 30 Sep 2012 18:11:09 -0600 Subject: parse an environment file Message-ID: $ crontab -l * * * * * env This produces mail with the following contents: HOME=/home/spjsf LOGNAME=spjsf PATH=/usr/bin:/bin PWD=/home/spjsf SHELL=/bin/sh SHLVL=1 USER=spjsf _=/usr/bin/env On the other hand $ env produces about 100 entries, most of which are provided by my .bashrc; cron provides only a limited number of environment variables. I want my python 3.2.2 script, called via cron, to know what those additional variables are. How? From peterfarrell66 at gmail.com Sun Sep 30 20:35:02 2012 From: peterfarrell66 at gmail.com (Peter Farrell) Date: Sun, 30 Sep 2012 17:35:02 -0700 (PDT) Subject: Can't import modules In-Reply-To: <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> Message-ID: <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> Thanks for trying to help, everybody. Sorry I didn't post the whole error message. Now my problem is I just installed VPython and I'm trying to run the very first example, bounce.py which I located. I opened it and ran it in Idle. I got this message: Traceback (most recent call last): File "C:\Python32\Lib\site-packages\visual\examples\bounce.py", line 1, in from visual import * File "C:\Python32\lib\site-packages\visual\__init__.py", line 1, in from .visual_all import * File "C:\Python32\lib\site-packages\visual\visual_all.py", line 1, in from vis import version File "C:\Python32\lib\site-packages\vis\__init__.py", line 3, in from .cvisual import (vector, dot, mag, mag2, norm, cross, rotate, SystemError: initialization of cvisual raised unreported exception I'm not a programmer, just a math teacher/tutor who's trying to teach my students to understand math through using something real like Python. I'll keep you posted on my progress. Thank you in advance for your help! Peter On Sunday, September 30, 2012 1:22:31 PM UTC-7, Hans Mulder wrote: > On 30/09/12 21:42:37, Peter Farrell wrote: > > > I'm still new to Python, so here's another easy one. After I save something > > > I've done as a .py file, how do I import it into something else I work on? > > > Every time I try to import something other than turtle or math, I get this error message: > > > > > > 'module' object is not callable > > > > > > What am I doing wrong? > > > > For starters, you're not showing us any code. > > > > The error message suggests that you have successfully imported > > a module, and you then try to use the module as if it were a > > callable. That won't work: modules are not callable. > > > > My crystal ball says that you may have been a Java programmer > > in an earlier life. In Java, a file must define exactly one > > class, and the class must have the same name as the file. > > > > Python is not Java. In Python, a file may define one class, > > or twenty, or none at all. To avoid confusion, do not give > > any of your classes the same name as any of your files. > > > > > > Hope this helps, > > > > -- HansM From d at davea.name Sun Sep 30 20:58:15 2012 From: d at davea.name (Dave Angel) Date: Sun, 30 Sep 2012 20:58:15 -0400 Subject: parse an environment file In-Reply-To: References: Message-ID: <5068EAA7.7070808@davea.name> On 09/30/2012 08:11 PM, Jason Friedman wrote: First comment: I don't know anything about an "environment file." An environment is an attribute of a process, and it's inherited by subprocesses that process launches. This is not a Python thing, it's an OS thing, for whatever OS you're running. > $ crontab -l > * * * * * env > > This produces mail with the following contents: > > HOME=/home/spjsf > LOGNAME=spjsf > PATH=/usr/bin:/bin > PWD=/home/spjsf > SHELL=/bin/sh > SHLVL=1 > USER=spjsf > _=/usr/bin/env In other words, these are the environment variables that cron has, and that it gives to any children it launches. > On the other hand > > $ env > > produces about 100 entries, most of which are provided by my .bashrc; > cron provides only a limited number of environment variables. Gee, those are variables specific to a particular (bash) shell, so how would a program launched by cron know about them? > I want my python 3.2.2 script, called via cron, to know what those > additional variables are. How? You'd have to change the environment that cron sees (before login), or add to the crontab, or /etc/default/cron, or else run some shell from cron that defines those variables and then runs the application. The way to do this is specific to whatever OS you're running, and is irrelevant to Python. Try googling. For some examples, none of which use Python: http://www.perlmonks.org/?node_id=624540 http://www.unix.com/solaris/164483-environment-variables-cron.html http://www.computing.net/answers/unix/how-to-set-environment-variable/5689.html http://linuxshellaccount.blogspot.com/2007/10/crontab-and-your-environment.html -- DaveA From dihedral88888 at googlemail.com Sun Sep 30 20:58:39 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 30 Sep 2012 17:58:39 -0700 (PDT) Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: References: Message-ID: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> On Sunday, September 30, 2012 12:15:57 AM UTC+8, Thomas Bach wrote: > Hi, > > > > say we have the following: > > > > >>> data = [('foo', 1), ('foo', 2), ('bar', 3), ('bar', 2)] > > > > is there a way to code a function iter_in_blocks such that > > > > >>> result = [ list(block) for block in iter_in_blocks(data) ] > > > > evaluates to > > > > >>> result = [ [('foo', 1), ('foo', 2)], [('bar', 3), ('bar', 2)] ] > > > > by _only_ _iterating_ over the list (caching all the elements sharing > > the same first element doesn't count)? > > > > I came up with the following > > > > def iter_in_blocks(iterable): > > my_iter = iter(iterable) > > while True: > > first = next(my_iter) > > pred = lambda entry: entry[0] == first[0] > > def block_iter(): > > yield first > > for entry in itertools.takewhile(pred, my_iter): > > yield entry > > yield block_iter() > > > > which does not work as itertools.takewhile consumes the first entry > > not fulfilling the pred. > > > > I currently have the intuition that the problem is not solvable > > without using e.g. a global to pass something back to iter_in_blocks > > from block_iter. Any other suggestions? > > > > Regards, > > Thomas Bach. Your question seems vague to me. If you know you are storing only immutable tuples in a list, then the way to iterate is simple. For example: data = [('foo', 1), ('foo', 2), ('bar', 3), ('bar', 2)] # all tuples for item in data: x1=item[0] # first entry in each tuple x2=item[1] print x1, x2 # or use yield in a function to iterate From dihedral88888 at googlemail.com Sun Sep 30 20:58:39 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 30 Sep 2012 17:58:39 -0700 (PDT) Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: References: Message-ID: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> On Sunday, September 30, 2012 12:15:57 AM UTC+8, Thomas Bach wrote: > Hi, > > > > say we have the following: > > > > >>> data = [('foo', 1), ('foo', 2), ('bar', 3), ('bar', 2)] > > > > is there a way to code a function iter_in_blocks such that > > > > >>> result = [ list(block) for block in iter_in_blocks(data) ] > > > > evaluates to > > > > >>> result = [ [('foo', 1), ('foo', 2)], [('bar', 3), ('bar', 2)] ] > > > > by _only_ _iterating_ over the list (caching all the elements sharing > > the same first element doesn't count)? > > > > I came up with the following > > > > def iter_in_blocks(iterable): > > my_iter = iter(iterable) > > while True: > > first = next(my_iter) > > pred = lambda entry: entry[0] == first[0] > > def block_iter(): > > yield first > > for entry in itertools.takewhile(pred, my_iter): > > yield entry > > yield block_iter() > > > > which does not work as itertools.takewhile consumes the first entry > > not fulfilling the pred. > > > > I currently have the intuition that the problem is not solvable > > without using e.g. a global to pass something back to iter_in_blocks > > from block_iter. Any other suggestions? > > > > Regards, > > Thomas Bach. Your question seems vague to me. If you know you are storing only immutable tuples in a list, then the way to iterate is simple. For example: data = [('foo', 1), ('foo', 2), ('bar', 3), ('bar', 2)] # all tuples for item in data: x1=item[0] # first entry in each tuple x2=item[1] print x1, x2 # or use yield in a function to iterate From d at davea.name Sun Sep 30 21:16:30 2012 From: d at davea.name (Dave Angel) Date: Sun, 30 Sep 2012 21:16:30 -0400 Subject: Can't import modules In-Reply-To: <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> Message-ID: <5068EEEE.2010809@davea.name> On 09/30/2012 08:35 PM, Peter Farrell wrote: You top-posted, which means there's no context; the message is now out of order. Please put your responses after the parts you're quoting, or don't bother quoting. > Thanks for trying to help, everybody. Sorry I didn't post the whole error message. Now my problem is I just installed VPython and I'm trying to run the very first example, bounce.py which I located. I opened it and ran it in Idle. I got this message: > > Traceback (most recent call last): > File "C:\Python32\Lib\site-packages\visual\examples\bounce.py", line 1, in > from visual import * > File "C:\Python32\lib\site-packages\visual\__init__.py", line 1, in > from .visual_all import * > File "C:\Python32\lib\site-packages\visual\visual_all.py", line 1, in > from vis import version > File "C:\Python32\lib\site-packages\vis\__init__.py", line 3, in > from .cvisual import (vector, dot, mag, mag2, norm, cross, rotate, > SystemError: initialization of cvisual raised unreported exception That's a different error message than you reported at first. If you can't even run an example supplied with the system, you'd better post a question on the vpython forum (I presume it's available from http://vpython.wikidot.com/system:join) Presumably the install program is broken. Or maybe you just can't run visual from IDLE. Try running from the terminal prompt. I'm amazed that it uses the form: from visual_all import * That's considered bad form. Still, it's probably not the problem. What happens if you write a two line program: import visual_all print("Import succeeded") > I'm not a programmer, just a math teacher/tutor who's trying to teach my students to understand math through using something real like Python. I'll keep you posted on my progress. > > Thank you in advance for your help! > > -- DaveA From steve+comp.lang.python at pearwood.info Sun Sep 30 21:17:15 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Oct 2012 01:17:15 GMT Subject: parse an environment file References: Message-ID: <5068ef1b$0$29997$c3e8da3$5496439d@news.astraweb.com> On Sun, 30 Sep 2012 18:11:09 -0600, Jason Friedman wrote: > $ crontab -l > * * * * * env > > This produces mail with the following contents: [snip] Yes, env returns the environment variables of the current environment. > On the other hand > > $ env > > produces about 100 entries, most of which are provided by my .bashrc; > cron provides only a limited number of environment variables. That's because it's a different environment. > I want my python 3.2.2 script, called via cron, to know what those > additional variables are. How? In general, you can't, because they may not even exist when your script runs. There's no guarantee that "your environment" (which one? you might have many, or none) exists at the time, and env certainly cannot guess which one that might be. But specifically, if you know the ID of a process, you may be able to see that process' environment variables by reading the /proc//environ virtual file, which is a NULL-delimited list of environment variables. As usual, permissions apply. In general, you can read your own processes, but not those of other users. -- Steven From joshua.landau.ws at gmail.com Sun Sep 30 21:21:20 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Mon, 1 Oct 2012 02:21:20 +0100 Subject: Can't import modules In-Reply-To: <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> Message-ID: On 1 October 2012 01:35, Peter Farrell wrote: > Thanks for trying to help, everybody. Sorry I didn't post the whole error > message. Now my problem is I just installed VPython and I'm trying to run > the very first example, bounce.py which I located. I opened it and ran it > in Idle. I got this message: > > Traceback (most recent call last): > File "C:\Python32\Lib\site-packages\visual\examples\bounce.py", line 1, > in > from visual import * > File "C:\Python32\lib\site-packages\visual\__init__.py", line 1, in > > from .visual_all import * > File "C:\Python32\lib\site-packages\visual\visual_all.py", line 1, in > > from vis import version > File "C:\Python32\lib\site-packages\vis\__init__.py", line 3, in > from .cvisual import (vector, dot, mag, mag2, norm, cross, rotate, > SystemError: initialization of cvisual raised unreported exception > > I'm not a programmer, just a math teacher/tutor who's trying to teach my > students to understand math through using something real like Python. I'll > keep you posted on my progress. > > Thank you in advance for your help! Please don't top post . Are you using Ubuntu, by chance? If you are, try looking at the VPython archives , specifically this. I chose that because although I know almost nothing about VPython it is recent. Try VPython's list even if it isn't as they're likely to know more than us. Also, this error is distinctly different to the one you first posted. What happened there? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun Sep 30 21:25:29 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Oct 2012 01:25:29 GMT Subject: Can't import modules References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> Message-ID: <5068f109$0$29997$c3e8da3$5496439d@news.astraweb.com> On Sun, 30 Sep 2012 17:35:02 -0700, Peter Farrell wrote: > Thanks for trying to help, everybody. Sorry I didn't post the whole > error message. Now my problem is I just installed VPython and I'm trying > to run the very first example, bounce.py which I located. I opened it > and ran it in Idle. I got this message: In general, any time you get unexpected or unusual errors in IDLE, you should try running the same code without IDLE, just at the regular Python prompt. Like all "Integrated Development Environments", IDLE sometimes messes about with things in the background that very occasionally interferes with the normal running of certain Python code, so it is always worth taken IDLE out of the picture whenever there is a mysterious failure. In Windows, I *think* that if you run "python" (or perhaps "python32") from the Start Menu, it will open an interactive prompt similar to IDLE. Once the Python interactive interpreter has launched, just enter: from visual import * and see if it works. If it fails, try: import visual My wild guess is that VPython (whatever that is!) only works under Python 2, not Python 3, but I could be wrong. Other than that, my advice is to check with a dedicated VPython mailing list. Oh, and if you do find the solution, please consider reporting what the solution is back here, for the benefit of the next person who runs into this issue. -- Steven From peterfarrell66 at gmail.com Sun Sep 30 21:35:50 2012 From: peterfarrell66 at gmail.com (Peter Farrell) Date: Sun, 30 Sep 2012 18:35:50 -0700 (PDT) Subject: Can't import modules In-Reply-To: <5068f109$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> <5068f109$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sunday, September 30, 2012 6:25:29 PM UTC-7, Steven D'Aprano wrote: > On Sun, 30 Sep 2012 17:35:02 -0700, Peter Farrell wrote: > > > > > Thanks for trying to help, everybody. Sorry I didn't post the whole > > > error message. Now my problem is I just installed VPython and I'm trying > > > to run the very first example, bounce.py which I located. I opened it > > > and ran it in Idle. I got this message: > > > > In general, any time you get unexpected or unusual errors in IDLE, you > > should try running the same code without IDLE, just at the regular Python > > prompt. Like all "Integrated Development Environments", IDLE sometimes > > messes about with things in the background that very occasionally > > interferes with the normal running of certain Python code, so it is > > always worth taken IDLE out of the picture whenever there is a mysterious > > failure. > > > > In Windows, I *think* that if you run "python" (or perhaps "python32") > > from the Start Menu, it will open an interactive prompt similar to IDLE. > > Once the Python interactive interpreter has launched, just enter: > > > > from visual import * > > > > and see if it works. If it fails, try: > > > > import visual > > > > > > My wild guess is that VPython (whatever that is!) only works under Python > > 2, not Python 3, but I could be wrong. > > > > Other than that, my advice is to check with a dedicated VPython mailing > > list. Oh, and if you do find the solution, please consider reporting what > > the solution is back here, for the benefit of the next person who runs > > into this issue. > > > > > > > > -- > > Steven Thanks again for the help. I entered the import statements you suggested into the Python Shell and they gave me the same error message. (Neither did visual_all, but of course the print statement worked.) Since I use Python 3.2.3 I've had trouble with programs and modules designed for Python 2 and many programs don't work on my 64-bit system. I was hoping it was a common error that newbies encounter. Thanks again, Python fans. I'll keep you posted on my progress! Peter From joshua.landau.ws at gmail.com Sun Sep 30 21:48:38 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Mon, 1 Oct 2012 02:48:38 +0100 Subject: Compairing filenames in a list In-Reply-To: References: Message-ID: On 30 September 2012 23:08, Arnaud Delobelle wrote: > On 30 September 2012 02:27, Kevin Anthony > wrote: > > I have a list of filenames, and i need to find files with the same name, > > different extensions, and split that into tuples. does anyone have any > > suggestions on an easy way to do this that isn't O(n^2)? > > >>> import os, itertools > >>> filenames = ["foo.png", "bar.csv", "foo.html", "bar.py"] > >>> dict((key, tuple(val)) for key, val in > itertools.groupby(sorted(filenames), lambda f: os.path.splitext(f)[0])) > {'foo': ('foo.html', 'foo.png'), 'bar': ('bar.csv', 'bar.py')} > That seems wasteful. Sort is O(n log n) I've seen this pattern a lot. Surely there should be an object for this... filenames = ["foo.png", "bar.csv", "foo.html", "bar.py"] > > import os > > from collections import defaultdict > grouped = defaultdict(list) > > for file in filenames: > splitname = os.path.splitext(file) > grouped[splitname[0]].append(splitname[1]) > > grouped > >>> defaultdict(, {'foo': ['.png', '.html'], 'bar': ['.csv', > '.py']}) This should be near-enough O(n) time. Pah, it's not like you need to optimize this anyway! -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun Sep 30 22:15:07 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Oct 2012 02:15:07 GMT Subject: Can't import modules References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> <5068f109$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5068fcab$0$29997$c3e8da3$5496439d@news.astraweb.com> On Sun, 30 Sep 2012 18:35:50 -0700, Peter Farrell wrote: > Since I use Python 3.2.3 I've had trouble with programs and modules > designed for Python 2 and many programs don't work on my 64-bit system. While Python tries very hard to be backward compatible, the transition from the 2.x series to the 3.x series was intentionally allowed to break backward compatibility in certain areas. If VPython only supports 2.x, you should ask the vendors to support at least 3.3 or better, preferably the full 3.x series. In the meantime, you may have to stick to the 2.x series. > I was hoping it was a common error that newbies encounter. Trying to run Python 2.x code in 3.x? Yes, that's common. Trying to run VPython? Not so much. Good luck! -- Steven From steve+comp.lang.python at pearwood.info Sun Sep 30 22:15:07 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Oct 2012 02:15:07 GMT Subject: Can't import modules References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> <5068f109$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5068fcab$0$1726$c3e8da3$76491128@news.astraweb.com> On Sun, 30 Sep 2012 18:35:50 -0700, Peter Farrell wrote: > Since I use Python 3.2.3 I've had trouble with programs and modules > designed for Python 2 and many programs don't work on my 64-bit system. While Python tries very hard to be backward compatible, the transition from the 2.x series to the 3.x series was intentionally allowed to break backward compatibility in certain areas. If VPython only supports 2.x, you should ask the vendors to support at least 3.3 or better, preferably the full 3.x series. In the meantime, you may have to stick to the 2.x series. > I was hoping it was a common error that newbies encounter. Trying to run Python 2.x code in 3.x? Yes, that's common. Trying to run VPython? Not so much. Good luck! -- Steven From dwightdhutto at gmail.com Sun Sep 30 22:39:53 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sun, 30 Sep 2012 22:39:53 -0400 Subject: Can't import modules In-Reply-To: <5068fcab$0$1726$c3e8da3$76491128@news.astraweb.com> References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> <5068f109$0$29997$c3e8da3$5496439d@news.astraweb.com> <5068fcab$0$1726$c3e8da3$76491128@news.astraweb.com> Message-ID: On Sun, Sep 30, 2012 at 10:15 PM, Steven D'Aprano wrote: > On Sun, 30 Sep 2012 18:35:50 -0700, Peter Farrell wrote: > >> Since I use Python 3.2.3 I've had trouble with programs and modules >> designed for Python 2 and many programs don't work on my 64-bit system. > > While Python tries very hard to be backward compatible, the transition > from the 2.x series to the 3.x series was intentionally allowed to break > backward compatibility in certain areas. > > If VPython only supports 2.x, Naw , that's your job, plus maybe looking through the python code for Vpython, and adding a little "from __future__ import *" you should ask the vendors to support at > least 3.3 or better, preferably the full 3.x series. In the meantime, you > may have to stick to the 2.x series. > > >> I was hoping it was a common error that newbies encounter. > > Trying to run Python 2.x code in 3.x? Yes, that's common. Trying to run > VPython? Not so much. > > Good luck! > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Sun Sep 30 22:48:02 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sun, 30 Sep 2012 22:48:02 -0400 Subject: Can't import modules In-Reply-To: References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> <5068f109$0$29997$c3e8da3$5496439d@news.astraweb.com> <5068fcab$0$1726$c3e8da3$76491128@news.astraweb.com> Message-ID: Plus from What's New From Python 3", which are things you should be able to change comes: http://docs.python.org/release/3.0.1/whatsnew/3.0.html Change the module yourself. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From eldiener at tropicsoft.invalid Sun Sep 30 23:06:04 2012 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 30 Sep 2012 23:06:04 -0400 Subject: Coexistence of Python 2.x and 3.x on same OS In-Reply-To: References: Message-ID: On 9/30/2012 3:38 PM, Andrew Berg wrote: > On 2012.09.30 14:14, Edward Diener wrote: >> The situation is so confusing on Windows, where the file associations, >> registry entries, and other internal software which allows a given >> Python release to work properly when invoking Python is so complicated, >> that I have given up on trying to install more than one Python release >> and finding a relaible, foolproof way of switching between them. So >> although I would like to use the latest 3.x series on Windows I have >> decide to stick with the latest 2.x series instead because much software >> using Python does not support 3.x yet. > > http://www.python.org/dev/peps/pep-0397/ > > Unix-based OSes should already obey the shebang line, and on Windows, > there's py.exe in 3.3 that will launch the intended version based on > that shebang line. The problem with that is that one has to already being using 3.3 to use this facility. I was hoping for a solution which was backwards compatible with Python 2.x. My thought is a program distributed by Python which finds the versions of Python on an OS, lets the end-user choose which version should be invoked when Python is invoked, and does whatever is necessary to make that version the default version. > While I was using the alpha/beta versions of 3.3, I > had no problems invoking either 3.2 or 3.3 with the shebang line on Windows. That does not solve the problem for Python 2.x distributions. From dwightdhutto at gmail.com Sun Sep 30 23:12:46 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sun, 30 Sep 2012 23:12:46 -0400 Subject: Can't import modules In-Reply-To: References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> <5068f109$0$29997$c3e8da3$5496439d@news.astraweb.com> <5068fcab$0$1726$c3e8da3$76491128@news.astraweb.com> Message-ID: On Sun, Sep 30, 2012 at 10:48 PM, Dwight Hutto wrote: > Plus from What's New From Python 3", which are things you should be > able to change comes: > > http://docs.python.org/release/3.0.1/whatsnew/3.0.html > > Change the module yourself. > > And, of course: http://docs.python.org/library/2to3.html -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From d at davea.name Sun Sep 30 23:18:01 2012 From: d at davea.name (Dave Angel) Date: Sun, 30 Sep 2012 23:18:01 -0400 Subject: Can't import modules In-Reply-To: References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> <5068f109$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50690B69.7020208@davea.name> On 09/30/2012 09:35 PM, Peter Farrell wrote: > On Sunday, September 30, 2012 6:25:29 PM UTC-7, Steven D'Aprano wrote: >> On Sun, 30 Sep 2012 17:35:02 -0700, Peter Farrell wrote: >> >> >> >>> Thanks for trying to help, everybody. Sorry I didn't post the whole >>> error message. Now my problem is I just installed VPython and I'm trying >>> to run the very first example, bounce.py which I located. I opened it >>> and ran it in Idle. I got this message: >> >> >> In general, any time you get unexpected or unusual errors in IDLE, you >> should try running the same code without IDLE, just at the regular Python >> prompt. >> > Thanks again for the help. I entered the import statements you suggested into the Python Shell and they gave me the same error message. (Neither did visual_all, but of course the print statement worked.) Don't run it in the Python Shell, and don't use IDLE at all. Run your test either at the cmd window, or from plain Python's interactive interpreter, or maybe from VIDLE. >From the official download page: http://www.vpython.org/contents/download_windows.html """How to run VPython * Start the program editor with the "VIDLE for Python" shortcut on the desktop or on the Start menu. * Open an example program -- for example, bounce2.py. * Press F5 to run (or use the Run menu). """ > Since I use Python 3.2.3 I've had trouble with programs and modules designed for Python 2 and many programs don't work on my 64-bit system. > > I was hoping it was a common error that newbies encounter. > > Thanks again, Python fans. I'll keep you posted on my progress! VPython has separate versions for Python 2.7 and 3.2 Hopefully you downloaded the 3.2 version, since you're running it in c:\python32 Also, these are for the 32bit version of CPython. So double-check which one you've got installed. -- DaveA From bahamutzero8825 at gmail.com Sun Sep 30 23:54:02 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 30 Sep 2012 22:54:02 -0500 Subject: Coexistence of Python 2.x and 3.x on same OS In-Reply-To: References: Message-ID: <506913DA.8010803@gmail.com> On 2012.09.30 22:06, Edward Diener wrote: > The problem with that is that one has to already being using 3.3 to use > this facility. I was hoping for a solution which was backwards > compatible with Python 2.x. It's a separate tool that comes with 3.3. You can install 3.3 and never use the actual 3.3 interpreter if you wish. > That does not solve the problem for Python 2.x distributions. Compatibility across versions of Python is irrelevant; the launcher doesn't execute any Python code itself. Straight from the PEP: > The launcher is not tied to a specific version of Python - eg., a > launcher distributed with Python 3.3 should be capable of locating and > executing any Python 2.x and Python 3.x version. -- CPython 3.3.0 | Windows NT 6.1.7601.17835 From d at davea.name Sun Sep 30 23:55:05 2012 From: d at davea.name (Dave Angel) Date: Sun, 30 Sep 2012 23:55:05 -0400 Subject: Coexistence of Python 2.x and 3.x on same OS In-Reply-To: References: Message-ID: <50691419.7000408@davea.name> On 09/30/2012 11:06 PM, Edward Diener wrote: > On 9/30/2012 3:38 PM, Andrew Berg wrote: >> On 2012.09.30 14:14, Edward Diener wrote: >>> The situation is so confusing on Windows, where the file associations, >>> registry entries, and other internal software which allows a given >>> Python release to work properly when invoking Python is so complicated, >>> that I have given up on trying to install more than one Python release >>> and finding a relaible, foolproof way of switching between them. So >>> although I would like to use the latest 3.x series on Windows I have >>> decide to stick with the latest 2.x series instead because much >>> software >>> using Python does not support 3.x yet. >> >> http://www.python.org/dev/peps/pep-0397/ >> >> Unix-based OSes should already obey the shebang line, and on Windows, >> there's py.exe in 3.3 that will launch the intended version based on >> that shebang line. > > The problem with that is that one has to already being using 3.3 to > use this facility. I was hoping for a solution which was backwards > compatible with Python 2.x. > > My thought is a program distributed by Python which finds the versions > of Python on an OS, lets the end-user choose which version should be > invoked when Python is invoked, and does whatever is necessary to make > that version the default version. > >> While I was using the alpha/beta versions of 3.3, I >> had no problems invoking either 3.2 or 3.3 with the shebang line on >> Windows. > > That does not solve the problem for Python 2.x distributions. > If you read the Pep, it says the launcher will work for both 2.x and 3.x http://www.python.org/dev/peps/pep-0397/ I've read that elsewhere, but I can't see just where you would get the necessary modules to run it with 2.x Possibly you'd have to build it from sources, as there are Windows binaries that get installed to the C:\Windows directory. -- DaveA