From spluque at gmail.com Sat Aug 1 00:21:03 2015 From: spluque at gmail.com (Seb) Date: Fri, 31 Jul 2015 23:21:03 -0500 Subject: debugging during package development Message-ID: <87fv43y6z4.fsf@gmail.com> Hello, It seems too cumbersome to have to update `sys.path` to include the development tree of a package (and sub-packages) that's still very young. With lots of debugging to do, the last thing I'd want is to worry about the search path. So I've been searching for better ways to work, but I can't seem hit the right keywords and come with all sorts of tangentially related stuff. I'm sure there must be some tool that sets up the development environment when the package source is not on `sys.path`. Any advice on this topic would be appreciated. Cheers, -- Seb From ben+python at benfinney.id.au Sat Aug 1 01:30:34 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 01 Aug 2015 15:30:34 +1000 Subject: debugging during package development References: <87fv43y6z4.fsf@gmail.com> Message-ID: <85r3nnlgn9.fsf@benfinney.id.au> Seb writes: > With lots of debugging to do, the last thing I'd want is to worry > about the search path. Short answer: you need ?python3 ./setup.py develop?. Medium-length answer: you need to add some infrastructure to get your project to the point where you can run ?python3 ./setup.py develop?. Longer answer below. > So I've been searching for better ways to work, > but I can't seem hit the right keywords and come with all sorts of > tangentially related stuff. The Python module search path is an abstraction, with only a partial relationship to the location of modules files in the filesystem. The expectation is that a module (or a package of modules) will be *installed* to a location already in the module search path (with ?python ./setup.py . This allows for cross-platform package management, especially on systems that don't have a working OS package manager. The trouble is that it does cause a significant learning curve for Python programmers, and is an ongoing sore point of Python. > I'm sure there must be some tool that sets up the development > environment when the package source is not on `sys.path`. Any advice > on this topic would be appreciated. What you need is to tell Distutils which Python modules form your project . Once you've got a working ?setup.py? for your project, run ?python3 ./setup.py develop? to allow your packages to be run in-place while you develop them. -- \ ?I think it would be a good idea.? ?Mohandas K. Gandhi (when | `\ asked what he thought of Western civilization) | _o__) | Ben Finney From steve at pearwood.info Sat Aug 1 01:45:32 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 01 Aug 2015 15:45:32 +1000 Subject: GvR Europython keynote described on lwn.net References: <87r3noltu3.fsf@jester.gateway.sonic.net> <106305a9-3ccd-4de4-a918-c27cec2d0b8c@googlegroups.com> Message-ID: <55bc5cfb$0$1643$c3e8da3$5496439d@news.astraweb.com> On Sat, 1 Aug 2015 01:08 pm, Rick Johnson wrote: > On Friday, July 31, 2015 at 1:33:36 AM UTC-5, Paul Rubin wrote: >> The Dropbox cluster runs a modified Python 2.7, he said, which >> elicited audience laughter. "I said it, it is no secret", he said. > > Yep, even the BDFL is actively developing in 2.7! He's no fool. Of course not. Dropbox pay him to work on their systems, and he wants to keep his job. Are you aware that Dropbox are heavily pushing for static type hints in Python 3 as a prerequisite for them porting their masses of Python 2 code to Python 3? That's one of the motives for the masses of effort put into PEP 484, and its support PEPs, 482 and 483: https://www.python.org/dev/peps/pep-0484/ https://www.python.org/dev/peps/pep-0483/ https://www.python.org/dev/peps/pep-0482/ As I understand it, Dropbox are paying Guido to work on static type hinting for Python, with the emphasis on proving program correctness, not speed, specifically because they want a big positive gain for moving to Python 3. -- Steven From dieter at handshake.de Sat Aug 1 01:50:57 2015 From: dieter at handshake.de (dieter) Date: Sat, 01 Aug 2015 07:50:57 +0200 Subject: 'open' is not defined References: <55babad0.c25e460a.2b9e.ffffb3cd@mx.google.com> <87si84hmmh.fsf@handshake.de> <55bb181c.6567460a.a006c.fffff5f1@mx.google.com> Message-ID: <87y4hv1rr2.fsf@handshake.de> writes: > What about using the append function to remove duplicate outputs entered on or thereafter line no. 9, i.e., As far as I know, "append" does not have intelligence in this respect. Thus, if you need intelligence, your program must implement it. In cases like yours, I use a) added = set(); l = list() for x ... if x not in added: added.insert(x); l.append(x) or b) l = list() for x ... if x not in l: l.append(x) Note that b) looks more natural - but I prefer a) (if the "x"s are hashable) as it is slightly more efficient. > LIST_APPEND(i) Calls list.append(TOS[-i], TOS). Used to implement list comprehensions. While the appended value is popped off, the list object remains on the stack so that it is available for further iterations of the loop. URL link available at https://docs.python.org/2.7/library/dis.html?highlight=append%20list#opcode-LIST_APPEND Nore that the "dis" module shows you low level Python implementation details (in fact the byte code of CPython's virtual maschine). You are not supposed to make direct use of those in your own programs. > > What is the command line for such an append function? As far as I know, there is none (interpreting "command line" as "in my program"). The documentation above indicates that the virtual maschine's command "LIST_APPEND" is used internally to implement Python's "list comprehension" ("[...x... for x in ... if ...]"). Maybe, it is used also for other purposes, maybe not. From dieter at handshake.de Sat Aug 1 01:56:36 2015 From: dieter at handshake.de (dieter) Date: Sat, 01 Aug 2015 07:56:36 +0200 Subject: debugging during package development References: <87fv43y6z4.fsf@gmail.com> Message-ID: <87twsj1rhn.fsf@handshake.de> Seb writes: > It seems too cumbersome to have to update `sys.path` to include the > development tree of a package (and sub-packages) that's still very > young. With lots of debugging to do, the last thing I'd want is to > worry about the search path. So I've been searching for better ways to > work, but I can't seem hit the right keywords and come with all sorts of > tangentially related stuff. I'm sure there must be some tool that sets > up the development environment when the package source is not on > `sys.path`. Any advice on this topic would be appreciated. On "*nix" like systems, you can set "sys.path" via the envvar "PYTHONPATH". Note that "sys.path" needs only contain the top level packages - subpackages are found automatically. From tjreedy at udel.edu Sat Aug 1 02:44:55 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 1 Aug 2015 02:44:55 -0400 Subject: debugging during package development In-Reply-To: <87fv43y6z4.fsf@gmail.com> References: <87fv43y6z4.fsf@gmail.com> Message-ID: On 8/1/2015 12:21 AM, Seb wrote: > It seems too cumbersome to have to update `sys.path` to include the > development tree of a package (and sub-packages) that's still very > young. With lots of debugging to do, the last thing I'd want is to > worry about the search path. So I've been searching for better ways to > work, but I can't seem hit the right keywords and come with all sorts of > tangentially related stuff. I'm sure there must be some tool that sets > up the development environment when the package source is not on > `sys.path`. Any advice on this topic would be appreciated. I am not sure what you are asking, but do you know about .pth files in site-packages? For each python installed, I put in site-packages a python.pth containing one line "F:/python". That file contains my project directory, call it x/ Running any version of python, 'from x import y' or 'from x.y import z' just works, the same as if x/ *were* in site-packages, and will be if I ever distribute the x package. No fuss with search paths; python plugs x into site-packages for me. I do not know where this is documented. -- Terry Jan Reedy From random832 at fastmail.us Sat Aug 1 02:50:59 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Sat, 01 Aug 2015 02:50:59 -0400 Subject: Trouble getting to windows My Documents directory In-Reply-To: References: <20150710094607.66e62712@bigbox.christie.dr> <1436574244.1600780.320804625.4F9C0CE1@webmail.messagingengine.com> Message-ID: <1438411859.917138.344922681.4DB14641@webmail.messagingengine.com> On Sat, Jul 11, 2015, at 03:28, Chris Warrick wrote: > That?s not necessarily ?older?. > > Windows XP/7/8: My Documents > Windows Vista/8.1: Documents Mine's called Documents on 7 and 8. Is the system you got this information from a new install or an upgrade? (It may also depend on whether it's a new *user profile* or one from before the upgrade) > As for localized versions, Vista and up do the translation in Windows > Explorer but use English names on disk. > > ?but even with all that, users (or their administrators) can move the > My Documents folder away from the home directory (to a file server, > for example). Yeah, the real point is that it can be an arbitrary location, but I was just illustrating that even in *default* circumstances it won't always be Documents From baruchel at gmail.com Sat Aug 1 06:07:48 2015 From: baruchel at gmail.com (baruchel at gmail.com) Date: Sat, 1 Aug 2015 03:07:48 -0700 (PDT) Subject: New module (written in C) for using the high-precision QD library In-Reply-To: References: <3015c193-3a3f-468a-b998-94f77066febe@googlegroups.com> Message-ID: <7b48aae6-f015-46e5-84c9-e3ad0ddb704e@googlegroups.com> Hi, Thank you for your answer. Actually this is the third version I am writing for using the QD library; the first onPython using ctypes; the second one was in Cython; this one is in C. I don't claim being a Cython expert and maybe my Cython code was not optimal but I can say the C version is significantly quicker (and the binary is about half the size of the Cython binary). I admit Cython is a great idea but for this very specific project I like rather using C: behind the scene thre is no need to interact with Python; data only relies on elementary C types, etc. I decided to migrate from Cython to C when I realized that I was merely embedding C in Cython almost all the time. Furthermore, the QD library is old, stable and simple. Once my module will be ready it won't evolve much; thus maintaining the project shouldn't be an issue. I am using Python 2 with the people I am working with and I release my work as it; maybe I will rewrite it for Python 3 one day but it is not my immediate purpose. Last day I started implementing the new type as dtype for Numpy; for the moment, I disabled this part in the code (because it is far to be really usable) but it can already be tried for having a short glance by uncommenting one line in the code. Best regards. tb. From spluque at gmail.com Sat Aug 1 09:22:11 2015 From: spluque at gmail.com (Sebastian Luque) Date: Sat, 01 Aug 2015 08:22:11 -0500 Subject: debugging during package development References: <87fv43y6z4.fsf@gmail.com> <85r3nnlgn9.fsf@benfinney.id.au> Message-ID: <87bnerxhx8.fsf@gmail.com> On Sat, 01 Aug 2015 15:30:34 +1000, Ben Finney wrote: > Seb writes: >> With lots of debugging to do, the last thing I'd want is to worry >> about the search path. > Short answer: you need ?python3 ./setup.py develop?. > Medium-length answer: you need to add some infrastructure to get your > project to the point where you can run ?python3 ./setup.py develop?. > Longer answer below. >> So I've been searching for better ways to work, but I can't seem hit >> the right keywords and come with all sorts of tangentially related >> stuff. > The Python module search path is an abstraction, with only a partial > relationship to the location of modules files in the filesystem. > The expectation is that a module (or a package of modules) will be > *installed* to a location already in the module search path (with > ?python ./setup.py . > This allows for cross-platform package management, especially on > systems that don't have a working OS package manager. The trouble is > that it does cause a significant learning curve for Python > programmers, and is an ongoing sore point of Python. >> I'm sure there must be some tool that sets up the development >> environment when the package source is not on `sys.path`. Any advice >> on this topic would be appreciated. > What you need is to tell Distutils which Python modules form your > project . > Once you've got a working ?setup.py? for your project, run ?python3 > ./setup.py develop? to allow your packages to be run in-place while > you develop them. This sounds exactly like what I was looking for. I was growing tired of doing 'python setup.py install', every time I wanted to debug something. The subpackages' modules have inter-dependencies, which require the whole package to be in `sys.path`. Unfortunately, I have to stick with Python 2.7... Thank you, -- Seb From Cecil at decebal.nl Sat Aug 1 10:33:20 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sat, 01 Aug 2015 16:33:20 +0200 Subject: Display a cleaned version of a XChat log Message-ID: <87pp37qdsf.fsf@Equus.decebal.nl> I discovered IRC again. ;-) I want to use Python to display a cleaned version of the XChat logs. One reason is that I keep channels open, and later want to look if there was anything interesting. But most lines are status messages that do not interest me and should be hidden from me. A *VERY* rudimentary version is: http://pastebin.com/jD2c8GBV. It gets rid of a lot of very uninteresting stuff, but also of a /me line like: Aug 01 15:44:14 * Cecil wants to use python to display cleaned xchat logs. Is there a way to recognise that a line is a /me line? I want to put it in a GUI of-course. A lot of stuff has to be added: - selecting log files - continuing where I left of - displaying the message from a certain period - automatically updating open channels - notifying when there is a message for myself - ? I am open for interesting feature to add and tips how to implement things. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From jcarmena at gmail.com Sat Aug 1 12:07:48 2015 From: jcarmena at gmail.com (Javier) Date: Sat, 1 Aug 2015 09:07:48 -0700 (PDT) Subject: Send data to asyncio coroutine In-Reply-To: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> Message-ID: <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> El martes, 21 de julio de 2015, 13:31:56 (UTC+2), Javier escribi?: > Hello, I'm trying to understand and link asyncio with ordinary coroutines. Now I just want to understand how to do this on asyncio: > > > def foo(): > data = yield 8 > print(data) > yield "bye" > > def bar(): > f = foo() > n = f.next() > print(n) > message = f.send("hello") > print(message) > > > What is the equivalent for coro.send("some data") in asyncio? > > coro.send on an asyncio coroutine throws AssertionError: yield from wasn't used with future. > > > Thank you Asyncio is a crazy headache! I realized that I can't use asyncio tcp servers with pickle! Asyncio is good as a concept but bad in real life. I think python's non blocking I/O is far from being something useful for developers till non-async code can invoke async code transparently. Duplicating all code/libs when you realize that something not fits asyncio is not a solution and even less a pythonic solution. From joel.goldstick at gmail.com Sat Aug 1 12:22:50 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 1 Aug 2015 12:22:50 -0400 Subject: I'm a newbie and I'm stumped... In-Reply-To: References: Message-ID: On Thu, Jul 30, 2015 at 9:22 PM, Dwight GoldWinde wrote: > Please help. > > I am running Python 3.4 on my Mac mini, OS X 10.10.2, using Coderunner 2 as > my editor. > > Here?s the code: > #!/usr/bin/env python3 > word = (input('Enter a word ?)) > > When running this inside of Coderunner, I get the follow error, after > entering the word ?serendipity?: > > Enter a word serendipity > > Traceback (most recent call last): > > File "test short.py", line 2, in > > word = (input('Enter a word ')) > > File "", line 1, in > > NameError: name 'serendipity' is not defined > > The error you are getting is the error you would get if you were using python 2.x. So, are you sure you are running 3.4? Can you go to a shell and run it from command line? also, use plain text to send mail > > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com From emile at fenx.com Sat Aug 1 12:30:08 2015 From: emile at fenx.com (Emile van Sebille) Date: Sat, 1 Aug 2015 09:30:08 -0700 Subject: I'm a newbie and I'm stumped... In-Reply-To: References: Message-ID: On 7/30/2015 6:22 PM, Dwight GoldWinde wrote: > I am running Python 3.4 on my Mac mini, OS X 10.10.2, using Coderunner 2 as > my editor. > > Here?s the code: > #!/usr/bin/env python3 > word = (input('Enter a word ?)) > > When running this inside of Coderunner, I get the follow error, after > entering the word ?serendipity?: > > Enter a word serendipity > Traceback (most recent call last): > File "test short.py", line 2, in > word = (input('Enter a word ')) > File "", line 1, in > NameError: name 'serendipity' is not defined I'd look at which python is actually running (sys.version): Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> word = (input('enter a word ')) enter a word test >>> emile at emile-OptiPlex-9010:~$ python Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> word = (input('enter a word ')) enter a word test Traceback (most recent call last): Emile File "", line 1, in File "", line 1, in NameError: name 'test' is not defined >>> From emile at fenx.com Sat Aug 1 12:37:02 2015 From: emile at fenx.com (Emile van Sebille) Date: Sat, 1 Aug 2015 09:37:02 -0700 Subject: Which Python do I need for the below? In-Reply-To: <377640C91279E84D9B61F71C964BA3424A1ACDB8@SACMBXIP02.sdcorp.global.sandisk.com> References: <377640C91279E84D9B61F71C964BA3424A1ACDB8@SACMBXIP02.sdcorp.global.sandisk.com> Message-ID: On 7/29/2015 10:52 AM, Joe Sanders wrote: > Hello- Which Python do I need for the below? with instructions please! > > [cid:image001.png at 01D0C9FD.677CDED0] Seeing that you have no responses yet I'm guessing most potential responders along with me are not opening attachments. If the image is of screen output, please copy that as text and ask again -- you're more likely to get a response that way. Emile From breamoreboy at yahoo.co.uk Sat Aug 1 12:37:18 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 1 Aug 2015 17:37:18 +0100 Subject: Which Python do I need for the below? In-Reply-To: <377640C91279E84D9B61F71C964BA3424A1ACDB8@SACMBXIP02.sdcorp.global.sandisk.com> References: <377640C91279E84D9B61F71C964BA3424A1ACDB8@SACMBXIP02.sdcorp.global.sandisk.com> Message-ID: On 29/07/2015 18:52, Joe Sanders wrote: > Hello- Which Python do I need for the below? with instructions please! > > Kind Regards, > > *Gerald"Joe"Sanders* > For your 32 bit machine https://www.python.org/downloads/release/python-343/ "Windows x86 MSI installer" which is the last one listed. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Sat Aug 1 12:41:09 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 1 Aug 2015 17:41:09 +0100 Subject: Send data to asyncio coroutine In-Reply-To: <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> Message-ID: On 01/08/2015 17:07, Javier wrote: > > Asyncio is a crazy headache! I realized that I can't use asyncio tcp servers with pickle! Asyncio is good as a concept but bad in real life. > > I think python's non blocking I/O is far from being something useful for developers till non-async code can invoke async code transparently. Duplicating all code/libs when you realize that something not fits asyncio is not a solution and even less a pythonic solution. > I'll keep my eyes open for your solution on pypi as clearly you know better than the Python core developers. Fully documented and tested of course. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rustompmody at gmail.com Sat Aug 1 13:09:34 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 1 Aug 2015 10:09:34 -0700 (PDT) Subject: Which Python do I need for the below? In-Reply-To: References: <377640C91279E84D9B61F71C964BA3424A1ACDB8@SACMBXIP02.sdcorp.global.sandisk.com> Message-ID: On Saturday, August 1, 2015 at 10:07:37 PM UTC+5:30, Emile van Sebille wrote: > On 7/29/2015 10:52 AM, Joe Sanders wrote: > > Hello- Which Python do I need for the below? with instructions please! > > > > [cid:image001.png at 01D0C9FD.677CDED0] > > Seeing that you have no responses yet I'm guessing most potential > responders along with me are not opening attachments. Most recipients are not receiving at all! [I only see Emile's response. Evidently GG is deleting mails that have attachments] From marko at pacujo.net Sat Aug 1 13:18:42 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Aug 2015 20:18:42 +0300 Subject: Send data to asyncio coroutine References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> Message-ID: <87a8ubudu5.fsf@elektro.pacujo.net> Javier : > Asyncio is a crazy headache! I realized that I can't use asyncio tcp > servers with pickle! Asyncio is good as a concept but bad in real > life. > > I think python's non blocking I/O is far from being something useful > for developers till non-async code can invoke async code > transparently. Duplicating all code/libs when you realize that > something not fits asyncio is not a solution and even less a pythonic > solution. After all these decades, we are still struggling to find the naturally flowing paradigm for asynchronous programming. Different approaches/libraries/frameworks don't usually mix well or at all. First, I believe it has been a grave mistake to write a ton of utility libraries that block. They make it easy to put together a prototype, but before long you realize the mess they have led you to and the only way out is a complete rewrite or a number of complicated adapters that drain performance, hurt quality and don't really add true value. Could asyncio be the basis of a de-facto Python way of doing asynchronous programming? Maybe. GvR definitely has that intention. However, I'm afraid the paradigm is quite unnatural. Essentially, it is thread programming where blocking calls are replaced with funny syntax. Most developers are familiar with multithreading, but they often are not actively aware what functions are blocking. Reading from a socket is blocking. Writing to a socket is blocking as well. Is file I/O blocking? Is database access blocking? Is socket.getaddrinfo() blocking? A function may be nonblocking in one release of a package but might then become blocking in the next release. I'm an advocate of the "callback hell" together with clearly expressed finite state machines. They are super easy to understand. They lead to very complicated code but the complications can be analyzed and debugged based on the elementary knowledge. Also, you don't need a complicated framework for it. The only thing missing from select.epoll() is timers, but timers are not all that hard to implement (especially if you had an a balanced tree implementation at your disposal). Still, even the select.epoll() method requires callback implementations of the different protocols and databases. Marko From jcarmena at gmail.com Sat Aug 1 13:50:46 2015 From: jcarmena at gmail.com (Javier) Date: Sat, 1 Aug 2015 10:50:46 -0700 (PDT) Subject: Send data to asyncio coroutine In-Reply-To: <87a8ubudu5.fsf@elektro.pacujo.net> References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> <87a8ubudu5.fsf@elektro.pacujo.net> Message-ID: <8798b190-9f83-468c-b829-3c35e05ccf04@googlegroups.com> El s?bado, 1 de agosto de 2015, 19:19:00 (UTC+2), Marko Rauhamaa escribi?: > Javier : > > > Asyncio is a crazy headache! I realized that I can't use asyncio tcp > > servers with pickle! Asyncio is good as a concept but bad in real > > life. > > > > I think python's non blocking I/O is far from being something useful > > for developers till non-async code can invoke async code > > transparently. Duplicating all code/libs when you realize that > > something not fits asyncio is not a solution and even less a pythonic > > solution. > > After all these decades, we are still struggling to find the naturally > flowing paradigm for asynchronous programming. Different > approaches/libraries/frameworks don't usually mix well or at all. > > First, I believe it has been a grave mistake to write a ton of utility > libraries that block. They make it easy to put together a prototype, but > before long you realize the mess they have led you to and the only way > out is a complete rewrite or a number of complicated adapters that drain > performance, hurt quality and don't really add true value. > > Could asyncio be the basis of a de-facto Python way of doing > asynchronous programming? Maybe. GvR definitely has that intention. > However, I'm afraid the paradigm is quite unnatural. Essentially, it is > thread programming where blocking calls are replaced with funny syntax. > Most developers are familiar with multithreading, but they often are not > actively aware what functions are blocking. Reading from a socket is > blocking. Writing to a socket is blocking as well. Is file I/O blocking? > Is database access blocking? Is socket.getaddrinfo() blocking? > > A function may be nonblocking in one release of a package but might then > become blocking in the next release. > > I'm an advocate of the "callback hell" together with clearly expressed > finite state machines. They are super easy to understand. They lead to > very complicated code but the complications can be analyzed and debugged > based on the elementary knowledge. Also, you don't need a complicated > framework for it. The only thing missing from select.epoll() is timers, > but timers are not all that hard to implement (especially if you had an > a balanced tree implementation at your disposal). > > Still, even the select.epoll() method requires callback implementations > of the different protocols and databases. > > > Marko I agree with you, Marko, I came from callbacks too. So, if GvR wants the yield from become de-facto, does it mean that all python libraries will evolve to become asyncio friendly libs? or that I have to write my own library so I can use existing libraries like pickle? I think "callback hell" is "peccata minuta" compared with "yield from hell". From jcarmena at gmail.com Sat Aug 1 14:22:26 2015 From: jcarmena at gmail.com (Javier) Date: Sat, 1 Aug 2015 11:22:26 -0700 (PDT) Subject: Send data to asyncio coroutine In-Reply-To: References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> Message-ID: El s?bado, 1 de agosto de 2015, 18:45:17 (UTC+2), Mark Lawrence escribi?: > On 01/08/2015 17:07, Javier wrote: > > > > Asyncio is a crazy headache! I realized that I can't use asyncio tcp servers with pickle! Asyncio is good as a concept but bad in real life. > > > > I think python's non blocking I/O is far from being something useful for developers till non-async code can invoke async code transparently. Duplicating all code/libs when you realize that something not fits asyncio is not a solution and even less a pythonic solution. > > > > I'll keep my eyes open for your solution on pypi as clearly you know > better than the Python core developers. Fully documented and tested of > course. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence Don't be rascal, friend. Nobody thinks that self is better than core developers, and personaly I don't think I am better than anybody, but, I have my own opinion. The fact that the core team is better at python coding and compilers than me does not mean that her implementation fits my needs/opinion. I dont like the current event loop implementation (plus yield from): - It forces me to use beta libraries for doing something that another production ready library already does, - I can't use one of the most awesome python features: yielding between generators and coroutines - As you said, I'm not as smart as they are but I thought python is for everybody, not only for them. Should I ask them how can I use pickle with streamreader? I think it would be better if it would become trivial. I read PEPs. I don't imagine a good users community if all of us would have to read the pythons source code to understand how to use new features or rewrite a new implementation proposal to be allowed to tell our opinion, as you claims, I would like that all the code would run on event loop, but till then I just believe that event loop should be a native feature, not a python hack. I believe that we should be able to call asyncio functions without doing "yield from" through all the stack. I believe that It's possible an implementation that allows generators for processing data streams and that allows to mix classic code with loop code. And finally I claim a place for not super-level pythoners that want to talk about features improvement without being asked for a reference implementation, each of us have our own role. :) From marko at pacujo.net Sat Aug 1 14:33:51 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Aug 2015 21:33:51 +0300 Subject: Send data to asyncio coroutine References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> <87a8ubudu5.fsf@elektro.pacujo.net> <8798b190-9f83-468c-b829-3c35e05ccf04@googlegroups.com> Message-ID: <87614yvoxc.fsf@elektro.pacujo.net> Javier : > I agree with you, Marko, I came from callbacks too. So, if GvR wants > the yield from become de-facto, does it mean that all python libraries > will evolve to become asyncio friendly libs? or that I have to write > my own library so I can use existing libraries like pickle? I think > "callback hell" is "peccata minuta" compared with "yield from hell". I guess GvR expects Twisted, Tornado et al jump on the asyncio bandwagon. Myself, I would like the lowest-level I/O transactions to be broken into their atomic, nonblocking primitives: request optional: update(s), cancellation response optional: preliminary response(s) Those primitives can be then used to put together asyncio coroutines or blocking functions for multithreading. Or they can be used as-is in classical callback programming. Marko From tjreedy at udel.edu Sat Aug 1 14:35:46 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 1 Aug 2015 14:35:46 -0400 Subject: I'm a newbie and I'm stumped... In-Reply-To: References: Message-ID: On 7/30/2015 9:22 PM, Dwight GoldWinde wrote: > Please help. > > I am running Python 3.4 on my Mac mini, OS X 10.10.2, using Coderunner 2 > as my editor. > > Here?s the code: > #!/usr/bin/env python3 > word = (input('Enter a word ?)) The outer parentheses are not needed. Ditto to the other comments, especially about not using html and the unicode quote that causes SyntaxError. -- Terry Jan Reedy From marko at pacujo.net Sat Aug 1 14:38:03 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Aug 2015 21:38:03 +0300 Subject: Send data to asyncio coroutine References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> Message-ID: <871tfmvoqc.fsf@elektro.pacujo.net> Javier : > El s?bado, 1 de agosto de 2015, 18:45:17 (UTC+2), Mark Lawrence escribi?: >> clearly you know better than the Python core developers > > Nobody thinks that self is better than core developers, and personaly > I don't think I am better than anybody, but, I have my own opinion. It is odd how an engineering forum like this one so often judges ideas based on the pedigree of the participants rather than objective technical arguments. Marko From breamoreboy at yahoo.co.uk Sat Aug 1 14:45:46 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 1 Aug 2015 19:45:46 +0100 Subject: Send data to asyncio coroutine In-Reply-To: <871tfmvoqc.fsf@elektro.pacujo.net> References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> <871tfmvoqc.fsf@elektro.pacujo.net> Message-ID: On 01/08/2015 19:38, Marko Rauhamaa wrote: > Javier : > >> El s?bado, 1 de agosto de 2015, 18:45:17 (UTC+2), Mark Lawrence escribi?: >>> clearly you know better than the Python core developers >> >> Nobody thinks that self is better than core developers, and personaly >> I don't think I am better than anybody, but, I have my own opinion. > > It is odd how an engineering forum like this one so often judges ideas > based on the pedigree of the participants rather than objective > technical arguments. > > > Marko > What I find odd is that the bleating and whinging comes long after the PEP process has finished and the code is already in production. Wouldn't it be easier for everybody all around to sort this out right at the start of the process? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rantingrickjohnson at gmail.com Sat Aug 1 14:57:47 2015 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 1 Aug 2015 11:57:47 -0700 (PDT) Subject: GvR Europython keynote described on lwn.net In-Reply-To: <55bc5cfb$0$1643$c3e8da3$5496439d@news.astraweb.com> References: <87r3noltu3.fsf@jester.gateway.sonic.net> <106305a9-3ccd-4de4-a918-c27cec2d0b8c@googlegroups.com> <55bc5cfb$0$1643$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, August 1, 2015 at 12:45:45 AM UTC-5, Steven D'Aprano wrote: > > Yep, even the BDFL is actively developing in 2.7! He's no fool. > > Of course not. Dropbox pay him to work on their systems, > and he wants to keep his job. Thanks for confirming my point that Python3 is not worth developing with for at least the next five years. > Are you aware that Dropbox are heavily pushing for static > type hints in Python 3 as a prerequisite for them porting > their masses of Python 2 code to Python 3? Well then, i hope they are ready to wait at least 10 years before adopting Python3, because it will take that long to work out all the kinks! Of course, with the cloud service wars heating up, no one can be sure how long any of them will survive. Web technology is moving much faster than Python. > That's one of the motives for the masses of effort put > into PEP 484, and its support PEPs, 482 and 483: I do find it flattering that many of my ideas regarding Python have been implemented: (1) It was me who recommended "optional type checking" way back around 2008 (Heck, you even agreed that it would be a good idea, but at the time, a moratorium was preventing new features) (2) The fresher look of Python.org is a result of my suggestions (3) The interactive online console was my idea to compete with the Ruby equivalent (4) I have pestered tutorial owners to upgrade their tutorials to py3 compatibility, and many did! (5) and last but not least, my courage to face down the trolls has given courage to the shadow lurkers, who now participate in open discussions on this list, and some have even moved over to more dangerous grounds like Python-ideas. All in all, my presence here has resulted in a fundamental transformation of this group, and this language. > As I understand it, Dropbox are paying Guido to work on > static type hinting for Python, with the emphasis on > proving program correctness, not speed, specifically > because they want a big positive gain for moving to Python > 3. Well it's true that reducing bugs should always be preferable to speed, but once the error potentials are reduced, Dropbox will no doubt pivot to performance enhancements -- this is the nature of our universe. From jcarmena at gmail.com Sat Aug 1 15:07:33 2015 From: jcarmena at gmail.com (Javier) Date: Sat, 1 Aug 2015 12:07:33 -0700 (PDT) Subject: Send data to asyncio coroutine In-Reply-To: References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> <871tfmvoqc.fsf@elektro.pacujo.net> Message-ID: <0310f559-8700-4e53-8e04-16eaf9e372b7@googlegroups.com> El s?bado, 1 de agosto de 2015, 20:46:49 (UTC+2), Mark Lawrence escribi?: > On 01/08/2015 19:38, Marko Rauhamaa wrote: > > Javier : > > > >> El s?bado, 1 de agosto de 2015, 18:45:17 (UTC+2), Mark Lawrence escribi?: > >>> clearly you know better than the Python core developers > >> > >> Nobody thinks that self is better than core developers, and personaly > >> I don't think I am better than anybody, but, I have my own opinion. > > > > It is odd how an engineering forum like this one so often judges ideas > > based on the pedigree of the participants rather than objective > > technical arguments. > > > > > > Marko > > > > What I find odd is that the bleating and whinging comes long after the > PEP process has finished and the code is already in production. > Wouldn't it be easier for everybody all around to sort this out right at > the start of the process? > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence I think so too, Mark, but I talk about it when I have used it. I came from blocking IO development. But isn't this a live language? Well! let's forget all this and let's work with python 3.4 :) My intention now is to use the asyncio.StreamReader passed as argument to the asyncio.start_server callback to read objects serialized with pickle. The problems are that pickle cant read from it (because dont yield from the full stack) and that I don't know the exact length of each serialized object, so I can't extract data manually. Knows anybody the steps to follow? Thanks From marko at pacujo.net Sat Aug 1 15:09:54 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Aug 2015 22:09:54 +0300 Subject: Send data to asyncio coroutine References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> <871tfmvoqc.fsf@elektro.pacujo.net> Message-ID: <87wpxeu8ot.fsf@elektro.pacujo.net> Mark Lawrence : > On 01/08/2015 19:38, Marko Rauhamaa wrote: >> It is odd how an engineering forum like this one so often judges >> ideas based on the pedigree of the participants rather than objective >> technical arguments. > > What I find odd is that the bleating and whinging comes long after the > PEP process has finished and the code is already in production. > Wouldn't it be easier for everybody all around to sort this out right > at the start of the process? Err... * You are free to say you don't like something, even aspects of Python. * Criticism can be well-founded even if the critic wasn't around when the developers put the spec together. * Most Python users (as in 99.999% of them) aren't Python developers. That's as it should be. * Even if critics had been around and voiced their criticism, asyncio probably would have been introduced. * Even if somebody doesn't like an idea, somebody else might love it. Are you happy with asyncio, Mark? Marko From marko at pacujo.net Sat Aug 1 15:14:54 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Aug 2015 22:14:54 +0300 Subject: Send data to asyncio coroutine References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> <871tfmvoqc.fsf@elektro.pacujo.net> <0310f559-8700-4e53-8e04-16eaf9e372b7@googlegroups.com> Message-ID: <87si82u8gh.fsf@elektro.pacujo.net> Javier : > My intention now is to use the asyncio.StreamReader passed as argument > to the asyncio.start_server callback to read objects serialized with > pickle. The problems are that pickle cant read from it (because dont > yield from the full stack) and that I don't know the exact length of > each serialized object, so I can't extract data manually. > > Knows anybody the steps to follow? You probably need to frame your pickled encoding. A simple thing would be to use struct.pack/unpack to encode the length of the pickle encoding in front of the pickle encoding. When decoding, you first read out the length, then the pickle encoding, and finally you unpickle the payload. Marko From breamoreboy at yahoo.co.uk Sat Aug 1 15:29:08 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 1 Aug 2015 20:29:08 +0100 Subject: Send data to asyncio coroutine In-Reply-To: <87wpxeu8ot.fsf@elektro.pacujo.net> References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> <871tfmvoqc.fsf@elektro.pacujo.net> <87wpxeu8ot.fsf@elektro.pacujo.net> Message-ID: On 01/08/2015 20:09, Marko Rauhamaa wrote: > Mark Lawrence : > >> On 01/08/2015 19:38, Marko Rauhamaa wrote: >>> It is odd how an engineering forum like this one so often judges >>> ideas based on the pedigree of the participants rather than objective >>> technical arguments. >> >> What I find odd is that the bleating and whinging comes long after the >> PEP process has finished and the code is already in production. >> Wouldn't it be easier for everybody all around to sort this out right >> at the start of the process? > > Err... > > * You are free to say you don't like something, even aspects of Python. > > * Criticism can be well-founded even if the critic wasn't around when > the developers put the spec together. > > * Most Python users (as in 99.999% of them) aren't Python developers. > That's as it should be. > > * Even if critics had been around and voiced their criticism, asyncio > probably would have been introduced. > > * Even if somebody doesn't like an idea, somebody else might love it. > > Are you happy with asyncio, Mark? > > > Marko > Yes. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Sat Aug 1 15:33:59 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 1 Aug 2015 20:33:59 +0100 Subject: Send data to asyncio coroutine In-Reply-To: <0310f559-8700-4e53-8e04-16eaf9e372b7@googlegroups.com> References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> <871tfmvoqc.fsf@elektro.pacujo.net> <0310f559-8700-4e53-8e04-16eaf9e372b7@googlegroups.com> Message-ID: On 01/08/2015 20:07, Javier wrote: > El s?bado, 1 de agosto de 2015, 20:46:49 (UTC+2), Mark Lawrence escribi?: > > Well! let's forget all this and let's work with python 3.4 :) > Please keep up, 3.5 is in beta and the current default will be 3.6 :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From emile at fenx.com Sat Aug 1 15:48:54 2015 From: emile at fenx.com (Emile van Sebille) Date: Sat, 1 Aug 2015 12:48:54 -0700 Subject: Which Python do I need for the below? In-Reply-To: References: <377640C91279E84D9B61F71C964BA3424A1ACDB8@SACMBXIP02.sdcorp.global.sandisk.com> Message-ID: On 8/1/2015 10:09 AM, Rustom Mody wrote: > On Saturday, August 1, 2015 at 10:07:37 PM UTC+5:30, Emile van Sebille wrote: >> Seeing that you have no responses yet I'm guessing most potential >> responders along with me are not opening attachments. > > Most recipients are not receiving at all! > [I only see Emile's response. Evidently GG is deleting mails that have attachments] Yet another side effect of the koolaid. :( Emile From mail at tinloaf.de Sat Aug 1 16:34:21 2015 From: mail at tinloaf.de (Lukas Barth) Date: Sat, 1 Aug 2015 13:34:21 -0700 (PDT) Subject: Most pythonic way of rotating a circular list to a canonical point Message-ID: Hi! I have a list of numbers that I treat as "circular", i.e. [1,2,3] and [2,3,1] should be the same. Now I want to rotate these to a well defined status, so that I can can compare them. If all elements are unique, the solution is easy: find the minimum element, find its index, then use mylist[:index] + mylist[index:], i.e. the minimum element will always be at the beginning. But say I have [0,1,0,2,0,3]. I can in fact guarantee that no *pair* will appear twice in that list, i.e. I could search for the minimum, if that is unique go on as above, otherwise find *all* positions of the minimum, see which is followed by the smallest element, and then rotate that position to the front. Now that seems an awful lot of code for a (seemingly?) simple problem. Is there a nice, pythonic way to do this? Thanks for enlightening me! Lukas From emile at fenx.com Sat Aug 1 16:49:58 2015 From: emile at fenx.com (Emile van Sebille) Date: Sat, 1 Aug 2015 13:49:58 -0700 Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: Message-ID: On 8/1/2015 1:34 PM, Lukas Barth wrote: > Hi! > > I have a list of numbers that I treat as "circular", i.e. [1,2,3] and [2,3,1] should be the same. Now I want to rotate these to a well defined status, so that I can can compare them. > > If all elements are unique, the solution is easy: find the minimum element, find its index, then use mylist[:index] + mylist[index:], i.e. the minimum element will always be at the beginning. > > But say I have [0,1,0,2,0,3]. I can in fact guarantee that no *pair* will appear twice in that list, i.e. I could search for the minimum, if that is unique go on as above, otherwise find *all* positions of the minimum, see which is followed by the smallest element, and then rotate that position to the front. > > Now that seems an awful lot of code for a (seemingly?) simple problem. Is there a nice, pythonic way to do this? Well, I have not understood the problem for such a seemingly simple one. :) Is the problem to determine if one list of circular numbers 'matches' another one despite rotation status? If so, I'd do something like: def matchcircularlists(L1,L2): #return True if L1 is a rotation variant of L2 return "".join(map(str,L1)) in "".join(map(str,L2+L2)) Emile From marko at pacujo.net Sat Aug 1 16:57:06 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Aug 2015 23:57:06 +0300 Subject: Most pythonic way of rotating a circular list to a canonical point References: Message-ID: <87fv42u3q5.fsf@elektro.pacujo.net> Lukas Barth : > I have a list of numbers that I treat as "circular", i.e. [1,2,3] and > [2,3,1] should be the same. Now I want to rotate these to a well defined > status, so that I can can compare them. > > If all elements are unique, the solution is easy: find the minimum > element, find its index, then use mylist[:index] + mylist[index:], i.e. > the minimum element will always be at the beginning. > > But say I have [0,1,0,2,0,3]. I can in fact guarantee that no *pair* > will appear twice in that list, i.e. I could search for the minimum, if > that is unique go on as above, otherwise find *all* positions of the > minimum, see which is followed by the smallest element, and then rotate > that position to the front. > > Now that seems an awful lot of code for a (seemingly?) simple problem. > Is there a nice, pythonic way to do this? How about: ======================================================================== def circularly_equal(l1, l2): length = len(l1) if length != len(l2): return False twice = l1 + l1 for i in range(length): if twice[i:i + length] == l2: return True return False ======================================================================== Marko From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Sat Aug 1 17:01:27 2015 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Sat, 01 Aug 2015 22:01:27 +0100 Subject: I'm a newbie and I'm stumped... References: Message-ID: On 31-07-2015 02:22, Dwight GoldWinde wrote: > Please help. > > I am running Python 3.4 on my Mac mini, OS X 10.10.2, using Coderunner 2 > as my editor. > > Here?s the code: > #!/usr/bin/env python3 > word = (input('Enter a word ?)) As is here, this code should raise a syntax error message like SyntaxError: EOL while scanning string literal On the right side of *Enter a word* you have to use the same single quote "'" as that on the left side. Besides this, the code must work assigning your string input to variable "word". The outer "()" are unnecessary but cause no hurt. From mail at tinloaf.de Sat Aug 1 17:04:34 2015 From: mail at tinloaf.de (Lukas Barth) Date: Sat, 1 Aug 2015 14:04:34 -0700 (PDT) Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: <87fv42u3q5.fsf@elektro.pacujo.net> References: <87fv42u3q5.fsf@elektro.pacujo.net> Message-ID: On Saturday, August 1, 2015 at 10:57:19 PM UTC+2, Marko Rauhamaa wrote: > ======================================================================== > def circularly_equal(l1, l2): > length = len(l1) > if length != len(l2): > return False > twice = l1 + l1 > for i in range(length): > if twice[i:i + length] == l2: > return True > return False > ======================================================================== Nice idea! But I actually really need those "canonic rotations", since I'm hashing them somewhere.. Lukas From mail at tinloaf.de Sat Aug 1 17:12:07 2015 From: mail at tinloaf.de (Lukas Barth) Date: Sat, 1 Aug 2015 14:12:07 -0700 (PDT) Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: Message-ID: <91eed423-5e38-4986-80d9-04d1fc363012@googlegroups.com> On Saturday, August 1, 2015 at 10:51:03 PM UTC+2, Emile van Sebille wrote: > Is the problem to determine if one list of circular numbers 'matches' > another one despite rotation status? If so, I'd do something like: Well.. no. I actually really need this "canonical" rotation, since I'm hashing this, returning it to other parts of the software, etc.. But thanks! Lukas From mail at tinloaf.de Sat Aug 1 17:24:15 2015 From: mail at tinloaf.de (Lukas Barth) Date: Sat, 1 Aug 2015 14:24:15 -0700 (PDT) Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: Message-ID: Perhaps I should clarify a bit: - I definitely need a "canonical rotation" - just a comparison result is not enough - It does not matter what that rotation is. Starting with the smallest element was just an idea by me, any rotation that can easily produced will do. From emile at fenx.com Sat Aug 1 17:29:13 2015 From: emile at fenx.com (Emile van Sebille) Date: Sat, 1 Aug 2015 14:29:13 -0700 Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: <91eed423-5e38-4986-80d9-04d1fc363012@googlegroups.com> References: <91eed423-5e38-4986-80d9-04d1fc363012@googlegroups.com> Message-ID: On 8/1/2015 2:12 PM, Lukas Barth wrote: > On Saturday, August 1, 2015 at 10:51:03 PM UTC+2, Emile van Sebille wrote: >> Is the problem to determine if one list of circular numbers 'matches' >> another one despite rotation status? If so, I'd do something like: > > Well.. no. I actually really need this "canonical" rotation, since I'm hashing this, returning it to other parts of the software, etc.. Then I'm not sure that I understand what exactly the problem is. Can you state it in terms of what you start with and what you expect to get? The only clue I see is "Now I want to rotate these to a well defined status, so that I can can compare them." Which is where I understood you to want to compare them. You might check at http://www.catb.org/esr/faqs/smart-questions.html Emile From emile at fenx.com Sat Aug 1 17:36:43 2015 From: emile at fenx.com (Emile van Sebille) Date: Sat, 1 Aug 2015 14:36:43 -0700 Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: Message-ID: On 8/1/2015 2:24 PM, Lukas Barth wrote: > Perhaps I should clarify a bit: > > - I definitely need a "canonical rotation" - just a comparison result is not enough Well, it looks to me that I don't know what a 'canonical rotation' is -- there's no wikipedia article and googling yields all sorts of specialized math related articles. Sorry, From no.email at nospam.invalid Sat Aug 1 17:43:14 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 01 Aug 2015 14:43:14 -0700 Subject: Most pythonic way of rotating a circular list to a canonical point References: Message-ID: <873802lm6l.fsf@jester.gateway.sonic.net> Lukas Barth writes: > - It does not matter what that rotation is. Starting with the smallest > element was just an idea by me, any rotation that can easily produced > will do. How large are these lists supposed to be? If they're (say) 5 elements, you could make the hash code consist of the concatenated hashes of each of the 5 rotations, or maybe a Bloom filter on those hashes. Then to do a lookup, hash your target list and see if it appears in the table. If the lists are very large that doesn't sound so great due to storage requirements.. From cs at zip.com.au Sat Aug 1 18:25:30 2015 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 2 Aug 2015 08:25:30 +1000 Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: Message-ID: <20150801222530.GA53191@cskk.homeip.net> On 01Aug2015 14:24, Lukas Barth wrote: >Perhaps I should clarify a bit: >- I definitely need a "canonical rotation" - just a comparison result is not enough Fine. This also eliminates any solution which just computes a hash. >- It does not matter what that rotation is. Starting with the smallest element was just an idea by me, any rotation that can easily produced will do. That's a fine way to start, but more work than is needed. Might I suggest instead simply starting with the leftmost element in the first list; call this elem0. Then walk the second list from 0 to len(list2). If that element equals elem0, _then_ compare the list at that point as you suggested. Is there an aspect of this which doesn't work? Cheers, Cameron Simpson From mail at tinloaf.de Sat Aug 1 18:51:53 2015 From: mail at tinloaf.de (Lukas Barth) Date: Sat, 1 Aug 2015 15:51:53 -0700 (PDT) Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: Message-ID: <9c5dc0c8-0066-4140-9883-f3af14f7b328@googlegroups.com> On Saturday, August 1, 2015 at 11:37:48 PM UTC+2, Emile van Sebille wrote: > Well, it looks to me that I don't know what a 'canonical rotation' is -- That's because it is not defined. ;) I need a way to rotate one of these lists in a way so that it will produce the same output every time, regardless of what the input rotation was. Example: [0,1,2,3,4] => [0,1,2,3,4] [2,3,4,0,1] => [0,1,2,3,4] [3,4,0,1,2] => [0,1,2,3,4] ... It doesn't have to be "[0,1,2,3,4]", it can just as well be [2,3,4,1,0], as long as it's always the same. Did that make it clearer? Thanks a lot, Lukas From mail at tinloaf.de Sat Aug 1 18:53:39 2015 From: mail at tinloaf.de (Lukas Barth) Date: Sat, 1 Aug 2015 15:53:39 -0700 (PDT) Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: <873802lm6l.fsf@jester.gateway.sonic.net> References: <873802lm6l.fsf@jester.gateway.sonic.net> Message-ID: <072c7f0b-f636-4c19-8b61-7422b054dcc9@googlegroups.com> On Saturday, August 1, 2015 at 11:43:28 PM UTC+2, Paul Rubin wrote: > How large are these lists supposed to be? Potentially large. Not so large though that iterating them (multiple times) should be a problem. > [Concatenated Hashes] > > If the lists are very large that doesn't sound so great due to storage > requirements.. Also, that still doesn't compute that one "canonical ordering"... Thanks, Lukas From mail at tinloaf.de Sat Aug 1 18:55:55 2015 From: mail at tinloaf.de (Lukas Barth) Date: Sat, 1 Aug 2015 15:55:55 -0700 (PDT) Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: Message-ID: <263dbfc5-7691-495b-8ebb-52d9de164f65@googlegroups.com> On Sunday, August 2, 2015 at 12:32:25 AM UTC+2, Cameron Simpson wrote: > Fine. This also eliminates any solution which just computes a hash. Exactly. > Might I suggest instead simply starting with the leftmost element in the first > list; call this elem0. Then walk the second list from 0 to len(list2). If that > element equals elem0, _then_ compare the list at that point as you suggested. > > Is there an aspect of this which doesn't work? The problem is: When I compute a hash over list1 (in its canonical form), I do not yet know list2 (or list3, or listN...) against which they will be compared later.. Lukas From joel.goldstick at gmail.com Sat Aug 1 18:58:14 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 1 Aug 2015 18:58:14 -0400 Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: <9c5dc0c8-0066-4140-9883-f3af14f7b328@googlegroups.com> References: <9c5dc0c8-0066-4140-9883-f3af14f7b328@googlegroups.com> Message-ID: On Sat, Aug 1, 2015 at 6:51 PM, Lukas Barth wrote: > On Saturday, August 1, 2015 at 11:37:48 PM UTC+2, Emile van Sebille wrote: >> Well, it looks to me that I don't know what a 'canonical rotation' is -- > > That's because it is not defined. ;) > > I need a way to rotate one of these lists in a way so that it will produce the same output every time, regardless of what the input rotation was. > > Example: > > [0,1,2,3,4] => [0,1,2,3,4] > [2,3,4,0,1] => [0,1,2,3,4] > [3,4,0,1,2] => [0,1,2,3,4] > ... > > It doesn't have to be "[0,1,2,3,4]", it can just as well be [2,3,4,1,0], as long as it's always the same. > > Did that make it clearer? > > Thanks a lot, > > Lukas I've been following along. The early suggestion to double one list and see if the second list is in the double list seems to prove they are the same -- one is just rotated to a different starting point. I don't understand the term 'canonical' in this example, but what is it that the solution given doesn't provide for you? -- Joel Goldstick http://joelgoldstick.com From oscar.j.benjamin at gmail.com Sat Aug 1 19:05:03 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 01 Aug 2015 23:05:03 +0000 Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: <87fv42u3q5.fsf@elektro.pacujo.net> Message-ID: On Sat, 1 Aug 2015 22:06 Lukas Barth wrote: Nice idea! But I actually really need those "canonic rotations", since I'm hashing them somewhere. Do you really need the canonical rotation or just a hash that is invariant under rotations? I don't know of a solution to the former that is better than what you already have but the latter is an easier problem: Find the minimum element. Compute the hash of the rotated sequence for each occurrence of the least common element. Add those hashes together or multiply them or some similar operation. That's your hash that will compare equal for any rotation of a given sequence. -- Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Sat Aug 1 19:10:07 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 01 Aug 2015 23:10:07 +0000 Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: <87fv42u3q5.fsf@elektro.pacujo.net> Message-ID: On Sun, 2 Aug 2015 00:05 Oscar Benjamin wrote: On Sat, 1 Aug 2015 22:06 Lukas Barth wrote: Nice idea! But I actually really need those "canonic rotations", since I'm hashing them somewhere. Do you really need the canonical rotation or just a hash that is invariant under rotations? I don't know of a solution to the former that is better than what you already have but the latter is an easier problem: Find the minimum element. Compute the hash of the rotated sequence for each occurrence of the least common element. Add those hashes together or multiply them or some similar operation. That's your hash that will compare equal for any rotation of a given sequence. I said "least common" but meant "minimum". A potential improvement would be to use the minimum element of the least common elements instead of just the minimum element. Presumably in most cases there would be at least some unique elements so if you take the minimum of those then you would only need to compute 1 sequence hash. Maybe this is unnecessary though. -- Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Aug 1 19:28:03 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Aug 2015 09:28:03 +1000 Subject: Send data to asyncio coroutine In-Reply-To: References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> <871tfmvoqc.fsf@elektro.pacujo.net> <0310f559-8700-4e53-8e04-16eaf9e372b7@googlegroups.com> Message-ID: On Sun, Aug 2, 2015 at 5:33 AM, Mark Lawrence wrote: > Please keep up, 3.5 is in beta and the current default will be 3.6 :) Not sure what you mean by "default", but I've been running 3.6.0a0 for a while now :) ChrisA From mail at tinloaf.de Sat Aug 1 19:32:10 2015 From: mail at tinloaf.de (Lukas Barth) Date: Sat, 1 Aug 2015 16:32:10 -0700 (PDT) Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: <87fv42u3q5.fsf@elektro.pacujo.net> Message-ID: On Sunday, August 2, 2015 at 1:05:32 AM UTC+2, Oscar Benjamin wrote: > Do you really need the canonical rotation or just a hash that is invariant under rotations? Having that canonical rotation would make the code simpler and faster, probably, but a rotationally invariant hash is a good start. > I don't know of a solution to the former that is better than what you already have but the latter is an easier problem: Find the minimum element. Compute the hash of the rotated sequence for each occurrence of the least common element. Add those hashes together or multiply them or some similar operation. That's your hash that will compare equal for any rotation of a given sequence. Yes, that sounds like an idea if I decide to just go with the hash. Thanks! Lukas From Joshua.R.English at gmail.com Sat Aug 1 19:43:44 2015 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 1 Aug 2015 16:43:44 -0700 (PDT) Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: <9c5dc0c8-0066-4140-9883-f3af14f7b328@googlegroups.com> References: <9c5dc0c8-0066-4140-9883-f3af14f7b328@googlegroups.com> Message-ID: <808f0fae-ebaf-48f0-8f11-d7cf0373e4f5@googlegroups.com> On Saturday, August 1, 2015 at 3:52:25 PM UTC-7, Lukas Barth wrote: > On Saturday, August 1, 2015 at 11:37:48 PM UTC+2, Emile van Sebille wrote: > > Well, it looks to me that I don't know what a 'canonical rotation' is -- > > That's because it is not defined. ;) > > I need a way to rotate one of these lists in a way so that it will produce the same output every time, regardless of what the input rotation was. > > Example: > > [0,1,2,3,4] => [0,1,2,3,4] > [2,3,4,0,1] => [0,1,2,3,4] > [3,4,0,1,2] => [0,1,2,3,4] > ... > > It doesn't have to be "[0,1,2,3,4]", it can just as well be [2,3,4,1,0], as long as it's always the same. > > Did that make it clearer? > Is this "canoncal rotation" different than sorting. I think you mean it to be, but these examples all look like sorting to me. I think the collections.deque object has a rotate method, and rotating through the possibilities looking for matches may work, or take any deque, rotate so the minimum value is at the first place in the deque, and then compare. Or am I not understanding what you mean? Josh From wolfram.hinderer at googlemail.com Sat Aug 1 20:07:46 2015 From: wolfram.hinderer at googlemail.com (wolfram.hinderer at googlemail.com) Date: Sat, 1 Aug 2015 17:07:46 -0700 (PDT) Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: Message-ID: Am Samstag, 1. August 2015 22:34:44 UTC+2 schrieb Lukas Barth: > Hi! > > I have a list of numbers that I treat as "circular", i.e. [1,2,3] and [2,3,1] should be the same. Now I want to rotate these to a well defined status, so that I can can compare them. > > If all elements are unique, the solution is easy: find the minimum element, find its index, then use mylist[:index] + mylist[index:], i.e. the minimum element will always be at the beginning. > > But say I have [0,1,0,2,0,3]. I can in fact guarantee that no *pair* will appear twice in that list, i.e. I could search for the minimum, if that is unique go on as above, otherwise find *all* positions of the minimum, see which is followed by the smallest element, and then rotate that position to the front. > > Now that seems an awful lot of code for a (seemingly?) simple problem. Is there a nice, pythonic way to do this? It's not that much code (unless I misunderstood your question): def f(A): i = min(range(len(A)-1), key=lambda i: A[i:i+2]) if [A[-1], A[0]] < A[i:i+2]: i = len(A) - 1 return A[i:] + A[:i] Examples: f([0,2,0,1,0,3,0]) Out[23]: [0, 0, 2, 0, 1, 0, 3] f([2,3,4,0,1]) Out[24]: [0, 1, 2, 3, 4] Wolfram From jcarmena at gmail.com Sat Aug 1 20:50:58 2015 From: jcarmena at gmail.com (Javier) Date: Sat, 1 Aug 2015 17:50:58 -0700 (PDT) Subject: Send data to asyncio coroutine In-Reply-To: <87si82u8gh.fsf@elektro.pacujo.net> References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> <6be85999-9a5a-4fd9-879b-f0777dc19643@googlegroups.com> <871tfmvoqc.fsf@elektro.pacujo.net> <0310f559-8700-4e53-8e04-16eaf9e372b7@googlegroups.com> <87si82u8gh.fsf@elektro.pacujo.net> Message-ID: <55386de2-659a-4bad-a481-09fcea1c4ef0@googlegroups.com> El s?bado, 1 de agosto de 2015, 21:15:07 (UTC+2), Marko Rauhamaa escribi?: > Javier : > > > My intention now is to use the asyncio.StreamReader passed as argument > > to the asyncio.start_server callback to read objects serialized with > > pickle. The problems are that pickle cant read from it (because dont > > yield from the full stack) and that I don't know the exact length of > > each serialized object, so I can't extract data manually. > > > > Knows anybody the steps to follow? > > You probably need to frame your pickled encoding. A simple thing would > be to use struct.pack/unpack to encode the length of the pickle encoding > in front of the pickle encoding. When decoding, you first read out the > length, then the pickle encoding, and finally you unpickle the payload. > > > Marko Great! it works! I could not find a way to send an integer with fixed length, struct.pack/unpack does the job perfectly. Thanks! From cs at zip.com.au Sat Aug 1 21:20:57 2015 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 2 Aug 2015 11:20:57 +1000 Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: <263dbfc5-7691-495b-8ebb-52d9de164f65@googlegroups.com> References: <263dbfc5-7691-495b-8ebb-52d9de164f65@googlegroups.com> Message-ID: <20150802012057.GA77201@cskk.homeip.net> On 01Aug2015 15:55, Lukas Barth wrote: >On Sunday, August 2, 2015 at 12:32:25 AM UTC+2, Cameron Simpson wrote: >> Fine. This also eliminates any solution which just computes a hash. > >Exactly. > >> Might I suggest instead simply starting with the leftmost element in the first >> list; call this elem0. Then walk the second list from 0 to len(list2). If that >> element equals elem0, _then_ compare the list at that point as you suggested. >> >> Is there an aspect of this which doesn't work? > >The problem is: When I compute a hash over list1 (in its canonical form), I do not yet know list2 (or list3, or listN...) against which they will be compared later.. Are you collating on the hash before doing anything? I think I may have missed part of your problem specification. I thought you had a list and needed to recognise other lists which were rotations of it, and possibly return them pre or post rotation. If you're hashing the first list I'm presuming you're using that to allocate it to a bucket (even notionally) to avoid wasting time comparing it against wildly different lists, just compare against likely matches? Or what? If that is the case, choose a hash function that: is affected by the list length and is independent of the list item ordering. That is easy to arrange and is guarrenteed that a rotated version of the list will have the same hash. Trivial hash function: sum(list1)+len(list1) It is simple and will work. It has downsides that might be a problem in other contexts, but since I don't know what you're using the hash for then I can address that. Remember, hash functions are arbitrary - they just have to obey particular constraints dictated by your needs. Comments? Cheers, Cameron Simpson From no.email at nospam.invalid Sat Aug 1 22:47:34 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 01 Aug 2015 19:47:34 -0700 Subject: Most pythonic way of rotating a circular list to a canonical point References: <873802lm6l.fsf@jester.gateway.sonic.net> <072c7f0b-f636-4c19-8b61-7422b054dcc9@googlegroups.com> Message-ID: <87y4hujtix.fsf@jester.gateway.sonic.net> Lukas Barth writes: >> [Concatenated Hashes] > Also, that still doesn't compute that one "canonical ordering"... It was intended to get rid of the need. What is the actual application? How does this sound? To circularly hash [a,b,c,d] use: H([b-a, c-b, d-c, a-d]) where H is your favorite hash function on a list of that element type. That should give the same hash value for any rotation of the list. It generalizes in the obvious way to other lengths. From no.email at nospam.invalid Sat Aug 1 23:02:35 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 01 Aug 2015 20:02:35 -0700 Subject: Most pythonic way of rotating a circular list to a canonical point References: <873802lm6l.fsf@jester.gateway.sonic.net> <072c7f0b-f636-4c19-8b61-7422b054dcc9@googlegroups.com> <87y4hujtix.fsf@jester.gateway.sonic.net> Message-ID: <87pp36jstw.fsf@jester.gateway.sonic.net> Paul Rubin writes: > H([b-a, c-b, d-c, a-d]) > where H is your favorite hash function on a list of that element type. I wrote that up unclearly. H is supposed to be a hash on one element, and then you combine H(b-a), H(c-b), etc. in a commutative way, such as by adding them. Still not sure if this works though. From cs at zip.com.au Sat Aug 1 23:53:27 2015 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 2 Aug 2015 13:53:27 +1000 Subject: __main__ vs official module name: distinct module instances Message-ID: <20150802035327.GA53036@cskk.homeip.net> Hi All, Maybe this should be over in python-ideas, since there is a proposal down the bottom of this message. But first the background... I've just wasted a silly amount of time debugging an issue that really I know about, but had forgotten. I have a number of modules which include a main() function, and down the bottom this code: if __name__ == '__main__': sys.exit(main(sys.argv)) so that I have a convenient command line tool if I invoke the module directly. I typically have tiny shell wrappers like this: #!/bin/sh exec python -m cs.app.maildb -- ${1+"$@"} In short, invoke this module as a main program, passing in the command line arguments. Very useful. My problem? When invoked this way, the module cs.app.maildb that is being executed is actually the module named "__main__". If some other piece of code imports "cs.app.maildb" they get a _different_ instance of the module. In the same program! And how did it cause me trouble? I am monkey patching my module for debug purposes, and that monkey patcher imports the module by name. So I was monkey patching cs.app.maildb, and _not_ patching __main__. And thus not seeing any effect from the patch. I realise that having __name__ == '__main__' at all almost implies this effect. I am not sure it needs to. The Proposal: What are the implications of modifying the python invocation: python -m cs.app.maildb to effectively do this (Python pseudo code): M = importlib.import("cs.app.maildb") M.__name__ = '__main__' sys.modules['__main__'] = M i.e. import the module by name, but bind it to _both_ "cs.app.maildb" and "__main__" in sys.modules. And of course hack .__name__ to support the standard boilerplate. This would save some confusion when the module is invoked from the python command line and also imported by the code; it is not intuitive that those two things give you distinct module instances. Aside from the module's .__name__ being '__main__' even when accessed by the code as cs.app.maildb, are there other implications to such a change that would break real world code? Cheers, Cameron Simpson The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man. - George Bernard Shaw From rosuav at gmail.com Sun Aug 2 00:12:11 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Aug 2015 14:12:11 +1000 Subject: __main__ vs official module name: distinct module instances In-Reply-To: <20150802035327.GA53036@cskk.homeip.net> References: <20150802035327.GA53036@cskk.homeip.net> Message-ID: On Sun, Aug 2, 2015 at 1:53 PM, Cameron Simpson wrote: > What are the implications of modifying the python invocation: > > python -m cs.app.maildb > > to effectively do this (Python pseudo code): > > M = importlib.import("cs.app.maildb") > M.__name__ = '__main__' > sys.modules['__main__'] = M > > i.e. import the module by name, but bind it to _both_ "cs.app.maildb" and > "__main__" in sys.modules. And of course hack .__name__ to support the > standard boilerplate. > > This would save some confusion when the module is invoked from the python > command line and also imported by the code; it is not intuitive that those > two things give you distinct module instances. > > Aside from the module's .__name__ being '__main__' even when accessed by the > code as cs.app.maildb, are there other implications to such a change that > would break real world code? That's the one implication that comes to mind. It breaks the invariant that "import X; X.__name__" should be the string form of X. But does anything ever actually depend on that, or do things depend on the weaker requirement that X.__name__ should be something which you can import to get back a reference to X? I'd support this proposal. I'm not seeing any glaring problems, and it does have the potential to prevent bizarre problems. It would still want to be a non-recommended course of action, though, as the change won't (presumably) be backported - so any code that assumes that importing its main file gives the same module as __main__ will silently do the wrong thing on Python 2.7. Toss it out onto -ideas and see what bounces back! ChrisA From rustompmody at gmail.com Sun Aug 2 00:32:22 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 1 Aug 2015 21:32:22 -0700 (PDT) Subject: My code won't work if I double click the saved file In-Reply-To: References: <04881038-a14e-4469-be33-7fcd77496f67@googlegroups.com>,> <20150730020633.GA13546@cskk.homeip.net>, Message-ID: On Saturday, August 1, 2015 at 9:28:56 PM UTC+5:30, Ben Iannitelli wrote: > Everyone else: sorry if I messed up with this post somehow, it's my first time writing back to anyone on the newsletter. Its fine Thanks for trying to help [Just try to (hard)break your lines at around 72 columns/chars as some people use last millenium mail-clients] From marko at pacujo.net Sun Aug 2 02:25:56 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 02 Aug 2015 09:25:56 +0300 Subject: Most pythonic way of rotating a circular list to a canonical point References: <87fv42u3q5.fsf@elektro.pacujo.net> Message-ID: <877fpetde3.fsf@elektro.pacujo.net> Lukas Barth : > On Saturday, August 1, 2015 at 10:57:19 PM UTC+2, Marko Rauhamaa wrote: >> ======================================================================== >> def circularly_equal(l1, l2): >> length = len(l1) >> if length != len(l2): >> return False >> twice = l1 + l1 >> for i in range(length): >> if twice[i:i + length] == l2: >> return True >> return False >> ======================================================================== > > Nice idea! But I actually really need those "canonic rotations", since > I'm hashing them somewhere.. First, lists can't be used as dict keys, but that minor point is easy to overcome. Secondly, a hash doesn't need to be unique, it's enough for it to be discerning. So you could, for example, choose: sum([ hash(x) for x in L ]) + hash(sum(L)) That doesn't discern any permutations, but depending on your application might be good enough. That way, you use the "pretty good" hash function together with the circular equality test and you won't be needing any canonical representation for the key. Marko From steve at pearwood.info Sun Aug 2 03:41:10 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 02 Aug 2015 17:41:10 +1000 Subject: __main__ vs official module name: distinct module instances References: Message-ID: <55bdc996$0$1663$c3e8da3$5496439d@news.astraweb.com> On Sun, 2 Aug 2015 01:53 pm, Cameron Simpson wrote: > Hi All, > > Maybe this should be over in python-ideas, since there is a proposal down > the bottom of this message. But first the background... > > I've just wasted a silly amount of time debugging an issue that really I > know about, but had forgotten. :-) > I have a number of modules which include a main() function, and down the > bottom this code: > > if __name__ == '__main__': > sys.exit(main(sys.argv)) > > so that I have a convenient command line tool if I invoke the module > directly. I typically have tiny shell wrappers like this: > > #!/bin/sh > exec python -m cs.app.maildb -- ${1+"$@"} I know this isn't really relevant to your problem, but why use "exec python" instead of just "python"? And can you explain the -- ${1+"$@"} bit for somebody who knows just enough sh to know that it looks useful but not enough to know exactly what it does? > In short, invoke this module as a main program, passing in the command > line arguments. Very useful. > > My problem? > > When invoked this way, the module cs.app.maildb that is being executed is > actually the module named "__main__". Yep. Now, what you could do in cs.app.maildb is this: # untested, but should work if __name__ = '__main__': import sys sys.modules['cs.app.maildb'] = sys.modules[__name__] sys.exit(main(sys.argv)) *** but that's the wrong solution *** The problem here is that by the time cs.app.maildb runs, some other part of cs or cs.app may have already imported it. The trick of setting the module object under both names can only work if you can guarantee to run this before importing anything that does a circular import of cs.app.maildb. The right existing solution is to avoid having the same module do double-duty as both runnable script and importable module. In a package, that's easy. Here's your package structure: cs +-- __init__.py +-- app +-- __init__.py +-- mailbd.py and possibly others. Every module that you want to be a runnable script becomes a submodule with a __main__.py file: cs +-- __init__.py +-- __main__.py +-- app +-- __init__.py +-- __main__.py +-- mailbd +-- __init__.py +-- __mail__.py and now you can call: python -m cs python -m cs.app python -m cs.app.mailbd as needed. The __main__.py files look like this: if __name__ = '__main__': import cs.app.maildb sys.exit(cs.app.maildb.main(sys.argv)) or as appropriate. Yes, it's a bit more work. If your package has 30 modules, and every one is runnable, that's a lot more work. But if your package is that, um, intricate, then perhaps it needs a redesign? The major use-case for this feature is where you have a package, and you want it to have a single entry point when running it as a script. (That would be "python -m cs" in the example above.) But it can be used when you have multiple entry points too. For a single .py file, you can usually assume that when you are running it as a stand alone script, there are no circular imports of itself: # spam.py import eggs if __name__ == '__main__': main() # eggs.py import spam # circular import If that expectation is violated, then you can run into the trouble you already did. So... * you can safely combine importable module and runnable script in the one file, provided the runnable script functionality doesn't depend on importing itself under the original name (either directly or indirectly); * if you must violate that expectation, the safest solution is to make the module a package with a __main__.py file that contains the runnable script portion; * if you don't wish to do that, you're screwed, and I think that the best you can do is program defensively by detecting the problem after the event and bailing out: # untested import __main__ import myactualfilename if os.path.samefile(__main__.__path__, myactualfilename.__path__): raise RuntimeError -- Steven From steve at pearwood.info Sun Aug 2 04:04:53 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 02 Aug 2015 18:04:53 +1000 Subject: GvR Europython keynote described on lwn.net References: <87r3noltu3.fsf@jester.gateway.sonic.net> <106305a9-3ccd-4de4-a918-c27cec2d0b8c@googlegroups.com> <55bc5cfb$0$1643$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55bdcf25$0$1653$c3e8da3$5496439d@news.astraweb.com> On Sun, 2 Aug 2015 04:57 am, Rick Johnson wrote: > On Saturday, August 1, 2015 at 12:45:45 AM UTC-5, Steven D'Aprano wrote: > >> > Yep, even the BDFL is actively developing in 2.7! He's no fool. >> >> Of course not. Dropbox pay him to work on their systems, >> and he wants to keep his job. > > Thanks for confirming my point that Python3 is not worth > developing with for at least the next five years. If Dropbox were using Python 1.5, would you conclude that Python 2 was not worth developing in? I happen to know that at last year's US PyCon there was at least one company still using Python 1.5. If it works for them, and they don't need security updates, why not? But this doesn't mean others should emulate them. As Laura has explained, there is at least one sector of Python users that not only doesn't want new features, but they don't want bug fixes either. They would rather work around bugs themselves, and stability is more important than correctness. If that works for them, great. But it doesn't work for everyone. Just because company X is using 2.7, why does that mean that *you* shouldn't using 3.x? Surely you should make your own decision, based on your own needs. (For the record, Dropbox isn't using Python 2.7. They're using a heavily customized private implementation of Python based on, but not the same as, version 2.7. Whatever benefits they get from using that, I can promise that *you* will not be getting them from the vanilla version of 2.7 available to the public.) >> Are you aware that Dropbox are heavily pushing for static >> type hints in Python 3 as a prerequisite for them porting >> their masses of Python 2 code to Python 3? > > Well then, i hope they are ready to wait at least 10 years > before adopting Python3, because it will take that long to > work out all the kinks! Nonsense. You can already download mypy and start using static type checking in Python today. > Of course, with the cloud service > wars heating up, no one can be sure how long any of them > will survive. Web technology is moving much faster than > Python. > >> That's one of the motives for the masses of effort put >> into PEP 484, and its support PEPs, 482 and 483: > > I do find it flattering that many of my ideas regarding > Python have been implemented: (1) It was me who recommended > "optional type checking" way back around 2008 Don't flatter yourself. People have been suggesting type checking for Python since Python 0.1. > (Heck, you > even agreed that it would be a good idea, but at the time, a > moratorium was preventing new features) (2) The fresher look > of Python.org is a result of my suggestions So you're the one to blame for the horrible new design and the reliance on Javascript to create an overall worse user experience? I'd call the new design a triumph of style over substance, except that the new style is worse than the old one. > (3) The > interactive online console was my idea to compete with the > Ruby equivalent (4) I have pestered tutorial owners to > upgrade their tutorials to py3 compatibility, and many did! > (5) and last but not least, my courage to face down the > trolls has given courage to the shadow lurkers, who now > participate in open discussions on this list, and some have > even moved over to more dangerous grounds like Python-ideas. So you're the one to blame for all the bike-shedding from people who think that copying design principles from PHP is a great idea? Please stop "helping". -- Steven From rosuav at gmail.com Sun Aug 2 04:16:30 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Aug 2015 18:16:30 +1000 Subject: __main__ vs official module name: distinct module instances In-Reply-To: <55bdc996$0$1663$c3e8da3$5496439d@news.astraweb.com> References: <55bdc996$0$1663$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 2, 2015 at 5:41 PM, Steven D'Aprano wrote: > * if you don't wish to do that, you're screwed, and I think that the > best you can do is program defensively by detecting the problem > after the event and bailing out: > > # untested > import __main__ > import myactualfilename > if os.path.samefile(__main__.__path__, myactualfilename.__path__): > raise RuntimeError Not sure what __path__ is here, as most of the things in my sys.modules don't have it; do you mean __file__? In theory, it should be possible to skim across sys.modules, looking for a match against __main__, and raising RuntimeError if any is found. From steve at pearwood.info Sun Aug 2 04:17:42 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 02 Aug 2015 18:17:42 +1000 Subject: Most pythonic way of rotating a circular list to a canonical point References: <9c5dc0c8-0066-4140-9883-f3af14f7b328@googlegroups.com> Message-ID: <55bdd226$0$1674$c3e8da3$5496439d@news.astraweb.com> On Sun, 2 Aug 2015 08:51 am, Lukas Barth wrote: > On Saturday, August 1, 2015 at 11:37:48 PM UTC+2, Emile van Sebille wrote: >> Well, it looks to me that I don't know what a 'canonical rotation' is -- > > That's because it is not defined. ;) > > I need a way to rotate one of these lists in a way so that it will produce > the same output every time, regardless of what the input rotation was. I'm not convinced that you necessarily do, but for the sake of the argument suppose you do... > Example: > > [0,1,2,3,4] => [0,1,2,3,4] > [2,3,4,0,1] => [0,1,2,3,4] > [3,4,0,1,2] => [0,1,2,3,4] > ... How is this different from sorted(the_list)? Ah, wait, I've just answered my own question... [0,1,2,4,3] != [0,1,2,3,4] > It doesn't have to be "[0,1,2,3,4]", it can just as well be [2,3,4,1,0], > as long as it's always the same. Keep a cache, and intern the first seen version of the list in the cache. CACHE = {} def intern(alist): t = MyTuple(alist) if t not in CACHE: CACHE[t] = alist return CACHE[t] # Untested class MyTuple(tuple): def __eq__(self, other): if self is other: return True if not isinstance(other, MyTuple): return NotImplemented if len(self) != len(other): return False d = self+self return other in d def __hash__(self): return hash(frozenset(self)) -- Steven From rosuav at gmail.com Sun Aug 2 04:18:36 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Aug 2015 18:18:36 +1000 Subject: __main__ vs official module name: distinct module instances In-Reply-To: References: <55bdc996$0$1663$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 2, 2015 at 6:16 PM, Chris Angelico wrote: > On Sun, Aug 2, 2015 at 5:41 PM, Steven D'Aprano wrote: >> * if you don't wish to do that, you're screwed, and I think that the >> best you can do is program defensively by detecting the problem >> after the event and bailing out: >> >> # untested >> import __main__ >> import myactualfilename >> if os.path.samefile(__main__.__path__, myactualfilename.__path__): >> raise RuntimeError > > Not sure what __path__ is here, as most of the things in my > sys.modules don't have it; do you mean __file__? In theory, it should > be possible to skim across sys.modules, looking for a match against > __main__, and raising RuntimeError if any is found. Oops, premature send. *In theory* it should be possible to do the above, but whichever attribute you look for, some modules may not have it. How does this play with, for instance, zipimport, where there's no actual file name for the module? ChrisA From Cecil at decebal.nl Sun Aug 2 06:11:28 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sun, 02 Aug 2015 12:11:28 +0200 Subject: Most Pythonic way to store (small) configuration Message-ID: <87k2teq9tb.fsf@Equus.decebal.nl> There are a lot of ways to store configuration information: - conf file - xml file - database - json file - and possible a lot of other ways I want to write a Python program to display cleaned log files. I do not think I need a lot of configuration to be stored: - some things relating to the GUI - default behaviour - default directory - log files to display, including some info - At least until where it was displayed Because of this I think a human readable file would be best. Personally I do not find XML very readable. So a conf or json file looks the most promising to me. And I would have a slight preference for a json file. Any comments, thoughts or tips? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From rosuav at gmail.com Sun Aug 2 06:49:08 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Aug 2015 20:49:08 +1000 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <87k2teq9tb.fsf@Equus.decebal.nl> References: <87k2teq9tb.fsf@Equus.decebal.nl> Message-ID: On Sun, Aug 2, 2015 at 8:11 PM, Cecil Westerhof wrote: > Because of this I think a human readable file would be best. > Personally I do not find XML very readable. So a conf or json file > looks the most promising to me. And I would have a slight preference > for a json file. > > Any comments, thoughts or tips? I'd agree with your analysis. XML is not readable; the two best options would be JSON, if you need the potential for deep structure, or the simple config file ("INI file") if you don't. ChrisA From pavlovevidence at gmail.com Sun Aug 2 06:51:09 2015 From: pavlovevidence at gmail.com (pavlovevidence at gmail.com) Date: Sun, 2 Aug 2015 03:51:09 -0700 (PDT) Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: Message-ID: <7c6c6764-2b84-4c94-8a79-ed0408f00021@googlegroups.com> On Saturday, August 1, 2015 at 1:34:44 PM UTC-7, Lukas Barth wrote: > Hi! > > I have a list of numbers that I treat as "circular", i.e. [1,2,3] and [2,3,1] should be the same. Now I want to rotate these to a well defined status, so that I can can compare them. > > If all elements are unique, the solution is easy: find the minimum element, find its index, then use mylist[:index] + mylist[index:], i.e. the minimum element will always be at the beginning. > > But say I have [0,1,0,2,0,3]. I can in fact guarantee that no *pair* will appear twice in that list, i.e. I could search for the minimum, if that is unique go on as above, otherwise find *all* positions of the minimum, see which is followed by the smallest element, and then rotate that position to the front. > > Now that seems an awful lot of code for a (seemingly?) simple problem. Is there a nice, pythonic way to do this? > > Thanks for enlightening me! [[[Warning: all code untested, sorry!]]] The general problem (no assumptions about the items in the list except that they're all sortable together) is interesting. It doesn't seem like a simple one to me at all. An acceptable criterion would be if you took the lexically smallest value of every rotation of the list; that would yield the same result for every initial rotation. You can do it in like this: anchor = min(range(len(X)),key=lambda i:X[i:]+X[:i]) canonical_X = X[anchor:]+X[:anchor] I doubt this would be that efficient, though, since it happens to construct every single rotation in the process of scanning. However, you'll notice that the minimum lexical value can only occur when the starting point is the minimum value in the list, so you can almost certainly improve performace to find all the minimum values and only test those rotations, especially if the number of minima is small compared to the list size. (However, be sure to timeit for actual evidence rather than my guessing.) min_value = min(X) i = X.index(min_value) while True: start_points.append(i) try: i = X.index(min_value,i+1) except ValueError: break anchor = min(start_points,key=lambda i:X[i:]+X[:i]) canonical_X = X[anchor:]+X[:anchor] Your lists aren't arbitrary, however and they actually seem to be ordered pairs (in which case the first question I have is why not have it be a list of 2-tuples? but I can imagine a few reasons). You say the pairs are known to be unique, so all you have to do is find the index of the minimum pair. One can use zip and slicing to generate 2-tuples from the flat list, whence you can find the minimum. pairs = list(zip(X[0::2],X[1::2])) min_pair = min(pairs) anchor = 2 * pairs.index(min_pair) canonical_X = X[anchor:]+X[:anchor] Carl Banks From ben+python at benfinney.id.au Sun Aug 2 07:54:59 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 02 Aug 2015 21:54:59 +1000 Subject: Most Pythonic way to store (small) configuration References: <87k2teq9tb.fsf@Equus.decebal.nl> Message-ID: <85k2tdlxbg.fsf@benfinney.id.au> Cecil Westerhof writes: > Because of this I think a human readable file would be best. I agree with that criterion; in the absence of compelling reasons otherwise, human-readable and -editable text is a good default. > Personally I do not find XML very readable. So a conf or json file > looks the most promising to me. And I would have a slight preference > for a json file. XML and JSON should both be considered data serialisation formats only. JSON is human-readable to an extent, but it is quite brittle, and there are no comments permitted in the syntax. So, both XML and JSON should be considered write-only, and produced only for consumption by a computer; they are a poor choice for presenting to a human. The ?INI? format as handled by the Python ?configparser? module is what I would recommend for a simple flat configuration file. It is more intuitive to edit, and has a conventional commenting format. If it were more complex I might recommend YAML, which is a very widespread, flexible hierarchical format, that still allows fairly natural editing and commenting. Its main downside (as opposed to INI format) is that the Python standard library does not support it. -- \ ?Simplicity and elegance are unpopular because they require | `\ hard work and discipline to achieve and education to be | _o__) appreciated.? ?Edsger W. Dijkstra | Ben Finney From breamoreboy at yahoo.co.uk Sun Aug 2 11:12:13 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 2 Aug 2015 16:12:13 +0100 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <85k2tdlxbg.fsf@benfinney.id.au> References: <87k2teq9tb.fsf@Equus.decebal.nl> <85k2tdlxbg.fsf@benfinney.id.au> Message-ID: On 02/08/2015 12:54, Ben Finney wrote: > Cecil Westerhof writes: > >> Because of this I think a human readable file would be best. > > The ?INI? format as handled by the Python ?configparser? module is what > I would recommend for a simple flat configuration file. It is more > intuitive to edit, and has a conventional commenting format. +1 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From Cecil at decebal.nl Sun Aug 2 12:51:00 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sun, 02 Aug 2015 18:51:00 +0200 Subject: Most Pythonic way to store (small) configuration References: <87k2teq9tb.fsf@Equus.decebal.nl> Message-ID: <87fv41r5vv.fsf@Equus.decebal.nl> On Sunday 2 Aug 2015 13:54 CEST, Ben Finney wrote: > Cecil Westerhof writes: > >> Because of this I think a human readable file would be best. > > I agree with that criterion; in the absence of compelling reasons > otherwise, human-readable and -editable text is a good default. > >> Personally I do not find XML very readable. So a conf or json file >> looks the most promising to me. And I would have a slight >> preference for a json file. > > XML and JSON should both be considered data serialisation formats > only. > > JSON is human-readable to an extent, but it is quite brittle, and > there are no comments permitted in the syntax. > > So, both XML and JSON should be considered write-only, and produced > only for consumption by a computer; they are a poor choice for > presenting to a human. > > The ?INI? format as handled by the Python ?configparser? module is > what I would recommend for a simple flat configuration file. It is > more intuitive to edit, and has a conventional commenting format. Well, I would use nested data. (A file will have extra fields besides the name.) That is why I was thinking about json. But I will look into it. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From python.list at tim.thechases.com Sun Aug 2 14:19:16 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 2 Aug 2015 13:19:16 -0500 Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: Message-ID: <20150802131916.0ca36a5b@bigbox.christie.dr> On 2015-08-01 13:34, Lukas Barth wrote: > I have a list of numbers that I treat as "circular", i.e. [1,2,3] > and [2,3,1] should be the same. Now I want to rotate these to a > well defined status, so that I can can compare them. > > If all elements are unique, the solution is easy: find the minimum > element, find its index, then use mylist[:index] + mylist[index:], > i.e. the minimum element will always be at the beginning. > > But say I have [0,1,0,2,0,3]. I can in fact guarantee that no > *pair* will appear twice in that list, i.e. I could search for the > minimum, if that is unique go on as above, otherwise find *all* > positions of the minimum, see which is followed by the smallest > element, and then rotate that position to the front. Well, you can pull the minimum (or maximum) of all the rotations to get the "canonical" version: def canonical(lst): """return the "canonical" representation of a list""" return min( lst if i == 0 else (lst[i:] + lst[:i]) for i in range(len(lst)) ) which you can determine, then hash once, and store. It's not a cheap operation, but once you've determined the canonical/hash version, then equality-testing becomes an O(1) test if comparing hashes, or O(N) if comparing lists rather than an O(N*2) brute-force test (which could be lower depending on the commonality). def circular_compare1(a, b): if a == b: return True return any(a == (b[i:] + b[:i]) for i in range(1, len(b))) def circular_compare2(a, b): lena = len(a) if lena != len(b): return False return any( all(a[i] == b[(i + offset) % lena] for i in range(lena)) for offset in range(lena) ) for fn in (circular_compare1, circular_compare2): for (a, b), expected in ( (([1,2,3], [1,2,3]), True), # the same (([1,2,3], [3,1,2]), True), # simple rotation (([1,2,3], [1,2,3,4]), False), # mismatched lengths (([0,1,0,2,0,3], [0,2,0,3,0,1]), True), # repeated elements, simple rotation ): result = bool(fn(a, b)) if result == expected: print "PASS %s %r/%r=%s, not %s" % ( fn.__name__, a, b, result, expected ) else: print "FAIL %s %r/%r=%s, not %s" % ( fn.__name__, a, b, result, expected ) ca = canonical(a) cb = canonical(b) print " Canonical A:", ca print " Canonical B:", cb print " Equal:", (ca == cb) -tim From orgnut at yahoo.com Sun Aug 2 16:01:40 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Sun, 02 Aug 2015 13:01:40 -0700 Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: Message-ID: On 08/01/2015 01:34 PM, Lukas Barth wrote: > Hi! > > I have a list of numbers that I treat as "circular", i.e. [1,2,3] and [2,3,1] should be the same. Now I want to rotate these to a well defined status, so that I can can compare them. > > If all elements are unique, the solution is easy: find the minimum element, find its index, then use mylist[:index] + mylist[index:], i.e. the minimum element will always be at the beginning. > > But say I have [0,1,0,2,0,3]. I can in fact guarantee that no *pair* will appear twice in that list, i.e. I could search for the minimum, if that is unique go on as above, otherwise find *all* positions of the minimum, see which is followed by the smallest element, and then rotate that position to the front. > > Now that seems an awful lot of code for a (seemingly?) simple problem. Is there a nice, pythonic way to do this? > > Thanks for enlightening me! > > Lukas > Let me try to re-state what I see is your actual problem. (Of course I could be wrong...) ;-) Most of the answers you have been getting concentrate on comparisons and hashes, but those are irrelevant to your need -- they come later. What you are trying to do is to uniquely and independently determine the "starting point" for the rotation. That is, which element will be rotated to index 0. Using the minimum is possible, but that fails if that minimum appears more than once in the list -- it does not give a unique solution. For a specific example... if you are given any _one_ of these lists: [1, 5, 0, 3, 0], [5, 0, 3, 0, 1], [0, 3, 0, 1, 5], [3, 0, 1, 5, 0], [0, 1, 5, 0, 3] it can be _independently_ rotated to (for example) [3, 0, 1, 5, 0] That example does not use the minimum as the starting point, but how the starting point can be absolutely and uniquely determined is your fundamental problem. I do not have an answer for that. But I thought this might be a clearer description of what I think you are really looking for. I hope I'm right. ;-) Good luck. -=- Larry -=- From lele at metapensiero.it Sun Aug 2 16:02:00 2015 From: lele at metapensiero.it (Lele Gaifax) Date: Sun, 02 Aug 2015 22:02:00 +0200 Subject: Most Pythonic way to store (small) configuration References: <87k2teq9tb.fsf@Equus.decebal.nl> <87fv41r5vv.fsf@Equus.decebal.nl> Message-ID: <873801xxvr.fsf@nautilus.nautilus> Cecil Westerhof writes: > Well, I would use nested data. (A file will have extra fields besides > the name.) That is why I was thinking about json. But I will look into > it. An alternative, very similar to JSON but with some good cherries picked from YAML is AXON, which is my preferite these days for this kind of things. http://intellimath.bitbucket.org/axon/ ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From liik.joonas at gmail.com Sun Aug 2 16:58:34 2015 From: liik.joonas at gmail.com (Joonas Liik) Date: Sun, 2 Aug 2015 23:58:34 +0300 Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: Message-ID: I have this feeling that you would get a lot more useful anwsers if you were to describe your actual problem in stead of what you think the solution is. There might be other, better solutions but since we know so little about what you are doing we will likely never find them by just guessing.. From python.list at tim.thechases.com Sun Aug 2 17:11:14 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 2 Aug 2015 16:11:14 -0500 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <85k2tdlxbg.fsf@benfinney.id.au> References: <87k2teq9tb.fsf@Equus.decebal.nl> <85k2tdlxbg.fsf@benfinney.id.au> Message-ID: <20150802161114.3d231178@bigbox.christie.dr> On 2015-08-02 21:54, Ben Finney wrote: > So, both XML and JSON should be considered write-only, and produced > only for consumption by a computer; they are a poor choice for > presenting to a human. > > The ?INI? format as handled by the Python ?configparser? module is > what I would recommend for a simple flat configuration file. It is > more intuitive to edit, and has a conventional commenting format. I second Ben's thoughts against XML & JSON -- they *can* be edited by hand, but put the onus on the user to make perfect XML/JSON. Config files (".ini") are more forgiving. However, the .ini format (or at least the stdlib implementation in ConfigParser.py) is not without its faults, mostly when you read a file, then write it back out: - comments and blank lines get lost in the process: [section] # set to local configuration location=path/to/foo will get written out as [section] location=path/to/foo - the order of options is not preserved: [section] thing=1 other=2 may get written back out as [section] other=2 thing=1 though this has improved once ConfigParser started attempting to use an OrderedDict by default for internal storage. - a single key can only appear once in a section: [section] option=one option=two gets written back out as [section] option=two - implicit encoding (is it UTF-8, Latin-1, etc?) When you understand that the underlying internal storage is a dict (ordered or unordered, depending on availability), a lot of the above makes sense. But it still makes me wish for the power of git's config-file format that seems to preserve original config files much better. An additional option is using a sqlite database. The sqlite library is part of the stdlib, and advantages include being a single file, expandability, consistent/reliable character encoding, cross-platform portability, and atomicity (utilities that read/write are blocked from getting/creating incomplete data seen by the other file). -tkc From rantingrickjohnson at gmail.com Sun Aug 2 18:34:54 2015 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 2 Aug 2015 15:34:54 -0700 (PDT) Subject: GvR Europython keynote described on lwn.net In-Reply-To: <55bdcf25$0$1653$c3e8da3$5496439d@news.astraweb.com> References: <87r3noltu3.fsf@jester.gateway.sonic.net> <106305a9-3ccd-4de4-a918-c27cec2d0b8c@googlegroups.com> <55bc5cfb$0$1643$c3e8da3$5496439d@news.astraweb.com> <55bdcf25$0$1653$c3e8da3$5496439d@news.astraweb.com> Message-ID: <917477df-5cda-4fab-bbb3-eb464bfa452e@googlegroups.com> On Sunday, August 2, 2015 at 3:05:09 AM UTC-5, Steven D'Aprano wrote: > If Dropbox were using Python 1.5, would you conclude that > Python 2 was not worth developing in? No, if Dropbox were using py1.5, i would conclude that it was being managed by monkeys -- since Py1.5 existed before Dropbox was even founded (in 2007). > I happen to know that at last year's US PyCon there was at > least one company still using Python 1.5. If it works for > them, and they don't need security updates, why not? But > this doesn't mean others should emulate them. Same answer, if they were using py1.5 "when it was hot", and it still works for them today, why bother with backwards incompatibility. They can hack 1.5 if they need to, it's open source after all! > As Laura has explained, there is at least one sector of > Python users that not only doesn't want new features, but > they don't want bug fixes either. They would rather work > around bugs themselves, and stability is more important > than correctness. If that works for them, great. But it > doesn't work for everyone. Does the word "reiterate" mean anything to you? > Just because company X is using 2.7, why does that mean > that *you* shouldn't using 3.x? Surely you should make > your own decision, based on your own needs. It's not just *ANY* company Steven, it's Guido's freaking employer! That would imply that even GvR himself is not motivated enough by 3000 to fight for it's adoption. More evidence that py3000 is not ready for mass consumption. > (For the record, Dropbox isn't using Python 2.7. They're > using a heavily customized private implementation of > Python based on, but not the same as, version 2.7. > Whatever benefits they get from using that, I can promise > that *you* will not be getting them from the vanilla > version of 2.7 available to the public.) So what? If i had to guess, i would guess that the hacks are mostly to bring py3000 features to 2.7 without suffering the ill effects that the py3000 recipe of: "excessive backwards incompatibility spicing" has had on the consumption of py3000. We don't like your spicy sauce, Swedish Chef! https://www.youtube.com/watch?v=SGZPlvbhMIg And if you folks think it burns at runtime, just wait until the exceptions are ejected! From cs at zip.com.au Sun Aug 2 18:49:30 2015 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 3 Aug 2015 08:49:30 +1000 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <87fv41r5vv.fsf@Equus.decebal.nl> References: <87fv41r5vv.fsf@Equus.decebal.nl> Message-ID: <20150802224930.GA21205@cskk.homeip.net> On 02Aug2015 18:51, Cecil Westerhof wrote: >On Sunday 2 Aug 2015 13:54 CEST, Ben Finney wrote: >> Cecil Westerhof writes: >>> Because of this I think a human readable file would be best. >> >> I agree with that criterion; in the absence of compelling reasons >> otherwise, human-readable and -editable text is a good default. [...] >> The ?INI? format as handled by the Python ?configparser? module is >> what I would recommend for a simple flat configuration file. It is >> more intuitive to edit, and has a conventional commenting format. > >Well, I would use nested data. (A file will have extra fields besides >the name.) That is why I was thinking about json. But I will look into >it. Like others, I also recommend an INI file. You can always move to something more complex (and harder to edit) if it doesn't work out. Note that "nested data" does not rule out an INI file unless you mean "recursive" data or quite a deep nesting of structure. Shallow structure (one or two levels) is very easy to embed in the INI format. Eg: [main] this = that size = 10 directory = /path/to/default/dir [gui] foreground = green style = baroque [*.log] stuff about log files... [/path/to/file1] title = something param1 = 5 param2 = 6 fields = column2, column7 [column2:/path/to/file1] format = numeric scale = logarithmic [column7:/path/to/file1] format = roman scale = linear See that by being a little tricky about the section names you can incorporate a fair degree of structure? I would not advocating going too fair down that rabbit hole, but for basic stuff it works well. And of course you can put structure within a section: [foo] complexity = {'blah': 'blah blah', 'frib': {'frob': 1, 'frab': 2}} format_width = 10 format_style = right-justified format_dialect = quoted i.e. you could put (small) JSON snippet in some fields, or present a few parameters to describe "format". There are several ways to do this kind of thing before reaching for more complex syntaxes. Just don't let it get too weird - that would probably be a sign you do want to reach for JSON or YAML. But start with INI. Simple and easy. Cheers, Cameron Simpson A squealing tire is a happy tire. - Bruce MacInnes, Skip Barber Driving School instructor From rosuav at gmail.com Sun Aug 2 19:25:19 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Aug 2015 09:25:19 +1000 Subject: GvR Europython keynote described on lwn.net In-Reply-To: <917477df-5cda-4fab-bbb3-eb464bfa452e@googlegroups.com> References: <87r3noltu3.fsf@jester.gateway.sonic.net> <106305a9-3ccd-4de4-a918-c27cec2d0b8c@googlegroups.com> <55bc5cfb$0$1643$c3e8da3$5496439d@news.astraweb.com> <55bdcf25$0$1653$c3e8da3$5496439d@news.astraweb.com> <917477df-5cda-4fab-bbb3-eb464bfa452e@googlegroups.com> Message-ID: On Mon, Aug 3, 2015 at 8:34 AM, Rick Johnson wrote: > On Sunday, August 2, 2015 at 3:05:09 AM UTC-5, Steven D'Aprano wrote: > >> If Dropbox were using Python 1.5, would you conclude that >> Python 2 was not worth developing in? > > No, if Dropbox were using py1.5, i would conclude that it was > being managed by monkeys -- since Py1.5 existed before > Dropbox was even founded (in 2007). I have a git repository on my hard disk with commits dating back to August 1995. That's clearly being managed by monkeys, because git repositories can't exist before git was founded (2005), right? Well, actually, this particular repo was started in CVS, then imported from there into SVN, and thence into git more recently. Suppose Dropbox (the company) inherited a codebase from an older company, which itself inherited it from someone else - maybe they could be all set up with a codebase that pre-existed them by a decade. >> Just because company X is using 2.7, why does that mean >> that *you* shouldn't using 3.x? Surely you should make >> your own decision, based on your own needs. > > It's not just *ANY* company Steven, it's Guido's freaking > employer! That would imply that even GvR himself is not > motivated enough by 3000 to fight for it's adoption. More > evidence that py3000 is not ready for mass consumption. Wind the clock back to 2012, when Guido was working for Google. Dropbox wants him. Is he going to refuse the job unless they *first* get onto Py3, or is he going to accept the job with a view to migrating them? The only form of "fight[ing] for it[']s adoption" that you seem to be advocating here is an rms-style "if it isn't what I believe in, let it sink like the Titanic". That's not the only way to encourage something. ChrisA From rantingrickjohnson at gmail.com Sun Aug 2 20:14:53 2015 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 2 Aug 2015 17:14:53 -0700 (PDT) Subject: GvR Europython keynote described on lwn.net In-Reply-To: References: <87r3noltu3.fsf@jester.gateway.sonic.net> <106305a9-3ccd-4de4-a918-c27cec2d0b8c@googlegroups.com> <55bc5cfb$0$1643$c3e8da3$5496439d@news.astraweb.com> <55bdcf25$0$1653$c3e8da3$5496439d@news.astraweb.com> <917477df-5cda-4fab-bbb3-eb464bfa452e@googlegroups.com> Message-ID: On Sunday, August 2, 2015 at 6:25:37 PM UTC-5, Chris Angelico wrote: > Wind the clock back to 2012, when Guido was working for Google. > Dropbox wants him. Is he going to refuse the job unless they *first* > get onto Py3, or is he going to accept the job with a view to > migrating them? Well, i don't know the specifics of why he departed from a global and mature company for a small (although promising) startup, but i do know that there is always the possibility that Google will sweep in and consume Dropbox if it becomes a threat or shows *real* potential. So there is always the possibility that he could be working at Google again; albeit in a "field office". Don't play coy Chris, you know damn good and well how this game is played, and you know that the founders of any startup dream of a buyout so they can sail off into the proverbial sunset. GvR is a pawn in a greater game. But we are all pawns in one form or another; are we not? He is but a small part of an industrious and creative young enterprise that will quickly become consumed by one of the powerful corporations, and for no other reason than to smother its competition in the cradle! Large corporations are where innovations go to die. Where spontaneity is slowly tortured to death inside the confining walls of a cubicle, and magnificent intellectual achievements are converted into cheap, plastic, soulless, *TRINKETS* that are purposefully designed for early failure in order to achieve maximum profitability! From breamoreboy at yahoo.co.uk Sun Aug 2 20:25:08 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 3 Aug 2015 01:25:08 +0100 Subject: Python 3 May Become Relevant Now Message-ID: rr should have a field day with this one http://nafiulis.me/python-3-may-become-relevant-now.html -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From cs at zip.com.au Sun Aug 2 20:57:44 2015 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 3 Aug 2015 10:57:44 +1000 Subject: __main__ vs official module name: distinct module instances In-Reply-To: <55bdc996$0$1663$c3e8da3$5496439d@news.astraweb.com> References: <55bdc996$0$1663$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20150803005744.GA14231@cskk.homeip.net> On 02Aug2015 17:41, Steven D'Aprano wrote: >On Sun, 2 Aug 2015 01:53 pm, Cameron Simpson wrote: >> Maybe this should be over in python-ideas, since there is a proposal down >> the bottom of this message. But first the background... >> >> I've just wasted a silly amount of time debugging an issue that really I >> know about, but had forgotten. > >:-) > > >> I have a number of modules which include a main() function, and down the >> bottom this code: >> >> if __name__ == '__main__': >> sys.exit(main(sys.argv)) >> >> so that I have a convenient command line tool if I invoke the module >> directly. I typically have tiny shell wrappers like this: >> >> #!/bin/sh >> exec python -m cs.app.maildb -- ${1+"$@"} TL;DR: pertinent discussion around my proposal is lower down. First I digress into Steven's shell query. >I know this isn't really relevant to your problem, but why use "exec python" >instead of just "python"? Saves a process. Who needs a shell process just hanging around waiting? Think of this as tail recursion optimisation. >And can you explain the -- ${1+"$@"} bit for somebody who knows just enough >sh to know that it looks useful but not enough to know exactly what it >does? Ah. In a modern shell one can just write $@. I prefer portable code. The more complicated version, which I use everywhere because it is portable, has to do with the behaviour of the $@ special variable. As you know, $* is the command line arguments as a single string, which is useless if you need to preserve them intact. "$@" is the command line arguments correctly quoted. Unlike every other "$foo" variable, which produces a single string, "$@" produces all the command line arguments as separate strings. Critical for passing them correctly to other commands. HOWEVER, if there are no arguments then "$@" produces a single empty string. Not desired. It is either a very old bug or a deliberate decision that no "$foo" shall utterly vanish. Thus this: ${1+"$@"} Consulting your nearest "man sh" in the PARAMETER SUBSTITUION section you will see that this only inserts "$@" if there is at least one argument, avoiding the "$@" => "" with no arguments. It does this by only inserting "$@" if $1 is defined. Sneaky and reliable. I believe in a modern shell a _bare_ $@ acts like a correctly behaving "$@" should have, but I always use the incantation above for portability. >> In short, invoke this module as a main program, passing in the command >> line arguments. Very useful. >> >> My problem? >> >> When invoked this way, the module cs.app.maildb that is being executed is >> actually the module named "__main__". > >Yep. Now, what you could do in cs.app.maildb is this: > ># untested, but should work >if __name__ = '__main__': > import sys > sys.modules['cs.app.maildb'] = sys.modules[__name__] > sys.exit(main(sys.argv)) Yes, but that is ghastly and complicated. And also relies on the boiler plate at the bottom knowing the module name. >*** but that's the wrong solution *** It is suboptimal. "Wrong" seems a stretch. >The problem here is that by the time cs.app.maildb runs, some other part of >cs or cs.app may have already imported it. The trick of setting the module >object under both names can only work if you can guarantee to run this >before importing anything that does a circular import of cs.app.maildb. That can be done if it takes place in the python interpreter. But there are side effects which need to be considered. My initial objective is that: python -m cs.app.maildb should import cs.app.maildb under the supplied name instead of "__main__" so that a recursive import did not instantiate a second module instance. That is, I think, a natural thing for users to expect from the above command line: "import cs.app.maildb, run its main program". On further thought last night I devised the logic below to implement python's "-m" option: # pseudocode, with values hardwired for clarity import sys M = new_empty_module(name='__main__', qualname='cs.app.maildb') sys.modules['cs.app.maildb'] = M M.execfile('/path/to/cs/app/maildb.py') # you know what I mean... The "qualname" above is an idea I thought of last night to allow introspection to cope with '__main__' and 'cs.app.maildb' at the same time, somewhat like the .__qualname__ attribute of a function as recently added to the language; under this scheme a module would get a __name__ and a __qualname__, normally the same, but __name__ set to '__main__' for the "main program module situation. This should sidestep any issues with recursive imports by having the module in place in sys.modules ahead of the running of its code. >The right existing solution is to avoid having the same module do >double-duty as both runnable script and importable module. I disagree. Supporting this double duty is, to me, a highly desirable feature. This is, in fact, a primary purpose of the present standard boilerplate. I _like_ that: a single file, short and succinct. >In a package, >that's easy. Here's your package structure: > >cs >+-- __init__.py >+-- app > +-- __init__.py > +-- mailbd.py > >and possibly others. Every module that you want to be a runnable script >becomes a submodule with a __main__.py file: > >cs >+-- __init__.py >+-- __main__.py >+-- app > +-- __init__.py > +-- __main__.py [...] Yes, nicely separated, but massive structural overkill for simple things like single file modules. >and now you can call: > >python -m cs >python -m cs.app >python -m cs.app.mailbd > >as needed. The __main__.py files look like this: > >if __name__ = '__main__': > import cs.app.maildb > sys.exit(cs.app.maildb.main(sys.argv)) > >or as appropriate. > >Yes, it's a bit more work. If your package has 30 modules, and every one is >runnable, that's a lot more work. But if your package is that, um, >intricate, then perhaps it needs a redesign? [hg/css]fleet*> grep '__name__ == .__main__' cs/**/*.py|wc -l 96 No, it is simply my personal kit. The design is ok for what it is. Pieces of it are slowly being published on PyPI as they become publishable (beta or better quality, proper distinfo metadata applied, checked to not import unpublished modules, not import gratuitous tissue paper modules, free of most debugging or off topic cruft, etc). To be honest, the majority of those __main__ calls actually run the unit tests for that module, not a proper "main program". A better grep: [hg/css-nodedb]fleet*> grep 'main(sys.argv)' cs/**/*.py|wc -l 14 says just 14. Far saner; those are modules/packages for which there really is an associated command line tool. >The major use-case for this feature is where you have a package, and you >want it to have a single entry point when running it as a script. (That >would be "python -m cs" in the example above.) But it can be used when you >have multiple entry points too. > >For a single .py file, you can usually assume that when you are running it >as a stand alone script, there are no circular imports of itself: > ># spam.py >import eggs >if __name__ == '__main__': > main() > ># eggs.py >import spam # circular import > >If that expectation is violated, then you can run into the trouble you >already did. As described, that expectation was violated. In the normal course of affairs one rarely trips over it. >So... >* you can safely combine importable module and runnable script in > the one file, provided the runnable script functionality doesn't > depend on importing itself under the original name (either > directly or indirectly); > >* if you must violate that expectation, the safest solution is to > make the module a package with a __main__.py file that contains > the runnable script portion; My proposal above is to solve this issue without requiring the breaking of a module into a multifile package just to address a counterintuitive edge case, and to avoid cognitive dissonance for Python users when they do traverse that edge case. I want "python -m foo" to accomplish more closely what the naive user expects. >* if you don't wish to do that, you're screwed, and I think that the > best you can do is program defensively by detecting the problem > after the event and bailing out: > > # untested > import __main__ > import myactualfilename > if os.path.samefile(__main__.__path__, myactualfilename.__path__): > raise RuntimeError Nasty and defeatist! I rail against this mode of thought! :-) Anyway, I'm about to raise my proposed implementation change higher up over on python-ideas with a plan to write a PEP if I don't get fundamental objections (i.e. "this breaks everything" versus your "you can work around it in these [cumbersome] ways"). Cheers, Cameron Simpson "My manner of thinking, so you say, cannot be approved. Do you suppose I care? A poor fool indeed is he who adopts a manner of thinking for others! My manner of thinking stems straight from my considered reflections; it holds with my existence, with the way I am made. It is not in my power to alter it; and were it, I'd not do so." Donatien Alphonse Francois de Sade From cs at zip.com.au Sun Aug 2 20:59:41 2015 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 3 Aug 2015 10:59:41 +1000 Subject: __main__ vs official module name: distinct module instances In-Reply-To: References: Message-ID: <20150803005941.GA13527@cskk.homeip.net> On 02Aug2015 18:18, Chris Angelico wrote: >On Sun, Aug 2, 2015 at 6:16 PM, Chris Angelico wrote: >> On Sun, Aug 2, 2015 at 5:41 PM, Steven D'Aprano wrote: >>> * if you don't wish to do that, you're screwed, and I think that the >>> best you can do is program defensively by detecting the problem >>> after the event and bailing out: >>> >>> # untested >>> import __main__ >>> import myactualfilename >>> if os.path.samefile(__main__.__path__, myactualfilename.__path__): >>> raise RuntimeError >> >> Not sure what __path__ is here, as most of the things in my >> sys.modules don't have it; do you mean __file__? In theory, it should >> be possible to skim across sys.modules, looking for a match against >> __main__, and raising RuntimeError if any is found. > >Oops, premature send. > >*In theory* it should be possible to do the above, but whichever >attribute you look for, some modules may not have it. How does this >play with, for instance, zipimport, where there's no actual file name >for the module? To my eyes, badly, which IMO strengthens my case for addressing the situation in the interpreter instead of requiring increasingly complex gyrations on the part of every programmer on the planet:-) Cheers, Cameron Simpson The CBR and ZXR should come with a warning sticker that says 'You are not Mick Doohan, do NOT be a prat' - UK's _BIKE_ magazine From ben+python at benfinney.id.au Sun Aug 2 21:16:09 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 03 Aug 2015 11:16:09 +1000 Subject: Most Pythonic way to store (small) configuration References: <87k2teq9tb.fsf@Equus.decebal.nl> <87fv41r5vv.fsf@Equus.decebal.nl> Message-ID: <85bnepkw86.fsf@benfinney.id.au> Cecil Westerhof writes: > On Sunday 2 Aug 2015 13:54 CEST, Ben Finney wrote: > > > So, both XML and JSON should be considered write-only, and produced > > only for consumption by a computer; they are a poor choice for > > presenting to a human. > > Well, I would use nested data. (A file will have extra fields besides > the name.) In that case, your needs are more complex than ?store some simple configuration?. You need a human-editable format (so, not JSON and not XML) which handles structured data well, and is widely implemented. For nested configuration data, you would be better served by YAML , and the PyYAML library is the one to use. -- \ ?????????????? | `\ (To study and not think is a waste. To think and not study | _o__) is dangerous.) ???? Confucius (551 BCE ? 479 BCE) | Ben Finney From steve at pearwood.info Sun Aug 2 21:27:27 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 03 Aug 2015 11:27:27 +1000 Subject: GvR Europython keynote described on lwn.net References: <87r3noltu3.fsf@jester.gateway.sonic.net> <106305a9-3ccd-4de4-a918-c27cec2d0b8c@googlegroups.com> <55bc5cfb$0$1643$c3e8da3$5496439d@news.astraweb.com> <55bdcf25$0$1653$c3e8da3$5496439d@news.astraweb.com> <917477df-5cda-4fab-bbb3-eb464bfa452e@googlegroups.com> Message-ID: <55bec37f$0$1646$c3e8da3$5496439d@news.astraweb.com> On Mon, 3 Aug 2015 08:34 am, Rick Johnson wrote: >> Just because company X is using 2.7, why does that mean >> that *you* shouldn't using 3.x? Surely you should make >> your own decision, based on your own needs. > > It's not just *ANY* company Steven, it's Guido's freaking > employer! That would imply that even GvR himself is not > motivated enough by 3000 to fight for it's adoption. More > evidence that py3000 is not ready for mass consumption. No, it's evidence that *Dropbox* is not ready for Python 3.x. It tells you ABSOLUTELY NOTHING about the suitability of Python 3.x for other companies and other users. Despite your earlier snarky comment about "reiterate", it is clear that you still don't get it, so I'll say it again. There is nothing wrong with individuals or companies choosing to stay with Python 2.7, or 2.6, or 2.5, or 1.5, if it meets their needs. GvR doesn't need to "fight" for Python 3's adoption. He works for a company where, *right now*, a customised version of 2.7 meets their needs. That doesn't mean that other companies aren't ready for 3.x, and it doesn't mean that Dropbox aren't preparing for 3.x. They are. You might think that they could just turn around tomorrow and say, "Right, as of tomorrow we're using Python 3 for new projects", but that's not how it works when you're a company running Python on hundreds, maybe thousands of production servers, all of which will need to have Python replaced *while running live* before the change over. >> (For the record, Dropbox isn't using Python 2.7. They're >> using a heavily customized private implementation of >> Python based on, but not the same as, version 2.7. >> Whatever benefits they get from using that, I can promise >> that *you* will not be getting them from the vanilla >> version of 2.7 available to the public.) > > So what? If i had to guess, i would guess that the hacks are > mostly to bring py3000 features to 2.7 These would be the features of Python 3 that nobody needs and nobody wants because Python 2 is good enough for everyone? I wouldn't want to guess what the customizations do. -- Steven From rantingrickjohnson at gmail.com Sun Aug 2 22:15:49 2015 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 2 Aug 2015 19:15:49 -0700 (PDT) Subject: Python 3 May Become Relevant Now In-Reply-To: References: Message-ID: <93cb8798-6ff3-453b-84ba-d0efa5fcd246@googlegroups.com> On Sunday, August 2, 2015 at 7:25:37 PM UTC-5, Mark Lawrence wrote: > rr should have a field day with this one [...] You must be nuts if you think i'm going to click that link for an article that was written today, Hahaha! Quote the relevant bits. From rosuav at gmail.com Sun Aug 2 22:45:34 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Aug 2015 12:45:34 +1000 Subject: Python 3 May Become Relevant Now In-Reply-To: <93cb8798-6ff3-453b-84ba-d0efa5fcd246@googlegroups.com> References: <93cb8798-6ff3-453b-84ba-d0efa5fcd246@googlegroups.com> Message-ID: On Mon, Aug 3, 2015 at 12:15 PM, Rick Johnson wrote: > On Sunday, August 2, 2015 at 7:25:37 PM UTC-5, Mark Lawrence wrote: >> rr should have a field day with this one [...] > > You must be nuts if you think i'm going to click that link > for an article that was written today, Hahaha! Quote the > relevant bits. How do you know it was written today, if you didn't click it? ChrisA From breamoreboy at yahoo.co.uk Sun Aug 2 23:10:10 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 3 Aug 2015 04:10:10 +0100 Subject: GvR Europython keynote described on lwn.net In-Reply-To: <55bec37f$0$1646$c3e8da3$5496439d@news.astraweb.com> References: <87r3noltu3.fsf@jester.gateway.sonic.net> <106305a9-3ccd-4de4-a918-c27cec2d0b8c@googlegroups.com> <55bc5cfb$0$1643$c3e8da3$5496439d@news.astraweb.com> <55bdcf25$0$1653$c3e8da3$5496439d@news.astraweb.com> <917477df-5cda-4fab-bbb3-eb464bfa452e@googlegroups.com> <55bec37f$0$1646$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/08/2015 02:27, Steven D'Aprano wrote: > On Mon, 3 Aug 2015 08:34 am, Rick Johnson wrote: > >> So what? If i had to guess, i would guess that the hacks are >> mostly to bring py3000 features to 2.7 > > These would be the features of Python 3 that nobody needs and nobody wants > because Python 2 is good enough for everyone? > > I wouldn't want to guess what the customizations do. > Is there actually a definitive list of goodies that were backported from 3.x to 2.6 or 2.7? Of course some bits and pieces are still being backported to 2.7. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From dan at tombstonezero.net Mon Aug 3 00:02:54 2015 From: dan at tombstonezero.net (Dan Sommers) Date: Mon, 3 Aug 2015 04:02:54 +0000 (UTC) Subject: Most Pythonic way to store (small) configuration References: <87k2teq9tb.fsf@Equus.decebal.nl> <85k2tdlxbg.fsf@benfinney.id.au> Message-ID: On Sun, 02 Aug 2015 16:11:14 -0500, Tim Chase wrote: > On 2015-08-02 21:54, Ben Finney wrote: >> So, both XML and JSON should be considered write-only, and produced >> only for consumption by a computer; they are a poor choice for >> presenting to a human. [snip] > I second Ben's thoughts against XML & JSON -- they *can* be edited by > hand, but put the onus on the user to make perfect XML/JSON. Config > files (".ini") are more forgiving. [snip] > An additional option is using a sqlite database. The sqlite library > is part of the stdlib, and advantages include being a single file, > expandability, consistent/reliable character encoding, cross-platform > portability, and atomicity (utilities that read/write are blocked from > getting/creating incomplete data seen by the other file). Well, I have at least some non-zero chance of reading and writing JSON or XML by hand. Can the same be said for a sqlite database? ;-) From rosuav at gmail.com Mon Aug 3 00:15:02 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Aug 2015 14:15:02 +1000 Subject: GvR Europython keynote described on lwn.net In-Reply-To: References: <87r3noltu3.fsf@jester.gateway.sonic.net> <106305a9-3ccd-4de4-a918-c27cec2d0b8c@googlegroups.com> <55bc5cfb$0$1643$c3e8da3$5496439d@news.astraweb.com> <55bdcf25$0$1653$c3e8da3$5496439d@news.astraweb.com> <917477df-5cda-4fab-bbb3-eb464bfa452e@googlegroups.com> <55bec37f$0$1646$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 3, 2015 at 1:10 PM, Mark Lawrence wrote: > On 03/08/2015 02:27, Steven D'Aprano wrote: >> >> On Mon, 3 Aug 2015 08:34 am, Rick Johnson wrote: >> >>> So what? If i had to guess, i would guess that the hacks are >>> mostly to bring py3000 features to 2.7 >> >> >> These would be the features of Python 3 that nobody needs and nobody wants >> because Python 2 is good enough for everyone? >> >> I wouldn't want to guess what the customizations do. >> > > Is there actually a definitive list of goodies that were backported from 3.x > to 2.6 or 2.7? Of course some bits and pieces are still being backported to > 2.7. You could probably find a definitive list of *language* features that got backported. Trying to find a full list of the *modules* that got backported will be harder, as they're not a part of Python 2.7 as such (the backports are on PyPI instead) - and some of them have slightly different names, too. ChrisA From umedoblock at gmail.com Mon Aug 3 01:47:36 2015 From: umedoblock at gmail.com (umedoblock) Date: Mon, 03 Aug 2015 14:47:36 +0900 Subject: how to determine for using c extension or not ? Message-ID: <55BF0078.2030806@gmail.com> Hello everyone. I use bisect module. bisect module developer give us c extension as _bisect. If Python3.3 use _bisect, _bisect override his functions in bisect.py. now, I use id() function to determine for using c extension or not. >>> import bisect >>> id(bisect.bisect) 139679893708880 >>> import _bisect >>> id(_bisect.bisect) 139679893708880 they return 139679893708880 as id. so i believe that i use c extension. My check is correct ? right ? or you have more good idea ? From Dwight at GoldWinde.com Mon Aug 3 02:57:05 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Mon, 03 Aug 2015 14:57:05 +0800 Subject: I'm a newbie and I'm still stumped... In-Reply-To: References: Message-ID: Thank you, Emile, Paul, Terry, and Joel for your suggestions! And the error persists. Maybe my error is coming from running the old version (2.7.6) of Python, but I can?t figure out why that would be happening??? I downloaded 3.4.3 again from the Python.org website for my Mac. I inserted the "import sys" and did ?print (sys.version)? into the code. So here what the code is: #!/usr/bin/env python3 import sys print (sys.version) word = input('Enter a word ') Here are the results I got below, showing the same error. The first line says, "2.7.6 (default, Sep 9 2014, 15:04:36)?. Does that mean I am running the old Python? How could that be since I am SURE I downloaded 3.4.3 (it even gives the folder name as ?Python 3.4? in the Applications folder on my Mac. 2.7.6 (default, Sep 9 2014, 15:04:36) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] Enter a word serendipity Traceback (most recent call last): File "test short.py", line 4, in word = input('Enter a word ') File "", line 1, in NameError: name 'serendipity' is not defined Please help? BIG SMILE... Always, Dwight www.3forliving.key.to (video playlist on YouTube) www.couragebooks.key.to (all my books on Amazon) #!/usr/bin/env python3 import sys print (sys.version) word = input('Enter a word ') 2.7.6 (default, Sep 9 2014, 15:04:36) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] Enter a word serendipity Traceback (most recent call last): File "test short.py", line 3, in word = input('Enter a word ') File "", line 1, in NameError: name 'serendipity' is not defined On 8/2/15, 12:30 AM, "Emile van Sebille" wrote: >On 7/30/2015 6:22 PM, Dwight GoldWinde wrote: >> I am running Python 3.4 on my Mac mini, OS X 10.10.2, using Coderunner >>2 as >> my editor. >> >> Here?s the code: >> #!/usr/bin/env python3 >> word = (input('Enter a word ?)) >> >> When running this inside of Coderunner, I get the follow error, after >> entering the word ?serendipity?: >> >> Enter a word serendipity >> Traceback (most recent call last): >> File "test short.py", line 2, in >> word = (input('Enter a word ')) >> File "", line 1, in >> NameError: name 'serendipity' is not defined > >I'd look at which python is actually running (sys.version): > >Python 3.4.0 (default, Apr 11 2014, 13:05:11) >[GCC 4.8.2] on linux >Type "help", "copyright", "credits" or "license" for more information. > >>> word = (input('enter a word ')) >enter a word test > >>> >emile at emile-OptiPlex-9010:~$ python >Python 2.7.6 (default, Mar 22 2014, 22:59:56) >[GCC 4.8.2] on linux2 >Type "help", "copyright", "credits" or "license" for more information. > >>> word = (input('enter a word ')) >enter a word test >Traceback (most recent call last): > > >Emile > File "", line 1, in > File "", line 1, in >NameError: name 'test' is not defined > >>> > > > >-- >https://mail.python.org/mailman/listinfo/python-list From no.email at nospam.invalid Mon Aug 3 03:14:18 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 03 Aug 2015 00:14:18 -0700 Subject: I'm a newbie and I'm still stumped... References: Message-ID: <87io8wkfn9.fsf@jester.gateway.sonic.net> Dwight GoldWinde writes: > word = input('Enter a word ') Use raw_input instead of input. In python 2.x, input treats the stuff you enter as a Python expression instead of a string. From GoldWinde at hotmail.com Mon Aug 3 04:19:24 2015 From: GoldWinde at hotmail.com (Dwight Hotmail) Date: Mon, 3 Aug 2015 16:19:24 +0800 Subject: FW: I'm a newbie and I'm still stumped... In-Reply-To: References: <87io8wkfn9.fsf@jester.gateway.sonic.net> Message-ID: On 8/3/15, 4:07 PM, "Dwight GoldWinde" wrote: >Thank you, Paul. > >But does this mean I am not using Python 3.4? > >BIG SMILE... > >Always, Dwight > > >www.3forliving.key.to (video playlist on YouTube) >www.couragebooks.key.to (all my books on Amazon) > > > > > > >On 8/3/15, 3:14 PM, "Paul Rubin" wrote: > >>Dwight GoldWinde writes: >>> word = input('Enter a word ') >> >>Use raw_input instead of input. In python 2.x, input treats the stuff >>you enter as a Python expression instead of a string. >>-- >>https://mail.python.org/mailman/listinfo/python-list From df at see.replyto.invalid Mon Aug 3 04:27:21 2015 From: df at see.replyto.invalid (Dave Farrance) Date: Mon, 03 Aug 2015 09:27:21 +0100 Subject: I'm a newbie and I'm still stumped... References: Message-ID: Dwight GoldWinde wrote: >Here are the results I got below, showing the same error. The first line >says, >"2.7.6 (default, Sep 9 2014, 15:04:36)?. Does that mean I am running the >old Python? How could that be since I am SURE I downloaded 3.4.3 (it even >gives the folder name as ?Python 3.4? in the Applications folder on my Mac. Yes, that's Python2. I've never used MAC OS, but I understand that it has the BASH shell, so you can use "which" try to figure out where python is being found on the path: $ echo $PATH $ which python Use the above to also check for the position of python2 and python3. You can check for aliases and links with the "type" and "file" commands. Do this for python, python2 and python3: $ type $(which python) $ file $(which python) From Dwight at GoldWinde.com Mon Aug 3 04:56:49 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Mon, 03 Aug 2015 16:56:49 +0800 Subject: I'm a newbie and I'm still stumped... In-Reply-To: References: Message-ID: On 8/3/15, 4:55 PM, "Dwight GoldWinde" wrote: >Okay, thank you, Dave, so I got the following info: >type $(which python3) >/Library/Frameworks/Python.framework/Versions/3.4/bin/python3 is >/Library/Frameworks/Python.framework/Versions/3.4/bin/python3 > > >But I can?t figure out what short of ?usr? statement (e.g. #!/usr/bin/env >python3) I need to point it there. Whatever I tried, still gives me >version 2. > >??? > >Dwight > >On 8/3/15, 4:27 PM, "Dave Farrance" wrote: > >>Dwight GoldWinde wrote: >> >>>Here are the results I got below, showing the same error. The first line >>>says, >>>"2.7.6 (default, Sep 9 2014, 15:04:36)?. Does that mean I am running the >>>old Python? How could that be since I am SURE I downloaded 3.4.3 (it >>>even >>>gives the folder name as ?Python 3.4? in the Applications folder on my >>>Mac. >> >>Yes, that's Python2. I've never used MAC OS, but I understand that it >>has the BASH shell, so you can use "which" try to figure out where >>python is being found on the path: >> >>$ echo $PATH >> >>$ which python >> >>Use the above to also check for the position of python2 and python3. >> >>You can check for aliases and links with the "type" and "file" commands. >>Do this for python, python2 and python3: >> >>$ type $(which python) >> >>$ file $(which python) >>-- >>https://mail.python.org/mailman/listinfo/python-list From c.buhtz at posteo.jp Mon Aug 3 05:13:37 2015 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Mon, 3 Aug 2015 11:13:37 +0200 Subject: Optimal solution for coloring logging output Message-ID: <3mlD6d4jmMzFpW0@dovecot04.posteo.de> I don't want to ask how to do this because there are so many "solutions" about it. There are so much different and part of unpythontic solutions I can not decide myself. What do you (as real pythontics) think about that. Which of the solutions fit to concepts of Python and its logging package? Coloring means here not only the message itself. The (levelname) should be included in the coloring. For myself coloring the (levelname) would be enough to avoid to much color in the output. 1. The solution itself shouldn't care about plattform differences because there are still some packages which are able to offer plattform-independent console-coloring. Which would you prefere? ;) 2. Some solutions derive from StreamHandler or much more bad hacking the emit() function. I think both of them are not responsible for how the output should look or be presented. 3. How to present the output is IMO the responsibility of a Formater, isn't it? So I should derive from the Formater. What do you as Pythonics think of that? ;) -- -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1 mQENBFQIluABCACfPwAhRAwFD3NXgv5CtVUGSiqdfJGVViVBqaKd+14E0pASA0MU G0Ewj7O7cGy/ZIoiZ0+lIEZmzJKHfuGwYhXjR/PhnUDrQIHLBvh9WuD6JQuULXfH kXtVm/i9wm76QAcvr2pwYgNzhcJntUHl2GcgnInYbZDeVmg+p9yIPJjuq73/lRS3 0/McgNoFOBhKK/S6STQuFyjr9OyJyYd1shoM3hmy+kg0HYm6OgQBJNg92WV9jwGe GzlipvEp2jpLwVsTxYir2oOPhfd9D1fC9F/l/3gXbfjd5GIIVrZFq2haZmoVeJ33 LJxo3RA5Tf9LoUeels1b4s9kFz6h7+AHERUpABEBAAG0IUNocmlzdGlhbiBCdWh0 eiA8YnVodHpAcG9zdGVvLmRlPokBPgQTAQIAKAUCVAiW4AIbAwUJAeEzgAYLCQgH AwIGFQgCCQoLBBYCAwECHgECF4AACgkQZLsXsAdRqOxNUAf/V/hDA5zGDpySuCEj DhjiVRK74J9Wd8gfH0WAf1Co5HZ24wZH8rgOIVIgXw8rWkOw/VA6xfdfT+64xjTY Fhkpbrk199nDzp72F7Jc4NC+x8xac2e3rK5ifSWhZx7L5A32pGYE+d16m3EEqImK D4gcZl38x9zdUnD4hHyXkIPz1uCfuMuGgWEnaUk4Wbj41CBZr3O0ABue6regV15U jaes8r+B8iCcY+0yP2kse+3iaCaMqNv5FgQZ9+b2Cql8pFkZJVtBVUw4GW3DWZJi du0O/YrC9TgS+xY9ht/MD2qSHwjcK1sdImjqBO7xP8TIOwKeYyDvGKnSO3EJ/sSA UPGEPrkBDQRUCJbgAQgA0k/Qg67CCUJE2/zuxBEoK4wLJpDRJzh8CQPZpjWx8VP0 KL892jwfxymXn8KNhuy1SgCBFSeV9jg4VZNWDlUGJc2lo82ajr9PzIsrQwu4lf0B zrUWV5hWepKu/kb8uSjx58YYfx0SFz4+9akX3Wwu9TUHntzL5Gk3Q26nnsr1xEJ+ VEumvCH9AE0Tk0K7dQpJ2/JcLuO+uhrpd/lHFDYVN5NsG3P015uFOkDI6N/xNFCj v95XNR93QlfKpK3qWlFGescfG+o/7Ub6s67/i/JoNbw0XgPEHmQfXpD7IHO4cu+p +ETb11cz+1mmi96cy98ID+uTiToJ8G//yD9rmtyxoQARAQABiQElBBgBAgAPBQJU CJbgAhsMBQkB4TOAAAoJEGS7F7AHUajs6sQH/iKs6sPc0vkRJLfbwrijZeecwCWF blo/jzIQ8jPykAj9SLjV20Xwqg3XcJyko8ZU6/zuRJq9xjlv9pZr/oVudQAt6v+h 2Cf4rKEjmau483wjMV2xjTXQhZi9+ttDbia4fgdmGtKsOicn5ae2fFXcXNPu3RiW sZKifWdokA6xqMW6iIG9YjjI5ShxngHWp2xfPscBFMDRtFOMags/Yx+YvwoyEZ4A dURYMFHFqpwILEc8hIzhRg1gq40AHbOaEdczS1Rr3T7/gS6eBs4u6HuY5g2Bierm lLjpspFPjMXwJAa/XLOBjMF2vsHPrZNcouNKkumQ36yq/Pm6DFXAseQDxOk= =PGP9 -----END PGP PUBLIC KEY BLOCK----- From jpiitula at ling.helsinki.fi Mon Aug 3 05:49:14 2015 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: Mon, 03 Aug 2015 12:49:14 +0300 Subject: I'm a newbie and I'm still stumped... References: Message-ID: Dwight GoldWinde quotes himself: > >> Okay, thank you, Dave, so I got the following info: type $(which >> python3) >> /Library/Frameworks/Python.framework/Versions/3.4/bin/python3 is >> /Library/Frameworks/Python.framework/Versions/3.4/bin/python3 >> >> But I can?t figure out what short of ?usr? statement >> (e.g. #!/usr/bin/env python3) I need to point it there. Whatever I >> tried, still gives me version 2. How are you launching your script? If your method involves clicking some pretty picture or something similar, you may be bypassing /usr/bin/env altogether and relying on some association of file types in Mac OS. Then you need to investigate file properties in Finder, or something like that. It should be safe to change the association for that individual script but not necessarily for all files with the same extension. If your method is to type "python scriptname" at the shell prompt, you are definitely bypassing /usr/bin/env and specifying the default python as the one to use. Solution: type "python3 scriptname" instead. (A more advanced solution: make scriptname executable and type "./scriptname" instead. This one uses /usr/bin/env to find the interpreter.) (You could try "#!/usr/bin/env aintgotnosuch" as your script's hashbang line to see if it even matters what that line says. Check first that you don't happen to have a program named "aintgotnosuch" in your path.) From jeanmichel at sequans.com Mon Aug 3 05:58:14 2015 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 3 Aug 2015 11:58:14 +0200 (CEST) Subject: Python 3 May Become Relevant Now In-Reply-To: Message-ID: <427038102.1314110.1438595894636.JavaMail.root@sequans.com> ----- Original Message ----- > From: "Mark Lawrence" > To: python-list at python.org > Sent: Monday, 3 August, 2015 2:25:08 AM > Subject: Python 3 May Become Relevant Now > > rr should have a field day with this one > http://nafiulis.me/python-3-may-become-relevant-now.html > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence "The problem was with a function (buried deep in the source code as one of many decorators) that usually returned a list but under a certain circumstances, it returned None" [...] "I'm not saying that the person who originally wrote the code is a bad programmer. I'll leave that up to you. What I am saying is that python allows you to make such silly mistakes." I do this all the time ... :( Well not exactly, with lists I'm trying to return an empty list but I may return None in certain situations, most of the time when a method cannot do its job because of missing data but this particular method does not know if it's expected or not, so it returns "None" like to tell the caller, "can't do it, deal with it". I really prefer to handle errors with a : if foo() is not None: ... than a try expect stupid block. But if I get things right, with python 3.5 type hint checker, I'd be screwed, as it is spefificaly designed to track this kind of "problem". What's the use of None then ? Any method returning None can only return None or suffer the type checker retribution. I don't get it. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From ian.g.kelly at gmail.com Mon Aug 3 06:26:48 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 3 Aug 2015 02:26:48 -0800 Subject: Python 3 May Become Relevant Now In-Reply-To: <427038102.1314110.1438595894636.JavaMail.root@sequans.com> References: <427038102.1314110.1438595894636.JavaMail.root@sequans.com> Message-ID: On Mon, Aug 3, 2015 at 1:58 AM, Jean-Michel Pichavant wrote: > But if I get things right, with python 3.5 type hint checker, I'd be screwed, as it is spefificaly designed to track this kind of "problem". > What's the use of None then ? Any method returning None can only return None or suffer the type checker retribution. > > I don't get it. This is where you would use optional types. Optional[List[X]] is a shorthand for the type Union[List[X], None]. In fact static type checking can be quite useful in this sort of case. If you return Optional[List[X]] in one place, and you have some other method that takes in the value but simply indicates that it takes List[X], then the static checker will flag that as an error, and you'll know that a part of your code likely isn't handling the None case correctly. From rosuav at gmail.com Mon Aug 3 06:28:21 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Aug 2015 20:28:21 +1000 Subject: Python 3 May Become Relevant Now In-Reply-To: <427038102.1314110.1438595894636.JavaMail.root@sequans.com> References: <427038102.1314110.1438595894636.JavaMail.root@sequans.com> Message-ID: On Mon, Aug 3, 2015 at 7:58 PM, Jean-Michel Pichavant wrote: > But if I get things right, with python 3.5 type hint checker, I'd be screwed, as it is spefificaly designed to track this kind of "problem". > What's the use of None then ? Any method returning None can only return None or suffer the type checker retribution. 1) Python 3.5 will not include a type checker. All it'll include is enough stubs that your code will run correctly; plus it has a set of specifications for how third-party checkers should be advised, which means you'll be able to use any such checker with the same code. But nothing will happen till you actually run such a checker. 2) Since "returns X or None" is such a common thing, it's very easy to spell. More complicated things are possible, too, but less cleanly. Python still allows you to return anything from anything, and that isn't changing; but there are a number of common cases - for instance, this function might always return a number, or maybe it'll always return a dictionary that maps strings to integers. Those are easily spelled. So no, a method that can return None is most definitely *not* required to return None in all cases. Although you may find that some linters and code style guides object to code like this: def some_function(some_arg): if some_condition: return some_expression where one branch has an explicit 'return' and another doesn't. That's a quite reasonable objection, and an explicit "return None" at the end will suppress the warning, by being more explicit that this might return this or that. ChrisA From GoldWinde at hotmail.com Mon Aug 3 06:30:30 2015 From: GoldWinde at hotmail.com (Dwight Hotmail) Date: Mon, 3 Aug 2015 18:30:30 +0800 Subject: I'm a newbie and you helped me find the answer... Message-ID: Thank you, Jussi. Problem finally solved. I am using Coderunner 2 as my editor. It has a language setting. I had set it as Python instead of Python 3. Duh! Thank you again, everyone! With appreciation, Dwight Dwight at GoldWinde.com www.goldwinde.com Author of the book, "Courage: the Choice that Makes the Difference--Your Key to a Thousand Doors" You can find all my books at http://www.couragebooks.key.to/ 1-206-923-9554 (USA Telephone) 1-206-350-0129 (voice mail and fax U.S.A.) 86-153-9867-5712 (China Telephone) goldwindedwight (Skype) goldwinde (Wechat) +8615398675712 (Whatsapp) www.3forliving.key.to (daily living video playlist) http://www.couragebooks.key.to/ (my books) On 8/3/15, 5:49 PM, "Jussi Piitulainen" wrote: >Dwight GoldWinde quotes himself: >> >>> Okay, thank you, Dave, so I got the following info: type $(which >>> python3) >>> /Library/Frameworks/Python.framework/Versions/3.4/bin/python3 is >>> /Library/Frameworks/Python.framework/Versions/3.4/bin/python3 >>> >>> But I can?t figure out what short of ?usr? statement >>> (e.g. #!/usr/bin/env python3) I need to point it there. Whatever I >>> tried, still gives me version 2. > >How are you launching your script? If your method involves clicking some >pretty picture or something similar, you may be bypassing /usr/bin/env >altogether and relying on some association of file types in Mac OS. Then >you need to investigate file properties in Finder, or something like >that. It should be safe to change the association for that individual >script but not necessarily for all files with the same extension. > >If your method is to type "python scriptname" at the shell prompt, you >are definitely bypassing /usr/bin/env and specifying the default python >as the one to use. Solution: type "python3 scriptname" instead. (A more >advanced solution: make scriptname executable and type "./scriptname" >instead. This one uses /usr/bin/env to find the interpreter.) > >(You could try "#!/usr/bin/env aintgotnosuch" as your script's hashbang >line to see if it even matters what that line says. Check first that you >don't happen to have a program named "aintgotnosuch" in your path.) >-- >https://mail.python.org/mailman/listinfo/python-list From umedoblock at gmail.com Mon Aug 3 08:40:49 2015 From: umedoblock at gmail.com (umedoblock) Date: Mon, 03 Aug 2015 21:40:49 +0900 Subject: how to determine for using c extension or not ? Message-ID: <55BF6151.2030202@gmail.com> Hello everyone. I use bisect module. bisect module developer give us c extension as _bisect. If Python3.3 use _bisect, _bisect override his functions in bisect.py. now, I use id() function to determine for using c extension or not. >>> >>> import bisect >>> >>> id(bisect.bisect) 139679893708880 >>> >>> import _bisect >>> >>> id(_bisect.bisect) 139679893708880 they return 139679893708880 as id. so i believe that i use c extension. My check is correct ? right ? or you have more good idea ? From umedoblock at gmail.com Mon Aug 3 08:44:32 2015 From: umedoblock at gmail.com (Hideyuki YASUDA) Date: Mon, 03 Aug 2015 21:44:32 +0900 Subject: how to determine for using c extension or not ? Message-ID: <55BF6230.4040203@gmail.com> Hello everyone. I use bisect module. bisect module developer give us c extension as _bisect. If Python3.3 use _bisect, _bisect override his functions in bisect.py. now, I use id() function to determine for using c extension or not. >>> import bisect >>> id(bisect.bisect) 139679893708880 >>> import _bisect >>> id(_bisect.bisect) 139679893708880 they return 139679893708880 as id. so i believe that i use c extension. My check is correct ? right ? or you have more good idea ? From jeanmichel at sequans.com Mon Aug 3 08:47:56 2015 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 3 Aug 2015 14:47:56 +0200 (CEST) Subject: Optimal solution for coloring logging output In-Reply-To: <3mlD6d4jmMzFpW0@dovecot04.posteo.de> Message-ID: <1073495349.1334822.1438606076873.JavaMail.root@sequans.com> ---- Original Message ----- > From: "c buhtz" > To: python-list at python.org > Sent: Monday, 3 August, 2015 11:13:37 AM > Subject: Optimal solution for coloring logging output > > I don't want to ask how to do this because there are so many > "solutions" about it. > > > There are so much different and part of unpythontic solutions I can > not > decide myself. What do you (as real pythontics) think about that. > Which of the solutions fit to concepts of Python and its logging > package? > > Coloring means here not only the message itself. The (levelname) > should > be included in the coloring. > For myself coloring the (levelname) would be enough to avoid to much > color in the output. > > 1. > The solution itself shouldn't care about plattform differences > because > there are still some packages which are able to offer > plattform-independent console-coloring. Which would you prefere? ;) > > 2. > Some solutions derive from StreamHandler or much more bad hacking the > emit() function. I think both of them are not responsible for how the > output should look or be presented. > > 3. > How to present the output is IMO the responsibility of a Formater, > isn't > it? So I should derive from the Formater. > > What do you as Pythonics think of that? ;) This is more or less how it could be done: 1/ use the module "curses" to get terminal colors (the doc suggests to use the "Console" moduel on windows) 2/ write a logging Formatter that will replace DEBUG/INFO/ERROR message by their colored version. import curses import logging import string import re curses.setupterm() class ColorFormat: #{ Foregroung colors BLACK = curses.tparm(curses.tigetstr('setaf'), curses.COLOR_BLACK) RED = curses.tparm(curses.tigetstr('setaf'), curses.COLOR_RED) GREEN = curses.tparm(curses.tigetstr('setaf'), curses.COLOR_GREEN) YELLOW = curses.tparm(curses.tigetstr('setaf'), curses.COLOR_YELLOW) BLUE = curses.tparm(curses.tigetstr('setaf'), curses.COLOR_BLUE) MAGENTA = curses.tparm(curses.tigetstr('setaf'), curses.COLOR_MAGENTA) CYAN = curses.tparm(curses.tigetstr('setaf'), curses.COLOR_CYAN) WHITE = curses.tparm(curses.tigetstr('setaf'), 9) # default white is 7, the 9 is a better white #{ Backgrounds colors BG_BLACK = curses.tparm(curses.tigetstr('setab'), curses.COLOR_BLACK) BG_RED = curses.tparm(curses.tigetstr('setab'), curses.COLOR_RED) BG_GREEN = curses.tparm(curses.tigetstr('setab'), curses.COLOR_GREEN) BG_YELLOW = curses.tparm(curses.tigetstr('setab'), curses.COLOR_YELLOW) BG_BLUE = curses.tparm(curses.tigetstr('setab'), curses.COLOR_BLUE) BG_MAGENTA = curses.tparm(curses.tigetstr('setab'), curses.COLOR_MAGENTA) BG_CYAN = curses.tparm(curses.tigetstr('setab'), curses.COLOR_CYAN) BG_WHITE = curses.tparm(curses.tigetstr('setab'), curses.COLOR_WHITE) #{ Format codes BOLD = curses.tparm(curses.tigetstr('bold'), curses.A_BOLD) UNDERLINE = curses.tparm(curses.tigetstr('smul'), curses.A_UNDERLINE) BLINK = curses.tparm(curses.tigetstr('blink'), curses.A_BLINK) NO_FORMAT = curses.tparm(curses.tigetstr('sgr0'), curses.A_NORMAL) NO_COLOR = curses.tigetstr('sgr0') #} def setFormat(attributeList): _set = '' # avoid collision with the builtin set type for attribute in attributeList: _set += getattr(ColorFormat, attribute, '') return _set class ColorFormatter(logging.Formatter): def format(self, record): parameters = record.__dict__.copy() parameters['message'] = record.getMessage() # ------------------------------------------------------------------ # Log Level Format : %(levelname) # ------------------------------------------------------------------ fmt = self._fmt pattern = r'(%\(levelname\)(?:-?\d+)?s)' if record.levelno <= logging.DEBUG: fmt = re.sub(pattern, setFormat(['BLUE']) + r'\1' + setFormat(['NO_COLOR']), fmt) elif record.levelno <= logging.INFO: fmt = re.sub(pattern, setFormat(['CYAN']) + r'\1' + setFormat(['NO_COLOR']), fmt) elif record.levelno <= logging.WARNING: fmt = re.sub(pattern, setFormat(['MAGENTA']) + r'\1' + setFormat(['NO_COLOR']), fmt) elif record.levelno <= logging.ERROR: fmt = re.sub(pattern, setFormat(['RED','BOLD']) + r'\1' + setFormat(['NO_COLOR']), fmt) else: fmt = re.sub(pattern, setFormat(['WHITE', 'BOLD', 'BG_RED']) + r'\1' + setFormat(['NO_COLOR']), fmt) # ------------------------------------------------------------------ # following is the classic format method from the default formatter # ------------------------------------------------------------------ if string.find(fmt,"%(asctime)") >= 0: record.asctime = self.formatTime(record, self.datefmt) parameters['asctime'] = record.asctime s = fmt % parameters if record.exc_info: # Cache the traceback text to avoid converting it multiple times # (it's constant anyway) if not record.exc_text: record.exc_text = self.formatException(record.exc_info) if record.exc_text: if s[-1] != "\n": s = s + "\n" s = s + record.exc_text return s if __name__ == '__main__': logger = logging.getLogger('Foo') logger.setLevel(logging.DEBUG) logger.addHandler(logging.StreamHandler()) logger.handlers[-1].setFormatter(ColorFormatter('%(levelname)s - %(message)s')) logger.error('This is an error') logger.debug('This is an debug') -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From kliateni at gmail.com Mon Aug 3 08:51:25 2015 From: kliateni at gmail.com (Karim) Date: Mon, 03 Aug 2015 14:51:25 +0200 Subject: Optimal solution for coloring logging output In-Reply-To: <1073495349.1334822.1438606076873.JavaMail.root@sequans.com> References: <1073495349.1334822.1438606076873.JavaMail.root@sequans.com> Message-ID: <55BF63CD.7050504@gmail.com> On 03/08/2015 14:47, Jean-Michel Pichavant wrote: > te a logging Formatter that will re Thank you Jean-Michel useful example K From umedoblock at gmail.com Mon Aug 3 09:08:27 2015 From: umedoblock at gmail.com (umedoblock) Date: Mon, 03 Aug 2015 22:08:27 +0900 Subject: how to determine for using c extension or not ? Message-ID: <55BF67CB.5030604@gmail.com> Hello everyone. I use bisect module. bisect module developer give us c extension as _bisect. If Python3.3 use _bisect, _bisect override his functions in bisect.py. now, I use id() function to determine for using c extension or not. >>> import bisect >>> id(bisect.bisect) 139679893708880 >>> import _bisect >>> id(_bisect.bisect) 139679893708880 they return 139679893708880 as id. so i believe that i use c extension. My check is correct ? right ? or you have more good idea ? From joel.goldstick at gmail.com Mon Aug 3 09:22:39 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 3 Aug 2015 09:22:39 -0400 Subject: how to determine for using c extension or not ? In-Reply-To: <55BF67CB.5030604@gmail.com> References: <55BF67CB.5030604@gmail.com> Message-ID: On Mon, Aug 3, 2015 at 9:08 AM, umedoblock wrote: > Hello everyone. > > I use bisect module. > bisect module developer give us c extension as _bisect. > > If Python3.3 use _bisect, _bisect override his functions in bisect.py. > > now, I use id() function to determine for using c extension or not. > >>>> import bisect >>>> id(bisect.bisect) > 139679893708880 >>>> import _bisect >>>> id(_bisect.bisect) > 139679893708880 > > they return 139679893708880 as id. > so i believe that i use c extension. > > My check is correct ? right ? > or you have more good idea ? > -- > https://mail.python.org/mailman/listinfo/python-list I don't know the answer to your question, but repeating it will not help you get an answer more quickly. This is a voluntary mailing list. If someone can help you, you will probably see a response within a few hours or a few days. -- Joel Goldstick http://joelgoldstick.com From skip.montanaro at gmail.com Mon Aug 3 09:30:24 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 3 Aug 2015 08:30:24 -0500 Subject: how to determine for using c extension or not ? In-Reply-To: <55BF0078.2030806@gmail.com> References: <55BF0078.2030806@gmail.com> Message-ID: id() tells you nothing about the nature of the function. Use the inspect.isbuiltin(): >>> import bisect >>> bisect.bisect >>> import inspect >>> def foo(): pass ... >>> inspect.isbuiltin(foo) False >>> inspect.isbuiltin(bisect.bisect) True It's perhaps a bit poorly named, but "builtin" functions are those not written in Python. That is, those written in C or C++. Skip From steve at pearwood.info Mon Aug 3 09:36:47 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 03 Aug 2015 23:36:47 +1000 Subject: how to determine for using c extension or not ? References: Message-ID: <55bf6e6f$0$1650$c3e8da3$5496439d@news.astraweb.com> On Mon, 3 Aug 2015 03:47 pm, umedoblock wrote: > Hello everyone. > > I use bisect module. You asked the same question FOUR times. Have patience. Your question goes all over the world, people may be asleep, or working, or just not know the answer. If you ask a question, and get no answers, you should wait a full day before asking again. > bisect module developer give us c extension as _bisect. > > If Python3.3 use _bisect, _bisect override his functions in bisect.py. So does Python 2.7. > now, I use id() function to determine for using c extension or not. The id() function doesn't tell you where objects come from or what language they are written in. But they will tell you if two objects are the same object. >>>> import bisect >>>> id(bisect.bisect) > 139679893708880 >>>> import _bisect >>>> id(_bisect.bisect) > 139679893708880 > > they return 139679893708880 as id. > so i believe that i use c extension. Correct. Also, you can do this: py> import bisect py> bisect.__file__ '/usr/local/lib/python2.7/bisect.pyc' py> bisect.bisect.__module__ # Where does the bisect file come from? '_bisect' py> import _bisect py> _bisect.__file__ '/usr/local/lib/python2.7/lib-dynload/_bisect.so' So you can see that _bisect is a .so file (on Linux; on Windows it will be a .dll file), which means written in C. -- Steven From steve at pearwood.info Mon Aug 3 09:38:07 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 03 Aug 2015 23:38:07 +1000 Subject: Most Pythonic way to store (small) configuration References: <87k2teq9tb.fsf@Equus.decebal.nl> <85k2tdlxbg.fsf@benfinney.id.au> Message-ID: <55bf6ebf$0$1650$c3e8da3$5496439d@news.astraweb.com> On Mon, 3 Aug 2015 02:02 pm, Dan Sommers wrote: > Well, I have at least some non-zero chance of reading and writing JSON > or XML by hand. ?Can the same be said for a sqlite database? Real programmers edit their SQL databases directly on the hard drive platter using a magnetised needle and a steady hand. -- Steven From rosuav at gmail.com Mon Aug 3 09:46:02 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Aug 2015 23:46:02 +1000 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <55bf6ebf$0$1650$c3e8da3$5496439d@news.astraweb.com> References: <87k2teq9tb.fsf@Equus.decebal.nl> <85k2tdlxbg.fsf@benfinney.id.au> <55bf6ebf$0$1650$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 3, 2015 at 11:38 PM, Steven D'Aprano wrote: > On Mon, 3 Aug 2015 02:02 pm, Dan Sommers wrote: > >> Well, I have at least some non-zero chance of reading and writing JSON >> or XML by hand. Can the same be said for a sqlite database? > > > Real programmers edit their SQL databases directly on the hard drive platter > using a magnetised needle and a steady hand. REAL programmers use emacs, with the C-x M-x M-butterfly command. ChrisA From umedoblock at gmail.com Mon Aug 3 10:01:59 2015 From: umedoblock at gmail.com (umedoblock) Date: Mon, 03 Aug 2015 23:01:59 +0900 Subject: how to determine for using c extension or not ? In-Reply-To: <55bf6e6f$0$1650$c3e8da3$5496439d@news.astraweb.com> References: <55bf6e6f$0$1650$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55BF7457.8030704@gmail.com> sorry, Joel, Skip, Steven, and python-list members. I think that I don't sent my mail to python-list at python.org or I don't have correct mail setting. so I send many mails. sorry... I should wait a day to get answer, sorry. On 2015?08?03? 22:36, Steven D'Aprano wrote: > On Mon, 3 Aug 2015 03:47 pm, umedoblock wrote: > >> Hello everyone. >> >> I use bisect module. > > You asked the same question FOUR times. Have patience. Your question goes > all over the world, people may be asleep, or working, or just not know the > answer. If you ask a question, and get no answers, you should wait a full > day before asking again. > > >> bisect module developer give us c extension as _bisect. >> >> If Python3.3 use _bisect, _bisect override his functions in bisect.py. > > So does Python 2.7. > > >> now, I use id() function to determine for using c extension or not. > > The id() function doesn't tell you where objects come from or what language > they are written in. But they will tell you if two objects are the same > object. > >>>>> import bisect >>>>> id(bisect.bisect) >> 139679893708880 >>>>> import _bisect >>>>> id(_bisect.bisect) >> 139679893708880 >> >> they return 139679893708880 as id. >> so i believe that i use c extension. > > Correct. > > Also, you can do this: > > > py> import bisect > py> bisect.__file__ > '/usr/local/lib/python2.7/bisect.pyc' > py> bisect.bisect.__module__ # Where does the bisect file come from? > '_bisect' > py> import _bisect > py> _bisect.__file__ > '/usr/local/lib/python2.7/lib-dynload/_bisect.so' > > So you can see that _bisect is a .so file (on Linux; on Windows it will be > a .dll file), which means written in C. > > From joel.goldstick at gmail.com Mon Aug 3 10:11:36 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 3 Aug 2015 10:11:36 -0400 Subject: how to determine for using c extension or not ? In-Reply-To: <55BF7457.8030704@gmail.com> References: <55bf6e6f$0$1650$c3e8da3$5496439d@news.astraweb.com> <55BF7457.8030704@gmail.com> Message-ID: On Mon, Aug 3, 2015 at 10:01 AM, umedoblock wrote: > sorry, Joel, Skip, Steven, and python-list members. > > I think that I don't sent my mail to python-list at python.org or I don't have > correct mail setting. > > so I send many mails. > > sorry... I should wait a day to get answer, sorry. > > > On 2015?08?03? 22:36, Steven D'Aprano wrote: >> >> On Mon, 3 Aug 2015 03:47 pm, umedoblock wrote: >> >>> Hello everyone. >>> >>> I use bisect module. >> >> >> You asked the same question FOUR times. Have patience. Your question goes >> all over the world, people may be asleep, or working, or just not know the >> answer. If you ask a question, and get no answers, you should wait a full >> day before asking again. >> >> >>> bisect module developer give us c extension as _bisect. >>> >>> If Python3.3 use _bisect, _bisect override his functions in bisect.py. >> >> >> So does Python 2.7. >> >> >>> now, I use id() function to determine for using c extension or not. >> >> >> The id() function doesn't tell you where objects come from or what >> language >> they are written in. But they will tell you if two objects are the same >> object. >> >>>>>> import bisect >>>>>> id(bisect.bisect) >>> >>> 139679893708880 >>>>>> >>>>>> import _bisect >>>>>> id(_bisect.bisect) >>> >>> 139679893708880 >>> >>> they return 139679893708880 as id. >>> so i believe that i use c extension. >> >> >> Correct. >> >> Also, you can do this: >> >> >> py> import bisect >> py> bisect.__file__ >> '/usr/local/lib/python2.7/bisect.pyc' >> py> bisect.bisect.__module__ # Where does the bisect file come from? >> '_bisect' >> py> import _bisect >> py> _bisect.__file__ >> '/usr/local/lib/python2.7/lib-dynload/_bisect.so' >> >> So you can see that _bisect is a .so file (on Linux; on Windows it will be >> a .dll file), which means written in C. >> >> > > -- > https://mail.python.org/mailman/listinfo/python-list Welcome to the mailing list, and as I see above, you got a good answer. -- Joel Goldstick http://joelgoldstick.com From breamoreboy at yahoo.co.uk Mon Aug 3 10:19:39 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 3 Aug 2015 15:19:39 +0100 Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: Message-ID: On 02/08/2015 21:58, Joonas Liik wrote: > I have this feeling that you would get a lot more useful anwsers if > you were to describe your actual problem in stead of what you think > the solution is. There might be other, better solutions but since we > know so little about what you are doing we will likely never find them > by just guessing.. > +1 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Mon Aug 3 10:31:11 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 3 Aug 2015 15:31:11 +0100 Subject: Optimal solution for coloring logging output In-Reply-To: <3mlD6d4jmMzFpW0@dovecot04.posteo.de> References: <3mlD6d4jmMzFpW0@dovecot04.posteo.de> Message-ID: On 03/08/2015 10:13, c.buhtz at posteo.jp wrote: > I don't want to ask how to do this because there are so many > "solutions" about it. > > > There are so much different and part of unpythontic solutions I can not > decide myself. What do you (as real pythontics) think about that. > Which of the solutions fit to concepts of Python and its logging > package? > > Coloring means here not only the message itself. The (levelname) should > be included in the coloring. > For myself coloring the (levelname) would be enough to avoid to much > color in the output. > > 1. > The solution itself shouldn't care about plattform differences because > there are still some packages which are able to offer > plattform-independent console-coloring. Which would you prefere? ;) > > 2. > Some solutions derive from StreamHandler or much more bad hacking the > emit() function. I think both of them are not responsible for how the > output should look or be presented. > > 3. > How to present the output is IMO the responsibility of a Formater, isn't > it? So I should derive from the Formater. > > What do you as Pythonics think of that? ;) > I'd go for this https://pypi.python.org/pypi/colorlog as recommended on a couple of answers on the stackoverflow thread you've referenced. A slight aside, we're "Pythonistas", not "pythontics" or "Pythonics " :) Should we subclass Pythonista into Pythonista2 and Pythonista3 so that people can show their preferred version? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Mon Aug 3 10:37:19 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 3 Aug 2015 15:37:19 +0100 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <55bf6ebf$0$1650$c3e8da3$5496439d@news.astraweb.com> References: <87k2teq9tb.fsf@Equus.decebal.nl> <85k2tdlxbg.fsf@benfinney.id.au> <55bf6ebf$0$1650$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/08/2015 14:38, Steven D'Aprano wrote: > On Mon, 3 Aug 2015 02:02 pm, Dan Sommers wrote: > >> Well, I have at least some non-zero chance of reading and writing JSON >> or XML by hand. Can the same be said for a sqlite database? > > Real programmers edit their SQL databases directly on the hard drive platter > using a magnetised needle and a steady hand. > I'd stick with SQLiteStudio or something similar if I were you. The last time I tried the above, having consumed 10 bottles of Newcastle Brown, the results were disastrous. I pricked my finger. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marco.buttu at gmail.com Mon Aug 3 10:54:38 2015 From: marco.buttu at gmail.com (Marco Buttu) Date: Mon, 03 Aug 2015 16:54:38 +0200 Subject: how to determine for using c extension or not ? In-Reply-To: References: <55BF0078.2030806@gmail.com> Message-ID: <55BF80AE.3070505@oa-cagliari.inaf.it> On 03/08/2015 15:30, Skip Montanaro wrote: > id() tells you nothing about the nature of the function. Use the > inspect.isbuiltin(): > ... > It's perhaps a bit poorly named, but "builtin" functions are those not > written in Python. That is, those written in C or C++. I think in the documentation there is an inconsistency about the term builtin. The "Built-in Functions" documentation says: """The Python interpreter has a number of functions and types built into it that are *always available*. They are listed here in alphabetical order""". https://docs.python.org/3/library/functions.html The functions in the documentation list, are the same functions we get from the `builtins` module. So, in the documentation we use the term built-in to indicate functions always available, whose names live in the builtin namespace. Sometimes, as mentioned by Skip, we say that the term "buit-in function" is also referred to a function written in C: https://docs.python.org/3/library/types.html#types.BuiltinFunctionType By using the same word (built-in) to indicate either objects written in C or objects who live in the builtin namespace could be a bit muddler. -- Marco Buttu INAF-Osservatorio Astronomico di Cagliari Via della Scienza n. 5, 09047 Selargius (CA) Phone: 070 711 80 217 Email: mbuttu at oa-cagliari.inaf.it From umedoblock at gmail.com Mon Aug 3 10:57:24 2015 From: umedoblock at gmail.com (umedoblock) Date: Mon, 03 Aug 2015 23:57:24 +0900 Subject: how to determine for using c extension or not ? In-Reply-To: References: <55bf6e6f$0$1650$c3e8da3$5496439d@news.astraweb.com> <55BF7457.8030704@gmail.com> Message-ID: <55BF8154.2030705@gmail.com> normal, no change >>> import bisect >>> bisect.bisect.__module__ '_bisect' I change from "from _bisect import *" to "pass" in bisect.py >>> import bisect >>> bisect.bisect.__module__ 'bisect' bisect.bisect.__module__ return different results. they are '_bisect' and 'bisect'. I know that c extension document recomended us to use _ for c extension name prefix. I use "bisect.bisect.__module__" sentence to determine for using c extension or not. thanks. On 2015?08?03? 23:11, Joel Goldstick wrote: > On Mon, Aug 3, 2015 at 10:01 AM, umedoblock wrote: >> sorry, Joel, Skip, Steven, and python-list members. >> >> I think that I don't sent my mail to python-list at python.org or I don't have >> correct mail setting. >> >> so I send many mails. >> >> sorry... I should wait a day to get answer, sorry. >> >> >> On 2015?08?03? 22:36, Steven D'Aprano wrote: >>> >>> On Mon, 3 Aug 2015 03:47 pm, umedoblock wrote: >>> >>>> Hello everyone. >>>> >>>> I use bisect module. >>> >>> >>> You asked the same question FOUR times. Have patience. Your question goes >>> all over the world, people may be asleep, or working, or just not know the >>> answer. If you ask a question, and get no answers, you should wait a full >>> day before asking again. >>> >>> >>>> bisect module developer give us c extension as _bisect. >>>> >>>> If Python3.3 use _bisect, _bisect override his functions in bisect.py. >>> >>> >>> So does Python 2.7. >>> >>> >>>> now, I use id() function to determine for using c extension or not. >>> >>> >>> The id() function doesn't tell you where objects come from or what >>> language >>> they are written in. But they will tell you if two objects are the same >>> object. >>> >>>>>>> import bisect >>>>>>> id(bisect.bisect) >>>> >>>> 139679893708880 >>>>>>> >>>>>>> import _bisect >>>>>>> id(_bisect.bisect) >>>> >>>> 139679893708880 >>>> >>>> they return 139679893708880 as id. >>>> so i believe that i use c extension. >>> >>> >>> Correct. >>> >>> Also, you can do this: >>> >>> >>> py> import bisect >>> py> bisect.__file__ >>> '/usr/local/lib/python2.7/bisect.pyc' >>> py> bisect.bisect.__module__ # Where does the bisect file come from? >>> '_bisect' >>> py> import _bisect >>> py> _bisect.__file__ >>> '/usr/local/lib/python2.7/lib-dynload/_bisect.so' >>> >>> So you can see that _bisect is a .so file (on Linux; on Windows it will be >>> a .dll file), which means written in C. >>> >>> >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > > Welcome to the mailing list, and as I see above, you got a good answer. > From gilles.lenfant at gmail.com Mon Aug 3 11:01:28 2015 From: gilles.lenfant at gmail.com (Gilles Lenfant) Date: Mon, 3 Aug 2015 08:01:28 -0700 (PDT) Subject: Parsing multipart HTTP response Message-ID: <648c131d-6315-4f83-88f0-b87bf3b530a9@googlegroups.com> Hi, I searched without succeeding a Python resource that is capable of parsing an HTTP multipart/mixed response stream, preferably as a generator that yields headers + content for each part. Google and friends didn't find or I didn't use the appropriate term. Any hint will be appreciated. -- Gilles Lenfant From oscar.j.benjamin at gmail.com Mon Aug 3 11:05:03 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 03 Aug 2015 15:05:03 +0000 Subject: how to determine for using c extension or not ? In-Reply-To: <55BF8154.2030705@gmail.com> References: <55bf6e6f$0$1650$c3e8da3$5496439d@news.astraweb.com> <55BF7457.8030704@gmail.com> <55BF8154.2030705@gmail.com> Message-ID: On Mon, 3 Aug 2015 at 15:58 umedoblock wrote: > > I use "bisect.bisect.__module__" sentence to determine for using c > extension or not. > > Why do you want to know if it uses the C extension? It shouldn't really matter. -- Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From gilles.lenfant at gmail.com Mon Aug 3 11:05:30 2015 From: gilles.lenfant at gmail.com (Gilles Lenfant) Date: Mon, 3 Aug 2015 08:05:30 -0700 (PDT) Subject: Parsing multipart HTTP response In-Reply-To: <648c131d-6315-4f83-88f0-b87bf3b530a9@googlegroups.com> References: <648c131d-6315-4f83-88f0-b87bf3b530a9@googlegroups.com> Message-ID: <90e7b566-0ba4-44f7-95d7-13ed69dd1112@googlegroups.com> Le lundi 3 ao?t 2015 17:01:40 UTC+2, Gilles Lenfant a ?crit?: > Hi, > > I searched without succeeding a Python resource that is capable of parsing an HTTP multipart/mixed response stream, preferably as a generator that yields headers + content for each part. > > Google and friends didn't find or I didn't use the appropriate term. > > Any hint will be appreciated. > -- > Gilles Lenfant Ah, aiohttp does something similar to what I need but requires Python 3.3 + when I'm stuck with Pyton 2.7 on that project. From breamoreboy at yahoo.co.uk Mon Aug 3 11:39:09 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 3 Aug 2015 16:39:09 +0100 Subject: Parsing multipart HTTP response In-Reply-To: <648c131d-6315-4f83-88f0-b87bf3b530a9@googlegroups.com> References: <648c131d-6315-4f83-88f0-b87bf3b530a9@googlegroups.com> Message-ID: On 03/08/2015 16:01, Gilles Lenfant wrote: > Hi, > > I searched without succeeding a Python resource that is capable of parsing an HTTP multipart/mixed response stream, preferably as a generator that yields headers + content for each part. > > Google and friends didn't find or I didn't use the appropriate term. > > Any hint will be appreciated. > -- > Gilles Lenfant > Hardly my field but how about:- https://pypi.python.org/pypi/requests-toolbelt/0.3.1 https://pypi.python.org/pypi/multipart/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rantingrickjohnson at gmail.com Mon Aug 3 11:42:41 2015 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 3 Aug 2015 08:42:41 -0700 (PDT) Subject: Python 3 May Become Relevant Now In-Reply-To: References: <93cb8798-6ff3-453b-84ba-d0efa5fcd246@googlegroups.com> Message-ID: <608e340d-c7c9-4f32-98f6-c70aa1059e4a@googlegroups.com> On Sunday, August 2, 2015 at 9:45:51 PM UTC-5, Chris Angelico wrote: > How do you know it was written today, if you didn't click it? Because i possess skills you can hardly fathom. There are always loopholes; back doors; knot holes; key holes; cracks; crevices; tells; Freudian slips; little white lies; and yes, even arthropods creeping and crawling in dark corners fitted with multiple visual sensors -- all one need do is discover them, and then *EXPLOIT* them! From rosuav at gmail.com Mon Aug 3 11:58:58 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Aug 2015 01:58:58 +1000 Subject: Python 3 May Become Relevant Now In-Reply-To: <608e340d-c7c9-4f32-98f6-c70aa1059e4a@googlegroups.com> References: <93cb8798-6ff3-453b-84ba-d0efa5fcd246@googlegroups.com> <608e340d-c7c9-4f32-98f6-c70aa1059e4a@googlegroups.com> Message-ID: On Tue, Aug 4, 2015 at 1:42 AM, Rick Johnson wrote: > On Sunday, August 2, 2015 at 9:45:51 PM UTC-5, Chris Angelico wrote: >> How do you know it was written today, if you didn't click it? > > Because i possess skills you can hardly fathom. There are always > loopholes; back doors; knot holes; key holes; cracks; crevices; > tells; Freudian slips; little white lies; and yes, even arthropods > creeping and crawling in dark corners fitted with multiple visual > sensors -- all one need do is discover them, and then *EXPLOIT* them! And you trust these more than you trust HTTP. Weird. ChrisA From gilles.lenfant at gmail.com Mon Aug 3 13:15:26 2015 From: gilles.lenfant at gmail.com (Gilles Lenfant) Date: Mon, 3 Aug 2015 10:15:26 -0700 (PDT) Subject: Parsing multipart HTTP response In-Reply-To: References: <648c131d-6315-4f83-88f0-b87bf3b530a9@googlegroups.com> Message-ID: <85fe942e-5318-4343-aa23-04033b7d270c@googlegroups.com> Le lundi 3 ao?t 2015 17:39:57 UTC+2, Mark Lawrence a ?crit?: > On 03/08/2015 16:01, Gilles Lenfant wrote: > > Hi, > > > > I searched without succeeding a Python resource that is capable of parsing an HTTP multipart/mixed response stream, preferably as a generator that yields headers + content for each part. > > > > Google and friends didn't find or I didn't use the appropriate term. > > > > Any hint will be appreciated. > > -- > > Gilles Lenfant > > > > Hardly my field but how about:- > > https://pypi.python.org/pypi/requests-toolbelt/0.3.1 > https://pypi.python.org/pypi/multipart/ > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence Thanks Mark, "multipart" is close to what I need and will give me some inpiration. Unfortunately, it works for multipart/form-data server-side handling, when I'm searching for a multipart/mixed client side handling of a response. In addition, it does not yield the headers specific to each data chunk from the response, and I need those headers. To be more specific, I'm buiding with the excellent "requests" lib and Python 2.7 (sorry, I can't go to Python 3.x at the moment) a client library for the documents database MarkLogic 8 that provides some APIs with multipart/mixed responses like this one: http://docs.marklogic.com/REST/POST/v1/eval In other words I need something that may be used like this : response = requests.post(some_uri, params=some_params, stream=True) if response.headers['content-type'].startswith('multipart/mixed'): boundary = parse_boundary(response.headers['content-type']) generator = iter_multipart_response(response, boundary) for part_headers, part_body in generator: # I'm consuming parsed headers and bodies from response # In my application code Cheers -- Gilles Lenfant From tjreedy at udel.edu Mon Aug 3 14:11:27 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 3 Aug 2015 14:11:27 -0400 Subject: how to determine for using c extension or not ? In-Reply-To: <55BF67CB.5030604@gmail.com> References: <55BF67CB.5030604@gmail.com> Message-ID: On 8/3/2015 9:08 AM, umedoblock wrote: Posting three times under two different names is not polite. Please to not repeat. > I use bisect module. > bisect module developer give us c extension as _bisect. We call that a C accelerator. > If Python3.3 use _bisect, _bisect override his functions in bisect.py. An accelerator may override either some or all functions. In this case, Lib/bisect.py ends with try: from _bisect import * except ImportError: pass For CPython, I expect that all 4 similar functions (and two synonyms) get replaced. > now, I use id() function to determine for using c extension or not. You should not care. If you think there is an undocumented difference in behavior, ask here if it is a bug. I expect that that test/test_bisect.py runs the same tests on both versions. We have a test helper function for such situations. It blocks the import of the accelerator so that the Python version can be tested. >>>> import bisect >>>> id(bisect.bisect) > 139679893708880 >>>> import _bisect >>>> id(_bisect.bisect) > 139679893708880 > > they return 139679893708880 as id. > so i believe that i use c extension. The bisect and _bisect modules are different objects. Since they and their global namespace exist simultaneously, then yes, the above says that both have the name 'bisect' bound to the C-coded built-in version. -- Terry Jan Reedy From deusex12345678 at gmail.com Mon Aug 3 15:14:27 2015 From: deusex12345678 at gmail.com (deus ex) Date: Mon, 3 Aug 2015 21:14:27 +0200 Subject: Usage of P(C)ython Logo for Coffee Mug In-Reply-To: References: <201507291555.t6TFtaCs022990@fido.openend.se> Message-ID: Ok great thanks for help, so for non-commercial use it looks ok! Dex 2015-07-29 21:36 GMT+02:00 Zachary Ware : > On Wed, Jul 29, 2015 at 2:01 PM, Terry Reedy wrote: > > On 7/29/2015 11:55 AM, Laura Creighton wrote: > >> We have SVG versions here: > >> https://www.python.org/community/logos/ > > > > See Guidelines for Use near the bottom, which as an *ask first* link if > in > > doubt. Given that your coffee cup would be suitable for use while > > programming Python, I would expect no difficultly. > > See also http://www.cafepress.com/pydotorg (linked from the logo page > linked above), which includes coffee mugs for both logo styles. > > -- > Zach > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From orgnut at yahoo.com Mon Aug 3 15:56:23 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Mon, 03 Aug 2015 12:56:23 -0700 Subject: Most pythonic way of rotating a circular list to a canonical point In-Reply-To: References: Message-ID: On 08/02/2015 01:58 PM, Joonas Liik wrote: > I have this feeling that you would get a lot more useful anwsers if > you were to describe your actual problem in stead of what you think > the solution is. There might be other, better solutions but since we > know so little about what you are doing we will likely never find them > by just guessing.. > Sorry if I wasn't clear. This is not _my_ problem, this was intended to re-state the OP's fundamental problem. And the quoted text was the OP's original message. I felt that most (anyway many) responders here were missing this point. This is what I saw as the OP's underlying problem, but as I also said in my message, my interpretation certainly could be wrong. :-) -=- Larry -=- From josephbigler at gmail.com Mon Aug 3 18:46:33 2015 From: josephbigler at gmail.com (josephbigler at gmail.com) Date: Mon, 3 Aug 2015 15:46:33 -0700 (PDT) Subject: I'm a newbie and I'm stumped... In-Reply-To: References: Message-ID: On Saturday, August 1, 2015 at 11:59:14 AM UTC-4, Dwight GoldWinde wrote: > Please help. > > > I am running Python 3.4 on my Mac mini, OS X 10.10.2, using Coderunner 2 as my editor. > > > Here's the code: > > #!/usr/bin/env python3 > word = (input('Enter a word ')) > > > When running this inside of Coderunner, I get the follow error, after entering the word 'serendipity': > > > > Enter a word serendipity > > Traceback (most recent call last): > > File "test short.py", line 2, in > > word = (input('Enter a word ')) > > File "", line 1, in > > NameError: name 'serendipity' is not defined If you want to run this in Python 3, try this CodeRunner->Preferences->Languages->Run Command edit "python $filename" to "python3 $filename" It appears coderunner 2 is using Python 2.7.1 Here's where I found the answer, from someone who had a similar issue. Please let us know either way if it solved the problem. http://stackoverflow.com/questions/19797616/coderunner-uses-old-2-71-version-of-python-instead-of-3-2-on-osx-10-7-5 From Dwight at GoldWinde.com Mon Aug 3 19:57:32 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Tue, 04 Aug 2015 07:57:32 +0800 Subject: How to import a function from another module... Message-ID: I am trying to import a function defined in another module. The code is this: name = 'Jim' sex = 'm' coach = 'Dwight' import importlib sentence = 'Hi, there, ' + name + '. My name is ' + coach + '. I will be your coach today.' importlib.import_module ('humprint', 'Macintosh HD/Users/dwightgoldwindex/Documents/Active Information/ACL/Testing Code/Simulate typing.py') The response and error message I receive is this: Traceback (most recent call last): File "Intro.py", line 7, in importlib.import_module ('humprint', 'Macintosh HD/Users/dwightgoldwindex/Documents/Active Information/ACL/Testing Code/Simulate typing.py') File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/importlib/_ _init__.py", line 109, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 2249, in _gcd_import File "", line 2199, in _sanity_check SystemError: Parent module 'Macintosh HD/Users/dwightgoldwindex/Documents/Active Information/ACL/Testing Code/Simulate typing.py' not loaded, cannot perform relative import How can I change my code to have the import work properly? Thank you. BIG SMILE... Always, Dwight www.3forliving.key.to (video playlist on YouTube) www.couragebooks.key.to (all my books on Amazon) -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Mon Aug 3 21:24:23 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 04 Aug 2015 11:24:23 +1000 Subject: How to import a function from another module... References: Message-ID: <55c01448$0$1648$c3e8da3$5496439d@news.astraweb.com> On Tue, 4 Aug 2015 09:57 am, Dwight GoldWinde wrote: > I am trying to import a function defined in another module. You can't use spaces in the name of importable Python modules: change the name from "Simulate typing.py" to "simulate_python.py". You can use spaces in file names if they are only used as a runnable script and not imported. Then use this: from simulate_python import humprint There's no need to use importlib. You may need to arrange for the simulate_python file to be placed somewhere in the Python search path. Do you need help with that? What you are trying to do with importlib is fight the language. Your life will be much simpler if you work within the parameters of how the language is designed to work. -- Steven From gcviola at gmail.com Mon Aug 3 22:37:47 2015 From: gcviola at gmail.com (Bill) Date: Tue, 4 Aug 2015 11:37:47 +0900 Subject: Uninstall Message-ID: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> How do I uninstall Python from a Mac? From toddrjen at gmail.com Tue Aug 4 01:22:52 2015 From: toddrjen at gmail.com (Todd) Date: Tue, 4 Aug 2015 07:22:52 +0200 Subject: Python 3 May Become Relevant Now In-Reply-To: <608e340d-c7c9-4f32-98f6-c70aa1059e4a@googlegroups.com> References: <93cb8798-6ff3-453b-84ba-d0efa5fcd246@googlegroups.com> <608e340d-c7c9-4f32-98f6-c70aa1059e4a@googlegroups.com> Message-ID: On Aug 3, 2015 17:46, "Rick Johnson" wrote: > > On Sunday, August 2, 2015 at 9:45:51 PM UTC-5, Chris Angelico wrote: > > How do you know it was written today, if you didn't click it? > > Because i possess skills you can hardly fathom. There are always > loopholes; back doors; knot holes; key holes; cracks; crevices; > tells; Freudian slips; little white lies; and yes, even arthropods > creeping and crawling in dark corners fitted with multiple visual > sensors -- all one need do is discover them, and then *EXPLOIT* them! > -- That sounds like a lot more work than simply clicking a link. -------------- next part -------------- An HTML attachment was scrubbed... URL: From c.buhtz at posteo.jp Tue Aug 4 04:41:52 2015 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Tue, 4 Aug 2015 10:41:52 +0200 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <55bf6ebf$0$1650$c3e8da3$5496439d@news.astraweb.com> References: <87k2teq9tb.fsf@Equus.decebal.nl> <85k2tdlxbg.fsf@benfinney.id.au> <55bf6ebf$0$1650$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3mlqMC2y3pzFpVj@dovecot04.posteo.de> Dear Cecil, I subscribed to late to answer to your top-post in that thread. I had the same topic for myself in the last months and tried a lot of things. In your situation I would prefere the INI-file format, too. But doen't user 'configparser' for that. As other fellows described it's a bad solution because option order and comments are not preserved when writing back. It is a quite incomplete implementation of human-readable-config files. Use 'configobj'[1][2] which can be handled very easy, too. You can have comments and everything you want in there. [1] https://pypi.python.org/pypi/configobj [2] https://github.com/DiffSK/configobj -- -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1 mQENBFQIluABCACfPwAhRAwFD3NXgv5CtVUGSiqdfJGVViVBqaKd+14E0pASA0MU G0Ewj7O7cGy/ZIoiZ0+lIEZmzJKHfuGwYhXjR/PhnUDrQIHLBvh9WuD6JQuULXfH kXtVm/i9wm76QAcvr2pwYgNzhcJntUHl2GcgnInYbZDeVmg+p9yIPJjuq73/lRS3 0/McgNoFOBhKK/S6STQuFyjr9OyJyYd1shoM3hmy+kg0HYm6OgQBJNg92WV9jwGe GzlipvEp2jpLwVsTxYir2oOPhfd9D1fC9F/l/3gXbfjd5GIIVrZFq2haZmoVeJ33 LJxo3RA5Tf9LoUeels1b4s9kFz6h7+AHERUpABEBAAG0IUNocmlzdGlhbiBCdWh0 eiA8YnVodHpAcG9zdGVvLmRlPokBPgQTAQIAKAUCVAiW4AIbAwUJAeEzgAYLCQgH AwIGFQgCCQoLBBYCAwECHgECF4AACgkQZLsXsAdRqOxNUAf/V/hDA5zGDpySuCEj DhjiVRK74J9Wd8gfH0WAf1Co5HZ24wZH8rgOIVIgXw8rWkOw/VA6xfdfT+64xjTY Fhkpbrk199nDzp72F7Jc4NC+x8xac2e3rK5ifSWhZx7L5A32pGYE+d16m3EEqImK D4gcZl38x9zdUnD4hHyXkIPz1uCfuMuGgWEnaUk4Wbj41CBZr3O0ABue6regV15U jaes8r+B8iCcY+0yP2kse+3iaCaMqNv5FgQZ9+b2Cql8pFkZJVtBVUw4GW3DWZJi du0O/YrC9TgS+xY9ht/MD2qSHwjcK1sdImjqBO7xP8TIOwKeYyDvGKnSO3EJ/sSA UPGEPrkBDQRUCJbgAQgA0k/Qg67CCUJE2/zuxBEoK4wLJpDRJzh8CQPZpjWx8VP0 KL892jwfxymXn8KNhuy1SgCBFSeV9jg4VZNWDlUGJc2lo82ajr9PzIsrQwu4lf0B zrUWV5hWepKu/kb8uSjx58YYfx0SFz4+9akX3Wwu9TUHntzL5Gk3Q26nnsr1xEJ+ VEumvCH9AE0Tk0K7dQpJ2/JcLuO+uhrpd/lHFDYVN5NsG3P015uFOkDI6N/xNFCj v95XNR93QlfKpK3qWlFGescfG+o/7Ub6s67/i/JoNbw0XgPEHmQfXpD7IHO4cu+p +ETb11cz+1mmi96cy98ID+uTiToJ8G//yD9rmtyxoQARAQABiQElBBgBAgAPBQJU CJbgAhsMBQkB4TOAAAoJEGS7F7AHUajs6sQH/iKs6sPc0vkRJLfbwrijZeecwCWF blo/jzIQ8jPykAj9SLjV20Xwqg3XcJyko8ZU6/zuRJq9xjlv9pZr/oVudQAt6v+h 2Cf4rKEjmau483wjMV2xjTXQhZi9+ttDbia4fgdmGtKsOicn5ae2fFXcXNPu3RiW sZKifWdokA6xqMW6iIG9YjjI5ShxngHWp2xfPscBFMDRtFOMags/Yx+YvwoyEZ4A dURYMFHFqpwILEc8hIzhRg1gq40AHbOaEdczS1Rr3T7/gS6eBs4u6HuY5g2Bierm lLjpspFPjMXwJAa/XLOBjMF2vsHPrZNcouNKkumQ36yq/Pm6DFXAseQDxOk= =PGP9 -----END PGP PUBLIC KEY BLOCK----- From info at egenix.com Tue Aug 4 04:43:05 2015 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 04 Aug 2015 10:43:05 +0200 Subject: ANN: eGenix Talks & Videos: Python Idioms Talk Message-ID: <55C07B19.5090904@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix Talks & Videos: Python Idioms Talk EuroPython 2015 This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/EuroPython-2015-Python-Idioms.html ________________________________________________________________________ EuroPython 2015 in Bilbao, Basque Country, Spain Marc-Andr? Lemburg, Python Core Developer, one of the EuroPython 2015 organizers and Senior Software Architect, held a talk at EuroPython focusing on programmers just starting with Python. We have now turned the talk into a video presentations for easy viewing and also released the presentation slides. ________________________________________________________________________ Python Idioms to help you write good code Talk given at the EuroPython 2015 conference in Bilbao, Basque Country, Spain, presenting Python idioms which are especially useful for programmers new to Python. Talk video and slides: http://www.egenix.com/library/presentations/EuroPython-2015-Python-Idioms/ Python focuses a lot on writing readable code and also tries to make solutions obvious, but this doesn?t necessarily mean that you cannot write unreadable code or design your code in ways which makes it hard to extend or maintain. The talk shows some useful idioms to apply when writing Python code, how to structure your modules and also goes into details on which techniques to use and which to think about twice, based on 20 years of experience writing Python. -- Marc-Andr? Lemburg More interesting eGenix presentations are available in the presentations and talks community section of our website. http://www.egenix.com/library/presentations/ ________________________________________________________________________ PYTHON COACHING AND CONSULTING If you are interested in learning more about these advanced techniques, eGenix now offers Python project coaching and consulting services to give your project teams advice on how to design Python applications, successfully run projects, or find excellent Python programmers. Please contact our eGenix Sales Team for information. http://www.egenix.com/services/ ________________________________________________________________________ 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 project 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, Aug 04 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From jeanmichel at sequans.com Tue Aug 4 05:11:34 2015 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 4 Aug 2015 11:11:34 +0200 (CEST) Subject: Most Pythonic way to store (small) configuration In-Reply-To: <87k2teq9tb.fsf@Equus.decebal.nl> Message-ID: <1077766544.14627.1438679494348.JavaMail.root@sequans.com> ----- Original Message ----- > From: "Cecil Westerhof" > To: python-list at python.org > Sent: Sunday, 2 August, 2015 12:11:28 PM > Subject: Most Pythonic way to store (small) configuration > > There are a lot of ways to store configuration information: > - conf file > - xml file > - database > - json file > - and possible a lot of other ways > > I want to write a Python program to display cleaned log files. I do > not think I need a lot of configuration to be stored: > - some things relating to the GUI > - default behaviour > - default directory > - log files to display, including some info > - At least until where it was displayed > > Because of this I think a human readable file would be best. > Personally I do not find XML very readable. So a conf or json file > looks the most promising to me. And I would have a slight preference > for a json file. > > Any comments, thoughts or tips? > > -- > Cecil Westerhof > Senior Software Engineer > LinkedIn: http://www.linkedin.com/in/cecilwesterhof > -- > https://mail.python.org/mailman/listinfo/python-list Did you consider using "serpent" ? It's a python serializer than can produce human readable text format. If your configuration is a dictionary for instance, there's possibly no work to do. see for yourself at : https://pypi.python.org/pypi/serpent Regards, JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From miloshzorica at gmail.com Tue Aug 4 06:39:07 2015 From: miloshzorica at gmail.com (milos zorica) Date: Tue, 4 Aug 2015 07:39:07 -0300 Subject: Uninstall In-Reply-To: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> Message-ID: you can't fully uninstall python from OSX, linux, BSD as there are many python dependent system tools -------------- next part -------------- An HTML attachment was scrubbed... URL: From ahsan.ch23 at gmail.com Tue Aug 4 07:31:05 2015 From: ahsan.ch23 at gmail.com (Ahsan Chauhan) Date: Tue, 4 Aug 2015 17:01:05 +0530 Subject: Problem in IDLE setup Message-ID: Respected Sir/Madam, I would like to bring it to your notice that IDLE's executable file is not working properly in Python3.5.0. So please look into this. Regards Ahsan Chauhan -------------- next part -------------- An HTML attachment was scrubbed... URL: From Dwight at GoldWinde.com Tue Aug 4 08:35:57 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Tue, 04 Aug 2015 20:35:57 +0800 Subject: How to import a function from another module... Message-ID: > Thank you, Steven. > I am a newbie with Python? so I really want to learn how to do it the easy > way. > Yes, could you tell me how to put the py.file that contains the function > in the Python search path??? > BIG SMILE... > Always, Dwight > www.3forliving.key.to (video playlist on YouTube) > www.couragebooks.key.to (all my books on Amazon) > On 8/4/15, 9:24 AM, "Steven D'Aprano" wrote: >> >On Tue, 4 Aug 2015 09:57 am, Dwight GoldWinde wrote: >> > >>> >> I am trying to import a function defined in another module. >> > >> >You can't use spaces in the name of importable Python modules: change the >> >name from "Simulate typing.py" to "simulate_python.py". You can use spaces >> >in file names if they are only used as a runnable script and not imported. >> > >> >Then use this: >> > >> >from simulate_python import humprint >> > >> >There's no need to use importlib. >> > >> >You may need to arrange for the simulate_python file to be placed >> >somewhere >> >in the Python search path. Do you need help with that? >> > >> >What you are trying to do with importlib is fight the language. Your life >> >will be much simpler if you work within the parameters of how the language >> >is designed to work. >> > >> > >> > >> >-- >> >Steven >> > >> >-- >> >https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonas at wielicki.name Tue Aug 4 08:42:22 2015 From: jonas at wielicki.name (Jonas Wielicki) Date: Tue, 4 Aug 2015 14:42:22 +0200 Subject: __main__ vs official module name: distinct module instances In-Reply-To: <20150802035327.GA53036@cskk.homeip.net> References: <20150802035327.GA53036@cskk.homeip.net> Message-ID: <55C0B32E.7090900@wielicki.name> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 On 02.08.2015 05:53, Cameron Simpson wrote: > When invoked this way, the module cs.app.maildb that is being > executed is actually the module named "__main__". If some other > piece of code imports "cs.app.maildb" they get a _different_ > instance of the module. In the same program! And how did it cause > me trouble? I am monkey patching my module for debug purposes, and > that monkey patcher imports the module by name. So I was monkey > patching cs.app.maildb, and _not_ patching __main__. And thus not > seeing any effect from the patch. > So I guess you just explained my issues with Flask and trying to wrap an application up in __main__.py. Thank you. And also, +1 on your proposal, please bring it to -ideas. regards, jwi -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCgAGBQJVwLMlAAoJEMBiAyWXYliKJSAP/i+UUJpQyVZVhTYAGax3ZPak MWhdvGpQhq5iJIDImBJCGtiLtt+8Qy/UuJC4sAbz080XRJs9V3goYWCdZABpynln VOCbd1vvTHadmOxTjX98D++bIg4ZFvaWFruk/TYcx35GtbQb52/LH6nq4b8EpMY+ 1wFdMQ8ccUixiMbvEeNtgRWw4g2fG5LGceiT1Hs9ThVlin5di0jjAz4MrZa49eNt tdTMQBaoap+yL1VXU10e+2vF8EiqtmfQwrRME2WLglJcYw8p2WMe+FLHvGVpKu9+ nVkZfWHBjOA9Ym4HdugCCiQPW12R/kuExrixjw6FYKeb7QXaF67yjWUXVOAW2XcP oaTIk4+U4WoeMReVyRzyWLPShKKaoR5djJbpKFW8GzD1XHulh/CWWuL/R1rt+LSF e5ME6HvKVZoh+4QT4CcL6K8Gv+w5RbgFXPidREuZzavXCQVo2IoCOs2JCClBu4Gy zy8tYk8gt5+8bub74Bkm6+FhdwMNQgKRCpXkgoqj5EgKEkeWiPl0d89geUq6PC0x boSKVDn1rg2OmQWSjqKs+rUHK6XSVt4C+P6pb/lW9zsAs87AfQcjdrG6xaC2+dKo /YeZVvq0Y1PCf6IIjPGp5DsKkN1bJtvUPGFH8ZFY+xZ/nHYI/UToKoo7cF5J2xf/ 0h2t4lfozMVs9fswpHlz =ITon -----END PGP SIGNATURE----- From umedoblock at gmail.com Tue Aug 4 09:41:44 2015 From: umedoblock at gmail.com (umedoblock) Date: Tue, 04 Aug 2015 22:41:44 +0900 Subject: how to determine for using c extension or not ? In-Reply-To: References: <55BF67CB.5030604@gmail.com> Message-ID: <55C0C118.8000705@gmail.com> On 2015?08?04? 03:11, Terry Reedy wrote: > Posting three times under two different names is not polite. Please to > not repeat. sorry... > You should not care. If you think there is an undocumented difference > in behavior, ask here if it is a bug. I don't think a bug in this question. > I expect that that test/test_bisect.py runs the same tests on both > versions. We have a test helper function for such situations. I didn't know test/support.py and support.import_fresh_module() function. I will use this function if I write some C accelerator. thanks. From umedoblock at gmail.com Tue Aug 4 09:59:24 2015 From: umedoblock at gmail.com (umedoblock) Date: Tue, 04 Aug 2015 22:59:24 +0900 Subject: how to determine for using c extension or not ? In-Reply-To: References: <55bf6e6f$0$1650$c3e8da3$5496439d@news.astraweb.com> <55BF7457.8030704@gmail.com> <55BF8154.2030705@gmail.com> Message-ID: <55C0C53C.2010404@gmail.com> On 2015?08?04? 00:05, Oscar Benjamin wrote: > On Mon, 3 Aug 2015 at 15:58 umedoblock > wrote: > > > I use "bisect.bisect.__module__" sentence to determine for using c > extension or not. > > > Why do you want to know if it uses the C extension? It shouldn't really > matter. I wrote some C accelerator. I sometimes want to know that python3.x in another machine use C accelerator or not. Because if python3.x doesn't use C acc, I shuold make C acc for another machine. Therefore I'd like to determine for using C acc or not. And I want to know that another machine use C acc or not to use a simple script. But I had felt not good idea about my way to use id(). So I ask this mailing list. > > -- > Oscar From invalid at invalid.invalid Tue Aug 4 10:29:11 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 4 Aug 2015 14:29:11 +0000 (UTC) Subject: Uninstall References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> Message-ID: On 2015-08-04, milos zorica wrote: > you can't fully uninstall python from OSX, linux, BSD as there are many > python dependent system tools Well, technically you _can_ uninstall Python if you really want, but all sorts of things will stop working. In some cases, it's very hard to recover from that situation. Among the things that will stop working on some flavors of Linux are the system utilities you normally use to install things like Python. -- Grant Edwards grant.b.edwards Yow! World War III? at No thanks! gmail.com From marco.nawijn at colosso.nl Tue Aug 4 10:53:21 2015 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Tue, 4 Aug 2015 07:53:21 -0700 (PDT) Subject: Most Pythonic way to store (small) configuration In-Reply-To: <87k2teq9tb.fsf@Equus.decebal.nl> References: <87k2teq9tb.fsf@Equus.decebal.nl> Message-ID: <663ad259-48e0-4eec-a946-7cd03805ddb1@googlegroups.com> On Sunday, August 2, 2015 at 12:14:51 PM UTC+2, Cecil Westerhof wrote: > There are a lot of ways to store configuration information: > - conf file > - xml file > - database > - json file > - and possible a lot of other ways > > I want to write a Python program to display cleaned log files. I do > not think I need a lot of configuration to be stored: > - some things relating to the GUI > - default behaviour > - default directory > - log files to display, including some info > - At least until where it was displayed > > Because of this I think a human readable file would be best. > Personally I do not find XML very readable. So a conf or json file > looks the most promising to me. And I would have a slight preference > for a json file. > > Any comments, thoughts or tips? > > -- > Cecil Westerhof > Senior Software Engineer > LinkedIn: http://www.linkedin.com/in/cecilwesterhof Why not use Python files itself as configuration files? I have done so several times and I am very pleased with it. I have tried both INI and JSON, but in the end always settled on using Python itself. If I have to share the configuration information with other languages (like C++ or Javascript) I use JSON as the For those who are interested, I provide a short summary below on how I handle configuration files. The scenario I want to support is that there is a hierarchical set of configuration files (as typically found in Unix like systems) that can be stored in a system wide folder (like /etc/app), in a user folder (like /home/user/.config/app) and in a local folder. Each configuration file has a fixed name, not necessarily ending in ".py". So for example, the name of the configuration file is "config.myapp". Next I start looking for the existence of these files and once I find them I start merging all the configuration settings into one Python dictionary. The function that I use can be found below. (you need proper import statements, but this is standard Python). def load_config(config_file, checked=False): '''Small utility function to load external configuration files. ''' if checked is False: if not isfile(config_file) or islink(config_file): msg = 'Config file "%s" does not exist.' LOGGER.warning(msg) return {} # Load the module object; we use the imp.load_source function because # the module configuration typically has a non-standard file extension # (by default the file is called "config.myapp") module_name = 'm%s' % str(uuid.uuid1()).replace('-', '') # Prevent bytecode generation for configuration files sys.dont_write_bytecode = True config_module = imp.load_source(module_name, config_file) # Continue with bytecode generation for other normal modules sys.dont_write_bytecode = False if not hasattr(config_module, '__config__'): msg = 'Missing "__config__" attribute in configuration file.' LOGGER.warning(msg) return {} else: return config_module.__config__ From miloshzorica at gmail.com Tue Aug 4 11:01:31 2015 From: miloshzorica at gmail.com (milos zorica) Date: Tue, 4 Aug 2015 12:01:31 -0300 Subject: Uninstall In-Reply-To: References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> Message-ID: that's my point -------------- next part -------------- An HTML attachment was scrubbed... URL: From marco.nawijn at colosso.nl Tue Aug 4 11:04:40 2015 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Tue, 4 Aug 2015 08:04:40 -0700 (PDT) Subject: How to import a function from another module... In-Reply-To: References: Message-ID: <6ff85c64-4dc7-4eeb-83d2-f6a766844c51@googlegroups.com> On Tuesday, August 4, 2015 at 3:11:41 PM UTC+2, Dwight GoldWinde wrote: > Thank you, Steven. > I am a newbie with Python? so I really want to learn how to do it the easy > way. > Yes, could you tell me how to put the py.file that contains the function > in the Python search path??? > > > > BIG SMILE... > > Always, Dwight > > > www.3forliving.key.to (video playlist on YouTube) > www.couragebooks.key.to (all my books on Amazon) > > > > > > > > > On 8/4/15, 9:24 AM, "Steven D'Aprano" wrote: > > >On Tue, 4 Aug 2015 09:57 am, Dwight GoldWinde wrote: > > > >> I am trying to import a function defined in another module. > > > >You can't use spaces in the name of importable Python modules: change the > >name from "Simulate typing.py" to "simulate_python.py". You can use spaces > >in file names if they are only used as a runnable script and not imported. > > > >Then use this: > > > >from simulate_python import humprint > > > >There's no need to use importlib. > > > >You may need to arrange for the simulate_python file to be placed > >somewhere > >in the Python search path. Do you need help with that? > > > >What you are trying to do with importlib is fight the language. Your life > >will be much simpler if you work within the parameters of how the language > >is designed to work. > > > > > > > >--? > >Steven > > > >--? > >https://mail.python.org/mailman/listinfo/python-list Hi Dwight, There are at least two ways to manipulate your search path, one from within Python, one by setting/updating an environmental variable in your operating system. 1. Dynamically add a search path in Python First note that if you want to know which parts are currently in the Python search path you can do the following (note that >>> means type it in the Python shell and I am using Python 2 syntax) >>> import sys >>> for path in sys.path: ... print path So, if you want to add a folder to your search path, in your script add the following *before* you access attributes etc. from the module your are trying to use: sys.path.append("the_path_that_contains_the_py_file") # Import stuff from the py file here The downside of this approach is that you have to do this in every script that accesses information from your ".py" file. If you want to do this once and for all, use the second method 2. Setting/updating the environment variable You can use the environment variable PYTHONPATH to inform Python on which search paths it should use (besides the default ones). From irmen.NOSPAM at xs4all.nl Tue Aug 4 13:06:08 2015 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Tue, 4 Aug 2015 19:06:08 +0200 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <663ad259-48e0-4eec-a946-7cd03805ddb1@googlegroups.com> References: <87k2teq9tb.fsf@Equus.decebal.nl> <663ad259-48e0-4eec-a946-7cd03805ddb1@googlegroups.com> Message-ID: <55c0f103$0$2959$e4fe514c@news2.news.xs4all.nl> On 4-8-2015 16:53, marco.nawijn at colosso.nl wrote: > Why not use Python files itself as configuration files? It could create a security risk if the config files are user-editable. (it will make it easy to inject code into your application) Irmen From sohcahtoa82 at gmail.com Tue Aug 4 14:31:50 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Tue, 4 Aug 2015 11:31:50 -0700 (PDT) Subject: Uninstall In-Reply-To: References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> Message-ID: <7cbf35cc-9ac2-4d76-a06b-c5436d21f2de@googlegroups.com> On Tuesday, August 4, 2015 at 7:29:29 AM UTC-7, Grant Edwards wrote: > On 2015-08-04, milos zorica wrote: > > > you can't fully uninstall python from OSX, linux, BSD as there are many > > python dependent system tools > > Well, technically you _can_ uninstall Python if you really want, but > all sorts of things will stop working. In some cases, it's very hard > to recover from that situation. Among the things that will stop > working on some flavors of Linux are the system utilities you normally > use to install things like Python. > > -- > Grant Edwards grant.b.edwards Yow! World War III? > at No thanks! > gmail.com milos: "You can't uninstall Python because it will break things" Grant: "Actually, you CAN uninstall Python, but it will break things" I really fucking hate how pedantic some of the people on this mailing list are. milos wasn't wrong. You just chose to take his message too literally. I thought it was pretty clear that when milos said "can't", he really meant "shouldn't". From marco.nawijn at colosso.nl Tue Aug 4 14:37:57 2015 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Tue, 4 Aug 2015 11:37:57 -0700 (PDT) Subject: Most Pythonic way to store (small) configuration In-Reply-To: <55c0f103$0$2959$e4fe514c@news2.news.xs4all.nl> References: <87k2teq9tb.fsf@Equus.decebal.nl> <663ad259-48e0-4eec-a946-7cd03805ddb1@googlegroups.com> <55c0f103$0$2959$e4fe514c@news2.news.xs4all.nl> Message-ID: On Tuesday, August 4, 2015 at 7:06:33 PM UTC+2, Irmen de Jong wrote: > On 4-8-2015 16:53, marco.nawijn at colosso.nl wrote: > > Why not use Python files itself as configuration files? > > It could create a security risk if the config files are user-editable. > (it will make it easy to inject code into your application) > > Irmen Yes, I am aware of the security risk, but right now I am not too worried about it. To be honest, JSON would be my preferred configuration file format, but as others already mentioned, there is no standard way of adding comments to a JSON file. Marco From ben+python at benfinney.id.au Tue Aug 4 15:59:12 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 05 Aug 2015 05:59:12 +1000 Subject: Most Pythonic way to store (small) configuration References: <87k2teq9tb.fsf@Equus.decebal.nl> <663ad259-48e0-4eec-a946-7cd03805ddb1@googlegroups.com> Message-ID: <85y4hqkepb.fsf@benfinney.id.au> marco.nawijn at colosso.nl writes: > Why not use Python files itself as configuration files? Because configuration data will be user-editable. (If it's not user-editable, that is itself a poor design choice.) If you allow executable code to be user-edited, that opens your program to arbitrary injection of executable code. Your program becomes wide open for security exploits, whether through malicious or accidental bugs, and simple human error can lead to arbitrary-scope damage to the user's system. On another dimension, configuration files specifying the behaviour of the system are much more useful if their format is easily parsed and re-worked by tools the user chooses. Your program should not be the only tool (and Python should not be the only language) that can read and/or write the configuration data with straightfoward data manipulation. So a complex full-blown programming language like Python is a poor choice for configuration data for that reason, too. Much better to choose a tightly-defined, limited-scope configuration data format that you can be confident any user cannot employ to run arbitrary code. -- \ ?For myself, I am an optimist ? it does not seem to be much use | `\ being anything else.? ?Winston Churchill, 1954-11-09 | _o__) | Ben Finney From breamoreboy at yahoo.co.uk Tue Aug 4 16:01:51 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 4 Aug 2015 21:01:51 +0100 Subject: Uninstall In-Reply-To: <7cbf35cc-9ac2-4d76-a06b-c5436d21f2de@googlegroups.com> References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> <7cbf35cc-9ac2-4d76-a06b-c5436d21f2de@googlegroups.com> Message-ID: On 04/08/2015 19:31, sohcahtoa82 at gmail.com wrote: > On Tuesday, August 4, 2015 at 7:29:29 AM UTC-7, Grant Edwards wrote: >> On 2015-08-04, milos zorica wrote: >> >>> you can't fully uninstall python from OSX, linux, BSD as there are many >>> python dependent system tools >> >> Well, technically you _can_ uninstall Python if you really want, but >> all sorts of things will stop working. In some cases, it's very hard >> to recover from that situation. Among the things that will stop >> working on some flavors of Linux are the system utilities you normally >> use to install things like Python. >> >> -- >> Grant Edwards grant.b.edwards Yow! World War III? >> at No thanks! >> gmail.com > > milos: "You can't uninstall Python because it will break things" > Grant: "Actually, you CAN uninstall Python, but it will break things" > > I really fucking hate how pedantic some of the people on this mailing list are. > > milos wasn't wrong. You just chose to take his message too literally. I thought it was pretty clear that when milos said "can't", he really meant "shouldn't". > The simple solution is not to subscribe. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From Cecil at decebal.nl Tue Aug 4 16:19:31 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Tue, 04 Aug 2015 22:19:31 +0200 Subject: Linux script to get most expensive processes Message-ID: <87twsehkmk.fsf@Equus.decebal.nl> Under Linux I like to get the most expensive processes. The two most useful commands are: ps -eo pid,user,pcpu,args --sort=-pcpu and: ps -eo pid,user,pcpu,args --sort=-vsize In my case I am only interested in the seven most expensive processes. For this I wrote the following script. ======================================================================== #!/usr/bin/env python3 import subprocess import sys def give_output(param): output = subprocess.check_output(([ 'ps', '--columns={0}' .format(max_line_length), '-eo', 'pid,user,start_time,{0},args'.format(param), '--sort=-{0}' .format(param) ])).splitlines() for line in output[:no_of_lines]: print(line.decode('utf-8')) accepted_params = { 'pcpu', 'rss', 'size', 'time', 'vsize', } current_platform = sys.platform max_line_length = 200 needed_platform = 'linux' no_of_lines = 8 # One extra for the heading if current_platform != needed_platform: raise Exception('Needs a {0} platform, got {1} platform'. format(needed_platform, current_platform)) no_of_parameters = len(sys.argv) - 1 if no_of_parameters == 0: to_check = 'pcpu' elif no_of_parameters == 1: to_check = sys.argv[1] else: raise Exception('Too many arguments') if (to_check != 'all') and not(to_check in accepted_params): raise Exception('Used illegal parameter: {0}'.format(to_check)) if to_check == 'all': for param in sorted(accepted_params): give_output(param) print() else: give_output(to_check) ======================================================================== Is this a reasonable way to do this? Getting the parameter is done quit simple, but I did not think fancy was necessary here. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From david.rios.gomes at gmail.com Tue Aug 4 16:49:42 2015 From: david.rios.gomes at gmail.com (David Rios) Date: Tue, 4 Aug 2015 17:49:42 -0300 Subject: consumer/producer with asyncio Message-ID: Hello everyone, I'm trying to implement a producer/consumer using asyncio, but I have some doubts about the best way to do it. I already have a working implementation using threads, and want to port it to asyncio for fun, to learn and also to avoid some problems that I have using threads, namely that sometimes the script locks and never finish. What the script have to do is to connect to a server, stream content from it, and send it for processing as items arrive. The processing part is to connect to other servers based on the item, send the item to process and wait for the response. The threaded version sets a pool of consumer threads that fetch items from a queue, while on the main thread the queue is populated. Special requirements that I have are that the script should be interruptible and should stop cleanly on errors. When I interrupt it or any part throws an exception for any reason, the script should stop producing items, the workers should finish the current job and then stop processing new items, at which point the script should perform appropriate housekeeping and exit. I have a mock implementation using asyncio here: https://gist.github.com/davidrios/011d044b5e7510f085dd But I think it is quite ugly, particularly all the nesting. What do you think? From emile at fenx.com Tue Aug 4 16:52:39 2015 From: emile at fenx.com (Emile van Sebille) Date: Tue, 4 Aug 2015 13:52:39 -0700 Subject: Linux script to get most expensive processes In-Reply-To: <87twsehkmk.fsf@Equus.decebal.nl> References: <87twsehkmk.fsf@Equus.decebal.nl> Message-ID: On 8/4/2015 1:19 PM, Cecil Westerhof wrote: > Under Linux I like to get the most expensive processes. The two most > useful commands are: > ps -eo pid,user,pcpu,args --sort=-pcpu > and: > ps -eo pid,user,pcpu,args --sort=-vsize > > In my case I am only interested in the seven most expensive processes. > For this I wrote the following script. > Is this a reasonable way to do this? Getting the parameter is done > quit simple, but I did not think fancy was necessary here. My platform shows as linux2 and it worked fine for me when checking for that. Emile From Cecil at decebal.nl Tue Aug 4 17:30:48 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Tue, 04 Aug 2015 23:30:48 +0200 Subject: Linux script to get most expensive processes References: <87twsehkmk.fsf@Equus.decebal.nl> Message-ID: <87pp32hhbr.fsf@Equus.decebal.nl> On Tuesday 4 Aug 2015 22:52 CEST, Emile van Sebille wrote: > On 8/4/2015 1:19 PM, Cecil Westerhof wrote: >> Under Linux I like to get the most expensive processes. The two >> most useful commands are: ps -eo pid,user,pcpu,args --sort=-pcpu >> and: ps -eo pid,user,pcpu,args --sort=-vsize >> >> In my case I am only interested in the seven most expensive >> processes. For this I wrote the following script. > >> Is this a reasonable way to do this? Getting the parameter is done >> quit simple, but I did not think fancy was necessary here. > > > My platform shows as linux2 and it worked fine for me when checking > for that. I heard that that was possible also, but none of my systems gives this. I should change it. I was also thinking about posix systems, but the Linux ps does more as others, so I did not do that. I amended the code to work with linux and linux2: ======================================================================== accepted_params = { 'pcpu', 'rss', 'size', 'time', 'vsize', } accepted_platforms = { 'linux', 'linux2', } current_platform = sys.platform max_line_length = 200 no_of_lines = 8 # One extra for the heading is_good_platform = False for platform in accepted_platforms: if platform == current_platform: is_good_platform = True break if not is_good_platform: raise Exception('Got an incompatiple platform: {0}'. format(current_platform)) ======================================================================== -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From python at mrabarnett.plus.com Tue Aug 4 18:00:02 2015 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 4 Aug 2015 23:00:02 +0100 Subject: Linux script to get most expensive processes In-Reply-To: <87pp32hhbr.fsf@Equus.decebal.nl> References: <87twsehkmk.fsf@Equus.decebal.nl> <87pp32hhbr.fsf@Equus.decebal.nl> Message-ID: <55C135E2.6090006@mrabarnett.plus.com> On 2015-08-04 22:30, Cecil Westerhof wrote: > On Tuesday 4 Aug 2015 22:52 CEST, Emile van Sebille wrote: > >> On 8/4/2015 1:19 PM, Cecil Westerhof wrote: >>> Under Linux I like to get the most expensive processes. The two >>> most useful commands are: ps -eo pid,user,pcpu,args --sort=-pcpu >>> and: ps -eo pid,user,pcpu,args --sort=-vsize >>> >>> In my case I am only interested in the seven most expensive >>> processes. For this I wrote the following script. >> >>> Is this a reasonable way to do this? Getting the parameter is done >>> quit simple, but I did not think fancy was necessary here. >> >> >> My platform shows as linux2 and it worked fine for me when checking >> for that. > > I heard that that was possible also, but none of my systems gives > this. I should change it. I was also thinking about posix systems, but > the Linux ps does more as others, so I did not do that. > > I amended the code to work with linux and linux2: > ======================================================================== > accepted_params = { > 'pcpu', > 'rss', > 'size', > 'time', > 'vsize', > } > accepted_platforms = { > 'linux', > 'linux2', > } > current_platform = sys.platform > max_line_length = 200 > no_of_lines = 8 # One extra for the heading > > is_good_platform = False > for platform in accepted_platforms: > if platform == current_platform: > is_good_platform = True > break > if not is_good_platform: > raise Exception('Got an incompatiple platform: {0}'. > format(current_platform)) > ======================================================================== > Doesn't that 'for' loop do the same as: is_good_platform = current_platform in accepted_platforms ? From ned at nedbatchelder.com Tue Aug 4 18:06:50 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 4 Aug 2015 15:06:50 -0700 (PDT) Subject: Uninstall In-Reply-To: <7cbf35cc-9ac2-4d76-a06b-c5436d21f2de@googlegroups.com> References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> <7cbf35cc-9ac2-4d76-a06b-c5436d21f2de@googlegroups.com> Message-ID: <4500b743-ba01-4479-8de3-eed1a963cccb@googlegroups.com> On Tuesday, August 4, 2015 at 2:32:16 PM UTC-4, sohca... at gmail.com wrote: > milos: "You can't uninstall Python because it will break things" > Grant: "Actually, you CAN uninstall Python, but it will break things" > > I really fucking hate how pedantic some of the people on this mailing list are. > > milos wasn't wrong. You just chose to take his message too literally. I thought it was pretty clear that when milos said "can't", he really meant "shouldn't". While I am often dismayed at the pedantry on this list (and many others), in this case, I think the clarification was warranted. When a beginner is about to attempt something dangerous, it is prudent to be sure the instructions are clear. "You can't uninstall, because things won't work" sounds a bit like, "you literally will not be able to uninstall things, because the operating system will prevent you because it protects itself." I wouldn't want the next message to be the original asker saying, "No, look, I was able to uninstall just fine!" without realizing they were damaging their system. --Ned. From emile at fenx.com Tue Aug 4 18:12:05 2015 From: emile at fenx.com (Emile van Sebille) Date: Tue, 4 Aug 2015 15:12:05 -0700 Subject: Linux script to get most expensive processes In-Reply-To: <87pp32hhbr.fsf@Equus.decebal.nl> References: <87twsehkmk.fsf@Equus.decebal.nl> <87pp32hhbr.fsf@Equus.decebal.nl> Message-ID: On 8/4/2015 2:30 PM, Cecil Westerhof wrote: > On Tuesday 4 Aug 2015 22:52 CEST, Emile van Sebille wrote: >> My platform shows as linux2 and it worked fine for me when checking >> for that. > > I heard that that was possible also, but none of my systems gives > this. I should change it. You could also use the platform module: >>> import platform >>> platform.system() 'Linux' >>> Emile From Cecil at decebal.nl Tue Aug 4 19:14:36 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 05 Aug 2015 01:14:36 +0200 Subject: Linux script to get most expensive processes References: <87twsehkmk.fsf@Equus.decebal.nl> <87pp32hhbr.fsf@Equus.decebal.nl> Message-ID: <87k2tahcir.fsf@Equus.decebal.nl> On Wednesday 5 Aug 2015 00:00 CEST, MRAB wrote: >> I amended the code to work with linux and linux2: >> ======================================================================== >> accepted_params = { 'pcpu', 'rss', 'size', 'time', 'vsize', } >> accepted_platforms = { 'linux', 'linux2', } current_platform = >> sys.platform max_line_length = 200 no_of_lines = 8 # One extra for >> the heading >> >> is_good_platform = False for platform in accepted_platforms: if >> platform == current_platform: is_good_platform = True break if not >> is_good_platform: raise Exception('Got an incompatiple platform: >> {0}'. format(current_platform)) >> ======================================================================== >> > Doesn't that 'for' loop do the same as: > > is_good_platform = current_platform in accepted_platforms You are right. Not very smart. Especially because I use the ?in? a little later. It now is: ======================================================================== if not current_platform in accepted_platforms: raise Exception('Got an incompatiple platform: {0}'. format(current_platform)) ======================================================================== And I do not need is_good_platform anymore. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Tue Aug 4 19:17:39 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 05 Aug 2015 01:17:39 +0200 Subject: Linux script to get most expensive processes References: <87twsehkmk.fsf@Equus.decebal.nl> <87pp32hhbr.fsf@Equus.decebal.nl> Message-ID: <87fv3yhcdo.fsf@Equus.decebal.nl> On Wednesday 5 Aug 2015 00:12 CEST, Emile van Sebille wrote: > On 8/4/2015 2:30 PM, Cecil Westerhof wrote: >> On Tuesday 4 Aug 2015 22:52 CEST, Emile van Sebille wrote: > >>> My platform shows as linux2 and it worked fine for me when >>> checking for that. >> >> I heard that that was possible also, but none of my systems gives >> this. I should change it. > > You could also use the platform module: > > >>>> import platform >>>> platform.system() > 'Linux' I already use sys, so I think sys.platform is a little better. ;-) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From torriem at gmail.com Tue Aug 4 21:32:06 2015 From: torriem at gmail.com (Michael Torrie) Date: Tue, 04 Aug 2015 19:32:06 -0600 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <85y4hqkepb.fsf@benfinney.id.au> References: <87k2teq9tb.fsf@Equus.decebal.nl> <663ad259-48e0-4eec-a946-7cd03805ddb1@googlegroups.com> <85y4hqkepb.fsf@benfinney.id.au> Message-ID: <55C16796.9060101@gmail.com> On 08/04/2015 01:59 PM, Ben Finney wrote: > marco.nawijn at colosso.nl writes: > >> Why not use Python files itself as configuration files? > > Because configuration data will be user-editable. (If it's not > user-editable, that is itself a poor design choice.) > > If you allow executable code to be user-edited, that opens your program > to arbitrary injection of executable code. Your program becomes wide > open for security exploits, whether through malicious or accidental > bugs, and simple human error can lead to arbitrary-scope damage to the > user's system. We need to state the context here. The only context in which having a Python config file is dangerous is when the python program runs as a different user/privilege than the owner of the config file. If the user owns the python files as well as the config file then none of this matters. In most cases, I've never bought the argument you and others are making here about security and demanding yet another DSL. In fact I find the argument to be rather circular in that we're dealing with programs that aren't compiled but written in Python anyway. I can open and edit any python file in the project that I want and make arbitrary, possibly "malicious" changes to it! Oh no! The idea that a malicious user could inject python code in this instance and somehow deliberately harm the system is kind of silly if you think about it. It's me that's running the python code in the first place. I could open any file and change it. I'm already running arbitrary code. If I'm talking about a system service that is doing things for non-root users, then yeah I'll agree with your argument completely. But not for most other situations. Even a system service, if the config file is owned by root, I'm okay with using python as configuration. Because if root's compromised, all bets are off anyway and all the python scripts could be modified. In fact python as configuration works very well for my purposes, and it works well for Django, and there are many other projects that also do this. I don't think you'd want to use any other mechanism for configuring Django, frankly. I'm a bit surprised no one has mentioned Django in this discussion yet. In many of my projects I put basic config variables in a file like config.py and import that in each module that needs it. The config module doubles as a global namespace for sharing between modules as well. From marfig at gmail.com Tue Aug 4 21:51:06 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Wed, 5 Aug 2015 02:51:06 +0100 Subject: Uninstall In-Reply-To: References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> <7cbf35cc-9ac2-4d76-a06b-c5436d21f2de@googlegroups.com> Message-ID: On Tue, Aug 4, 2015 at 9:01 PM, Mark Lawrence wrote: > On 04/08/2015 19:31, sohcahtoa82 at gmail.com wrote: > >> On Tuesday, August 4, 2015 at 7:29:29 AM UTC-7, Grant Edwards wrote: >> >>> On 2015-08-04, milos zorica wrote: >>> >>> you can't fully uninstall python from OSX, linux, BSD as there are many >>>> python dependent system tools >>>> >>> >>> Well, technically you _can_ uninstall Python if you really want, but >>> all sorts of things will stop working. In some cases, it's very hard >>> to recover from that situation. Among the things that will stop >>> working on some flavors of Linux are the system utilities you normally >>> use to install things like Python. >>> >>> -- >>> Grant Edwards grant.b.edwards Yow! World War III? >>> at No thanks! >>> gmail.com >>> >> >> milos: "You can't uninstall Python because it will break things" >> Grant: "Actually, you CAN uninstall Python, but it will break things" >> >> I really fucking hate how pedantic some of the people on this mailing >> list are. >> >> milos wasn't wrong. You just chose to take his message too literally. I >> thought it was pretty clear that when milos said "can't", he really meant >> "shouldn't". >> >> > The simple solution is not to subscribe. > > Or even better, tell you to fuck off. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ned at nedbatchelder.com Tue Aug 4 22:03:16 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 4 Aug 2015 19:03:16 -0700 (PDT) Subject: Uninstall In-Reply-To: References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> <7cbf35cc-9ac2-4d76-a06b-c5436d21f2de@googlegroups.com> Message-ID: <3508ea03-cac3-472d-916e-575b62052cf7@googlegroups.com> On Tuesday, August 4, 2015 at 9:51:27 PM UTC-4, Mario Figueiredo wrote: > On Tue, Aug 4, 2015 at 9:01 PM, Mark Lawrence wrote: >> >> The simple solution is not to subscribe. > > > Or even better, tell you to fuck off.? Can we please try to stay civil? --Ned. From marfig at gmail.com Tue Aug 4 22:08:02 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Wed, 5 Aug 2015 03:08:02 +0100 Subject: Uninstall In-Reply-To: <4500b743-ba01-4479-8de3-eed1a963cccb@googlegroups.com> References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> <7cbf35cc-9ac2-4d76-a06b-c5436d21f2de@googlegroups.com> <4500b743-ba01-4479-8de3-eed1a963cccb@googlegroups.com> Message-ID: On Tue, Aug 4, 2015 at 11:06 PM, Ned Batchelder wrote: > > On Tuesday, August 4, 2015 at 2:32:16 PM UTC-4, sohca... at gmail.com wrote: > > milos: "You can't uninstall Python because it will break things" > > Grant: "Actually, you CAN uninstall Python, but it will break things" > > > > I really fucking hate how pedantic some of the people on this mailing list are. > > > > milos wasn't wrong. You just chose to take his message too literally. I thought it was pretty clear that when milos said "can't", he really meant "shouldn't". > > While I am often dismayed at the pedantry on this list (and many others), > in this case, I think the clarification was warranted. When a beginner > is about to attempt something dangerous, it is prudent to be sure the > instructions are clear. > > "You can't uninstall, because things won't work" sounds a bit like, > "you literally will not be able to uninstall things, because the operating > system will prevent you because it protects itself." > > I wouldn't want the next message to be the original asker saying, "No, > look, I was able to uninstall just fine!" without realizing they were > damaging their system. > Pedantry sort of comes with the territory. It's in the job description, so to speak. DJ Wiza should know that. There's that used joke of the programmer's wife that asks him to bring 3 loaves of bread and if there are any eggs to bring a dozen, and the programmer brings her wife a dozen loaves of bread. But being an asshole does not. That is something one chooses to become. Your answer squarely puts you in the group of people that chose to be in life to be a pain to others and actually gain the respect of even those that don't even know them. Unlike some other people in here. But Mark is right in a way... People like him is a reason I rarely frequent this place anymore. -------------- next part -------------- An HTML attachment was scrubbed... URL: From marfig at gmail.com Tue Aug 4 22:18:53 2015 From: marfig at gmail.com (Mario Figueiredo) Date: Wed, 5 Aug 2015 03:18:53 +0100 Subject: Uninstall In-Reply-To: References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> <7cbf35cc-9ac2-4d76-a06b-c5436d21f2de@googlegroups.com> <4500b743-ba01-4479-8de3-eed1a963cccb@googlegroups.com> Message-ID: On Wed, Aug 5, 2015 at 3:08 AM, Mario Figueiredo wrote: > > But being an asshole does not. That is something one chooses to become. Your answer squarely puts you in the group of people that chose to be in life to be a pain to others [...] An ugly mistyping there completely changed the meaning of what I intended to say. For clarification, I mean to say: "Your answer squarely puts you in the group of people that DIDN'T chose to be in life to be a pain to others" -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Tue Aug 4 22:19:53 2015 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 5 Aug 2015 12:19:53 +1000 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <55C16796.9060101@gmail.com> References: <55C16796.9060101@gmail.com> Message-ID: <20150805021953.GA65285@cskk.homeip.net> On 04Aug2015 19:32, Michael Torrie wrote: >On 08/04/2015 01:59 PM, Ben Finney wrote: >> marco.nawijn at colosso.nl writes: >>> Why not use Python files itself as configuration files? >> >> Because configuration data will be user-editable. (If it's not >> user-editable, that is itself a poor design choice.) >> >> If you allow executable code to be user-edited, that opens your program >> to arbitrary injection of executable code. [...] > >We need to state the context here. The only context in which having a >Python config file is dangerous is when the python program runs as a >different user/privilege than the owner of the config file. If the user >owns the python files as well as the config file then none of this matters. [...] >If I'm talking about a system service that is doing things for non-root >users, then yeah I'll agree with your argument completely. But not for >most other situations. Even a system service, if the config file is >owned by root, I'm okay with using python as configuration. [...] >In fact python as configuration works very well for my purposes, and it >works well for Django, and there are many other projects that also do >this. I don't think you'd want to use any other mechanism for >configuring Django, frankly. I'm a bit surprised no one has mentioned >Django in this discussion yet. [...] Django crossed my mind as well, but my take is very different. I'm of two minds on Django's use of Python files for config. On the one hand it is very flexible, it can express comoplicated/subtle(/fragile?) setups as needs and, if you are writing the Django app instead of just using it, it is in the same language as the app. On the other hand, if you want to consult that config from _outside_ the app with another tool not necessarily written in Python you're screwed. Many things can read a .ini file. Very few things can read arbitrary Python code, and any that can _must_ expose themselves to whatever that code may do. If the consulting code is in a different security context (system config monitors, admin scripts, etc) then we're back in the risk zone. So on the whole I am against python code as the config file format. Really, who needs a Turing complete configuration file? Go with something simple, both in syntax and semantics. It is easier to read, easier to write/modify, and easier to access from multiple tools. Cheers, Cameron Simpson A protocol is complete when there is nothing left to remove. - Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking From random832 at fastmail.us Tue Aug 4 22:44:31 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Tue, 04 Aug 2015 22:44:31 -0400 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <55C16796.9060101@gmail.com> References: <87k2teq9tb.fsf@Equus.decebal.nl> <663ad259-48e0-4eec-a946-7cd03805ddb1@googlegroups.com> <85y4hqkepb.fsf@benfinney.id.au> <55C16796.9060101@gmail.com> Message-ID: <1438742671.36658.348000713.4F778711@webmail.messagingengine.com> On Tue, Aug 4, 2015, at 21:32, Michael Torrie wrote: > In many of my projects I put basic config variables in a file like > config.py and import that in each module that needs it. The config > module doubles as a global namespace for sharing between modules as well. What about JSONP? That is, a file consisting exactly of "config_data = [JSON object]" That would get you some of the benefits of having your config file exist as a python module, but still allow it to be examined by other tools, written out, etc. From rustompmody at gmail.com Wed Aug 5 00:42:19 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 4 Aug 2015 21:42:19 -0700 (PDT) Subject: Uninstall In-Reply-To: References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> <7cbf35cc-9ac2-4d76-a06b-c5436d21f2de@googlegroups.com> <4500b743-ba01-4479-8de3-eed1a963cccb@googlegroups.com> Message-ID: <57aa645b-b5e2-4442-a8aa-673e918f4c6b@googlegroups.com> On Wednesday, August 5, 2015 at 7:49:10 AM UTC+5:30, Mario Figueiredo wrote: > On Wed, Aug 5, 2015 at 3:08 AM, Mario Figueiredo wrote: > > > > But being an asshole does not. That is something one chooses to become. Your answer squarely puts you in the group of people that chose to be in life to be a pain to others [...] > > > An ugly mistyping there completely changed the meaning of what I intended to say. For clarification, I mean to say: "Your answer squarely puts you in the group of people that DIDN'T chose to be in life to be a pain to others" And nobody's yet asked whether the python on the mac the OP wants to uninstall is the system python or something he added later From torriem at gmail.com Wed Aug 5 00:48:51 2015 From: torriem at gmail.com (Michael Torrie) Date: Tue, 04 Aug 2015 22:48:51 -0600 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <1438742671.36658.348000713.4F778711@webmail.messagingengine.com> References: <87k2teq9tb.fsf@Equus.decebal.nl> <663ad259-48e0-4eec-a946-7cd03805ddb1@googlegroups.com> <85y4hqkepb.fsf@benfinney.id.au> <55C16796.9060101@gmail.com> <1438742671.36658.348000713.4F778711@webmail.messagingengine.com> Message-ID: <55C195B3.4040305@gmail.com> On 08/04/2015 08:44 PM, random832 at fastmail.us wrote: > On Tue, Aug 4, 2015, at 21:32, Michael Torrie wrote: >> In many of my projects I put basic config variables in a file like >> config.py and import that in each module that needs it. The config >> module doubles as a global namespace for sharing between modules as well. > > What about JSONP? That is, a file consisting exactly of "config_data = > [JSON object]" That would get you some of the benefits of having your > config file exist as a python module, but still allow it to be examined > by other tools, written out, etc. But I don't need it to be examined by other tools. So the added complication of yet another layer isn't worth it or needed. Python's syntax is simple enough that a person with a text editor can certainly do it. Again, context is everything. My programs are written for mostly my own use. If I was writing a system that was like, say, Apache, I would certainly do a DSL with a robust error checking and reporting system that could clearly help people with syntax errors, etc. From rustompmody at gmail.com Wed Aug 5 00:55:04 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 4 Aug 2015 21:55:04 -0700 (PDT) Subject: Most Pythonic way to store (small) configuration In-Reply-To: References: <87k2teq9tb.fsf@Equus.decebal.nl> <663ad259-48e0-4eec-a946-7cd03805ddb1@googlegroups.com> <85y4hqkepb.fsf@benfinney.id.au> <55C16796.9060101@gmail.com> <1438742671.36658.348000713.4F778711@webmail.messagingengine.com> Message-ID: <4312284d-583c-4263-926d-730875fe933d@googlegroups.com> On Wednesday, August 5, 2015 at 10:19:11 AM UTC+5:30, Michael Torrie wrote: > On 08/04/2015 08:44 PM, wrote: > > On Tue, Aug 4, 2015, at 21:32, Michael Torrie wrote: > >> In many of my projects I put basic config variables in a file like > >> config.py and import that in each module that needs it. The config > >> module doubles as a global namespace for sharing between modules as well. > > > > What about JSONP? That is, a file consisting exactly of "config_data = > > [JSON object]" That would get you some of the benefits of having your > > config file exist as a python module, but still allow it to be examined > > by other tools, written out, etc. > > But I don't need it to be examined by other tools. So the added > complication of yet another layer isn't worth it or needed. Python's > syntax is simple enough that a person with a text editor can certainly > do it. Again, context is everything. My programs are written for > mostly my own use. If I was writing a system that was like, say, > Apache, I would certainly do a DSL with a robust error checking and > reporting system that could clearly help people with syntax errors, etc. I think the main point is Cameron's > So on the whole I am against python code as the config file format. Really, > who needs a Turing complete configuration file? stated more strongly: I sure dont want to use something Turing complete from something that is inherently more trivial. And if the cost is of matching the trivial format to the trivial-izing reader (say json) it seems like a small price to pay. In the past Ive always recommended yaml even though the cost is higher -- a separate install [yeah Ive had clients tell me that yaml's out because of that] [Does yaml have comments?] From torriem at gmail.com Wed Aug 5 00:55:59 2015 From: torriem at gmail.com (Michael Torrie) Date: Tue, 04 Aug 2015 22:55:59 -0600 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <20150805021953.GA65285@cskk.homeip.net> References: <55C16796.9060101@gmail.com> <20150805021953.GA65285@cskk.homeip.net> Message-ID: <55C1975F.4040008@gmail.com> On 08/04/2015 08:19 PM, Cameron Simpson wrote: > So on the whole I am against python code as the config file format. Really, who > needs a Turing complete configuration file? In Django's case, since you're intimately referring to certain classes and methods, particularly in the url mapping section, I think using straight Python is the way to go. It's the most flexibility for the least amount of work. And someone working with Django already has familiarity with both Django and Python. I'm sure everything could be put in a DSL, but then you'd be inventing a subset of Python anyway. And like I say, since the same person editing the config file is also editing the other Django project files, the issue of code injection is moot; he's already doing that! So for the OP's case, if his needs are simple like mine are, then a simple python file he imports could be just fine. I'm hard pressed to make a case for something different if the needs are simple like that. > Go with something simple, both in syntax and semantics. It is easier to read, > easier to write/modify, and easier to access from multiple tools. Python as configuration is simpler for my purposes, in both ways. And multiple tools for me == text editors. I have no need of machine-generated config files. Maybe Cecil doesn't either. Such tools are of limited use anyway in my experience. For example webadmin never cut it for me. Neither did the old web-based Samba configurater. From paul.anton.letnes at gmail.com Wed Aug 5 01:45:34 2015 From: paul.anton.letnes at gmail.com (paul.anton.letnes at gmail.com) Date: Tue, 4 Aug 2015 22:45:34 -0700 (PDT) Subject: Uninstall In-Reply-To: <57aa645b-b5e2-4442-a8aa-673e918f4c6b@googlegroups.com> References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> <7cbf35cc-9ac2-4d76-a06b-c5436d21f2de@googlegroups.com> <4500b743-ba01-4479-8de3-eed1a963cccb@googlegroups.com> <57aa645b-b5e2-4442-a8aa-673e918f4c6b@googlegroups.com> Message-ID: <7f3eb732-95e8-489d-a388-72111301785a@googlegroups.com> Right. Try "which python" in the terminal and report back! Cheers Paul From pavel at schon.cz Wed Aug 5 02:48:55 2015 From: pavel at schon.cz (Pavel S) Date: Tue, 4 Aug 2015 23:48:55 -0700 (PDT) Subject: GOTCHA with list comprehension Message-ID: Hi, I recently found interesting GOTCHA while doing list comprehension in python 2.6: >>> values = ( True, False, 1, 2, 3, None ) >>> [ value for value in values if value if not None ] [True, 1, 2, 3] I was wondering why this list comprehension returns incorrect results and finally found a typo in the condition. The typo wasn't visible at the first look. My intention was: if value is not None But I wrote: if value if not None Is that a language feature of list comprehension that it accepts conditions like: if A if B if C if D ...? From lele at metapensiero.it Wed Aug 5 02:54:51 2015 From: lele at metapensiero.it (Lele Gaifax) Date: Wed, 05 Aug 2015 08:54:51 +0200 Subject: Most Pythonic way to store (small) configuration References: <87k2teq9tb.fsf@Equus.decebal.nl> <663ad259-48e0-4eec-a946-7cd03805ddb1@googlegroups.com> <85y4hqkepb.fsf@benfinney.id.au> <55C16796.9060101@gmail.com> <1438742671.36658.348000713.4F778711@webmail.messagingengine.com> <4312284d-583c-4263-926d-730875fe933d@googlegroups.com> Message-ID: <87d1z2cjic.fsf@nautilus.nautilus> Rustom Mody writes: > Does yaml have comments? Yes, the same syntax as Python's. ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From pavel at schon.cz Wed Aug 5 03:03:29 2015 From: pavel at schon.cz (Pavel S) Date: Wed, 5 Aug 2015 00:03:29 -0700 (PDT) Subject: GOTCHA with list comprehension In-Reply-To: References: Message-ID: <631b480d-497a-4451-9577-2788f9d4c85b@googlegroups.com> It seems this is allowed by the grammar: list_display ::= "[" [expression_list | list_comprehension] "]" list_comprehension ::= expression list_for list_for ::= "for" target_list "in" old_expression_list [list_iter] old_expression_list ::= old_expression [("," old_expression)+ [","]] old_expression ::= or_test | old_lambda_expr list_iter ::= list_for | list_if list_if ::= "if" old_expression [list_iter] So chaining multiple ifs is fine: [ i for i in range(10) if True if True if True if True ] Dne st?eda 5. srpna 2015 8:49:20 UTC+2 Pavel S napsal(a): > Hi, > > I recently found interesting GOTCHA while doing list comprehension in python 2.6: > > >>> values = ( True, False, 1, 2, 3, None ) > >>> [ value for value in values if value if not None ] > [True, 1, 2, 3] > > I was wondering why this list comprehension returns incorrect results and finally found a typo in the condition. The typo wasn't visible at the first look. > > My intention was: if value is not None > But I wrote: if value if not None > > Is that a language feature of list comprehension that it accepts conditions like: if A if B if C if D ...? From __peter__ at web.de Wed Aug 5 03:04:51 2015 From: __peter__ at web.de (Peter Otten) Date: Wed, 05 Aug 2015 09:04:51 +0200 Subject: GOTCHA with list comprehension References: Message-ID: Pavel S wrote: > Hi, > > I recently found interesting GOTCHA while doing list comprehension in > python 2.6: > >>>> values = ( True, False, 1, 2, 3, None ) >>>> [ value for value in values if value if not None ] > [True, 1, 2, 3] > > I was wondering why this list comprehension returns incorrect results and > finally found a typo in the condition. The typo wasn't visible at the > first look. > > My intention was: if value is not None > But I wrote: if value if not None > > Is that a language feature of list comprehension that it accepts > conditions like: if A if B if C if D ...? I think it's just that a condition may be a constant expression. Python evaluates (not None) for every item in values. Other variants: >>> if 42: ... print("branch always taken") ... branch always taken >>> always_yes = "yes" if True else "no" >>> always_yes 'yes' >>> [c for c in "foo" if "true in a boolean context"] ['f', 'o', 'o'] An optimizer might detect that (not None) is always True in a boolean context, but that would be an implementation detail. From rosuav at gmail.com Wed Aug 5 03:05:49 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Aug 2015 17:05:49 +1000 Subject: GOTCHA with list comprehension In-Reply-To: References: Message-ID: On Wed, Aug 5, 2015 at 4:48 PM, Pavel S wrote: > Hi, > > I recently found interesting GOTCHA while doing list comprehension in python 2.6: > >>>> values = ( True, False, 1, 2, 3, None ) >>>> [ value for value in values if value if not None ] > [True, 1, 2, 3] > > I was wondering why this list comprehension returns incorrect results and finally found a typo in the condition. The typo wasn't visible at the first look. > > My intention was: if value is not None > But I wrote: if value if not None > > Is that a language feature of list comprehension that it accepts conditions like: if A if B if C if D ...? It certainly is. You can chain 'for' and 'if' clauses as much as you like, and they behave exactly the way you'd expect. You might possibly get a warning from a linter with your code, though, as it has an always-true condition ("if not None" can never be false), so it's possible something might hint at what's going on; but other than that, all you can do is test stuff and see if it's giving the right result. Incidentally, why Python 2.6? Python 2.7 has been out for a pretty long time now, and if you can't move to version 3.x, I would at least recommend using 2.7. Since the release of 2.6.9 back before Frozen came out, that branch has been completely unmaintained. Grab yourself a 2.7 and take advantage of some neat new features (for old values of "new"), and improved compatibility with 3.x. ChrisA From pavel at schon.cz Wed Aug 5 03:10:57 2015 From: pavel at schon.cz (Pavel S) Date: Wed, 5 Aug 2015 00:10:57 -0700 (PDT) Subject: GOTCHA with list comprehension In-Reply-To: References: Message-ID: <414aa23b-6690-449e-846b-af6278999a94@googlegroups.com> $ cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.5 (Santiago) $ python --version Python 2.6.6 > Incidentally, why Python 2.6? > > ChrisA From rosuav at gmail.com Wed Aug 5 03:20:05 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Aug 2015 17:20:05 +1000 Subject: GOTCHA with list comprehension In-Reply-To: <631b480d-497a-4451-9577-2788f9d4c85b@googlegroups.com> References: <631b480d-497a-4451-9577-2788f9d4c85b@googlegroups.com> Message-ID: On Wed, Aug 5, 2015 at 5:03 PM, Pavel S wrote: > It seems this is allowed by the grammar: > > list_display ::= "[" [expression_list | list_comprehension] "]" > list_comprehension ::= expression list_for > list_for ::= "for" target_list "in" old_expression_list [list_iter] > old_expression_list ::= old_expression [("," old_expression)+ [","]] > old_expression ::= or_test | old_lambda_expr > list_iter ::= list_for | list_if > list_if ::= "if" old_expression [list_iter] > > So chaining multiple ifs is fine: > > [ i for i in range(10) if True if True if True if True ] Yep. A chain of 'if' clauses isn't materially different from a single 'if' with a bunch of 'and' checks, but if you alternate 'if' and 'for' clauses, you get a comprehension that conditionally nests its iterations. ChrisA From rosuav at gmail.com Wed Aug 5 03:21:45 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Aug 2015 17:21:45 +1000 Subject: GOTCHA with list comprehension In-Reply-To: <414aa23b-6690-449e-846b-af6278999a94@googlegroups.com> References: <414aa23b-6690-449e-846b-af6278999a94@googlegroups.com> Message-ID: On Wed, Aug 5, 2015 at 5:10 PM, Pavel S wrote: > $ cat /etc/redhat-release > Red Hat Enterprise Linux Server release 6.5 (Santiago) > $ python --version > Python 2.6.6 > >> Incidentally, why Python 2.6? >> I guess that would be why :) That's probably actually a patched 2.6.6 - from what I understand of how Red Hat works, the version number is the number of the *oldest* part of the code, so that quite possibly has a lot of backported fixes. When I said 2.6 was out of support, I meant from python.org; Red Hat supports stuff for a lot longer. So, yeah, perfectly good reason for sticking with 2.6. For now. :) ChrisA From pavel at schon.cz Wed Aug 5 03:33:52 2015 From: pavel at schon.cz (Pavel S) Date: Wed, 5 Aug 2015 00:33:52 -0700 (PDT) Subject: GOTCHA with list comprehension In-Reply-To: References: <414aa23b-6690-449e-846b-af6278999a94@googlegroups.com> Message-ID: Hi Chris, yeah, I have to stick on the software which my employer provides to me (we're enterprise company). I'm not root on that system. I'm happy with 2.6 now, two years ago we were on older RHEL with python 2.4 and it was a real pain :) > > $ cat /etc/redhat-release > > Red Hat Enterprise Linux Server release 6.5 (Santiago) > > $ python --version > > Python 2.6.6 > > > >> Incidentally, why Python 2.6? > >> > > I guess that would be why :) > > That's probably actually a patched 2.6.6 - from what I understand of > how Red Hat works, the version number is the number of the *oldest* > part of the code, so that quite possibly has a lot of backported > fixes. When I said 2.6 was out of support, I meant from python.org; > Red Hat supports stuff for a lot longer. > > So, yeah, perfectly good reason for sticking with 2.6. For now. :) > > ChrisA From steve+comp.lang.python at pearwood.info Wed Aug 5 04:32:26 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 05 Aug 2015 18:32:26 +1000 Subject: Most Pythonic way to store (small) configuration References: <87k2teq9tb.fsf@Equus.decebal.nl> <663ad259-48e0-4eec-a946-7cd03805ddb1@googlegroups.com> Message-ID: <55c1ca1b$0$1582$c3e8da3$5496439d@news.astraweb.com> On Wednesday 05 August 2015 05:59, Ben Finney wrote: > marco.nawijn at colosso.nl writes: > >> Why not use Python files itself as configuration files? > > Because configuration data will be user-editable. (If it's not > user-editable, that is itself a poor design choice.) > > If you allow executable code to be user-edited, that opens your program > to arbitrary injection of executable code. Your program becomes wide > open for security exploits, whether through malicious or accidental > bugs, and simple human error can lead to arbitrary-scope damage to the > user's system. Yeah... it's almost as if you allowed the user to edit the source code of your application, or even write their own code. And nobody would do that! *wink* I'm not entirely disagreeing, just adding some nuance to the discussion. My own personal feeling is that using code as config is a little disquieting. It's a bit of a code smell. Do you really need that much power just to allow people to set some configuration settings? Using a Turing Complete programming language just to set a bunch of name:value pairs seems to be gross overkill. But on the other hand, config systems do tend to grow in power. People often want conditional and computed settings. Rather than invent your own (buggy) mini-language to allow conf like this: if $PLATFORM = 'Windows' set location = 'C:\The Stuff'; if $PLATFORM = 'Linux' set location = $baselocation + '/thestuff'; using Python seems like a much better idea. Code smell or not, I don't think that Python code as config is that much of a problem, for most applications. Yes, the user can insert arbitrary code into their config file, and have it run... but it's their user account running it, they presumably could just insert that code into a file and run it with python regardless. There's (usually) no security implications. Although I can think of some exceptions. For example, the company I work for has a Linux desktop designed for untrusted, hostile users (prisoners in jail), and using .py files as config would *definitely* not be allowed for that. But I think that's an exceptional case. > On another dimension, configuration files specifying the behaviour of > the system are much more useful if their format is easily parsed and > re-worked by tools the user chooses. > > Your program should not be the only tool (and Python should not be the > only language) that can read and/or write the configuration data with > straightfoward data manipulation. Python is an open standard that anyone can use, or write their own should they wish. If you don't like CPython, use Jython or PyPy or MyFirstPythonInterpreter to pass the config data. A better argument may be that *running arbitrary code* should not be required in order to parse a config file. I'm sympathetic to that argument too. But if that's your worry, and you absolutely must read a .py config file, you could write your own stripped down interpreter of a limited subset of the language, and use that. No, it won't be able to determine all the config settings from arbitrary .py files, but it may give you a practical solution which is good enough for what you need. > So a complex full-blown programming language like Python is a poor > choice for configuration data for that reason, too. > > Much better to choose a tightly-defined, limited-scope configuration > data format that you can be confident any user cannot employ to run > arbitrary code. Sure, if your config requirements are met by such a data format. -- Steve From marko at pacujo.net Wed Aug 5 05:01:12 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 05 Aug 2015 12:01:12 +0300 Subject: GOTCHA with list comprehension References: Message-ID: <87wpxacdnr.fsf@elektro.pacujo.net> Chris Angelico : > You can chain 'for' and 'if' clauses as much as you like, and they > behave exactly the way you'd expect. How do you know what I'd expect? I wouldn't know what to expect myself. Marko From rosuav at gmail.com Wed Aug 5 05:52:03 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Aug 2015 19:52:03 +1000 Subject: GOTCHA with list comprehension In-Reply-To: <87wpxacdnr.fsf@elektro.pacujo.net> References: <87wpxacdnr.fsf@elektro.pacujo.net> Message-ID: On Wed, Aug 5, 2015 at 7:01 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> You can chain 'for' and 'if' clauses as much as you like, and they >> behave exactly the way you'd expect. > > How do you know what I'd expect? > > I wouldn't know what to expect myself. A list comprehension can always be unwound into statement form. [1] For example: squares = [n*n for n in range(10)] can be unwound into: squares = [] for n in range(10): squares.append(n*n) You simply take the expression at the beginning and put that into the append() method call, and then the rest become statements. Here's a filtered version: odd_squares = [n*n for n in range(20) if n%2] Which becomes: odd_squares = [] for n in range(20): if n%2: odd_squares.append(n*n) So what would you expect nested 'if' clauses to do? Well, they become nested 'if' statements: primes = [n for n in range(2,24) if n%2 if n%3] primes = [] for n in range(2,24): if n%2: if n%3: primes.append(n) What if we have multiple 'for' loops? Same thing! ways_to_get_seven = [(a,b) for a in range(1,7) for b in range(1,7) if a+b==7] ways_to_get_seven = [] for a in range(1,7): for b in range(1,7): if a+b==7: ways_to_get_seven.append((a,b)) No matter what combination of 'if' and 'for' you use, it can be unwound like this, and it'll always behave the same way. Not sure what to expect? Follow the simple rules of unwinding, and then read the code that way. Of course, if you don't know how to predict what the statement form will do, then you won't understand what the comprehension will do. But that's not the comprehension's fault. peculiar = [a*x*x+b*x+c for a in range(1,10) for b in range(2,30) for c in range(-3,5) if b*b-4*a*c>=0 if (-b+math.sqrt(b*b-4*a*c))/2/a>0 for x in (x*.01 for x in range(-500,500))] I suppose you could graph that. Or something. But that's just bad code, don't blame the list comp for that... ChrisA [1] To be technically correct, this unwinding should be done in a nested function, which you then call. There are some other minor technicalities too. But it's pretty much this. From rosuav at gmail.com Wed Aug 5 06:01:51 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Aug 2015 20:01:51 +1000 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <55c1ca1b$0$1582$c3e8da3$5496439d@news.astraweb.com> References: <87k2teq9tb.fsf@Equus.decebal.nl> <663ad259-48e0-4eec-a946-7cd03805ddb1@googlegroups.com> <55c1ca1b$0$1582$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 5, 2015 at 6:32 PM, Steven D'Aprano wrote: > My own personal feeling is that using code as config is a little > disquieting. It's a bit of a code smell. Do you really need that much power > just to allow people to set some configuration settings? Using a Turing > Complete programming language just to set a bunch of name:value pairs seems > to be gross overkill. > > But on the other hand, config systems do tend to grow in power. People often > want conditional and computed settings. Rather than invent your own (buggy) > mini-language to allow conf like this: > > if $PLATFORM = 'Windows' set location = 'C:\The Stuff'; > if $PLATFORM = 'Linux' set location = $baselocation + '/thestuff'; > > using Python seems like a much better idea. I often have config files where the example is really simple, like this: https://github.com/Rosuav/LetMeKnow/blob/master/keys_sample.py https://github.com/Rosuav/Yosemite/blob/master/config.py but the in-production versions sometimes have a teensy bit more code in them - maybe an if-expression, maybe pulling something from os.environ. In both of those cases, any person editing the config file will also have full power to tamper with the source code, so the security issue doesn't apply; and apart from requiring quotes around string values, it's pretty much the level of simplicity you'd get out of any other config file format. You get comments, you get freedom to add whitespace anywhere you like (or not add it, if you so desire), it's great! Right? Well, there is another subtlety, and that's that there's no error checking. If you duplicate an entry, nobody will issue even a warning. For small config files, that's fine; but what if you're editing something the size of postgresql.conf? You can't keep it all on screen or in your head, and if you simply search the file for some keyword, would you notice that there are two of them? So, I'd recommend this if - and ONLY if - the files are normally going to be small enough to fit on a single page. Otherwise, consider carefully whether you'd later on want to add error checking like that, and consider how hard it would be to hack that in. Drink responsibly. ChrisA From breamoreboy at yahoo.co.uk Wed Aug 5 06:25:04 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 5 Aug 2015 11:25:04 +0100 Subject: Uninstall In-Reply-To: References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> <7cbf35cc-9ac2-4d76-a06b-c5436d21f2de@googlegroups.com> Message-ID: On 05/08/2015 02:51, Mario Figueiredo wrote: [chopped to pieces] > On Tue, Aug 4, 2015 at 9:01 PM, Mark Lawrence > wrote: > On 04/08/2015 19:31, sohcahtoa82 at gmail.com > wrote: > On Tuesday, August 4, 2015 at 7:29:29 AM UTC-7, Grant Edwards wrote: > On 2015-08-04, milos zorica > The simple solution is not to subscribe. > > Or even better, tell you to fuck off. > I trust that you also have a good day :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From PointedEars at web.de Wed Aug 5 06:56:02 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 05 Aug 2015 12:56:02 +0200 Subject: Linux script to get most expensive processes References: <87twsehkmk.fsf@Equus.decebal.nl> Message-ID: <3702826.bDmuSmBusV@PointedEars.de> Cecil Westerhof wrote: > Under Linux I like to get the most expensive processes. The two most > useful commands are: > ps -eo pid,user,pcpu,args --sort=-pcpu > and: > ps -eo pid,user,pcpu,args --sort=-vsize > > In my case I am only interested in the seven most expensive processes. > For this I wrote the following script. Don?t. Use ps -eo pid,user,pcpu,args --sort=-pcpu | head -n 8 or ps -eo pid,user,pcpu,args --sort=-pcpu | sed -n '2,8p' and the like instead. (procps ps(1) also has an output modifier to omit the headers, but I could not get that to work with the sorting just now. [Thanks for pointing out the ?--sort? option of *procps* ps(1) 3.3.10. I was not aware of it, and had used $ alias cpu alias cpu='ps -ww aux | sort -nk3 | tail' instead.] > ======================================================================== > #!/usr/bin/env python3 > > import subprocess > import sys > > > def give_output(param): > output = subprocess.check_output(([ > 'ps', > '--columns={0}' .format(max_line_length), > '-eo', > 'pid,user,start_time,{0},args'.format(param), > '--sort=-{0}' .format(param) > ])).splitlines() > [?] > ======================================================================== > > Is this a reasonable way to do this? No. > Getting the parameter is done quit[e] simple, but I did not think fancy > was necessary here. It is not. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From PointedEars at web.de Wed Aug 5 07:02:02 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 05 Aug 2015 13:02:02 +0200 Subject: Uninstall References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> <7cbf35cc-9ac2-4d76-a06b-c5436d21f2de@googlegroups.com> Message-ID: <1804901.SJlN1V6M1A@PointedEars.de> Mark Lawrence wrote: > On 04/08/2015 19:31, sohcahtoa82 at gmail.com wrote: >> I really fucking hate how pedantic some of the people on this mailing >> list are. >> >> milos wasn't wrong. You just chose to take his message too literally. I >> thought it was pretty clear that when milos said "can't", he really meant >> "shouldn't". > > The simple solution is not to subscribe. Too late. The simple solution for them is to _unsubscribe_ now :) -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From marko at pacujo.net Wed Aug 5 07:10:13 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 05 Aug 2015 14:10:13 +0300 Subject: GOTCHA with list comprehension References: <87wpxacdnr.fsf@elektro.pacujo.net> Message-ID: <87r3nic7oq.fsf@elektro.pacujo.net> Chris Angelico : > On Wed, Aug 5, 2015 at 7:01 PM, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> You can chain 'for' and 'if' clauses as much as you like, and they >>> behave exactly the way you'd expect. >> >> How do you know what I'd expect? >> >> I wouldn't know what to expect myself. > [...] > So what would you expect nested 'if' clauses to do? Well, they become > nested 'if' statements: > > primes = [n for n in range(2,24) if n%2 if n%3] > > primes = [] > for n in range(2,24): > if n%2: > if n%3: > primes.append(n) > > What if we have multiple 'for' loops? Same thing! So no need to appeal to my expectations. Better just define it (as you now did). Marko From breamoreboy at yahoo.co.uk Wed Aug 5 09:08:43 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 5 Aug 2015 14:08:43 +0100 Subject: Problem in IDLE setup In-Reply-To: References: Message-ID: On 04/08/2015 12:31, Ahsan Chauhan wrote: > Respected Sir/Madam, > I would like to bring it to your notice that IDLE's executable file is > not working properly in Python3.5.0. So please look into this. > Regards > Ahsan Chauhan > Please state exactly what you're tried to do, what you expected to happen, and what actually happened. If you have a traceback please cut and paste all of it into your response. What OS are you using? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From python.list at tim.thechases.com Wed Aug 5 09:18:52 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 5 Aug 2015 08:18:52 -0500 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <87k2teq9tb.fsf@Equus.decebal.nl> References: <87k2teq9tb.fsf@Equus.decebal.nl> Message-ID: <20150805081852.7d386f13@bigbox.christie.dr> On 2015-08-02 12:11, Cecil Westerhof wrote: > There are a lot of ways to store configuration information: > - conf file > - xml file > - database > - json file > - and possible a lot of other ways > > I want to write a Python program to display cleaned log files. I do > not think I need a lot of configuration to be stored: > - some things relating to the GUI > - default behaviour > - default directory > - log files to display, including some info > - At least until where it was displayed > > Because of this I think a human readable file would be best. Yet another mostly-built-in option is to just have a simple file of key/value pairs, optionally with comments. This can be read with something like config = {} with open('config.ini') as f: for row in f: row = row.strip() if not row or row.startswith(('#', ';')): continue k, _, v = row.partition('=') config[k.strip().upper()] = v.lstrip() which is pretty straight-forward and easy format to edit. -tkc From rustompmody at gmail.com Wed Aug 5 09:37:04 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 5 Aug 2015 06:37:04 -0700 (PDT) Subject: Most Pythonic way to store (small) configuration In-Reply-To: References: <87k2teq9tb.fsf@Equus.decebal.nl> Message-ID: <36333f24-3bda-4534-b22f-20c99e8d791c@googlegroups.com> On Wednesday, August 5, 2015 at 6:58:01 PM UTC+5:30, Tim Chase wrote: > On 2015-08-02 12:11, Cecil Westerhof wrote: > > There are a lot of ways to store configuration information: > > - conf file > > - xml file > > - database > > - json file > > - and possible a lot of other ways > > > > I want to write a Python program to display cleaned log files. I do > > not think I need a lot of configuration to be stored: > > - some things relating to the GUI > > - default behaviour > > - default directory > > - log files to display, including some info > > - At least until where it was displayed > > > > Because of this I think a human readable file would be best. > > Yet another mostly-built-in option is to just have a simple file of > key/value pairs, optionally with comments. This can be read with > something like > > config = {} > with open('config.ini') as f: > for row in f: > row = row.strip() > if not row or row.startswith(('#', ';')): > continue > k, _, v = row.partition('=') > config[k.strip().upper()] = v.lstrip() > > which is pretty straight-forward and easy format to edit. > > -tkc JSON handles basic types like this: >>> from json import loads >>> loads("""{"anInt":1, "aString":"2"}""") {'aString': '2', 'anInt': 1} From rustompmody at gmail.com Wed Aug 5 09:46:15 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 5 Aug 2015 06:46:15 -0700 (PDT) Subject: Most Pythonic way to store (small) configuration In-Reply-To: <87k2teq9tb.fsf@Equus.decebal.nl> References: <87k2teq9tb.fsf@Equus.decebal.nl> Message-ID: <592c8e6c-5c5f-4c21-858d-76226a13eef7@googlegroups.com> On Sunday, August 2, 2015 at 3:44:51 PM UTC+5:30, Cecil Westerhof wrote: > There are a lot of ways to store configuration information: > - conf file > - xml file > - database > - json file > - and possible a lot of other ways One that I dont think has been mentioned: ast.literal_eval From invalid at invalid.invalid Wed Aug 5 10:00:02 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 5 Aug 2015 14:00:02 +0000 (UTC) Subject: Most Pythonic way to store (small) configuration References: <87k2teq9tb.fsf@Equus.decebal.nl> <663ad259-48e0-4eec-a946-7cd03805ddb1@googlegroups.com> <85y4hqkepb.fsf@benfinney.id.au> Message-ID: On 2015-08-05, Michael Torrie wrote: > On 08/04/2015 01:59 PM, Ben Finney wrote: >> marco.nawijn at colosso.nl writes: >> >>> Why not use Python files itself as configuration files? >> >> Because configuration data will be user-editable. (If it's not >> user-editable, that is itself a poor design choice.) >> >> If you allow executable code to be user-edited, that opens your program >> to arbitrary injection of executable code. Your program becomes wide >> open for security exploits, whether through malicious or accidental >> bugs, and simple human error can lead to arbitrary-scope damage to the >> user's system. > > We need to state the context here. The only context in which having a > Python config file is dangerous is when the python program runs as a > different user/privilege than the owner of the config file. If the user > owns the python files as well as the config file then none of this matters. Yes, it does. We're not just talking about intentional, malicious damange, we're also talking about _accidental_ damage caused by an incorrect edit of a configuration files. It's much harder to cause damage by mis-editing an "ini" format file that's parsed with the config file library than it is by mis-editing a Python file that's imported. -- Grant Edwards grant.b.edwards Yow! Clear the laundromat!! at This whirl-o-matic just had gmail.com a nuclear meltdown!! From steve at pearwood.info Wed Aug 5 10:08:13 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 06 Aug 2015 00:08:13 +1000 Subject: Most Pythonic way to store (small) configuration References: <87k2teq9tb.fsf@Equus.decebal.nl> <592c8e6c-5c5f-4c21-858d-76226a13eef7@googlegroups.com> Message-ID: <55c218ce$0$1653$c3e8da3$5496439d@news.astraweb.com> On Wed, 5 Aug 2015 11:46 pm, Rustom Mody wrote: > On Sunday, August 2, 2015 at 3:44:51 PM UTC+5:30, Cecil Westerhof wrote: >> There are a lot of ways to store configuration information: >> - conf file >> - xml file >> - database >> - json file >> - and possible a lot of other ways > > One that I dont think has been mentioned: > ast.literal_eval Probably because it doesn't work :-) py> import ast py> s = "x = 23" # pretend I read this line from a file py> ast.literal_eval(s) Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.3/ast.py", line 47, in literal_eval node_or_string = parse(node_or_string, mode='eval') File "/usr/local/lib/python3.3/ast.py", line 35, in parse return compile(source, filename, mode, PyCF_ONLY_AST) File "", line 1 x = 23 ^ SyntaxError: invalid syntax You might be able to build Yet Another Config Format using literal_eval as a building block, for evaluating values, but *in and of itself* it isn't a way to store config information, any more than int float or any other function which takes a string and evaluates it as a Python primitive or built-in type. However, there are at least config formats in the standard library which I believe we've missed: shelve, and plistlib. help(shelve) A "shelf" is a persistent, dictionary-like object. The difference with dbm databases is that the values (not the keys!) in a shelf can be essentially arbitrary Python objects -- anything that the "pickle" module can handle. This includes most class instances, recursive data types, and objects containing lots of shared sub-objects. The keys are ordinary strings. help(plistlib) The property list (.plist) file format is a simple XML pickle supporting basic object types, like dictionaries, lists, numbers and strings. Usually the top level object is a dictionary. -- Steven From rustompmody at gmail.com Wed Aug 5 10:25:58 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 5 Aug 2015 07:25:58 -0700 (PDT) Subject: Most Pythonic way to store (small) configuration In-Reply-To: <55c218ce$0$1653$c3e8da3$5496439d@news.astraweb.com> References: <87k2teq9tb.fsf@Equus.decebal.nl> <592c8e6c-5c5f-4c21-858d-76226a13eef7@googlegroups.com> <55c218ce$0$1653$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, August 5, 2015 at 7:38:46 PM UTC+5:30, Steven D'Aprano wrote: > On Wed, 5 Aug 2015 11:46 pm, Rustom Mody wrote: > > > On Sunday, August 2, 2015 at 3:44:51 PM UTC+5:30, Cecil Westerhof wrote: > >> There are a lot of ways to store configuration information: > >> - conf file > >> - xml file > >> - database > >> - json file > >> - and possible a lot of other ways > > > > One that I dont think has been mentioned: > > ast.literal_eval > > > Probably because it doesn't work :-) In the way you describe... yes Works alright if you give it *literals* >>> from ast import literal_eval >>> literal_eval('{"x":"hello", "y":2, "z":3.142}') {'z': 3.142, 'x': 'hello', 'y': 2} which is identical the the json.loads behavior >>> loads('{"x":"hello", "y":2, "z":3.142}') {'z': 3.142, 'x': 'hello', 'y': 2} of course the natural method of use would of course get the string from the open-ing of a config file -- something along the lines configuration = literal_eval(open("~/.fooconfig")) From jennyfurtado2 at gmail.com Wed Aug 5 11:13:11 2015 From: jennyfurtado2 at gmail.com (jennyfurtado2 at gmail.com) Date: Wed, 5 Aug 2015 08:13:11 -0700 (PDT) Subject: Is this an example of tail recursion? Message-ID: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> I am trying to learn differences between tail recursion and non tail recursion. Is the following recursive code tail recursive? If it is not how to convert it to tail recursion? If it is how to convert it to non tail recursion? class CastleDefenseI: INFINITY = 999999999 def __init__(self): self.dpw = 0 def soldiersVsDefenders(self,soldiers,defenders): # soldiers win if defenders <=0: return 0 # castle/defenders win if soldiers <= 0: return self.INFINITY # do another round of fighting # 1. Soldiers kill as many defenders defendersLeft = defenders - soldiers # 2. defendersLeft kill as many soldiers soldiersLeft = soldiers - defendersLeft return 1 + self.soldiersVsDefenders(soldiersLeft,defendersLeft) def oneWave(self,soldiers,defenders,castleHits): # castle/defenders wins if soldiers <= 0: return self.INFINITY # castle is dead, let soldiers play against defenders if castleHits <= 0: defendersLeft = defenders - self.dpw return self.soldiersVsDefenders(soldiers,defendersLeft) # try every possibility: # 1) all soldiers hit the castle, none hits the defenders # 2) one soldier hits the castle, the others hit the defenders # 3) two soldiers hit the castle, the others hit the defenders # ... # soldiers) no soldier hits the castle, all others hit the # defenders mini = self.INFINITY for i in range(0,soldiers): if i > defenders: break soldiersLeft = soldiers - (defenders -i) defendersLeft = defenders - i + self.dpw castleHitsLeft = castleHits - (soldiers -i) mini = min(mini,1 + self.oneWave(soldiersLeft,defendersLeft,castleHitsLeft)) return mini def playGame(self,soldiers,castleHits,defendersPerWave): self.dpw = defendersPerWave numWaves = self.oneWave(soldiers,0,castleHits) if numWaves >= self.INFINITY: return -1 else: return numWaves From rustompmody at gmail.com Wed Aug 5 11:21:21 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 5 Aug 2015 08:21:21 -0700 (PDT) Subject: Is this an example of tail recursion? In-Reply-To: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> References: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> Message-ID: On Wednesday, August 5, 2015 at 8:43:31 PM UTC+5:30, jennyf... at gmail.com wrote: > I am trying to learn differences between tail recursion and non tail recursion. > > Is the following recursive code tail recursive? > If it is not how to convert it to tail recursion? > If it is how to convert it to non tail recursion? > > class CastleDefenseI: > INFINITY = 999999999 > > def __init__(self): > self.dpw = 0 > > def soldiersVsDefenders(self,soldiers,defenders): > # soldiers win > if defenders <=0: > return 0 > # castle/defenders win > if soldiers <= 0: > return self.INFINITY > > # do another round of fighting > # 1. Soldiers kill as many defenders > defendersLeft = defenders - soldiers > # 2. defendersLeft kill as many soldiers > soldiersLeft = soldiers - defendersLeft > return 1 + self.soldiersVsDefenders(soldiersLeft,defendersLeft) Yes it *looks* tail recursive However if you rewrite 1 + x as 1 .__add__(x) you get return 1 .__add__(self.soldiersVsDefenders(soldiersLeft,defendersLeft)) Now you can see its not tail recursive I guess the same applies to the other functions > > def oneWave(self,soldiers,defenders,castleHits): > # castle/defenders wins > if soldiers <= 0: > return self.INFINITY > # castle is dead, let soldiers play against defenders > if castleHits <= 0: > defendersLeft = defenders - self.dpw > return self.soldiersVsDefenders(soldiers,defendersLeft) > > # try every possibility: > # 1) all soldiers hit the castle, none hits the defenders > # 2) one soldier hits the castle, the others hit the defenders > # 3) two soldiers hit the castle, the others hit the defenders > # ... > # soldiers) no soldier hits the castle, all others hit the > # defenders > mini = self.INFINITY > for i in range(0,soldiers): > if i > defenders: > break > soldiersLeft = soldiers - (defenders -i) > defendersLeft = defenders - i + self.dpw > castleHitsLeft = castleHits - (soldiers -i) > mini = min(mini,1 + self.oneWave(soldiersLeft,defendersLeft,castleHitsLeft)) > return mini > > def playGame(self,soldiers,castleHits,defendersPerWave): > self.dpw = defendersPerWave > numWaves = self.oneWave(soldiers,0,castleHits) > if numWaves >= self.INFINITY: > return -1 > else: > return numWaves From jennyfurtado2 at gmail.com Wed Aug 5 11:37:37 2015 From: jennyfurtado2 at gmail.com (jennyfurtado2 at gmail.com) Date: Wed, 5 Aug 2015 08:37:37 -0700 (PDT) Subject: Is this an example of tail recursion? In-Reply-To: References: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> Message-ID: On Wednesday, August 5, 2015 at 9:21:33 AM UTC-6, Rustom Mody wrote: > On Wednesday, August 5, 2015 at 8:43:31 PM UTC+5:30, jennyf... at gmail.com wrote: > > I am trying to learn differences between tail recursion and non tail recursion. > > > > Is the following recursive code tail recursive? > > If it is not how to convert it to tail recursion? > > If it is how to convert it to non tail recursion? > > > > class CastleDefenseI: > > INFINITY = 999999999 > > > > def __init__(self): > > self.dpw = 0 > > > > def soldiersVsDefenders(self,soldiers,defenders): > > # soldiers win > > if defenders <=0: > > return 0 > > # castle/defenders win > > if soldiers <= 0: > > return self.INFINITY > > > > # do another round of fighting > > # 1. Soldiers kill as many defenders > > defendersLeft = defenders - soldiers > > # 2. defendersLeft kill as many soldiers > > soldiersLeft = soldiers - defendersLeft > > return 1 + self.soldiersVsDefenders(soldiersLeft,defendersLeft) > > Yes it *looks* tail recursive > However if you rewrite 1 + x as 1 .__add__(x) you get > return 1 .__add__(self.soldiersVsDefenders(soldiersLeft,defendersLeft)) > > Now you can see its not tail recursive > I guess the same applies to the other functions > > > > > def oneWave(self,soldiers,defenders,castleHits): > > # castle/defenders wins > > if soldiers <= 0: > > return self.INFINITY > > # castle is dead, let soldiers play against defenders > > if castleHits <= 0: > > defendersLeft = defenders - self.dpw > > return self.soldiersVsDefenders(soldiers,defendersLeft) > > > > # try every possibility: > > # 1) all soldiers hit the castle, none hits the defenders > > # 2) one soldier hits the castle, the others hit the defenders > > # 3) two soldiers hit the castle, the others hit the defenders > > # ... > > # soldiers) no soldier hits the castle, all others hit the > > # defenders > > mini = self.INFINITY > > for i in range(0,soldiers): > > if i > defenders: > > break > > soldiersLeft = soldiers - (defenders -i) > > defendersLeft = defenders - i + self.dpw > > castleHitsLeft = castleHits - (soldiers -i) > > mini = min(mini,1 + self.oneWave(soldiersLeft,defendersLeft,castleHitsLeft)) > > return mini > > > > def playGame(self,soldiers,castleHits,defendersPerWave): > > self.dpw = defendersPerWave > > numWaves = self.oneWave(soldiers,0,castleHits) > > if numWaves >= self.INFINITY: > > return -1 > > else: > > return numWaves On Wednesday, August 5, 2015 at 9:21:33 AM UTC-6, Rustom Mody wrote: > On Wednesday, August 5, 2015 at 8:43:31 PM UTC+5:30, jennyf... at gmail.com wrote: > > I am trying to learn differences between tail recursion and non tail recursion. > > > > Is the following recursive code tail recursive? > > If it is not how to convert it to tail recursion? > > If it is how to convert it to non tail recursion? > > > > class CastleDefenseI: > > INFINITY = 999999999 > > > > def __init__(self): > > self.dpw = 0 > > > > def soldiersVsDefenders(self,soldiers,defenders): > > # soldiers win > > if defenders <=0: > > return 0 > > # castle/defenders win > > if soldiers <= 0: > > return self.INFINITY > > > > # do another round of fighting > > # 1. Soldiers kill as many defenders > > defendersLeft = defenders - soldiers > > # 2. defendersLeft kill as many soldiers > > soldiersLeft = soldiers - defendersLeft > > return 1 + self.soldiersVsDefenders(soldiersLeft,defendersLeft) > > Yes it *looks* tail recursive > However if you rewrite 1 + x as 1 .__add__(x) you get > return 1 .__add__(self.soldiersVsDefenders(soldiersLeft,defendersLeft)) > > Now you can see its not tail recursive > I guess the same applies to the other functions > > > > > def oneWave(self,soldiers,defenders,castleHits): > > # castle/defenders wins > > if soldiers <= 0: > > return self.INFINITY > > # castle is dead, let soldiers play against defenders > > if castleHits <= 0: > > defendersLeft = defenders - self.dpw > > return self.soldiersVsDefenders(soldiers,defendersLeft) > > > > # try every possibility: > > # 1) all soldiers hit the castle, none hits the defenders > > # 2) one soldier hits the castle, the others hit the defenders > > # 3) two soldiers hit the castle, the others hit the defenders > > # ... > > # soldiers) no soldier hits the castle, all others hit the > > # defenders > > mini = self.INFINITY > > for i in range(0,soldiers): > > if i > defenders: > > break > > soldiersLeft = soldiers - (defenders -i) > > defendersLeft = defenders - i + self.dpw > > castleHitsLeft = castleHits - (soldiers -i) > > mini = min(mini,1 + self.oneWave(soldiersLeft,defendersLeft,castleHitsLeft)) > > return mini > > > > def playGame(self,soldiers,castleHits,defendersPerWave): > > self.dpw = defendersPerWave > > numWaves = self.oneWave(soldiers,0,castleHits) > > if numWaves >= self.INFINITY: > > return -1 > > else: > > return numWaves Sorry I am missing a subtle point: Isnt 1+ self.soldiersVsDefenders... ending up calling 1.__add__(self.soldiersVsDefenders...)? From rosuav at gmail.com Wed Aug 5 11:51:57 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Aug 2015 01:51:57 +1000 Subject: Is this an example of tail recursion? In-Reply-To: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> References: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> Message-ID: On Thu, Aug 6, 2015 at 1:13 AM, wrote: > I am trying to learn differences between tail recursion and non tail recursion. Tail recursion is where you do exactly this: return some_function(...) Absolutely nothing is allowed to happen around or after that function, and that also means you can't do that inside a try/except/finally block, nor a with block, etc, etc, etc. It has to be nothing more than a function call, and you return the exact result of that call. > Is the following recursive code tail recursive? > If it is not how to convert it to tail recursion? > If it is how to convert it to non tail recursion? > > def __init__(self): > self.dpw = 0 Not tail recursive - not recursive - doesn't call anything. Trivial case. :) > def soldiersVsDefenders(self,soldiers,defenders): > # soldiers win > if defenders <=0: > return 0 > # castle/defenders win > if soldiers <= 0: > return self.INFINITY In these cases, equally trivial - not recursive in any form. > # do another round of fighting > # 1. Soldiers kill as many defenders > defendersLeft = defenders - soldiers > # 2. defendersLeft kill as many soldiers > soldiersLeft = soldiers - defendersLeft (Interesting that the attacking soldiers get the first strike.) > return 1 + self.soldiersVsDefenders(soldiersLeft,defendersLeft) This is NOT tail recursion, because you add 1 at the end of it. The way to make it tail recursive would be to add another argument to the function, which it would keep adding to; whenever it returns, you would add the accumulator to the return value: def soldiersVsDefenders(self,soldiers,defenders, accum=0): if defenders <= 0: return 0 + accum if soldiers <= 0: return self.INFINITY + accum # other code goes here return self.soldiersVsDefenders(soldiersLeft,defendersLeft,1+accum) Now it's tail recursive. If this looks ugly, it's because it is; tail recursion often isn't worth the effort. Note that, as far as Python's concerned, this is a tail call, but isn't necessarily *recursion* (which implies that you somehow know you're calling the same function). If someone subclasses your code and overrides this method, your code will call the subclass's version - if the subclass calls through to super(), you'll end up with mutual recursion, but still not a simple case of tail recursion. However, you could choose to ignore this possibility and manually convert this into iteration: def soldiersVsDefenders(self,soldiers,defenders): rounds = 0 while soldiers and defenders: # do another round of fighting # 1. Soldiers kill as many defenders defendersLeft = defenders - soldiers # 2. defendersLeft kill as many soldiers soldiersLeft = soldiers - defendersLeft rounds += 1 if defenders <= 0: return rounds return self.INFINITY + rounds How's that look? Better? Worse? On to the next function. > def oneWave(self,soldiers,defenders,castleHits): > # castle is dead, let soldiers play against defenders > if castleHits <= 0: > defendersLeft = defenders - self.dpw > return self.soldiersVsDefenders(soldiers,defendersLeft) This is a tail call. It's not tail *recursion* because you're calling a completely different function, but you are indeed calling another function and directly returning its return value. > mini = self.INFINITY > for i in range(0,soldiers): > if i > defenders: > break > soldiersLeft = soldiers - (defenders -i) > defendersLeft = defenders - i + self.dpw > castleHitsLeft = castleHits - (soldiers -i) > mini = min(mini,1 + self.oneWave(soldiersLeft,defendersLeft,castleHitsLeft)) > return mini Not sure what the point of all this is, but sure. This clearly isn't tail recursion, though, as it's doing a whole lot of other work after the recursive call. Having a loop and recursion like this is pretty scary, but in terms of "is this or isn't this tail recursive", it's pretty clear. > def playGame(self,soldiers,castleHits,defendersPerWave): > self.dpw = defendersPerWave > numWaves = self.oneWave(soldiers,0,castleHits) > if numWaves >= self.INFINITY: > return -1 > else: > return numWaves And this is, again, no tail call. If the trap for INFINITY becoming -1 were inside oneWave(), then this could be turned into a tail call, but as it is, there's more work to be done after the other function returns, so it's not a tail call. Hope that helps! ChrisA From rosuav at gmail.com Wed Aug 5 11:54:41 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Aug 2015 01:54:41 +1000 Subject: Is this an example of tail recursion? In-Reply-To: References: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> Message-ID: On Thu, Aug 6, 2015 at 1:37 AM, wrote: > Sorry I am missing a subtle point: Isnt 1+ self.soldiersVsDefenders... ending up calling 1.__add__(self.soldiersVsDefenders...)? I think his point is that it is, in effect, doing that; but honestly, calling this a tail call into the int+int addition function is pretty pointless. I mean, sure, it's technically a sort of tail call, but it's definitely not tail recursion, and it's such a trivial operation (adding one to a probably-small number) that it's hardly even worth mentioning. The main point of tail recursion is how it interacts with the self-call, and that's not the tail call here. ChrisA From jennyfurtado2 at gmail.com Wed Aug 5 11:59:49 2015 From: jennyfurtado2 at gmail.com (jenny) Date: Wed, 5 Aug 2015 08:59:49 -0700 (PDT) Subject: Is this an example of tail recursion? In-Reply-To: References: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> Message-ID: On Wednesday, August 5, 2015 at 9:52:14 AM UTC-6, Chris Angelico wrote: > On Thu, Aug 6, 2015 at 1:13 AM, wrote: > > I am trying to learn differences between tail recursion and non tail recursion. > > Tail recursion is where you do exactly this: > > return some_function(...) > > Absolutely nothing is allowed to happen around or after that function, > and that also means you can't do that inside a try/except/finally > block, nor a with block, etc, etc, etc. It has to be nothing more than > a function call, and you return the exact result of that call. > > > Is the following recursive code tail recursive? > > If it is not how to convert it to tail recursion? > > If it is how to convert it to non tail recursion? > > > > def __init__(self): > > self.dpw = 0 > > Not tail recursive - not recursive - doesn't call anything. Trivial case. :) > > > def soldiersVsDefenders(self,soldiers,defenders): > > # soldiers win > > if defenders <=0: > > return 0 > > # castle/defenders win > > if soldiers <= 0: > > return self.INFINITY > > In these cases, equally trivial - not recursive in any form. > > > # do another round of fighting > > # 1. Soldiers kill as many defenders > > defendersLeft = defenders - soldiers > > # 2. defendersLeft kill as many soldiers > > soldiersLeft = soldiers - defendersLeft > > (Interesting that the attacking soldiers get the first strike.) > > > return 1 + self.soldiersVsDefenders(soldiersLeft,defendersLeft) > > This is NOT tail recursion, because you add 1 at the end of it. The > way to make it tail recursive would be to add another argument to the > function, which it would keep adding to; whenever it returns, you > would add the accumulator to the return value: > > def soldiersVsDefenders(self,soldiers,defenders, accum=0): > if defenders <= 0: > return 0 + accum > if soldiers <= 0: > return self.INFINITY + accum > # other code goes here > return self.soldiersVsDefenders(soldiersLeft,defendersLeft,1+accum) > > Now it's tail recursive. If this looks ugly, it's because it is; tail > recursion often isn't worth the effort. > > Note that, as far as Python's concerned, this is a tail call, but > isn't necessarily *recursion* (which implies that you somehow know > you're calling the same function). If someone subclasses your code and > overrides this method, your code will call the subclass's version - if > the subclass calls through to super(), you'll end up with mutual > recursion, but still not a simple case of tail recursion. However, you > could choose to ignore this possibility and manually convert this into > iteration: > > def soldiersVsDefenders(self,soldiers,defenders): > rounds = 0 > while soldiers and defenders: > # do another round of fighting > # 1. Soldiers kill as many defenders > defendersLeft = defenders - soldiers > # 2. defendersLeft kill as many soldiers > soldiersLeft = soldiers - defendersLeft > rounds += 1 > if defenders <= 0: > return rounds > return self.INFINITY + rounds > > How's that look? Better? Worse? > > On to the next function. > > > def oneWave(self,soldiers,defenders,castleHits): > > # castle is dead, let soldiers play against defenders > > if castleHits <= 0: > > defendersLeft = defenders - self.dpw > > return self.soldiersVsDefenders(soldiers,defendersLeft) > > This is a tail call. It's not tail *recursion* because you're calling > a completely different function, but you are indeed calling another > function and directly returning its return value. > > > mini = self.INFINITY > > for i in range(0,soldiers): > > if i > defenders: > > break > > soldiersLeft = soldiers - (defenders -i) > > defendersLeft = defenders - i + self.dpw > > castleHitsLeft = castleHits - (soldiers -i) > > mini = min(mini,1 + self.oneWave(soldiersLeft,defendersLeft,castleHitsLeft)) > > return mini > > Not sure what the point of all this is, but sure. This clearly isn't > tail recursion, though, as it's doing a whole lot of other work after > the recursive call. Having a loop and recursion like this is pretty > scary, but in terms of "is this or isn't this tail recursive", it's > pretty clear. > > > def playGame(self,soldiers,castleHits,defendersPerWave): > > self.dpw = defendersPerWave > > numWaves = self.oneWave(soldiers,0,castleHits) > > if numWaves >= self.INFINITY: > > return -1 > > else: > > return numWaves > > And this is, again, no tail call. If the trap for INFINITY becoming -1 > were inside oneWave(), then this could be turned into a tail call, but > as it is, there's more work to be done after the other function > returns, so it's not a tail call. > > Hope that helps! > > ChrisA Thank you Chris! That was a very nice explanation. From rustompmody at gmail.com Wed Aug 5 12:10:09 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 5 Aug 2015 09:10:09 -0700 (PDT) Subject: Is this an example of tail recursion? In-Reply-To: References: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> Message-ID: <01c7a472-9186-4e20-8b96-ae2c27af70f6@googlegroups.com> On Wednesday, August 5, 2015 at 9:07:52 PM UTC+5:30, jennyf... at gmail.com wrote: > On Wednesday, August 5, 2015 at 9:21:33 AM UTC-6, Rustom Mody wrote: > > On Wednesday, August 5, 2015 at 8:43:31 PM UTC+5:30, jennyf... at gmail.com wrote: > > > I am trying to learn differences between tail recursion and non tail recursion. > > > > > > Is the following recursive code tail recursive? > > > If it is not how to convert it to tail recursion? > > > If it is how to convert it to non tail recursion? > > > > > > class CastleDefenseI: > > > INFINITY = 999999999 > > > > > > def __init__(self): > > > self.dpw = 0 > > > > > > def soldiersVsDefenders(self,soldiers,defenders): > > > # soldiers win > > > if defenders <=0: > > > return 0 > > > # castle/defenders win > > > if soldiers <= 0: > > > return self.INFINITY > > > > > > # do another round of fighting > > > # 1. Soldiers kill as many defenders > > > defendersLeft = defenders - soldiers > > > # 2. defendersLeft kill as many soldiers > > > soldiersLeft = soldiers - defendersLeft > > > return 1 + self.soldiersVsDefenders(soldiersLeft,defendersLeft) > > > > Yes it *looks* tail recursive > > However if you rewrite 1 + x as 1 .__add__(x) you get > > return 1 .__add__(self.soldiersVsDefenders(soldiersLeft,defendersLeft)) > > > > Now you can see its not tail recursive > > I guess the same applies to the other functions > > > > > > > > def oneWave(self,soldiers,defenders,castleHits): > > > # castle/defenders wins > > > if soldiers <= 0: > > > return self.INFINITY > > > # castle is dead, let soldiers play against defenders > > > if castleHits <= 0: > > > defendersLeft = defenders - self.dpw > > > return self.soldiersVsDefenders(soldiers,defendersLeft) > > > > > > # try every possibility: > > > # 1) all soldiers hit the castle, none hits the defenders > > > # 2) one soldier hits the castle, the others hit the defenders > > > # 3) two soldiers hit the castle, the others hit the defenders > > > # ... > > > # soldiers) no soldier hits the castle, all others hit the > > > # defenders > > > mini = self.INFINITY > > > for i in range(0,soldiers): > > > if i > defenders: > > > break > > > soldiersLeft = soldiers - (defenders -i) > > > defendersLeft = defenders - i + self.dpw > > > castleHitsLeft = castleHits - (soldiers -i) > > > mini = min(mini,1 + self.oneWave(soldiersLeft,defendersLeft,castleHitsLeft)) > > > return mini > > > > > > def playGame(self,soldiers,castleHits,defendersPerWave): > > > self.dpw = defendersPerWave > > > numWaves = self.oneWave(soldiers,0,castleHits) > > > if numWaves >= self.INFINITY: > > > return -1 > > > else: > > > return numWaves > > > > On Wednesday, August 5, 2015 at 9:21:33 AM UTC-6, Rustom Mody wrote: > > On Wednesday, August 5, 2015 at 8:43:31 PM UTC+5:30, jennyf... at gmail.com wrote: > > > I am trying to learn differences between tail recursion and non tail recursion. > > > > > > Is the following recursive code tail recursive? > > > If it is not how to convert it to tail recursion? > > > If it is how to convert it to non tail recursion? > > > > > > class CastleDefenseI: > > > INFINITY = 999999999 > > > > > > def __init__(self): > > > self.dpw = 0 > > > > > > def soldiersVsDefenders(self,soldiers,defenders): > > > # soldiers win > > > if defenders <=0: > > > return 0 > > > # castle/defenders win > > > if soldiers <= 0: > > > return self.INFINITY > > > > > > # do another round of fighting > > > # 1. Soldiers kill as many defenders > > > defendersLeft = defenders - soldiers > > > # 2. defendersLeft kill as many soldiers > > > soldiersLeft = soldiers - defendersLeft > > > return 1 + self.soldiersVsDefenders(soldiersLeft,defendersLeft) > > > > Yes it *looks* tail recursive > > However if you rewrite 1 + x as 1 .__add__(x) you get > > return 1 .__add__(self.soldiersVsDefenders(soldiersLeft,defendersLeft)) > > > > Now you can see its not tail recursive > > I guess the same applies to the other functions > > > > > > > > def oneWave(self,soldiers,defenders,castleHits): > > > # castle/defenders wins > > > if soldiers <= 0: > > > return self.INFINITY > > > # castle is dead, let soldiers play against defenders > > > if castleHits <= 0: > > > defendersLeft = defenders - self.dpw > > > return self.soldiersVsDefenders(soldiers,defendersLeft) > > > > > > # try every possibility: > > > # 1) all soldiers hit the castle, none hits the defenders > > > # 2) one soldier hits the castle, the others hit the defenders > > > # 3) two soldiers hit the castle, the others hit the defenders > > > # ... > > > # soldiers) no soldier hits the castle, all others hit the > > > # defenders > > > mini = self.INFINITY > > > for i in range(0,soldiers): > > > if i > defenders: > > > break > > > soldiersLeft = soldiers - (defenders -i) > > > defendersLeft = defenders - i + self.dpw > > > castleHitsLeft = castleHits - (soldiers -i) > > > mini = min(mini,1 + self.oneWave(soldiersLeft,defendersLeft,castleHitsLeft)) > > > return mini > > > > > > def playGame(self,soldiers,castleHits,defendersPerWave): > > > self.dpw = defendersPerWave > > > numWaves = self.oneWave(soldiers,0,castleHits) > > > if numWaves >= self.INFINITY: > > > return -1 > > > else: > > > return numWaves > > Sorry I am missing a subtle point: Isnt 1+ self.soldiersVsDefenders... ending up calling 1.__add__(self.soldiersVsDefenders...)? 1 + x does not *call* 1 .__add__(x) It *is* that [Barring corner cases of radd etc] IOW I am desugaring the syntax into explicit method-calls so you can see all the calls explicitly Then it becomes evident -- visibly and in fact --that the tail call is the __add__ method not the solderdiersVsDefenders As for Chris': > I think his point is that it is, in effect, doing that; but honestly, > calling this a tail call into the int+int addition function is pretty > pointless. I mean, sure, it's technically a sort of tail call, but > it's definitely not tail recursion, and it's such a trivial operation > (adding one to a probably-small number) that it's hardly even worth > mentioning. The main point of tail recursion is how it interacts with > the self-call, and that's not the tail call here. Ive no idea what he is saying. Tail-call has nothing to do with triviality or otherwise of computation When you do return foo(bar(baz(x))) foo is a tail call; bar and baz not. Tail recursion is a special case of tail call where that expression is embedded in a definition of foo Languages like scheme take pains to eliminate ALL tail calls Not python so your question is a bit academic (in python context) From python at activemail.us Wed Aug 5 12:12:38 2015 From: python at activemail.us (Rick Smith) Date: Wed, 05 Aug 2015 16:12:38 +0000 Subject: Installation Successful, but pythonw and idle doesn't function Message-ID: <201508051612.t75GCc5m017047@rs103.luxsci.com> I was able to install various versions of Python (3.5.0b4 32bit being the most recent) multiple times (uninstalling in between) and they worked ("python --version" at the command line worked). However pythonw.exe did not and does not work. I was simply returned to the command prompt, without ANY interaction or error. prompt>pythonw prompt> I also attempted to run "idle", with the following results: C:\Users\judy\AppData\Local\Programs\Python\Python35-32\Lib\idlelib>idle.py ** IDLE can't import Tkinter. Your Python may not be configured for Tk. ** I finally attempted the installation using ONLY the default installation choice and got the same results. I had attempted previous installations using a "custom" configuration each time, also with the SAME results. There was an older version (2.3.5) installed from a CD from a Python book, but this was uninstalled as well. (I believe that version did work with pythonw.) I have checked online for answers and they involve adding paths to the "Path" environmental variable, moving libraries or deleting files in the ".idlerc" directory. I have attempted ALL of the. One mentioned using the ActiveState version, which I will try later. So, I am at a complete loss -- I am running Windows Visa Home Premium 32 bit, but I did not see any "incompatibility" with Vista mentioned. I did search for all "python" in the registry and did find "residue" from every unique version installed. I removed all of them and attempted a fresh, default install of the latest version -- same problem. The path included: C:\Users\judy\AppData\Local\Programs\Python\Python35-32\Scripts\;C:\Users\judy\AppData\Local\Programs\Python\Python35-32\;C:\Users\judy\AppData\Local\Programs\Python\Python35-32\DLLs;C:\Users\judy\AppData\Local\Programs\Python\Python35-32\LIB;C:\Users\judy\AppData\Local\Programs\Python\Python35-32\LIB\LIB-TK;C:\Users\judy\AppData\Local\Programs\Python\Python35-32\LIB\tkinter; The long path was due to the default installation. I added the final path item. I also added a "PythonPath" environment variable with the same contents as I saw that mentioned as a solution to this issue. The problem seems rare and may be due to a previous installation and Vista -- I can't tell. Am willing to try anything. I have NO idea of what to do next to install the python.org version on this Toshiba laptop. Please let me know. Thank you. Rick Smith From jennyfurtado2 at gmail.com Wed Aug 5 12:15:22 2015 From: jennyfurtado2 at gmail.com (jennyfurtado2 at gmail.com) Date: Wed, 5 Aug 2015 09:15:22 -0700 (PDT) Subject: Is this an example of tail recursion? In-Reply-To: <01c7a472-9186-4e20-8b96-ae2c27af70f6@googlegroups.com> References: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> <01c7a472-9186-4e20-8b96-ae2c27af70f6@googlegroups.com> Message-ID: <66322bf1-d8ca-4f84-b8bc-7ede9fffc25f@googlegroups.com> On Wednesday, August 5, 2015 at 10:10:22 AM UTC-6, Rustom Mody wrote: > On Wednesday, August 5, 2015 at 9:07:52 PM UTC+5:30, jennyf... at gmail.com wrote: > > On Wednesday, August 5, 2015 at 9:21:33 AM UTC-6, Rustom Mody wrote: > > > On Wednesday, August 5, 2015 at 8:43:31 PM UTC+5:30, jennyf... at gmail.com wrote: > > > > I am trying to learn differences between tail recursion and non tail recursion. > > > > > > > > Is the following recursive code tail recursive? > > > > If it is not how to convert it to tail recursion? > > > > If it is how to convert it to non tail recursion? > > > > > > > > class CastleDefenseI: > > > > INFINITY = 999999999 > > > > > > > > def __init__(self): > > > > self.dpw = 0 > > > > > > > > def soldiersVsDefenders(self,soldiers,defenders): > > > > # soldiers win > > > > if defenders <=0: > > > > return 0 > > > > # castle/defenders win > > > > if soldiers <= 0: > > > > return self.INFINITY > > > > > > > > # do another round of fighting > > > > # 1. Soldiers kill as many defenders > > > > defendersLeft = defenders - soldiers > > > > # 2. defendersLeft kill as many soldiers > > > > soldiersLeft = soldiers - defendersLeft > > > > return 1 + self.soldiersVsDefenders(soldiersLeft,defendersLeft) > > > > > > Yes it *looks* tail recursive > > > However if you rewrite 1 + x as 1 .__add__(x) you get > > > return 1 .__add__(self.soldiersVsDefenders(soldiersLeft,defendersLeft)) > > > > > > Now you can see its not tail recursive > > > I guess the same applies to the other functions > > > > > > > > > > > def oneWave(self,soldiers,defenders,castleHits): > > > > # castle/defenders wins > > > > if soldiers <= 0: > > > > return self.INFINITY > > > > # castle is dead, let soldiers play against defenders > > > > if castleHits <= 0: > > > > defendersLeft = defenders - self.dpw > > > > return self.soldiersVsDefenders(soldiers,defendersLeft) > > > > > > > > # try every possibility: > > > > # 1) all soldiers hit the castle, none hits the defenders > > > > # 2) one soldier hits the castle, the others hit the defenders > > > > # 3) two soldiers hit the castle, the others hit the defenders > > > > # ... > > > > # soldiers) no soldier hits the castle, all others hit the > > > > # defenders > > > > mini = self.INFINITY > > > > for i in range(0,soldiers): > > > > if i > defenders: > > > > break > > > > soldiersLeft = soldiers - (defenders -i) > > > > defendersLeft = defenders - i + self.dpw > > > > castleHitsLeft = castleHits - (soldiers -i) > > > > mini = min(mini,1 + self.oneWave(soldiersLeft,defendersLeft,castleHitsLeft)) > > > > return mini > > > > > > > > def playGame(self,soldiers,castleHits,defendersPerWave): > > > > self.dpw = defendersPerWave > > > > numWaves = self.oneWave(soldiers,0,castleHits) > > > > if numWaves >= self.INFINITY: > > > > return -1 > > > > else: > > > > return numWaves > > > > > > > > On Wednesday, August 5, 2015 at 9:21:33 AM UTC-6, Rustom Mody wrote: > > > On Wednesday, August 5, 2015 at 8:43:31 PM UTC+5:30, jennyf... at gmail.com wrote: > > > > I am trying to learn differences between tail recursion and non tail recursion. > > > > > > > > Is the following recursive code tail recursive? > > > > If it is not how to convert it to tail recursion? > > > > If it is how to convert it to non tail recursion? > > > > > > > > class CastleDefenseI: > > > > INFINITY = 999999999 > > > > > > > > def __init__(self): > > > > self.dpw = 0 > > > > > > > > def soldiersVsDefenders(self,soldiers,defenders): > > > > # soldiers win > > > > if defenders <=0: > > > > return 0 > > > > # castle/defenders win > > > > if soldiers <= 0: > > > > return self.INFINITY > > > > > > > > # do another round of fighting > > > > # 1. Soldiers kill as many defenders > > > > defendersLeft = defenders - soldiers > > > > # 2. defendersLeft kill as many soldiers > > > > soldiersLeft = soldiers - defendersLeft > > > > return 1 + self.soldiersVsDefenders(soldiersLeft,defendersLeft) > > > > > > Yes it *looks* tail recursive > > > However if you rewrite 1 + x as 1 .__add__(x) you get > > > return 1 .__add__(self.soldiersVsDefenders(soldiersLeft,defendersLeft)) > > > > > > Now you can see its not tail recursive > > > I guess the same applies to the other functions > > > > > > > > > > > def oneWave(self,soldiers,defenders,castleHits): > > > > # castle/defenders wins > > > > if soldiers <= 0: > > > > return self.INFINITY > > > > # castle is dead, let soldiers play against defenders > > > > if castleHits <= 0: > > > > defendersLeft = defenders - self.dpw > > > > return self.soldiersVsDefenders(soldiers,defendersLeft) > > > > > > > > # try every possibility: > > > > # 1) all soldiers hit the castle, none hits the defenders > > > > # 2) one soldier hits the castle, the others hit the defenders > > > > # 3) two soldiers hit the castle, the others hit the defenders > > > > # ... > > > > # soldiers) no soldier hits the castle, all others hit the > > > > # defenders > > > > mini = self.INFINITY > > > > for i in range(0,soldiers): > > > > if i > defenders: > > > > break > > > > soldiersLeft = soldiers - (defenders -i) > > > > defendersLeft = defenders - i + self.dpw > > > > castleHitsLeft = castleHits - (soldiers -i) > > > > mini = min(mini,1 + self.oneWave(soldiersLeft,defendersLeft,castleHitsLeft)) > > > > return mini > > > > > > > > def playGame(self,soldiers,castleHits,defendersPerWave): > > > > self.dpw = defendersPerWave > > > > numWaves = self.oneWave(soldiers,0,castleHits) > > > > if numWaves >= self.INFINITY: > > > > return -1 > > > > else: > > > > return numWaves > > > > Sorry I am missing a subtle point: Isnt 1+ self.soldiersVsDefenders... ending up calling 1.__add__(self.soldiersVsDefenders...)? > > 1 + x > does not *call* 1 .__add__(x) > It *is* that > [Barring corner cases of radd etc] > IOW I am desugaring the syntax into explicit method-calls so you can see > all the calls explicitly > Then it becomes evident -- visibly and in fact --that the tail call is the > __add__ method not the solderdiersVsDefenders > > As for Chris': > > I think his point is that it is, in effect, doing that; but honestly, > > calling this a tail call into the int+int addition function is pretty > > pointless. I mean, sure, it's technically a sort of tail call, but > > it's definitely not tail recursion, and it's such a trivial operation > > (adding one to a probably-small number) that it's hardly even worth > > mentioning. The main point of tail recursion is how it interacts with > > the self-call, and that's not the tail call here. > > Ive no idea what he is saying. > Tail-call has nothing to do with triviality or otherwise of computation > > When you do > return foo(bar(baz(x))) > foo is a tail call; bar and baz not. > > Tail recursion is a special case of tail call where that expression is > embedded in a definition of foo > > Languages like scheme take pains to eliminate ALL tail calls > Not python so your question is a bit academic (in python context) Thanks Rustom. I get the __add__ point now. From rosuav at gmail.com Wed Aug 5 12:28:57 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Aug 2015 02:28:57 +1000 Subject: Is this an example of tail recursion? In-Reply-To: <01c7a472-9186-4e20-8b96-ae2c27af70f6@googlegroups.com> References: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> <01c7a472-9186-4e20-8b96-ae2c27af70f6@googlegroups.com> Message-ID: On Thu, Aug 6, 2015 at 2:10 AM, Rustom Mody wrote: > 1 + x > does not *call* 1 .__add__(x) > It *is* that > [Barring corner cases of radd etc] > IOW I am desugaring the syntax into explicit method-calls so you can see > all the calls explicitly > Then it becomes evident -- visibly and in fact --that the tail call is the > __add__ method not the solderdiersVsDefenders Except that it *isn't* that, precisely because of those other cases. When Python sees an expression like "1 + x" and doesn't yet know what x is, it can't do anything other than record the fact that there'll be a BINARY_ADD of the integer 1 and whatever that thing is. That object might well define __radd__, so the call is most definitely not equivalent to the operator. And the ultimate result of that addition might not even be a function call at all, if it's implemented in C. Or if you're running in PyPy and the optimizer turned it into machine code. So no, even though you can define addition for *your own classes* using __add__ or __radd__, you can't reinterpret every addition as a function call. ChrisA From jennyfurtado2 at gmail.com Wed Aug 5 12:33:16 2015 From: jennyfurtado2 at gmail.com (jennyfurtado2 at gmail.com) Date: Wed, 5 Aug 2015 09:33:16 -0700 (PDT) Subject: How to trace the recursive path? Message-ID: Consider this code (shown in my previous post) class CastleDefenseI: INFINITY = 999999999 def __init__(self): self.dpw = 0 def soldiersVsDefenders(self,soldiers,defenders): # soldiers win if defenders <=0: return 0 # castle/defenders win if soldiers <= 0: return self.INFINITY # do another round of fighting # 1. Soldiers kill as many defenders defendersLeft = defenders - soldiers # 2. defendersLeft kill as many soldiers soldiersLeft = soldiers - defendersLeft return 1 + self.soldiersVsDefenders(soldiersLeft,defendersLeft) def oneWave(self,soldiers,defenders,castleHits): # castle/defenders wins if soldiers <= 0: return self.INFINITY # castle is dead, let soldiers play against defenders if castleHits <= 0: defendersLeft = defenders - self.dpw return self.soldiersVsDefenders(soldiers,defendersLeft) # try every possibility: # 1) all soldiers hit the castle, none hits the defenders # 2) one soldier hits the castle, the others hit the defenders # 3) two soldiers hit the castle, the others hit the defenders # ... # soldiers) no soldier hits the castle, all others hit the # defenders mini = self.INFINITY for i in range(0,soldiers): if i > defenders: break soldiersLeft = soldiers - (defenders -i) defendersLeft = defenders - i + self.dpw castleHitsLeft = castleHits - (soldiers -i) mini = min(mini,1 + self.oneWave(soldiersLeft,defendersLeft,castleHitsLeft)) return mini def playGame(self,soldiers,castleHits,defendersPerWave): self.dpw = defendersPerWave numWaves = self.oneWave(soldiers,0,castleHits) if numWaves >= self.INFINITY: return -1 else: return numWaves solution = CastleDefenseI() gameSoldiers = 10 castleHits = 11 defendersPerWave = 15 #prints 4 print solution.playGame(gameSoldiers, castleHits, defendersPerWave) How would I print the path that leads to if soldiers <= 0 (in oneWave and soldiersVsDefenders) if defenders<=0 (in soldiersVsDefenders) I have started going down this direction (incorrect) class CastleDefenseI: INFINITY = 999999999 def __init__(self): self.dpw = 0 def soldiersVsDefenders(self,soldiers,defenders,path): # soldiers win if defenders <=0: return 0 # castle/defenders win if soldiers <= 0: return self.INFINITY # do another round of fighting # 1. Soldiers kill as many defenders defendersLeft = defenders - soldiers # 2. defendersLeft kill as many soldiers soldiersLeft = soldiers - defendersLeft path.append({"soldiers":soldiersLeft,"defenders":defendersLeft, "castleHits":0}) return 1 + self.soldiersVsDefenders(soldiersLeft,defendersLeft,path) def oneWave(self,soldiers,defenders,castleHits,path): # castle/defenders wins if soldiers <= 0: print path return self.INFINITY # castle is dead, let soldiers play against defenders if castleHits <= 0: defendersLeft = defenders - self.dpw path.append({"soldiers":soldiers,"defenders":defendersLeft,"castleHits":0}) return self.soldiersVsDefenders(soldiers,defendersLeft,path) # try every possibility: # 1) all soldiers hit the castle, none hits the defenders # 2) one soldier hits the castle, the others hit the defenders # 3) two soldiers hit the castle, the others hit the defenders # ... # soldiers) no soldier hits the castle, all others hit the # defenders mini = self.INFINITY for i in range(0,soldiers): if i > defenders: break soldiersLeft = soldiers - (defenders -i) defendersLeft = defenders - i + self.dpw castleHitsLeft = castleHits - (soldiers -i) path = [] path.append({"soldiers":soldiersLeft,"defenders":defendersLeft,"castleHits":castleHitsLeft}) mini = min(mini,1 + self.oneWave(soldiersLeft,defendersLeft,castleHitsLeft,path)) return mini def playGame(self,soldiers,castleHits,defendersPerWave): self.dpw = defendersPerWave numWaves = self.oneWave(soldiers,0,castleHits,[]) if numWaves >= self.INFINITY: return -1 else: return numWaves solution = CastleDefenseI() gameSoldiers = 10 castleHits = 11 defendersPerWave = 15 #prints 4 print solution.playGame(gameSoldiers, castleHits, defendersPerWave) From jennyfurtado2 at gmail.com Wed Aug 5 12:41:17 2015 From: jennyfurtado2 at gmail.com (jennyfurtado2 at gmail.com) Date: Wed, 5 Aug 2015 09:41:17 -0700 (PDT) Subject: Is this an example of tail recursion? In-Reply-To: References: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> <01c7a472-9186-4e20-8b96-ae2c27af70f6@googlegroups.com> Message-ID: <85e343b4-2265-4e65-90ae-53d00ff88ebd@googlegroups.com> On Wednesday, August 5, 2015 at 10:29:21 AM UTC-6, Chris Angelico wrote: > On Thu, Aug 6, 2015 at 2:10 AM, Rustom Mody wrote: > > 1 + x > > does not *call* 1 .__add__(x) > > It *is* that > > [Barring corner cases of radd etc] > > IOW I am desugaring the syntax into explicit method-calls so you can see > > all the calls explicitly > > Then it becomes evident -- visibly and in fact --that the tail call is the > > __add__ method not the solderdiersVsDefenders > > Except that it *isn't* that, precisely because of those other cases. > When Python sees an expression like "1 + x" and doesn't yet know what > x is, it can't do anything other than record the fact that there'll be > a BINARY_ADD of the integer 1 and whatever that thing is. That object > might well define __radd__, so the call is most definitely not > equivalent to the operator. > > And the ultimate result of that addition might not even be a function > call at all, if it's implemented in C. Or if you're running in PyPy > and the optimizer turned it into machine code. So no, even though you > can define addition for *your own classes* using __add__ or __radd__, > you can't reinterpret every addition as a function call. > > ChrisA Good (intricate) point. From rustompmody at gmail.com Wed Aug 5 12:51:47 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 5 Aug 2015 09:51:47 -0700 (PDT) Subject: Is this an example of tail recursion? In-Reply-To: <85e343b4-2265-4e65-90ae-53d00ff88ebd@googlegroups.com> References: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> <01c7a472-9186-4e20-8b96-ae2c27af70f6@googlegroups.com> <85e343b4-2265-4e65-90ae-53d00ff88ebd@googlegroups.com> Message-ID: On Wednesday, August 5, 2015 at 10:11:30 PM UTC+5:30, wrote: > On Wednesday, August 5, 2015 at 10:29:21 AM UTC-6, Chris Angelico wrote: > > On Thu, Aug 6, 2015 at 2:10 AM, Rustom Mody wrote: > > > 1 + x > > > does not *call* 1 .__add__(x) > > > It *is* that > > > [Barring corner cases of radd etc] > > > IOW I am desugaring the syntax into explicit method-calls so you can see > > > all the calls explicitly > > > Then it becomes evident -- visibly and in fact --that the tail call is the > > > __add__ method not the solderdiersVsDefenders > > > > Except that it *isn't* that, precisely because of those other cases. > > When Python sees an expression like "1 + x" and doesn't yet know what > > x is, it can't do anything other than record the fact that there'll be > > a BINARY_ADD of the integer 1 and whatever that thing is. That object > > might well define __radd__, so the call is most definitely not > > equivalent to the operator. > > > > And the ultimate result of that addition might not even be a function > > call at all, if it's implemented in C. Or if you're running in PyPy > > and the optimizer turned it into machine code. So no, even though you > > can define addition for *your own classes* using __add__ or __radd__, > > you can't reinterpret every addition as a function call. > > > > ChrisA > > Good (intricate) point. And I continue to have no idea what Chris is talking about. Here is C printf >>> from ctypes import * >>> cdll.LoadLibrary("libc.so.6") >>> libc = CDLL("libc.so.6") >>> libc.printf(b"%s", b"Hello") 5 Hello>>> As far as I can see printf is a C function and its behaving like (an ill-behaved) python function as well. Likewise for anything else written ina C extension module Or a C-builtin If its callable from within python its python That it may also be C seems to me beside the point [As I said I dont get the point] From rosuav at gmail.com Wed Aug 5 13:10:00 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Aug 2015 03:10:00 +1000 Subject: Is this an example of tail recursion? In-Reply-To: References: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> <01c7a472-9186-4e20-8b96-ae2c27af70f6@googlegroups.com> <85e343b4-2265-4e65-90ae-53d00ff88ebd@googlegroups.com> Message-ID: On Thu, Aug 6, 2015 at 2:51 AM, Rustom Mody wrote: > And I continue to have no idea what Chris is talking about. > Here is C printf >>>> from ctypes import * >>>> cdll.LoadLibrary("libc.so.6") >>>> libc = CDLL("libc.so.6") >>>> libc.printf(b"%s", b"Hello") > 5 > Hello>>> > > As far as I can see printf is a C function and its behaving like (an > ill-behaved) python function as well. > Likewise for anything else written ina C extension module > Or a C-builtin > > If its callable from within python its python > That it may also be C seems to me beside the point > [As I said I dont get the point] Sure, if it's callable from within Python. Where is this implemented in CPython? def f(x): return x+2 f(1) There's PyNumber_Add() in abstract.c, which looks for the nb_add slot. That contains a pointer to long_add, which is defined in longobject.c. Is that the same thing as (1).__add__? Not really, but that's kinda what implements the underlying operation. Also, the function is declared as 'static', so I don't think you can find it using ctypes. Adding two Python objects is *not* a function call. It is an operator-controlled action. It's very similar, in many ways, to a method call, but it isn't exactly that, and it certainly isn't the sort of thing that you could tail-call-optimize as the concept applies only to cases where you can actually replace a stack frame. ChrisA From z2911 at bk.ru Wed Aug 5 16:00:23 2015 From: z2911 at bk.ru (John Doe) Date: Wed, 05 Aug 2015 23:00:23 +0300 Subject: QUEST: does HACKING make FOR loop quicker. Message-ID: <55C26B57.9080603@bk.ru> Presumption ------------------------------------------------------------------------ 1. Lists are mutable sequences. 2. There is a subtlety when the sequence is being modified by the FOR loop (this can only occur for mutable sequences, i.e. lists) Preamble ===================================================================== To pass by reference or by copy of - that is the question from hamlet. ("hamlet" - a community of people smaller than a village python3.4-linux64) xlist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] i = 0 for x in xlist: print(xlist) print("\txlist[%d] = %d" % (i, x)) if x%2 == 0 : xlist.remove(x) print(xlist, "\n\n") i = i + 1 So, catch the output and help me, PLEASE, improve the answer: Does it appropriate ALWAYS RE-evaluate the terms of the expression list in FOR-scope on each iteration? But if I want to pass ONCE a copy to FOR instead of a reference (as seen from an output) and reduce unreasonable RE-evaluation, what I must to do for that? ======================================================================== Assumption. Wind of changes. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Sometimes FOR-loop may do a global work. (depends on size of expression list) Sometimes on external DB. (just a joke) So, what can FOR-loop do for You, depends what can You do for expression list, which can be mutable far outside YOUR NICE LOGIC. QUEST ************************************************************************ Your example of FOR-loop with a simple logic and sensitive information, operated by means of external list-array and Your elaborative vision of hacking possibilities through mutation of a list's terms. TIA RSVP From python.list at tim.thechases.com Wed Aug 5 16:55:32 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 5 Aug 2015 15:55:32 -0500 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <36333f24-3bda-4534-b22f-20c99e8d791c@googlegroups.com> References: <87k2teq9tb.fsf@Equus.decebal.nl> <36333f24-3bda-4534-b22f-20c99e8d791c@googlegroups.com> Message-ID: <20150805155532.143e764c@bigbox.christie.dr> On 2015-08-05 06:37, Rustom Mody wrote: > > config = {} > > with open('config.ini') as f: > > for row in f: > > row = row.strip() > > if not row or row.startswith(('#', ';')): > > continue > > k, _, v = row.partition('=') > > config[k.strip().upper()] = v.lstrip() > > > > which is pretty straight-forward and easy format to edit. > > > > -tkc > > JSON handles basic types like this: > >>> from json import loads > >>> loads("""{"anInt":1, "aString":"2"}""") > {'aString': '2', 'anInt': 1} But requires the person hand-editing the file to make sure that opening braces close, that quoted text is properly opened/closed, has peculiarities regarding things following back-slashes, etc. There's a certain simplicity to simply having key/value pairs separated by an "=" and then letting the application do whatever it needs/wants with those key/value strings. -tkc From appliedthoughterm at gmail.com Wed Aug 5 17:05:17 2015 From: appliedthoughterm at gmail.com (Pranesh Srinivasan) Date: Wed, 5 Aug 2015 14:05:17 -0700 (PDT) Subject: Looking for OpenStack Developer Message-ID: Hi, Hope you are doing well !!! My name is Siva and I'm a recruiter at TheAppliedthought , a global staffing and IT consulting company. Please find the below job description which may suits any of your consultants who are available in market or who are looking for change, please send me latest updated resume along with contact details and expected hourly rate to my email id siva at theappliedthought.com or you can reach me on 407-574-7610. Position: Python + Angular JS + Knowledge in Open Stack + Linux Location: Houston, TX Duration: Long Term Job Description Skills Required * Python * Angular JS * Open Stack * Linux Thanks & Regards Siva Executive-Talent Acquisition & Bench Sales Email: siva at theappliedthought.com IM: malladi sivaramakrishna88 Phone: 407-574-7610 Fax: 407-641-8184 From breamoreboy at yahoo.co.uk Wed Aug 5 17:39:59 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 5 Aug 2015 22:39:59 +0100 Subject: QUEST: does HACKING make FOR loop quicker. In-Reply-To: <55C26B57.9080603@bk.ru> References: <55C26B57.9080603@bk.ru> Message-ID: On 05/08/2015 21:00, John Doe wrote: Three strikes and you're out, good bye troll. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marko at pacujo.net Wed Aug 5 17:47:37 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 06 Aug 2015 00:47:37 +0300 Subject: Most Pythonic way to store (small) configuration References: <87k2teq9tb.fsf@Equus.decebal.nl> <36333f24-3bda-4534-b22f-20c99e8d791c@googlegroups.com> Message-ID: <87fv3xpfuu.fsf@elektro.pacujo.net> Tim Chase : > There's a certain simplicity to simply having key/value pairs > separated by an "=" and then letting the application do whatever it > needs/wants with those key/value strings. That trap has lured in a lot of wildlife. What to do with lists? Is whitespace significant? Case in point, systemd configuration files: It specifies all kinds of application-do-whatever-it-needs syntax: * backslash escapes * double quotes and single quotes * line continuations * percent specifiers * dollar substitution with or without braces * double-dollar escape * together with undocumented quirks (for example, how do you specify a command whose pathname contains whitespace?) All of which makes it all but impossible to algorithmically escape a literal command into the ExecStart= entry. When you start with something that's too simple, you end up with layers of ever-increasing complexity but never attain the expressive power of JSON, S-expressions and the like (I don't have the stomach to mention XML). Marko From PointedEars at web.de Wed Aug 5 18:09:04 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 06 Aug 2015 00:09:04 +0200 Subject: Installation Successful, but pythonw and idle doesn't function References: Message-ID: <2089419.rtOe05Tiyo@PointedEars.de> Rick Smith wrote: > However pythonw.exe did not and does not work. I was simply returned to > the command prompt, without ANY interaction or error. > > prompt>pythonw > > prompt> Works as designed. You are proceeding from a false assumption. pythonw.exe is not meant to provide an interactive Python shell. A little Web research would have showed that to you. (First hit for ?pythonw? on Google with my account. I have never visited that site before or can remember to have searched for ?pythonw?.) > I also attempted to run "idle", with the following results: > > C: \Users\judy\AppData\Local\Programs\Python\Python35-32\Lib\idlelib>idle.py > ** IDLE can't import Tkinter. > Your Python may not be configured for Tk. ** I do not know IDLE well (if at all after all this time). Make sure that you have installed the prerequisites. But it strikes me as odd to run a GUI- based application from the Windows command shell. Is there not an icon that you can use instead to run it? Presumably that would execute a .bat or .cmd script that sets up the PYTHONPATH. RTFM, STFW. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From PointedEars at web.de Wed Aug 5 18:14:50 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 06 Aug 2015 00:14:50 +0200 Subject: Installation Successful, but pythonw and idle doesn't function References: <2089419.rtOe05Tiyo@PointedEars.de> Message-ID: <46417500.4ZKFyJPit3@PointedEars.de> Thomas 'PointedEars' Lahn wrote: > > > (First hit for ?pythonw? on Google with my account. I have never visited > that site before or can remember to have searched for ?pythonw?.) JFTR: s/site/question/. I am rather active on Stack Overflow (but not much regarding Python, IIRC). -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From emile at fenx.com Wed Aug 5 18:35:31 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 5 Aug 2015 15:35:31 -0700 Subject: Uninstall In-Reply-To: References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> <7cbf35cc-9ac2-4d76-a06b-c5436d21f2de@googlegroups.com> Message-ID: On 8/4/2015 6:51 PM, Mario Figueiredo wrote: > On Tue, Aug 4, 2015 at 9:01 PM, Mark Lawrence >> The simple solution is not to subscribe. Yes -- it's about gotten to that point. > Or even better, tell you to fuck off. Now that's a first to my recollection. I must say I prefer the pedantry to your civility. But-neither-is-much-to-my-liking-ly y'rs, Emile From python.list at tim.thechases.com Wed Aug 5 19:43:54 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 5 Aug 2015 18:43:54 -0500 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <87fv3xpfuu.fsf@elektro.pacujo.net> References: <87k2teq9tb.fsf@Equus.decebal.nl> <36333f24-3bda-4534-b22f-20c99e8d791c@googlegroups.com> <87fv3xpfuu.fsf@elektro.pacujo.net> Message-ID: <20150805184354.596616fd@bigbox.christie.dr> On 2015-08-06 00:47, Marko Rauhamaa wrote: > > There's a certain simplicity to simply having key/value pairs > > separated by an "=" and then letting the application do whatever > > it needs/wants with those key/value strings. > > That trap has lured in a lot of wildlife. > > What to do with lists? > > Is whitespace significant? As I said, simple. Lists? Not in a simple config format. Though I suppose, just like the .ini format, you could use a convention of comma or space-separated list items. Or quoted white-space-separated items like shlex handles nicely. Or if you really need, pass the value portion of the key/value pair through ast.literal_eval() Significant whitespace? Not usually simple (just stuck touching a project where someone committed with tons of trailing whitespaces. grumble), so strip 'em off as if they're an error condition. I've never had a config-file where I wanted leading/trailing whitespace as significant. > Case in point, systemd configuration files: The antithesis of "simplicity" ;-) -tkc From rosuav at gmail.com Wed Aug 5 20:07:35 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Aug 2015 10:07:35 +1000 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <20150805184354.596616fd@bigbox.christie.dr> References: <87k2teq9tb.fsf@Equus.decebal.nl> <36333f24-3bda-4534-b22f-20c99e8d791c@googlegroups.com> <87fv3xpfuu.fsf@elektro.pacujo.net> <20150805184354.596616fd@bigbox.christie.dr> Message-ID: On Thu, Aug 6, 2015 at 9:43 AM, Tim Chase wrote: > Significant whitespace? Not usually simple (just stuck touching a > project where someone committed with tons of trailing whitespaces. > grumble), so strip 'em off as if they're an error condition. I've > never had a config-file where I wanted leading/trailing whitespace as > significant. If you're configuring a prompt, sometimes you need to be able to include a space at the end of it. Since trailing whitespace on a line in the file itself is a bad idea, you need some way of marking it. That might mean quoting the string, or having a Unicode or byte escape like \x20 that means space, or something like that. If you define that spaces around your equals sign are insignificant, you need the same sort of system to cope with the possibility of actual leading whitespace, too. >> Case in point, systemd configuration files: > > The antithesis of "simplicity" ;-) Ehh... I reckon they're pretty simple. They're somewhat more powerful than Upstart config files, and pay some complexity cost for that; but they're a lot simpler than sysvinit "config files" (which are actually shell scripts), especially with all the dependency handling cruft that goes into encoded comments. Frankly, I do my best to avoid ever touching those. I'm not sure what else to compare them against (never used any init system other than the three just mentioned), so I don't see systemd files as being particularly complex. ChrisA From tjreedy at udel.edu Wed Aug 5 20:20:49 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 5 Aug 2015 20:20:49 -0400 Subject: Problem in IDLE setup In-Reply-To: References: Message-ID: On 8/5/2015 9:08 AM, Mark Lawrence wrote: > On 04/08/2015 12:31, Ahsan Chauhan wrote: >> Respected Sir/Madam, >> I would like to bring it to your notice that IDLE's executable file is >> not working properly in Python3.5.0. 3.5.0 has not been released. 3.5.0b4 is the most recent. Make sure that you are using that. I use it on Win7 daily without problems. 3.5.0c1 will be out this weekend. > Please state exactly what you're tried to do, what you expected to > happen, and what actually happened. If you have a traceback please cut > and paste all of it into your response. What OS are you using? If on Windows, find the Command Prompt console and enter > python -m idlelib or, if that does not start 3.5, > py -3.5 -m idlelib -- Terry Jan Reedy From torriem at gmail.com Wed Aug 5 20:29:18 2015 From: torriem at gmail.com (Michael Torrie) Date: Wed, 05 Aug 2015 18:29:18 -0600 Subject: QUEST: does HACKING make FOR loop quicker. In-Reply-To: References: <55C26B57.9080603@bk.ru> Message-ID: <55C2AA5E.2000806@gmail.com> On 08/05/2015 03:39 PM, Mark Lawrence wrote: > On 05/08/2015 21:00, John Doe wrote: > > Three strikes and you're out, good bye troll. While the original post is incomprehensible to me, I see only one post. What were the other two strikes? From joel.goldstick at gmail.com Wed Aug 5 20:42:58 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 5 Aug 2015 20:42:58 -0400 Subject: QUEST: does HACKING make FOR loop quicker. In-Reply-To: <55C2AA5E.2000806@gmail.com> References: <55C26B57.9080603@bk.ru> <55C2AA5E.2000806@gmail.com> Message-ID: On Wed, Aug 5, 2015 at 8:29 PM, Michael Torrie wrote: > On 08/05/2015 03:39 PM, Mark Lawrence wrote: >> On 05/08/2015 21:00, John Doe wrote: >> >> Three strikes and you're out, good bye troll. > > While the original post is incomprehensible to me, I see only one post. > What were the other two strikes? > > -- > https://mail.python.org/mailman/listinfo/python-list I count 2, but the second is the repeat of the first. -- Joel Goldstick http://joelgoldstick.com From rustompmody at gmail.com Wed Aug 5 21:01:35 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 5 Aug 2015 18:01:35 -0700 (PDT) Subject: Most Pythonic way to store (small) configuration In-Reply-To: References: <87k2teq9tb.fsf@Equus.decebal.nl> <36333f24-3bda-4534-b22f-20c99e8d791c@googlegroups.com> Message-ID: <55e15744-67f3-4055-9948-ec7bfaafdd58@googlegroups.com> On Thursday, August 6, 2015 at 2:31:52 AM UTC+5:30, Tim Chase wrote: > On 2015-08-05 06:37, Rustom Mody wrote: > > > config = {} > > > with open('config.ini') as f: > > > for row in f: > > > row = row.strip() > > > if not row or row.startswith(('#', ';')): > > > continue > > > k, _, v = row.partition('=') > > > config[k.strip().upper()] = v.lstrip() > > > > > > which is pretty straight-forward and easy format to edit. > > > > > > -tkc > > > > JSON handles basic types like this: > > >>> from json import loads > > >>> loads("""{"anInt":1, "aString":"2"}""") > > {'aString': '2', 'anInt': 1} > > But requires the person hand-editing the file to make sure that > opening braces close, that quoted text is properly opened/closed, has > peculiarities regarding things following back-slashes, etc. > > There's a certain simplicity to simply having key/value pairs > separated by an "=" and then letting the application do whatever it > needs/wants with those key/value strings. > > -tkc I just checked that literal_eval accepts comments. So thats one plus for that. However I must admit that in checking that out I was faced with more than (I) expected unfriendly error messages like Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/ast.py", line 84, in literal_eval return _convert(node_or_string) File "/usr/lib/python3.4/ast.py", line 62, in _convert in zip(node.keys, node.values)) File "/usr/lib/python3.4/ast.py", line 61, in return dict((_convert(k), _convert(v)) for k, v File "/usr/lib/python3.4/ast.py", line 83, in _convert raise ValueError('malformed node or string: ' + repr(node)) ValueError: malformed node or string: <_ast.Name object at 0x7fe1173ebac8> By contrast here is a more friendly error message (had put a comma where a colon required) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/ast.py", line 46, in literal_eval node_or_string = parse(node_or_string, mode='eval') File "/usr/lib/python3.4/ast.py", line 35, in parse return compile(source, filename, mode, PyCF_ONLY_AST) File "", line 2 "i", 1} So overall whether ast.literal_eval is a good idea is not clear to me From tjreedy at udel.edu Wed Aug 5 21:06:31 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 5 Aug 2015 21:06:31 -0400 Subject: Who uses IDLE -- please answer if you ever do, know, or teach Message-ID: There have been discussions, such as today on Idle-sig , about who uses Idle and who we should design it for. If you use Idle in any way, or know of or teach classes using Idle, please answer as many of the questions below as you are willing, and as are appropriate Private answers are welcome. They will be deleted as soon as they are tallied (without names). I realized that this list is a biased sample of the universe of people who have studied Python at least, say, a month. But biased data should be better than my current vague impressions. 0. Classes where Idle is used: Where? Level? Idle users: 1. Are you grade school (1=12)? undergraduate (Freshman-Senior)? post-graduate (from whatever)? 2. Are you beginner (1st class, maybe 2nd depending on intensity of first)? post-beginner? 3. With respect to programming, are you amateur (unpaid) professional (paid for programming) -- Terry Jan Reedy, Idle maintainer From rustompmody at gmail.com Wed Aug 5 21:06:54 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 5 Aug 2015 18:06:54 -0700 (PDT) Subject: Most Pythonic way to store (small) configuration In-Reply-To: <55e15744-67f3-4055-9948-ec7bfaafdd58@googlegroups.com> References: <87k2teq9tb.fsf@Equus.decebal.nl> <36333f24-3bda-4534-b22f-20c99e8d791c@googlegroups.com> <55e15744-67f3-4055-9948-ec7bfaafdd58@googlegroups.com> Message-ID: On Thursday, August 6, 2015 at 6:32:03 AM UTC+5:30, Rustom Mody wrote: > By contrast here is a more friendly error message (had put a comma where a colon > required) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python3.4/ast.py", line 46, in literal_eval > node_or_string = parse(node_or_string, mode='eval') > File "/usr/lib/python3.4/ast.py", line 35, in parse > return compile(source, filename, mode, PyCF_ONLY_AST) > File "", line 2 > "i", 1} Uh... The more helpfulness not evident as the most crucial line not cut-pasted Heres the full bt Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/ast.py", line 46, in literal_eval node_or_string = parse(node_or_string, mode='eval') File "/usr/lib/python3.4/ast.py", line 35, in parse return compile(source, filename, mode, PyCF_ONLY_AST) File "", line 2 "i", 1} ^ SyntaxError: invalid syntax From tjreedy at udel.edu Wed Aug 5 21:07:00 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 5 Aug 2015 21:07:00 -0400 Subject: Installation Successful, but pythonw and idle doesn't function In-Reply-To: <201508051612.t75GCc5m017047@rs103.luxsci.com> References: <201508051612.t75GCc5m017047@rs103.luxsci.com> Message-ID: On 8/5/2015 12:12 PM, Rick Smith wrote: > > I was able to install various versions of Python (3.5.0b4 32bit being > the most recent) multiple times (uninstalling in between) and they > worked ("python --version" at the command line worked). > > However pythonw.exe did not and does not work. I was simply returned to > the command prompt, without ANY interaction or error. C:\Programs\Python35>pythonw C:\Programs\Python35> Normal behavior. Try > python -m idlelib or, if that does not start 3.5, > py -3.5 -m idlelib and you should either see Idle or an error message If Idle is starting but not connecting, as you seems to say, there there is a problems with your network socket configuration or another program. Adding -n at the end of the command line will will bypass that, though you could have other problems in certain situations. Please see my Who uses IDLE? thread. -- Terry Jan Reedy From tjreedy at udel.edu Wed Aug 5 21:15:37 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 5 Aug 2015 21:15:37 -0400 Subject: How to trace the recursive path? In-Reply-To: References: Message-ID: trace --trackcalls Display the calling relationships exposed by running the program. will give you part of what you want, but only counts. I would just add print('xyx calledl') at the top of each function you want traced. -- Terry Jan Reedy From ben+python at benfinney.id.au Wed Aug 5 21:17:12 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 06 Aug 2015 11:17:12 +1000 Subject: Who uses IDLE -- please answer if you ever do, know, or teach References: Message-ID: <85pp31jjvr.fsf@benfinney.id.au> Terry Reedy writes: > Private answers are welcome. They will be deleted as soon as they are > tallied (without names). Are you also expecting questionnaire answers in this forum? I suspect it will become a free-ranging discussion; hopefully you're prepared to pick through and collect the responses if so. -- \ ?The Stones, I love the Stones; I can't believe they're still | `\ doing it after all these years. I watch them whenever I can: | _o__) Fred, Barney, ...? ?Steven Wright | Ben Finney From rustompmody at gmail.com Wed Aug 5 21:21:59 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 5 Aug 2015 18:21:59 -0700 (PDT) Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: Message-ID: On Thursday, August 6, 2015 at 6:36:56 AM UTC+5:30, Terry Reedy wrote: > There have been discussions, such as today on Idle-sig , about who uses > Idle and who we should design it for. If you use Idle in any way, or > know of or teach classes using Idle, please answer as many of the > questions below as you are willing, and as are appropriate > > Private answers are welcome. They will be deleted as soon as they are > tallied (without names). > > I realized that this list is a biased sample of the universe of people > who have studied Python at least, say, a month. But biased data should > be better than my current vague impressions. > > 0. Classes where Idle is used: > Where? > Level? > > Idle users: > > 1. Are you > grade school (1=12)? > undergraduate (Freshman-Senior)? > post-graduate (from whatever)? > > 2. Are you > beginner (1st class, maybe 2nd depending on intensity of first)? > post-beginner? > > 3. With respect to programming, are you > amateur (unpaid) > professional (paid for programming) > > -- > Terry Jan Reedy, Idle maintainer I used idle to teach a 2nd year engineering course last sem It was a more pleasant experience than I expected One feature that would help teachers: It would be nice to (have setting to) auto-save the interaction window [Yeah I tried to see if I could do it by hand but could not find where] Useful for giving as handouts of the class So students rest easy and dont need to take 'literal' notes of the session I will now be teaching more advanced students and switching back to emacs -- python, C, and others -- so really no option to emacs. Not ideal at all but nothing else remotely comparable From tjreedy at udel.edu Wed Aug 5 21:31:02 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 5 Aug 2015 21:31:02 -0400 Subject: Installation Successful, but pythonw and idle doesn't function In-Reply-To: <2089419.rtOe05Tiyo@PointedEars.de> References: <2089419.rtOe05Tiyo@PointedEars.de> Message-ID: On 8/5/2015 6:09 PM, Thomas 'PointedEars' Lahn wrote: > Rick Smith wrote: >> I also attempted to run "idle", with the following results: >> >> C: > \Users\judy\AppData\Local\Programs\Python\Python35-32\Lib\idlelib>idle.py >> ** IDLE can't import Tkinter. >> Your Python may not be configured for Tk. ** Rick, can you run python? What happens with 'import tkinter'? > I do not know IDLE well (if at all after all this time). Make sure that you > have installed the prerequisites. A Windows install should install tkinter and Idle together. > But it strikes me as odd to run a GUI- > based application from the Windows command shell. This is the right thing to do when there is a problem, as some error messages get delivered to the console. The prime example is the above. If Idle cannot import tkinter, it cannot use a tkinter message box. > Is there not an icon that you can use instead to run it? In the start menu, but that error message would not appear. -- Terry Jan Reedy From no.email at nospam.invalid Wed Aug 5 22:12:00 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 05 Aug 2015 19:12:00 -0700 Subject: Who uses IDLE -- please answer if you ever do, know, or teach References: Message-ID: <87r3nhi2rz.fsf@jester.gateway.sonic.net> Terry Reedy writes: > There have been discussions, such as today on Idle-sig , about who > uses Idle and who we should design it for. I use it sometimes. I mostly use Emacs with Python-mode but find Idle is nice for quickly experimenting with something or probing an API. I know there are fancier IDE's out there but I'm mostly an Emacs user. > 0. Classes where Idle is used: N/A > 1. Are you grade school (1=12)?.... Working programmer. > 2. Are you post-beginner? Yes > 3. With respect to programming, are you > amateur (unpaid) > professional (paid for programming) Professional. From rosuav at gmail.com Wed Aug 5 22:30:21 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Aug 2015 12:30:21 +1000 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: Message-ID: On Thu, Aug 6, 2015 at 11:06 AM, Terry Reedy wrote: > There have been discussions, such as today on Idle-sig , about who uses Idle > and who we should design it for. If you use Idle in any way, or know of or > teach classes using Idle, please answer as many of the questions below as > you are willing, and as are appropriate When I'm talking to my students about interactive Python on Windows, I'll sometimes recommend Idle. It's not any sort of official thing, but when they're having issues (particularly if they're tinkering with a 'while' or 'for' loop, as Idle recalls those as coherent units instead of fetching up individual lines), I'll point them to it as another way to tackle a problem. Usually on Linux or Mac OS they're better able to manage with the console interpreter and readline, but Windows sucks so Idle has a bigger advantage (plus, a lot of Linux distro-supplied Pythons don't include Idle, whereas I can be fairly confident that a Windows Python will have it). > 1. Are you > grade school (1=12)? > undergraduate (Freshman-Senior)? > post-graduate (from whatever)? I'm a high school dropout; my students probably cover all three of those categories. > 2. Are you > beginner (1st class, maybe 2nd depending on intensity of first)? > post-beginner? Usually Idle is mentioned only in the context of the very early explorations. After that, it's all "use a text editor, and then run it", and students use whichever editors they like. Most don't ask about editor options. Possibly I'd recommend Idle's editor mode in some cases, but it's usually more convenient to have a single editor which also understands HTML and CSS, as this is a web programming course. > 3. With respect to programming, are you > amateur (unpaid) > professional (paid for programming) Pro. A lot of my students are currently amateurs; a decent number are professional and moving around in skillset. (Do you count as a pro programmer if you're currently paid to work with Excel macros, and you're learning Python so you can do better? Line gets blurry.) If Idle didn't exist, it wouldn't kill what I'm doing, but it is a convenient option to have around. ChrisA From zachary.ware+pylist at gmail.com Wed Aug 5 22:43:20 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Wed, 5 Aug 2015 21:43:20 -0500 Subject: Installation Successful, but pythonw and idle doesn't function In-Reply-To: <201508051612.t75GCc5m017047@rs103.luxsci.com> References: <201508051612.t75GCc5m017047@rs103.luxsci.com> Message-ID: Hi Rick, On Wed, Aug 5, 2015 at 11:12 AM, Rick Smith wrote: > I was able to install various versions of Python (3.5.0b4 32bit being the > most recent) multiple times (uninstalling in between) and they worked > ("python --version" at the command line worked). > > However pythonw.exe did not and does not work. I was simply returned to the > command prompt, without ANY interaction or error. > > prompt>pythonw > > prompt> As I believe others have mentioned, 'pythonw' is not the one you want to use 99% of the time. 'pythonw' is a 'win32' app rather than a 'console' app, meaning that it has no attached console, and if you just run it with no arguments, it will appear to do nothing (though actually, it starts, finds it has no input, and ends very quickly). > I also attempted to run "idle", with the following results: > > > C:\Users\judy\AppData\Local\Programs\Python\Python35-32\Lib\idlelib>idle.py > ** IDLE can't import Tkinter. > Your Python may not be configured for Tk. ** You hit upon a bug in 3.5.0b4, which is that the installer is broken for tkinter unless you have Microsoft Visual Studio 2015 installed. See http://bugs.python.org/issue24771 for details, the fix will be included in 3.5.0rc1. Your best bet is to avoid using pre-release software, and stick with Python 3.4.3 until such time as 3.5.0 final is released. Hope this helps, -- Zach From lac at openend.se Wed Aug 5 23:50:07 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 06 Aug 2015 05:50:07 +0200 Subject: Uninstall In-Reply-To: Message from Bill of "Tue, 04 Aug 2015 11:37:47 +0900." <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> Message-ID: <201508060350.t763o7uC021533@fido.openend.se> In a message of Tue, 04 Aug 2015 11:37:47 +0900, Bill writes: >How do I uninstall Python from a Mac? > > >-- >https://mail.python.org/mailman/listinfo/python-list How did you get it in the first place? If you installed it yourself, then you have to retrace what steps you took to install it in order to remove it. Did you get it from python.org? Did you get it from ActiveState? Did you get it from MacPorts? From brew? How you uninstall it is different depending on where it came from. If you didn't install it yourself, then either somebody else installed it for you, or it came with your mac, and Apple installed it for you. If this is the system version of Python that Apple installed for you that you are talking about, then it may not be a good idea for you to uninstall it at all. Apple's own software for internal housekeeping may require Python in order to work properly. Laura From breamoreboy at yahoo.co.uk Thu Aug 6 00:06:07 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 6 Aug 2015 05:06:07 +0100 Subject: QUEST: does HACKING make FOR loop quicker. In-Reply-To: <55C2AA5E.2000806@gmail.com> References: <55C26B57.9080603@bk.ru> <55C2AA5E.2000806@gmail.com> Message-ID: On 06/08/2015 01:29, Michael Torrie wrote: > On 08/05/2015 03:39 PM, Mark Lawrence wrote: >> On 05/08/2015 21:00, John Doe wrote: >> >> Three strikes and you're out, good bye troll. > > While the original post is incomprehensible to me, I see only one post. > What were the other two strikes? > Same question originally on the tutor mailing list, then the development mailing list. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From lac at openend.se Thu Aug 6 00:06:12 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 06 Aug 2015 06:06:12 +0200 Subject: Linux script to get most expensive processes In-Reply-To: Message from Emile van Sebille of "Tue, 04 Aug 2015 13:52:39 -0700." References: <87twsehkmk.fsf@Equus.decebal.nl> Message-ID: <201508060406.t7646CSd025192@fido.openend.se> If you are running this script with Python 2 write: if sys.platform.startswith('linux'): to handle the case where you get linux or linux2 (and a few other weird things some embedded systems give you ...) Right now I think every linux system returns linux for Python 3, so it is less of an issue (now, anyway). Laura From lac at openend.se Thu Aug 6 00:39:43 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 06 Aug 2015 06:39:43 +0200 Subject: GOTCHA with list comprehension In-Reply-To: Message from Chris Angelico of "Wed, 05 Aug 2015 17:05:49 +1000." References: Message-ID: <201508060439.t764dhdh032346@fido.openend.se> In a message of Wed, 05 Aug 2015 17:05:49 +1000, Chris Angelico writes: >Incidentally, why Python 2.6? Python 2.7 has been out for a pretty >long time now, and if you can't move to version 3.x, I would at least >recommend using 2.7. Since the release of 2.6.9 back before Frozen >came out, that branch has been completely unmaintained. Grab yourself >a 2.7 and take advantage of some neat new features (for old values of >"new"), and improved compatibility with 3.x. > >ChrisA Be careful suggesting that people upgrade, at least until you have found out that they aren't running CentOS enterprise edition. The CentOS packaging system is utterly dependent on having the Python version it expects, and if you install a more recent version (from source, say) the whole packaging system will stop working. Recovering from this problem is also very, very difficult (unless you just restore from a recent full backup). Been there, done that. :( Laura From miki.tebeka at gmail.com Thu Aug 6 00:41:47 2015 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 5 Aug 2015 21:41:47 -0700 (PDT) Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: Message-ID: <093fdc4f-1bb1-4ead-826f-4a7c858b263d@googlegroups.com> Greetings, > 0. Classes where Idle is used: > Where? At client site. Mostly big companies. > Level? >From beginner to advanced. > Idle users: > 1. Are you > grade school (1=12)? > undergraduate (Freshman-Senior)? > post-graduate (from whatever)? post-graduate > 2. Are you > beginner (1st class, maybe 2nd depending on intensity of first)? > post-beginner? post-beginner > 3. With respect to programming, are you > amateur (unpaid) > professional (paid for programming) professional From rosuav at gmail.com Thu Aug 6 00:44:15 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Aug 2015 14:44:15 +1000 Subject: GOTCHA with list comprehension In-Reply-To: <201508060439.t764dhdh032346@fido.openend.se> References: <201508060439.t764dhdh032346@fido.openend.se> Message-ID: On Thu, Aug 6, 2015 at 2:39 PM, Laura Creighton wrote: > In a message of Wed, 05 Aug 2015 17:05:49 +1000, Chris Angelico writes: >>Incidentally, why Python 2.6? Python 2.7 has been out for a pretty >>long time now, and if you can't move to version 3.x, I would at least >>recommend using 2.7. Since the release of 2.6.9 back before Frozen >>came out, that branch has been completely unmaintained. Grab yourself >>a 2.7 and take advantage of some neat new features (for old values of >>"new"), and improved compatibility with 3.x. >> >>ChrisA > > Be careful suggesting that people upgrade, at least until you have > found out that they aren't running CentOS enterprise edition. The > CentOS packaging system is utterly dependent on having the Python > version it expects, and if you install a more recent version > (from source, say) the whole packaging system will stop working. > Recovering from this problem is also very, very difficult (unless > you just restore from a recent full backup). > > Been there, done that. :( Yeah. Fortunately there are ways to leave the system Python untouched while adding in another Python for some other purpose... and, if you're desperate enough, you can even leave the Apache-Python bridge using an older build of Python while running key parts of your web application in a newer version, but that requires a certain measure of insanity! There will come a time, though, when every supported Linux distro is shipping either 2.7 or 3.x. And it isn't far off. When that happens, advising the upgrade will be simple. ChrisA From lac at openend.se Thu Aug 6 01:04:56 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 06 Aug 2015 07:04:56 +0200 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: Message from Terry Reedy of "Wed, 05 Aug 2015 21:06:31 -0400." References: Message-ID: <201508060504.t7654u0R006010@fido.openend.se> In a message of Wed, 05 Aug 2015 21:06:31 -0400, Terry Reedy writes: >0. Classes where Idle is used: >Where -- my house or sometimes at the board game society >Level -- beginners and there are 8 children right now. >Idle users: > >1. Are you I am post graduate, but the kids are all grade school. >2. Are you >beginner (1st class, maybe 2nd depending on intensity of first)? >post-beginner? I am post-beginner, the kids are all beginners. >3. With respect to programming, are you >amateur (unpaid) >professional (paid for programming) The teaching is unpaid. I get paid for other things. > >-- >Terry Jan Reedy, Idle maintainer Laura From no.email at nospam.invalid Thu Aug 6 01:46:18 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 05 Aug 2015 22:46:18 -0700 Subject: Who uses IDLE -- please answer if you ever do, know, or teach References: <87r3nhi2rz.fsf@jester.gateway.sonic.net> Message-ID: <87k2t9hsut.fsf@jester.gateway.sonic.net> Paul Rubin writes: > I use it sometimes. I mostly use Emacs with Python-mode but find Idle > is nice for quickly experimenting with something or probing an API. Added: I sometimes used Idle in places where Emacs isn't available, e.g. client machines running Windows. It's nice that Idle is there if the Python environment is there. From ppk.phanikumar at gmail.com Thu Aug 6 01:56:22 2015 From: ppk.phanikumar at gmail.com (ppk.phanikumar at gmail.com) Date: Wed, 5 Aug 2015 22:56:22 -0700 (PDT) Subject: how to simulate keydown and keyup events using win32api . Message-ID: <31127c7c-ccd6-468c-ae8b-0e0dee8c0e16@googlegroups.com> win32api.keybd_event(code,0,0,0) time.sleep(2) win32api.keybd_event(code,0,win32con.KEYEVENTF_KEYUP,0) the above code is simulating single click on button but not press Key Hold but i want to hold the until key up event is called eg: for key 'a' down it have to simulate key continous set until keyUp is called but not like "a" please specify any python API to simulate continues keyDown until it receives keyUp event From gcviola at gmail.com Thu Aug 6 02:10:13 2015 From: gcviola at gmail.com (Bill) Date: Thu, 6 Aug 2015 15:10:13 +0900 Subject: Uninstall In-Reply-To: <201508060350.t763o7uC021533@fido.openend.se> References: <3E52DBEE-7F1F-49BB-9730-BA35BF5554B2@gmail.com> <201508060350.t763o7uC021533@fido.openend.se> Message-ID: Thank you. I downloaded it from Python.org. I didn't know that Python came with the Mac OS. I have a better understanding of all this now and no longer feel that I need to uninstall it has I can chose either version. Thank you again. > On Aug 6, 2015, at 12:50 PM, Laura Creighton wrote: > > In a message of Tue, 04 Aug 2015 11:37:47 +0900, Bill writes: >> How do I uninstall Python from a Mac? >> >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > > How did you get it in the first place? > > If you installed it yourself, then you have to retrace what steps you > took to install it in order to remove it. Did you get it from python.org? > Did you get it from ActiveState? Did you get it from MacPorts? From brew? > How you uninstall it is different depending on where it came from. > > If you didn't install it yourself, then either somebody else installed > it for you, or it came with your mac, and Apple installed it for you. > If this is the system version of Python that Apple installed for you > that you are talking about, then it may not be a good idea for you > to uninstall it at all. Apple's own software for internal housekeeping > may require Python in order to work properly. > > Laura From lac at openend.se Thu Aug 6 02:18:06 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 06 Aug 2015 08:18:06 +0200 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: Message from Paul Rubin of "Wed, 05 Aug 2015 22:46:18 -0700." <87k2t9hsut.fsf@jester.gateway.sonic.net> References: <87r3nhi2rz.fsf@jester.gateway.sonic.net><87k2t9hsut.fsf@jester.gateway.sonic.net> Message-ID: <201508060618.t766I6H0020899@fido.openend.se> Added: right now most children I know who want to program want to write games that run on their cell phones and tablets. So Idle integration with kivy would be very nice, if Idle developers are looking for new directions. Laura From steve+comp.lang.python at pearwood.info Thu Aug 6 02:46:03 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 06 Aug 2015 16:46:03 +1000 Subject: QUEST: does HACKING make FOR loop quicker. References: <55C26B57.9080603@bk.ru> Message-ID: <55c302ac$0$11116$c3e8da3@news.astraweb.com> On Thursday 06 August 2015 10:29, Michael Torrie wrote: > On 08/05/2015 03:39 PM, Mark Lawrence wrote: >> On 05/08/2015 21:00, John Doe wrote: >> >> Three strikes and you're out, good bye troll. > > While the original post is incomprehensible to me, I see only one post. > What were the other two strikes? John Doe has already asked this question on the tutor list, where I answered it (to the best as I can understand his question), and the Python-Dev list. I've told him at least twice off-list that if his question hasn't been answered, he should explain what he means in more detail on the tutor list. At least the question isn't off-topic here. I just wish I understood what part of my answer doesn't satisfy. Despite John Doe emailing me off list four times, I still don't know what he actually wants. https://mail.python.org/pipermail/tutor/2015-August/106244.html -- Steve From PointedEars at web.de Thu Aug 6 02:56:11 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 06 Aug 2015 08:56:11 +0200 Subject: Installation Successful, but pythonw and idle doesn't function References: <2089419.rtOe05Tiyo@PointedEars.de> Message-ID: <1972506.uHfIMgh0XK@PointedEars.de> Terry Reedy wrote: > On 8/5/2015 6:09 PM, Thomas 'PointedEars' Lahn wrote: >> Rick Smith wrote: >>> I also attempted to run "idle", with the following results: >>> >>> C: >> \Users\judy\AppData\Local\Programs\Python\Python35-32\Lib\idlelib>idle.py >>> ** IDLE can't import Tkinter. >>> Your Python may not be configured for Tk. ** > > Rick, can you run python? What happens with 'import tkinter'? > >> I do not know IDLE well (if at all after all this time). Make sure that >> you have installed the prerequisites. > > A Windows install should install tkinter and Idle together. > >> But it strikes me as odd to run a GUI-based application from the Windows >> command shell. > > This is the right thing to do when there is a problem, as some error > messages get delivered to the console. The prime example is the above. > If Idle cannot import tkinter, it cannot use a tkinter message box. Clarification: It is _not_ the right thing to do to run a GUI-based application obviously *written in Python*, like IDLE, *this way*. Because, AISB, usually there is a script that sets up the environment (e.g. the PYTHONPATH), and the working directory may matter. So one should always look for the application shortcut (icon) first, and, if found, use its properties to run the application. In 32-bit Windows, the easiest way is to type Windows+R (or, in the Start Menu go to the search field, or select the ?Run?? command), and type cmd /k "cd $WORKDIR & $COMMAND" which changes to the working directory of the shortcut (replace $WORKDIR with what you find there), and if successful executes $COMMAND there (dito), while keeping the ?Command Prompt? window open because the command shell does not exit (it would if you used ?/c? instead of ?/k?). > > Is there not an icon that you can use instead to run it? > > In the start menu, but that error message would not appear. Yes, the ?Run command in shell? checkbox appears to be restricted to application icons on real operating systems :-> But you can modify the command of the shortcut to say ?cmd /k "$ORIGINAL_COMMAND"? to work around this. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From rosuav at gmail.com Thu Aug 6 03:19:55 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Aug 2015 17:19:55 +1000 Subject: QUEST: does HACKING make FOR loop quicker. In-Reply-To: <55c302ac$0$11116$c3e8da3@news.astraweb.com> References: <55C26B57.9080603@bk.ru> <55c302ac$0$11116$c3e8da3@news.astraweb.com> Message-ID: On Thu, Aug 6, 2015 at 4:46 PM, Steven D'Aprano wrote: > At least the question isn't off-topic here. I just wish I understood what > part of my answer doesn't satisfy. Despite John Doe emailing me off list > four times, I still don't know what he actually wants. Congratulations, you scored one more off-list email than I did. Possibly because, after twice telling him that posting to python-list or -tutor was the right way to ask, I simply didn't bother responding to the third. And I'm just as in the dark about what he wants to know. ChrisA From steve+comp.lang.python at pearwood.info Thu Aug 6 03:33:44 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 06 Aug 2015 17:33:44 +1000 Subject: Most Pythonic way to store (small) configuration References: <87k2teq9tb.fsf@Equus.decebal.nl> <36333f24-3bda-4534-b22f-20c99e8d791c@googlegroups.com> <87fv3xpfuu.fsf@elektro.pacujo.net> <20150805184354.596616fd@bigbox.christie.dr> Message-ID: <55c30dd9$0$1653$c3e8da3$5496439d@news.astraweb.com> On Thursday 06 August 2015 10:07, Chris Angelico wrote: > On Thu, Aug 6, 2015 at 9:43 AM, Tim Chase > wrote: >> Significant whitespace? Not usually simple (just stuck touching a >> project where someone committed with tons of trailing whitespaces. >> grumble), so strip 'em off as if they're an error condition. I've >> never had a config-file where I wanted leading/trailing whitespace as >> significant. > > If you're configuring a prompt, sometimes you need to be able to > include a space at the end of it. "Sometimes"? What sort of filthy perv doesn't separate their prompts from the user input with at least one space? Disgusting, I call it. this is a prompt and this isn't versus this is a promptand this isn't Come the revolution, anyone who writes the second will be taken out and shot. The right solution to that is to have the display function add a space to the end of the prompt if there isn't already one, that way you don't need to care about putting a space at the end of the prompt yourself. > Since trailing whitespace on a line > in the file itself is a bad idea, you need some way of marking it. I'm partial to one of two schemes: - strings need to be quoted, so leading and trailing spaces are easy: key = " this has both leading and trailing spaces " - strings don't need to be quoted, and spaces are significant *except* at the ends of the string: key = this has no leading or trailing spaces If you need spaces at the end, use an escape sequence: key = \sthis has both leading and trailing spaces\s say, or ^SP or \N{SPACE} or whatever floats your boat. Unless your requirements are limited to only printable ASCII strings, you're going to need to provide some sort of escape sequence anyway, to allow (say) newlines. -- Steve From rosuav at gmail.com Thu Aug 6 03:51:07 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Aug 2015 17:51:07 +1000 Subject: Most Pythonic way to store (small) configuration In-Reply-To: <55c30dd9$0$1653$c3e8da3$5496439d@news.astraweb.com> References: <87k2teq9tb.fsf@Equus.decebal.nl> <36333f24-3bda-4534-b22f-20c99e8d791c@googlegroups.com> <87fv3xpfuu.fsf@elektro.pacujo.net> <20150805184354.596616fd@bigbox.christie.dr> <55c30dd9$0$1653$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Aug 6, 2015 at 5:33 PM, Steven D'Aprano wrote: > On Thursday 06 August 2015 10:07, Chris Angelico wrote: > >> On Thu, Aug 6, 2015 at 9:43 AM, Tim Chase >> wrote: >>> Significant whitespace? Not usually simple (just stuck touching a >>> project where someone committed with tons of trailing whitespaces. >>> grumble), so strip 'em off as if they're an error condition. I've >>> never had a config-file where I wanted leading/trailing whitespace as >>> significant. >> >> If you're configuring a prompt, sometimes you need to be able to >> include a space at the end of it. > > "Sometimes"? What sort of filthy perv doesn't separate their prompts from > the user input with at least one space? Disgusting, I call it. > > this is a prompt and this isn't > > versus > > this is a promptand this isn't > > Come the revolution, anyone who writes the second will be taken out and > shot. Oh, well, there are these people in backwards nations that still have prompts that look like this: C:\> and have no space after them. I *was* trying to be courteous, but maybe courtesy is wasted on those who'll be shot come the revolution anyway. > The right solution to that is to have the display function add a space to > the end of the prompt if there isn't already one, that way you don't need to > care about putting a space at the end of the prompt yourself. That's an option that solves one specific instance of the problem, but I'm sure there are other places where you may or may not want a trailing space, so it needs a marker. >> Since trailing whitespace on a line >> in the file itself is a bad idea, you need some way of marking it. > > I'm partial to one of two schemes: > > - strings need to be quoted, so leading and trailing spaces are easy: > > key = " this has both leading and trailing spaces " Yeah, this is fine for a lot of cases. It does add small complexity, though, to the simple case where you're setting simple tokens as values. > - strings don't need to be quoted, and spaces are significant *except* > at the ends of the string: > > key = this has no leading or trailing spaces > > If you need spaces at the end, use an escape sequence: > > key = \sthis has both leading and trailing spaces\s > > say, or ^SP or \N{SPACE} or whatever floats your boat. Unless your > requirements are limited to only printable ASCII strings, you're going to > need to provide some sort of escape sequence anyway, to allow (say) > newlines. This is starting to get toward a full-blown DSL, which is costly. At this point, you may as well go for something well-known, which is what this thread's all about. A compromise might be: Unquoted strings get trimmed and are restricted to one line, but if you want leading/trailing spaces, or leading/trailing quote characters, or embedded newlines, or Unicode escapes, you must first put quotes around the string. server = 127.0.0.1 message = "Hi there!\nTwo line message being delivered." windows_path = c:\users\adam That way, you pay the complexity cost of full string parsing only if you actually need it. ChrisA From ben+python at benfinney.id.au Thu Aug 6 04:32:56 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 06 Aug 2015 18:32:56 +1000 Subject: Test doubles for Python standard library HTTP classes Message-ID: <85d1z0ke9z.fsf@benfinney.id.au> Howdy all, What standard Python library is there to make test doubles of ?httplib.HTTPConnection? and ?urllib2.HTTPBasicAuthHandler? and so on? I have a code base (Python 2 code) which performs HTTP sessions using the various HTTP-level classes in the standard library. Testing this code will be made much easier if I can create numerous test doubles[0] with pre-determined behaviour and instrumentation for later inspection, to allow the functions I'm testing to interact with those doubles instead of the real thing. There are some libraries that provide a much higher-level API, but I need to provide double behaviour at the level this code expects, i.e. at the level of the API provided by ?httplib? and ?urllib2? classes. What standard code libraries provide classes which make it easy to double the behaviour of ?httplib? classes and ?urllib2? classes, etc. for test cases? [0] Test double is a more general term covering all of stubs, fakes, spies, mocks, etc. to double specifically as a fixture in a test case. -- \ ?The most merciful thing in the world? is the inability of the | `\ human mind to correlate all its contents.? ?Howard Philips | _o__) Lovecraft | Ben Finney From tjreedy at udel.edu Thu Aug 6 04:54:46 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 6 Aug 2015 04:54:46 -0400 Subject: Installation Successful, but pythonw and idle doesn't function In-Reply-To: References: <201508051612.t75GCc5m017047@rs103.luxsci.com> Message-ID: On 8/5/2015 10:43 PM, Zachary Ware wrote: >> C:\Users\judy\AppData\Local\Programs\Python\Python35-32\Lib\idlelib>idle.py >> ** IDLE can't import Tkinter. >> Your Python may not be configured for Tk. ** > > You hit upon a bug in 3.5.0b4, which is that the installer is broken > for tkinter unless you have Microsoft Visual Studio 2015 installed. > See http://bugs.python.org/issue24771 for details, the fix will be > included in 3.5.0rc1. This is pretty unusual. > Your best bet is to avoid using pre-release software, and stick with > Python 3.4.3 until such time as 3.5.0 final is released. Actually, people do a service by installing and testing pre-release software. They just need to realize that this is what they are doing ;-). There was a bug in 3.4.0, I believe it was, that was caught on the second day when someone installed and ran the test suite of their software. It would have nicer if that testing had been done sooner. -- Terry Jan Reedy From hayesstw at telkomsa.net Thu Aug 6 05:29:28 2015 From: hayesstw at telkomsa.net (Steve Hayes) Date: Thu, 06 Aug 2015 11:29:28 +0200 Subject: Who uses IDLE -- please answer if you ever do, know, or teach References: Message-ID: <85a6sa93u9l1o7jhqa4t57mmi9nnfupjg0@4ax.com> On Wed, 5 Aug 2015 21:06:31 -0400, Terry Reedy wrote: >There have been discussions, such as today on Idle-sig , about who uses >Idle and who we should design it for. If you use Idle in any way, or >know of or teach classes using Idle, please answer as many of the >questions below as you are willing, and as are appropriate > >Private answers are welcome. They will be deleted as soon as they are >tallied (without names). > >I realized that this list is a biased sample of the universe of people >who have studied Python at least, say, a month. But biased data should >be better than my current vague impressions. > >0. Classes where Idle is used: >Where? >Level? > >Idle users: > >1. Are you >post-graduate (from whatever)? >2. Are you >beginner (1st class, maybe 2nd depending on intensity of first)? if you mean with Python >3. With respect to programming, are you >amateur (unpaid) -- Steve Hayes from Tshwane, South Africa Web: http://www.khanya.org.za/stevesig.htm Blog: http://khanya.wordpress.com E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk From muchomojo at gmail.com Thu Aug 6 06:45:57 2015 From: muchomojo at gmail.com (Stephen Kennedy) Date: Thu, 6 Aug 2015 03:45:57 -0700 (PDT) Subject: Pruning with os.scandir? Message-ID: <5eb45661-fc5a-4e87-9e59-82d5985a55e4@googlegroups.com> I just saw PEP 471 announced. Mostly it looks great! One thing I found puzzling though is the lack of control of iteration. With os.walk, one can modify the dirs list inplace to avoid recursing into subtrees (As mentioned somewhere, in theory one could even add to this list though that would be a strange case). I can't see how to do this with os.scandir. I hope I am missing something? Don't make me walk the entire contents of .git, tmp and build folders please. Stephen. From __peter__ at web.de Thu Aug 6 08:29:49 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 06 Aug 2015 14:29:49 +0200 Subject: Pruning with os.scandir? References: <5eb45661-fc5a-4e87-9e59-82d5985a55e4@googlegroups.com> Message-ID: Stephen Kennedy wrote: > I just saw PEP 471 announced. Mostly it looks great! One thing I found > puzzling though is the lack of control of iteration. With os.walk, one can > modify the dirs list inplace to avoid recursing into subtrees (As > mentioned somewhere, in theory one could even add to this list though that > would be a strange case). > > I can't see how to do this with os.scandir. I hope I am missing something? > Don't make me walk the entire contents of .git, tmp and build folders > please. I think you misunderstood. scandir() is the generator-producing equivalent of listdir() which returns a list. Neither of them recurses into subdirectories: $ tree . ??? [4.0K] top ??? [4.0K] one ??? [4.0K] three ? ??? [4.0K] bar ? ??? [4.0K] foo ??? [4.0K] two 6 directories, 0 files $ python3.5 Python 3.5.0b2+ (3.5:9aee273bf8b7+, Jun 25 2015, 09:25:29) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.listdir() ['top'] >>> os.scandir() >>> list(_) [] The /implementation/ of walk() was modified to use the more efficient scandir() under the hood, the user interface does not change: >>> for path, folders, files in os.walk("."): ... try: folders.remove("three") ... except: pass ... for name in folders + files: ... print(os.path.join(path, name)) ... ./top ./top/two ./top/one From nulla.epistola at web.de Thu Aug 6 09:07:05 2015 From: nulla.epistola at web.de (Sibylle Koczian) Date: Thu, 6 Aug 2015 15:07:05 +0200 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: Message-ID: <55C35BF9.9010203@web.de> Am 06.08.2015 um 03:06 schrieb Terry Reedy: > There have been discussions, such as today on Idle-sig , about who uses > Idle and who we should design it for. If you use Idle in any way, or > know of or teach classes using Idle, please answer as many of the > questions below as you are willing, and as are appropriate > I'm using Idle mostly on Windows where the Python command-line window or the Windows command window aren't very usable (encoding problems, copying from and to the window inconvenient and so on). For programs with more than two or three modules the Wing IDE is still nicer. > Idle users: > > 1. Are you > grade school (1=12)? > undergraduate (Freshman-Senior)? > post-graduate (from whatever)? post-graduate > > 2. Are you > beginner (1st class, maybe 2nd depending on intensity of first)? > post-beginner? post-beginner > > 3. With respect to programming, are you > amateur (unpaid) > professional (paid for programming) > amateur and programming just for my own convenience and fun. From nulla.epistola at web.de Thu Aug 6 09:07:05 2015 From: nulla.epistola at web.de (Sibylle Koczian) Date: Thu, 6 Aug 2015 15:07:05 +0200 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: Message-ID: <55C35BF9.9010203@web.de> Am 06.08.2015 um 03:06 schrieb Terry Reedy: > There have been discussions, such as today on Idle-sig , about who uses > Idle and who we should design it for. If you use Idle in any way, or > know of or teach classes using Idle, please answer as many of the > questions below as you are willing, and as are appropriate > I'm using Idle mostly on Windows where the Python command-line window or the Windows command window aren't very usable (encoding problems, copying from and to the window inconvenient and so on). For programs with more than two or three modules the Wing IDE is still nicer. > Idle users: > > 1. Are you > grade school (1=12)? > undergraduate (Freshman-Senior)? > post-graduate (from whatever)? post-graduate > > 2. Are you > beginner (1st class, maybe 2nd depending on intensity of first)? > post-beginner? post-beginner > > 3. With respect to programming, are you > amateur (unpaid) > professional (paid for programming) > amateur and programming just for my own convenience and fun. From muchomojo at gmail.com Thu Aug 6 09:37:15 2015 From: muchomojo at gmail.com (Stephen Kennedy) Date: Thu, 6 Aug 2015 06:37:15 -0700 (PDT) Subject: Pruning with os.scandir? In-Reply-To: References: <5eb45661-fc5a-4e87-9e59-82d5985a55e4@googlegroups.com> Message-ID: <51140129-d16c-4d63-9624-323180b4a750@googlegroups.com> > I think you misunderstood. scandir() is the generator-producing equivalent > of listdir() which returns a list. Neither of them recurses into > subdirectories: Ah great, that makes sense. An article I read gave the impression that os.scandir() was replacing os.walk(), not simply being used in its implementation. Thanks, Stephen. From zachary.ware+pylist at gmail.com Thu Aug 6 09:54:38 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Thu, 6 Aug 2015 08:54:38 -0500 Subject: Installation Successful, but pythonw and idle doesn't function In-Reply-To: References: <201508051612.t75GCc5m017047@rs103.luxsci.com> Message-ID: On Aug 6, 2015 3:55 AM, "Terry Reedy" wrote: > Actually, people do a service by installing and testing pre-release software. They just need to realize that this is what they are doing ;-). Indeed. However, I was assuming (possibly rashly, and if that's the case, my apologies to Rick) that Rick is quite new to Python, in which case he really is better off avoiding even pre-x.y.1 releases :). It's hard to learn something when you can't tell what's a bug, what's not, and what's just completely broken. -- Zach (On a phone) -------------- next part -------------- An HTML attachment was scrubbed... URL: From tandrewjohnson at outlook.com Thu Aug 6 11:35:24 2015 From: tandrewjohnson at outlook.com (Timothy Johnson) Date: Thu, 6 Aug 2015 11:35:24 -0400 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: Message-ID: <55C37EBC.3020604@outlook.com> On 8/5/2015 9:06 PM, Terry Reedy wrote: > There have been discussions, such as today on Idle-sig , about who uses > Idle and who we should design it for. If you use Idle in any way, or > know of or teach classes using Idle, please answer as many of the > questions below as you are willing, and as are appropriate > > Private answers are welcome. They will be deleted as soon as they are > tallied (without names). > > I realized that this list is a biased sample of the universe of people > who have studied Python at least, say, a month. But biased data should > be better than my current vague impressions. > > 0. Classes where Idle is used: > Where? > Level? > N/A > Idle users: > > 1. Are you > grade school (1=12)? > undergraduate (Freshman-Senior)? > post-graduate (from whatever)? > New freshman (starting college this fall) > 2. Are you > beginner (1st class, maybe 2nd depending on intensity of first)? > post-beginner? > Post-beginner (I'd call myself intermediate, but not expert) > 3. With respect to programming, are you > amateur (unpaid) > professional (paid for programming) > Amateur and programming just for convenience and fun (like Sibylle) PS: I actually don't use Idle very often, except to solve Project Euler problems because it works well for that. Most of the time I use PyDev and Notepad++ to edit Python code, but if more features were added to Idle I would consider using it more. From tandrewjohnson at outlook.com Thu Aug 6 11:35:24 2015 From: tandrewjohnson at outlook.com (Timothy Johnson) Date: Thu, 6 Aug 2015 11:35:24 -0400 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: Message-ID: On 8/5/2015 9:06 PM, Terry Reedy wrote: > There have been discussions, such as today on Idle-sig , about who uses > Idle and who we should design it for. If you use Idle in any way, or > know of or teach classes using Idle, please answer as many of the > questions below as you are willing, and as are appropriate > > Private answers are welcome. They will be deleted as soon as they are > tallied (without names). > > I realized that this list is a biased sample of the universe of people > who have studied Python at least, say, a month. But biased data should > be better than my current vague impressions. > > 0. Classes where Idle is used: > Where? > Level? > N/A > Idle users: > > 1. Are you > grade school (1=12)? > undergraduate (Freshman-Senior)? > post-graduate (from whatever)? > New freshman (starting college this fall) > 2. Are you > beginner (1st class, maybe 2nd depending on intensity of first)? > post-beginner? > Post-beginner (I'd call myself intermediate, but not expert) > 3. With respect to programming, are you > amateur (unpaid) > professional (paid for programming) > Amateur and programming just for convenience and fun (like Sibylle) PS: I actually don't use Idle very often, except to solve Project Euler problems because it works well for that. Most of the time I use PyDev and Notepad++ to edit Python code, but if more features were added to Idle I would consider using it more. From joel.goldstick at gmail.com Thu Aug 6 11:53:41 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 6 Aug 2015 11:53:41 -0400 Subject: QUEST: does HACKING make FOR loop quicker. In-Reply-To: References: <55C26B57.9080603@bk.ru> <55c302ac$0$11116$c3e8da3@news.astraweb.com> Message-ID: On Thu, Aug 6, 2015 at 3:19 AM, Chris Angelico wrote: > On Thu, Aug 6, 2015 at 4:46 PM, Steven D'Aprano > wrote: >> At least the question isn't off-topic here. I just wish I understood what >> part of my answer doesn't satisfy. Despite John Doe emailing me off list >> four times, I still don't know what he actually wants. > > Congratulations, you scored one more off-list email than I did. > Possibly because, after twice telling him that posting to python-list > or -tutor was the right way to ask, I simply didn't bother responding > to the third. And I'm just as in the dark about what he wants to know. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list My money is on a bot. -- Joel Goldstick http://joelgoldstick.com From breamoreboy at yahoo.co.uk Thu Aug 6 12:19:50 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 6 Aug 2015 17:19:50 +0100 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: Message-ID: On 06/08/2015 02:06, Terry Reedy wrote: > > 0. Classes where Idle is used: > Where? > Level? N/A > > Idle users: > > 1. Are you > grade school (1=12)? > undergraduate (Freshman-Senior)? > post-graduate (from whatever)? post-graduate > > 2. Are you > beginner (1st class, maybe 2nd depending on intensity of first)? > post-beginner? post-beginner > > 3. With respect to programming, are you > amateur (unpaid) > professional (paid for programming) > All Python work as an amateur. Former professional who's no longer working due to poor health. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From sairam.kumar8491 at gmail.com Thu Aug 6 14:06:50 2015 From: sairam.kumar8491 at gmail.com (sairam kumar) Date: Thu, 6 Aug 2015 23:36:50 +0530 Subject: Python Scheduling Message-ID: Hi Experts, I am Automating some repetitive works through Sikuli and Python scripting languages.I have multiple workflows.i need to schedule this script for every two hours.can anyone guide me how to schedule the scripts for every two hours. is there any way to schedule the python programming through Task scheduler in windows platform. below the things i am using: OS :Windows Programming languages : Sikuli,Python Thanks Sairam -------------- next part -------------- An HTML attachment was scrubbed... URL: From 69xxxooo at gmail.com Thu Aug 6 14:27:23 2015 From: 69xxxooo at gmail.com (Xxx Ooo) Date: Thu, 6 Aug 2015 11:27:23 -0700 (PDT) Subject: python for barcode Message-ID: I try to do a program to modify barcode which kind of like "Msoffice" if you suggestion? Thanks Raymond From lac at openend.se Thu Aug 6 15:18:01 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 06 Aug 2015 21:18:01 +0200 Subject: python for barcode In-Reply-To: Message from Xxx Ooo <69xxxooo@gmail.com> of "Thu, 06 Aug 2015 11:27:23 -0700." References: Message-ID: <201508061918.t76JI1WF009912@fido.openend.se> In a message of Thu, 06 Aug 2015 11:27:23 -0700, Xxx Ooo writes: >I try to do a program to modify barcode which kind of like "Msoffice" >if you suggestion? >Thanks > >Raymond I don't know what you mean by 'kind of like Msoffice'. Mostly I use reportlab for things like this. blogpost about it here: https://dzone.com/articles/how-create-barcodes-your-pdfs But I don't know if 'inside a pdf' is the sort of thing you are looking for. Laura From torriem at gmail.com Thu Aug 6 15:36:34 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 06 Aug 2015 13:36:34 -0600 Subject: python for barcode In-Reply-To: References: Message-ID: <55C3B742.9020607@gmail.com> On 08/06/2015 12:27 PM, Xxx Ooo wrote: > I try to do a program to modify barcode which kind of like "Msoffice" > if you suggestion? You'll have to explain better what you're looking for and what you've done so far. Also explain how this relates to Python. I have no idea what "like 'Msoffice'" means. And I don't know what you mean by "modify barcode." From piseema at gmail.com Thu Aug 6 16:06:36 2015 From: piseema at gmail.com (PK Khatri) Date: Thu, 6 Aug 2015 13:06:36 -0700 (PDT) Subject: How to use regex (re) Message-ID: <306503ec-4052-4438-b778-781797f9941a@googlegroups.com> I have a following script which extracts xyz.tgz and outputs to a folder which contains several sub-folders and files. source_dir = "c:\\TEST" dest_dir = "c:\\TEST" for src_name in glob.glob(os.path.join(source_dir, '*.tgz')): base = os.path.basename(src_name) dest_name = os.path.join(dest_dir, base[:-4]) with tarfile.open(src_name, 'r') as infile: infile.extractall(dest_dir) When above script is ran, the output is a single directory within that directory the structure looks like this: folder_1 folder_2 folder_n file_1 file_2 file_n In these folder, there are sub-folders and files. Among those file there are some data i am interested in to search and output to a file. For eg. Among the folders there is a file called **'localcli_network-ip-neighbor-list.txt**' which contains IP address(s) which I would like to output to a file. From nonami.ayo at gmail.com Thu Aug 6 17:20:31 2015 From: nonami.ayo at gmail.com (Nonami Animashaun) Date: Thu, 06 Aug 2015 21:20:31 +0000 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: Message-ID: > 0. Classes where Idle is used: > Where? > Level? > > Mostly on windows, can't remember ever using Idle on a linux system before. > Idle users: > > 1. Are you > grade school (1=12)? > undergraduate (Freshman-Senior)? > post-graduate (from whatever)? > Post-graduate > > 2. Are you > beginner (1st class, maybe 2nd depending on intensity of first)? > post-beginner? > Beginner > > 3. With respect to programming, are you > amateur (unpaid) > professional (paid for programming) > > Amateur, Occasionally use python for paid programming but use pycharm, eclipse with PyDev, Or sublime text in those cases mostly. Never Idle. > -- > Terry Jan Reedy, Idle maintainer > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Aug 6 18:58:40 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 6 Aug 2015 18:58:40 -0400 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: Message-ID: On 8/5/2015 9:21 PM, Rustom Mody wrote: > I used idle to teach a 2nd year engineering course last sem > It was a more pleasant experience than I expected > One feature that would help teachers: > It would be nice to (have setting to) auto-save the interaction window > [Yeah I tried to see if I could do it by hand but could not find where] > Useful for giving as handouts of the class > So students rest easy and dont need to take 'literal' notes of the session To prevent this idea from getting lost, I added "A follow-on issue would be to have an option to prompt to save (as with editor windows) or autosave when closing the shell. A default path might be .idlerc/shellsave.txt." to https://bugs.python.org/issue21937 and a reference in my personal list. -- Terry Jan Reedy From tjreedy at udel.edu Thu Aug 6 19:31:30 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 6 Aug 2015 19:31:30 -0400 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: <55C37EBC.3020604@outlook.com> References: <55C37EBC.3020604@outlook.com> Message-ID: On 8/6/2015 11:35 AM, Timothy Johnson wrote: > problems because it works well for that. Most of the time I use PyDev > and Notepad++ to edit Python code, but if more features were added to > Idle I would consider using it more. What 1 or 2 features would you most like to see? -- Terry Jan Reedy From tjreedy at udel.edu Thu Aug 6 19:35:17 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 6 Aug 2015 19:35:17 -0400 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: <85pp31jjvr.fsf@benfinney.id.au> References: <85pp31jjvr.fsf@benfinney.id.au> Message-ID: On 8/5/2015 9:17 PM, Ben Finney wrote: > Terry Reedy writes: > >> Private answers are welcome. They will be deleted as soon as they are >> tallied (without names). > > Are you also expecting questionnaire answers in this forum? Either or both. > I suspect it will become a free-ranging discussion; This has not happened so far. I am not commenting on direct answers to the questions, only ideas for new features. > hopefully you're prepared to pick through and collect the > responses if so. So far, they have been even more varies than I expected. -- Terry Jan Reedy From sohcahtoa82 at gmail.com Thu Aug 6 20:34:48 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Thu, 6 Aug 2015 17:34:48 -0700 (PDT) Subject: except block isn't catching exception Message-ID: <48587161-1bd6-47e4-b2c9-7a37c60a59e5@googlegroups.com> I've run into strange behavior involving a blocking call to a socket accept() on the main thread and thread.interrupt_main() being called on a worker thread. Here's my code: # BEGIN exception_test.py import socket import thread import threading import time def worker(): time.sleep(2) print 'Interrupting main' thread.interrupt_main() print 'main interrupted!' sock = socket.socket() sock.bind(('127.0.0.1', 8080)) sock.settimeout(5) sock.listen(0) t = threading.Thread(target=worker) t.start() try: connection, _ = sock.accept() except KeyboardInterrupt: print 'KeyboardInterrupt!' except socket.timeout: print 'Socket timeout!' print 'exiting' # END exception_test.py I would expect this output: Interrupting main main interrupted! KeyboardInterrupt caught! exiting But instead, I'm seeing this: Interrupting main main interrupted! Traceback (most recent call last): File "exception_test.py", line 23, in connection, _ = sock.accept() KeyboardInterrupt Despite my "except KeyboardInterrupt", the KeyboardInterrupt forced by the thread.interrupt_main() in the worker thread isn't being caught. Other things worth noting is that the exception takes about 3 seconds after the call to thread.interrupt_main(). It appears to not actually happen until the sock.accept() times out. If the call to sock.settimeout(5) is removed, the KeyboardInterrupt never appears and flow is still blocked on the sock.accept(). My Python version is 2.7.3. I know its out of date, but I don't really have a choice. From rosuav at gmail.com Thu Aug 6 20:46:03 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Aug 2015 10:46:03 +1000 Subject: except block isn't catching exception In-Reply-To: <48587161-1bd6-47e4-b2c9-7a37c60a59e5@googlegroups.com> References: <48587161-1bd6-47e4-b2c9-7a37c60a59e5@googlegroups.com> Message-ID: On Fri, Aug 7, 2015 at 10:34 AM, wrote: > Despite my "except KeyboardInterrupt", the KeyboardInterrupt forced by the thread.interrupt_main() in the worker thread isn't being caught. > > Other things worth noting is that the exception takes about 3 seconds after the call to thread.interrupt_main(). It appears to not actually happen until the sock.accept() times out. If the call to sock.settimeout(5) is removed, the KeyboardInterrupt never appears and flow is still blocked on the sock.accept(). > > My Python version is 2.7.3. I know its out of date, but I don't really have a choice. As far as I know, the only effect of thread.interrupt_main() is to set a flag saying "Hey main thread, next time you go checking for these things, there's a KeyboardInterrupt waiting for you". It doesn't actually send an OS-level signal, which means it cannot interrupt a blocking call. So you have a few choices: 1) Shorten the timeout on sock.accept() to an (if you'll excuse the pun) acceptable delay, and then simply check a flag. Something like this: interrupt = False while not interrupt: try: connection, _ = sock.accept() except socket.timeout: # On timeout, check flag and keep sleeping pass If you wish to also have an actual timeout, you could monitor that separately. 2) Instead of blocking on sock.accept directly, have another event which the other thread can raise, which will wake the main thread. You could use select.select() for this. 3) Bury the details of select.select() away behind a nice framework like asyncio, merge your two threads, and run everything through a back-end event loop. 4) Use separate processes, and signal the interrupt using an OS-level notification (on Unix systems, SIGINT; on Windows, there's an equivalent called BreakSignal or something). This will break out of the underlying system call that handles accept(). thread.interrupt_main() is similar to just setting a global that you periodically check, except that the periodic check is handled for you by the system. That's really all. ChrisA From tjreedy at udel.edu Thu Aug 6 22:07:26 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 6 Aug 2015 22:07:26 -0400 Subject: Linux users: please run gui tests Message-ID: Python has an extensive test suite run after each 'batch' of commits on a variety of buildbots. However, the Linux buildbots all (AFAIK) run 'headless', with gui's disabled. Hence the following test_tk test_ttk_guionly test_idle (and on 3.5, test_tix, but not important) are skipped either in whole or in part. We are planning on adding the use of tkinter.ttk to Idle after the 3.5.0 release, but a couple of other core developers have expressed concern about the reliability of tkinter.ttk on Linux. There is also an unresolved issue where test_ttk hung on Ubuntu Unity 3 years ago. https://bugs.python.org/issue14799 I would appreciate it if some people could run the linux version of py -3.4 -m test -ugui test_tk test_ttk_guionly test_idle (or 3.5). I guess this means 'python3 for the executable. and report here python version, linux system, and result. Alteration of environment and locale is a known issue, skip that. -- Terry Jan Reedy From ben+python at benfinney.id.au Thu Aug 6 22:18:51 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 07 Aug 2015 12:18:51 +1000 Subject: Linux users: please run gui tests References: Message-ID: <85y4hnj0xg.fsf@benfinney.id.au> Terry Reedy writes: > I would appreciate it if some people could run the linux version of > py -3.4 -m test -ugui test_tk test_ttk_guionly test_idle > (or 3.5). I guess this means 'python3 for the executable. Could you verify exactly what is the command to run? I'd hate for a bunch of commands to be run and reported that don't actually give you the information you need. -- \ ?It is clear that thought is not free if the profession of | `\ certain opinions makes it impossible to earn a living.? | _o__) ?Bertrand Russell, _Free Thought and Official Propaganda_, 1928 | Ben Finney From rosuav at gmail.com Thu Aug 6 22:20:33 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Aug 2015 12:20:33 +1000 Subject: Linux users: please run gui tests In-Reply-To: References: Message-ID: On Fri, Aug 7, 2015 at 12:07 PM, Terry Reedy wrote: > I would appreciate it if some people could run the linux version of > py -3.4 -m test -ugui test_tk test_ttk_guionly test_idle > (or 3.5). I guess this means 'python3 for the executable. > > and report here python version, linux system, and result. > Alteration of environment and locale is a known issue, skip that. A boatload of windows flicker during the test, which wouldn't surprise me if they weren't all empty, but I suppose it knows what it's doing. Toward the end of the test, there are a couple of beeps. rosuav at sikorsky:~$ python3 -V Python 3.6.0a0 rosuav at sikorsky:~$ python3 -m test -ugui test_tk test_ttk_guionly test_idle [1/3] test_tk [2/3] test_ttk_guionly [3/3] test_idle All 3 tests OK. rosuav at sikorsky:~$ python3.5 -V Python 3.5.0b1+ rosuav at sikorsky:~$ python3.5 -m test -ugui test_tk test_ttk_guionly test_idle [1/3] test_tk [2/3] test_ttk_guionly [3/3] test_idle All 3 tests OK. rosuav at sikorsky:~$ python3.4 -V Python 3.4.2 rosuav at sikorsky:~$ python3.4 -m test -ugui test_tk test_ttk_guionly test_idle /usr/bin/python3.4: No module named test.__main__; 'test' is a package and cannot be directly executed rosuav at sikorsky:~$ uname -a Linux sikorsky 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-3~deb8u1 (2015-04-24) x86_64 GNU/Linux The 3.4 is my system Python (Debian Wheezy), and /usr/lib/python3.4/test doesn't have much in it, so I'm guessing tests weren't installed. ChrisA From invalid at invalid.invalid Thu Aug 6 23:43:41 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 7 Aug 2015 03:43:41 +0000 (UTC) Subject: Linux users: please run gui tests References: Message-ID: On 2015-08-07, Terry Reedy wrote: > Python has an extensive test suite run after each 'batch' of commits on > a variety of buildbots. However, the Linux buildbots all (AFAIK) run > 'headless', with gui's disabled. Hence the following > test_tk test_ttk_guionly test_idle > (and on 3.5, test_tix, but not important) > are skipped either in whole or in part. > > We are planning on adding the use of tkinter.ttk to Idle after the 3.5.0 > release, but a couple of other core developers have expressed concern > about the reliability of tkinter.ttk on Linux. > > There is also an unresolved issue where test_ttk hung on Ubuntu Unity 3 > years ago. https://bugs.python.org/issue14799 > > I would appreciate it if some people could run the linux version of > py -3.4 -m test -ugui test_tk test_ttk_guionly test_idle > (or 3.5). I guess this means 'python3 for the executable. > > and report here python version, linux system, and result. > Alteration of environment and locale is a known issue, skip that. $ uname -a Linux aleph 3.12.21-gentoo-r1 #1 SMP PREEMPT Wed Jul 2 22:46:08 CDT 2014 i686 Intel(R) Core(TM) i3-3220T CPU @ 2.80GHz GenuineIntel GNU/Linux $ python3 --version Python 3.3.5 $ py -3.4 -m test -ugui test_tk test_ttk_guionly test_idle bash: py: command not found $ python3 -3.4 -m test -ugui test_tk test_ttk_guionly test_idle Unknown option: -3 usage: python3 [option] ... [-c cmd | -m mod | file | -] [arg] ... Try `python -h' for more information. -- Grant From invalid at invalid.invalid Thu Aug 6 23:46:37 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 7 Aug 2015 03:46:37 +0000 (UTC) Subject: Linux users: please run gui tests References: Message-ID: On 2015-08-07, Grant Edwards wrote: > On 2015-08-07, Terry Reedy wrote: >> Python has an extensive test suite run after each 'batch' of commits on >> a variety of buildbots. However, the Linux buildbots all (AFAIK) run >> 'headless', with gui's disabled. Hence the following >> test_tk test_ttk_guionly test_idle >> (and on 3.5, test_tix, but not important) >> are skipped either in whole or in part. >> >> We are planning on adding the use of tkinter.ttk to Idle after the 3.5.0 >> release, but a couple of other core developers have expressed concern >> about the reliability of tkinter.ttk on Linux. >> >> There is also an unresolved issue where test_ttk hung on Ubuntu Unity 3 >> years ago. https://bugs.python.org/issue14799 >> >> I would appreciate it if some people could run the linux version of >> py -3.4 -m test -ugui test_tk test_ttk_guionly test_idle >> (or 3.5). I guess this means 'python3 for the executable. >> >> and report here python version, linux system, and result. >> Alteration of environment and locale is a known issue, skip that. > > $ uname -a > Linux aleph 3.12.21-gentoo-r1 #1 SMP PREEMPT Wed Jul 2 22:46:08 CDT 2014 i686 Intel(R) Core(TM) i3-3220T CPU @ 2.80GHz GenuineIntel GNU/Linux > > $ python3 --version > Python 3.3.5 > > $ py -3.4 -m test -ugui test_tk test_ttk_guionly test_idle > bash: py: command not found > > $ python3 -3.4 -m test -ugui test_tk test_ttk_guionly test_idle > Unknown option: -3 > usage: python3 [option] ... [-c cmd | -m mod | file | -] [arg] ... > Try `python -h' for more information. Ah, I guess the -3.4 isn't valid. $ python3 --version Python 3.3.5 $ python3 -m test -ugui test_tk test_ttk_guionly test_idle [1/3] test_tk [2/3] test_ttk_guionly [3/3] test_idle All 3 tests OK. $ python3.4 --version Python 3.4.1 $ python3.4 -m test -ugui test_tk test_ttk_guionly test_idle [1/3] test_tk [2/3] test_ttk_guionly [3/3] test_idle All 3 tests OK. In both cases, some small, yellow windows flash briefly on the screen. From rosuav at gmail.com Thu Aug 6 23:53:31 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Aug 2015 13:53:31 +1000 Subject: Linux users: please run gui tests In-Reply-To: References: Message-ID: On Fri, Aug 7, 2015 at 12:20 PM, Chris Angelico wrote: > rosuav at sikorsky:~$ uname -a > Linux sikorsky 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-3~deb8u1 > (2015-04-24) x86_64 GNU/Linux > > The 3.4 is my system Python (Debian Wheezy) Oh, and for what it's worth, I'm running Xfce here. ChrisA From breamoreboy at yahoo.co.uk Fri Aug 7 03:08:16 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 7 Aug 2015 08:08:16 +0100 Subject: Linux users: please run gui tests In-Reply-To: References: Message-ID: On 07/08/2015 04:46, Grant Edwards wrote: > On 2015-08-07, Grant Edwards wrote: >> On 2015-08-07, Terry Reedy wrote: >>> Python has an extensive test suite run after each 'batch' of commits on >>> a variety of buildbots. However, the Linux buildbots all (AFAIK) run >>> 'headless', with gui's disabled. Hence the following >>> test_tk test_ttk_guionly test_idle >>> (and on 3.5, test_tix, but not important) >>> are skipped either in whole or in part. >>> >>> We are planning on adding the use of tkinter.ttk to Idle after the 3.5.0 >>> release, but a couple of other core developers have expressed concern >>> about the reliability of tkinter.ttk on Linux. >>> >>> There is also an unresolved issue where test_ttk hung on Ubuntu Unity 3 >>> years ago. https://bugs.python.org/issue14799 >>> >>> I would appreciate it if some people could run the linux version of >>> py -3.4 -m test -ugui test_tk test_ttk_guionly test_idle >>> (or 3.5). I guess this means 'python3 for the executable. >>> >>> and report here python version, linux system, and result. >>> Alteration of environment and locale is a known issue, skip that. >> >> $ uname -a >> Linux aleph 3.12.21-gentoo-r1 #1 SMP PREEMPT Wed Jul 2 22:46:08 CDT 2014 i686 Intel(R) Core(TM) i3-3220T CPU @ 2.80GHz GenuineIntel GNU/Linux >> >> $ python3 --version >> Python 3.3.5 >> >> $ py -3.4 -m test -ugui test_tk test_ttk_guionly test_idle >> bash: py: command not found >> >> $ python3 -3.4 -m test -ugui test_tk test_ttk_guionly test_idle >> Unknown option: -3 >> usage: python3 [option] ... [-c cmd | -m mod | file | -] [arg] ... >> Try `python -h' for more information. > > Ah, I guess the -3.4 isn't valid. > Correct. The "py -3.4" is the Python Launcher for Windows, hence the "run the linux version of". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From shekharchandra058 at gmail.com Fri Aug 7 03:10:36 2015 From: shekharchandra058 at gmail.com (Shekhar Chandra) Date: Fri, 7 Aug 2015 00:10:36 -0700 (PDT) Subject: Getting and/or setting network interface parameters on OS X Message-ID: Looking for a Python 2.7 module through which I can fetch the below details for all available network interfaces on a OS X device : Gateways DNS server DHCP server WINS server IP address DNS suffix I also want to set them for a specific interface. From anthra.norell at bluewin.ch Fri Aug 7 03:22:04 2015 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Fri, 07 Aug 2015 09:22:04 +0200 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: Message-ID: <55C45C9C.6080205@bluewin.ch> On 08/06/2015 03:21 AM, Rustom Mody wrote: > On Thursday, August 6, 2015 at 6:36:56 AM UTC+5:30, Terry Reedy wrote: >> There have been discussions, such as today on Idle-sig , about who uses >> Idle and who we should design it for. If you use Idle in any way, or >> know of or teach classes using Idle, please answer as many of the >> questions below as you are willing, and as are appropriate >> >> Private answers are welcome. They will be deleted as soon as they are >> tallied (without names). >> >> I realized that this list is a biased sample of the universe of people >> who have studied Python at least, say, a month. But biased data should >> be better than my current vague impressions. >> >> 0. Classes where Idle is used: >> Where? >> Level? >> >> Idle users: >> >> 1. Are you >> grade school (1=12)? >> undergraduate (Freshman-Senior)? >> post-graduate (from whatever)? >> >> 2. Are you >> beginner (1st class, maybe 2nd depending on intensity of first)? >> post-beginner? >> >> 3. With respect to programming, are you >> amateur (unpaid) >> professional (paid for programming) >> >> -- >> Terry Jan Reedy, Idle maintainer > I used idle to teach a 2nd year engineering course last sem > It was a more pleasant experience than I expected > One feature that would help teachers: > It would be nice to (have setting to) auto-save the interaction window > [Yeah I tried to see if I could do it by hand but could not find where] > Useful for giving as handouts of the class > So students rest easy and dont need to take 'literal' notes of the session > > I will now be teaching more advanced students and switching back to emacs > -- python, C, and others -- so really no option to emacs. > Not ideal at all but nothing else remotely comparable I've been using Idle full time to simultaneously manage my financial holdings, develop the management system and manually fix errors. While the ultimate goal is a push-button system, I have not reached that stage and am compelled to work trial-and-error style. For this way of working I found Idle well-suited, since the majority of jobs I do are hacks and quick fixes, not production runs running reliably. I recently came up with a data transformation framework that greatly expedites interactive development. It is based on transformer objects that wrap a transformation function. The base class Transformer handles the flow of the data in a manner that allows linking the transformer modules together in chains. With a toolbox of often used standards, a great variety of transformation tasks can be accomplished by simply lining up a bunch of toolbox transformers in chains. Bridging a gap now and then is a relatively simple matter of writing a transformation function that converts the output format upstream of the gap to the required input format downstream of the gap. The system works very well. It saves me a lot of time. I am currently writing a manual with the intention to upload it for comment and also to upload the system, if the comments are not too discouraging. If I may show a few examples below . . . Frederic (moderately knowledgeable non-professional) ------------------------------------------------------ >>> import TYX >>> FR = TYX.File_Reader () >>> CSVP = TYX.CSV_Parser () >>> TAB = TYX.Tabulator () >>> print TAB (CSVP (FR ('Downloads/xyz.csv'))) # Calls nest ------------------------------------------- Date,Open,Close,High,Low,Volume 07/18/2014,34.36,34.25,34.36,34.25,485 07/17/2014,34.55,34.50,34.55,34.47,"2,415" 07/16/2014,34.65,34.63,34.68,34.52,"83,477" ------------------------------------------- >>> CSVP.get () # display all parameters CSV_Parser dialect > None delimiter > '\t' quote > '"' has_header > False strip_fields > True headers > [] >>> CSVP.set (delimiter = ',') >>> TAB.set (table_format = 'pipe') >>> print TAB (CSVP ()) # Transformers retain their input |:-----------|:------|:------|:------|:------|:-------| | Date | Open | Close | High | Low | Volume | | 07/18/2014 | 34.36 | 34.25 | 34.36 | 34.25 | 485 | | 07/17/2014 | 34.55 | 34.50 | 34.55 | 34.47 | 2,415 | | 07/16/2014 | 34.65 | 34.63 | 34.68 | 34.52 | 83,477 | >>> class formatter (TYX.Transformer): def __init__ (self): TYX.Transformer.__init__ (self, symbol = None) # declare parameter def transform (self, records): symbol = self.get ('symbol') if symbol: out = [] for d, o, c, h, l, v in records [1:]: # Clip headers month, day, year = d.split ('/') d = '%s-%s-%s' % (year, month, day) v = v.replace (',', '') out.append ((d, symbol, o, c, h, l, v)) return out >>> fo = formatter () >>> fo.set (symbol = 'XYZ') >>> TAB.set (float_format = 'f') >>> print TAB (fo (CSVP())) # Transformers also retain their output |:-----------|:----|----------:|----------:|----------:|----------:|------:| | 2014-07-18 | XYZ | 34.360000 | 34.250000 | 34.360000 | 34.250000 | 485 | | 2014-07-17 | XYZ | 34.550000 | 34.500000 | 34.550000 | 34.470000 | 2415 | | 2014-07-16 | XYZ | 34.650000 | 34.630000 | 34.680000 | 34.520000 | 83477 | >>> DBW = TYX.MySQL_Writer (DB, USER, PASSWORD, table_name = 'quotes') >>> DBW (fo ()) 0 0 means it worked >>> Q2DB = Chain (FR, CSVP, fo, DBW) >>> TL = TYX.Text_To_Lines () >>> SR = TYX.System_Read () >>> for file_name in TL (SR ('ls -1 ~/Downloads/*.csv')): symbol = file_name.rsplit ('/', 1)[1].split ('.')[0].upper () print symbol Q2DB.set (symbol = symbol, file_name = file_name) Q2DB () ABC 0 DEF 0 . . . End of hacking. The production Transformer is next. >>> class Quotes_CSV_To_DB (TYX.Chain): def __init__ (self): TYX.Chain.__init__ ( self, TYX.File_Reader (), TYX.CSV_Parser (delimiter = ','), formatter (), TYX.MySQL_Writer (DB, USER, PASSWORD, table_name = 'quotes') ) >>> Q2DB = Quotes_CSV_To_DB () >>> for file_name in TL (SR ('ls -1 ~/Downloads/*.csv')): . . . >>> Q2DB.get () # display all parameters ============================================== Q2DB symbol = 'QQQ' file_name = '/home/fr/Downloads/qqq.csv' ============================================== File_Reader file_name > '/home/fr/Downloads/qqq.csv' ---------------------------------------------- CSV_Parser dialect > None delimiter > ',' headers > [] quote > '"' strip_fields > True has_header > False ---------------------------------------------- formatter symbol > QQQ ---------------------------------------------- MySQL_Writer db_name > 'fr' table_name > 'quotes' user > 'fr' permit > 2 password > None ---------------------------------------------- ============================================== -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Aug 7 03:26:52 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Aug 2015 17:26:52 +1000 Subject: Getting and/or setting network interface parameters on OS X In-Reply-To: References: Message-ID: On Fri, Aug 7, 2015 at 5:10 PM, Shekhar Chandra wrote: > Looking for a Python 2.7 module through which I can fetch the below details for all available network interfaces on a OS X device : > > Gateways > DNS server > DHCP server > WINS server > IP address > DNS suffix > > I also want to set them for a specific interface. Start here: https://pypi.python.org/pypi If that doesn't answer your question, then try looking for a command you can invoke, which you'd then parse the output of. ChrisA From Cecil at decebal.nl Fri Aug 7 03:53:14 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 07 Aug 2015 09:53:14 +0200 Subject: Linux users: please run gui tests References: Message-ID: <87wpx7fsb9.fsf@Equus.decebal.nl> On Friday 7 Aug 2015 04:07 CEST, Terry Reedy wrote: > Python has an extensive test suite run after each 'batch' of commits > on a variety of buildbots. However, the Linux buildbots all (AFAIK) > run headless', with gui's disabled. Hence the following test_tk > test_ttk_guionly test_idle (and on 3.5, test_tix, but not important) > are skipped either in whole or in part. > > We are planning on adding the use of tkinter.ttk to Idle after the > 3.5.0 release, but a couple of other core developers have expressed > concern about the reliability of tkinter.ttk on Linux. > > There is also an unresolved issue where test_ttk hung on Ubuntu > Unity 3 years ago. https://bugs.python.org/issue14799 > > I would appreciate it if some people could run the linux version of > py -3.4 -m test -ugui test_tk test_ttk_guionly test_idle > (or 3.5). I guess this means 'python3 for the executable. > > and report here python version, linux system, and result. > Alteration of environment and locale is a known issue, skip that. I made a Bash script: python3 --version python3 -m test -ugui test_tk test_ttk_guionly test_idle This gives: Python 3.4.1 [1/3] test_tk [2/3] test_ttk_guionly [3/3] test_idle All 3 tests OK. This was on openSUSE 13.2. I also tried to run it on Debian, but there I get: No moduke named test.__main__; 'test' is a package and cannot be directly executed -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Fri Aug 7 04:23:36 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 07 Aug 2015 10:23:36 +0200 Subject: Linux users: please run gui tests References: <87wpx7fsb9.fsf@Equus.decebal.nl> Message-ID: <87si7vfqwn.fsf@Equus.decebal.nl> On Friday 7 Aug 2015 09:53 CEST, Cecil Westerhof wrote: > On Friday 7 Aug 2015 04:07 CEST, Terry Reedy wrote: > >> Python has an extensive test suite run after each 'batch' of >> commits on a variety of buildbots. However, the Linux buildbots all >> (AFAIK) run headless', with gui's disabled. Hence the following >> test_tk test_ttk_guionly test_idle (and on 3.5, test_tix, but not >> important) are skipped either in whole or in part. >> >> We are planning on adding the use of tkinter.ttk to Idle after the >> 3.5.0 release, but a couple of other core developers have expressed >> concern about the reliability of tkinter.ttk on Linux. >> >> There is also an unresolved issue where test_ttk hung on Ubuntu >> Unity 3 years ago. https://bugs.python.org/issue14799 >> >> I would appreciate it if some people could run the linux version of >> py -3.4 -m test -ugui test_tk test_ttk_guionly test_idle >> (or 3.5). I guess this means 'python3 for the executable. >> >> and report here python version, linux system, and result. >> Alteration of environment and locale is a known issue, skip that. > > I made a Bash script: > python3 --version > python3 -m test -ugui test_tk test_ttk_guionly test_idle > > This gives: > Python 3.4.1 > [1/3] test_tk > [2/3] test_ttk_guionly > [3/3] test_idle > All 3 tests OK. > > This was on openSUSE 13.2. > > I also tried to run it on Debian, but there I get: > No moduke named test.__main__; 'test' is a package and cannot be > directly executed I also tried it on an Ubuntu system: there I got the same error. (Not very strange because it is a Debian derivative.) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From __peter__ at web.de Fri Aug 7 04:48:51 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 07 Aug 2015 10:48:51 +0200 Subject: Linux users: please run gui tests References: Message-ID: Terry Reedy wrote: > Python has an extensive test suite run after each 'batch' of commits on > a variety of buildbots. However, the Linux buildbots all (AFAIK) run > 'headless', with gui's disabled. Hence the following > test_tk test_ttk_guionly test_idle > (and on 3.5, test_tix, but not important) > are skipped either in whole or in part. > > We are planning on adding the use of tkinter.ttk to Idle after the 3.5.0 > release, but a couple of other core developers have expressed concern > about the reliability of tkinter.ttk on Linux. > > There is also an unresolved issue where test_ttk hung on Ubuntu Unity 3 > years ago. https://bugs.python.org/issue14799 > > I would appreciate it if some people could run the linux version of > py -3.4 -m test -ugui test_tk test_ttk_guionly test_idle > (or 3.5). I guess this means 'python3 for the executable. > > and report here python version, linux system, and result. > Alteration of environment and locale is a known issue, skip that. The first attempt gave $ python3.5 -m test -ugui test_tk test_ttk_guionly test_idle [1/3] test_tk [2/3] test_ttk_guionly test test_ttk_guionly failed -- Traceback (most recent call last): File "/usr/local/lib/python3.5/tkinter/test/test_ttk/test_widgets.py", line 947, in test_tab_identifiers self.fail("Tab with text 'a' not found") AssertionError: Tab with text 'a' not found [3/3/1] test_idle 2 tests OK. 1 test failed: test_ttk_guionly In subsequent repetions all tests completed without error. My completely unbased guess is that my system is too slow so that the Tab was not yet there when the check was performed. This is on Linux Mint 17 with $ uname -mrs Linux 3.13.0-24-generic x86_64 $ python3.5 Python 3.5.0b2+ (3.5:9aee273bf8b7+, Jun 25 2015, 09:25:29) [GCC 4.8.4] on linux From __peter__ at web.de Fri Aug 7 05:15:33 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 07 Aug 2015 11:15:33 +0200 Subject: Linux users: please run gui tests References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> Message-ID: Cecil Westerhof wrote: >> python3 --version >> python3 -m test -ugui test_tk test_ttk_guionly test_idle >> >> This gives: >> Python 3.4.1 >> [1/3] test_tk >> [2/3] test_ttk_guionly >> [3/3] test_idle >> All 3 tests OK. >> >> This was on openSUSE 13.2. >> >> I also tried to run it on Debian, but there I get: >> No moduke named test.__main__; 'test' is a package and cannot be >> directly executed > > I also tried it on an Ubuntu system: there I got the same error. (Not > very strange because it is a Debian derivative.) By default Debian doesn't install the test suite -- that's why you cannot run it ;) Install it with $ sudo apt-get install libpython3.4-testsuite and then try again. From rosuav at gmail.com Fri Aug 7 05:51:51 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Aug 2015 19:51:51 +1000 Subject: Linux users: please run gui tests In-Reply-To: References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> Message-ID: On Fri, Aug 7, 2015 at 7:15 PM, Peter Otten <__peter__ at web.de> wrote: > By default Debian doesn't install the test suite -- that's why you cannot > run it ;) > > Install it with > > $ sudo apt-get install libpython3.4-testsuite > > and then try again. Which makes it work fine on my system. ChrisA From sgsuneel at gmail.com Fri Aug 7 06:52:09 2015 From: sgsuneel at gmail.com (Suneel Mohan SG) Date: Fri, 7 Aug 2015 03:52:09 -0700 (PDT) Subject: Python Scheduling In-Reply-To: References: Message-ID: Sairam, What's your OS? Windows 7 does have a Task Scheduler. Go to Control Panel -> Administrative Tools -> Task Scheduler. Hope this helps. Br, Suneel. On Friday, August 7, 2015 at 2:27:03 PM UTC+5:30, sairam kumar wrote: > Hi Experts, > > > ? ? I am Automating some repetitive works through Sikuli and Python scripting languages.I have multiple workflows.i need to schedule this script for every two hours.can anyone guide me how to schedule the scripts for every two hours. > > > is there any way to schedule the python programming through Task scheduler in windows platform. > > > below the things i am using: > > > OS ?:Windows > Programming languages : Sikuli,Python > > > Thanks > Sairam From Cecil at decebal.nl Fri Aug 7 06:59:09 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 07 Aug 2015 12:59:09 +0200 Subject: Linux users: please run gui tests References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> Message-ID: <87d1yzfjpe.fsf@Equus.decebal.nl> On Friday 7 Aug 2015 11:15 CEST, Peter Otten wrote: > Cecil Westerhof wrote: > >>> python3 --version >>> python3 -m test -ugui test_tk test_ttk_guionly test_idle >>> >>> This gives: >>> Python 3.4.1 >>> [1/3] test_tk >>> [2/3] test_ttk_guionly >>> [3/3] test_idle >>> All 3 tests OK. >>> >>> This was on openSUSE 13.2. >>> >>> I also tried to run it on Debian, but there I get: >>> No moduke named test.__main__; 'test' is a package and cannot be >>> directly executed >> >> I also tried it on an Ubuntu system: there I got the same error. >> (Not very strange because it is a Debian derivative.) > > By default Debian doesn't install the test suite -- that's why you > cannot run it ;) > > Install it with > > $ sudo apt-get install libpython3.4-testsuite > > and then try again. python3-tk needs also to be installed. I changed the script to: uname -mrs python3 --version start=$(date +%s) python3 -m test -ugui test_tk test_ttk_guionly test_idle end=$(date +%s) printf "Running the tests took %d seconds\n" $((end - start)) On my openSUSE system this gives: Linux 3.16.7-21-desktop x86_64 Python 3.4.1 [1/3] test_tk [2/3] test_ttk_guionly [3/3] test_idle All 3 tests OK. Running the tests took 20 seconds On the Debian system this gives: Linux 3.16.0-4-586 i686 Python 3.4.2 [1/3] test_tk [2/3] test_ttk_guionly [3/3] test_idle All 3 tests OK. Running the tests took 16 seconds -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From uri at speedy.net Fri Aug 7 07:00:20 2015 From: uri at speedy.net (Uri Even-Chen) Date: Fri, 7 Aug 2015 14:00:20 +0300 Subject: pyjs - a compiler from Python to JavaScript Message-ID: To Python developers, Are you familiar with pyjs ? I saw the website and I see that the latest stable release is from May 2012. Is it possible to use pyjs to compile Python to JavaScript? Which versions of Python are supported? Are versions 2.7 and 3.4 supported? And is it possible to use Django (in the client side) and JavaScript frameworks such as jQuery, jQuery UI and jQuery plugins together with pyjs? Thanks, Uri. *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 Email: uri at speedy.net Website: http://www.speedysoftware.com/uri/en/ > Speedypedia in Hebrew and English -------------- next part -------------- An HTML attachment was scrubbed... URL: From tandrewjohnson at outlook.com Fri Aug 7 07:29:33 2015 From: tandrewjohnson at outlook.com (tjohnson) Date: Fri, 7 Aug 2015 07:29:33 -0400 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: <55C37EBC.3020604@outlook.com> Message-ID: <55C4969D.2010005@outlook.com> On 8/6/2015 7:31 PM, Terry Reedy wrote: > On 8/6/2015 11:35 AM, Timothy Johnson wrote: > >> problems because it works well for that. Most of the time I use PyDev >> and Notepad++ to edit Python code, but if more features were added to >> Idle I would consider using it more. > > What 1 or 2 features would you most like to see? > Practically, I'd say a line number margin and right edge indicator. Theoretically, a tabbed editor and dockable interpreter pane. Thanks for asking. From tandrewjohnson at outlook.com Fri Aug 7 07:29:33 2015 From: tandrewjohnson at outlook.com (tjohnson) Date: Fri, 7 Aug 2015 07:29:33 -0400 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: <55C37EBC.3020604@outlook.com> Message-ID: On 8/6/2015 7:31 PM, Terry Reedy wrote: > On 8/6/2015 11:35 AM, Timothy Johnson wrote: > >> problems because it works well for that. Most of the time I use PyDev >> and Notepad++ to edit Python code, but if more features were added to >> Idle I would consider using it more. > > What 1 or 2 features would you most like to see? > Practically, I'd say a line number margin and right edge indicator. Theoretically, a tabbed editor and dockable interpreter pane. Thanks for asking. From Cecil at decebal.nl Fri Aug 7 08:36:28 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 07 Aug 2015 14:36:28 +0200 Subject: Linux users: please run gui tests References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <87d1yzfjpe.fsf@Equus.decebal.nl> Message-ID: <877fp7ff77.fsf@Equus.decebal.nl> On Friday 7 Aug 2015 12:59 CEST, Cecil Westerhof wrote: > On Friday 7 Aug 2015 11:15 CEST, Peter Otten wrote: > >> Cecil Westerhof wrote: >> >>>> python3 --version >>>> python3 -m test -ugui test_tk test_ttk_guionly test_idle >>>> >>>> This gives: >>>> Python 3.4.1 >>>> [1/3] test_tk >>>> [2/3] test_ttk_guionly >>>> [3/3] test_idle >>>> All 3 tests OK. >>>> >>>> This was on openSUSE 13.2. >>>> >>>> I also tried to run it on Debian, but there I get: >>>> No moduke named test.__main__; 'test' is a package and cannot be >>>> directly executed >>> >>> I also tried it on an Ubuntu system: there I got the same error. >>> (Not very strange because it is a Debian derivative.) >> >> By default Debian doesn't install the test suite -- that's why you >> cannot run it ;) >> >> Install it with >> >> $ sudo apt-get install libpython3.4-testsuite >> >> and then try again. > > python3-tk needs also to be installed. > > I changed the script to: > uname -mrs > python3 --version > start=$(date +%s) > python3 -m test -ugui test_tk test_ttk_guionly test_idle > end=$(date +%s) > printf "Running the tests took %d seconds\n" $((end - start)) > > On my openSUSE system this gives: > Linux 3.16.7-21-desktop x86_64 > Python 3.4.1 > [1/3] test_tk > [2/3] test_ttk_guionly > [3/3] test_idle > All 3 tests OK. > Running the tests took 20 seconds > > On the Debian system this gives: > Linux 3.16.0-4-586 i686 > Python 3.4.2 > [1/3] test_tk > [2/3] test_ttk_guionly > [3/3] test_idle > All 3 tests OK. > Running the tests took 16 seconds On another Debian system I get: Linux 3.16.0-4-amd64 x86_64 Python 3.4.2 [1/3] test_tk [2/3] test_ttk_guionly [3/3] test_idle All 3 tests OK. Running the tests took 28 seconds -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From lac at openend.se Fri Aug 7 08:38:34 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 07 Aug 2015 14:38:34 +0200 Subject: Linux users: please run gui tests In-Reply-To: Message from Chris Angelico of "Fri, 07 Aug 2015 19:51:51 +1000." References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> Message-ID: <201508071238.t77CcY7n018432@fido.openend.se> In a message of Fri, 07 Aug 2015 19:51:51 +1000, Chris Angelico writes: >On Fri, Aug 7, 2015 at 7:15 PM, Peter Otten <__peter__ at web.de> wrote: >> By default Debian doesn't install the test suite -- that's why you cannot >> run it ;) >> >> Install it with >> >> $ sudo apt-get install libpython3.4-testsuite >> >> and then try again. > >Which makes it work fine on my system. > >ChrisA Not here. I'm running debian unstable (jessie) I've already got libpython3.4-testsuite installed, and I cannot run the tests. lac at smartwheels:~$ lsb_release -a LSB Version: core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-3.0-noarch:core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:core-4.0-amd64:core-4.0-noarch:core-4.1-amd64:core-4.1-noarch:security-4.0-amd64:security-4.0-noarch:security-4.1-amd64:security-4.1-noarch Distributor ID: Debian Description: Debian GNU/Linux 8.0 (jessie) Release: 8.0 Codename: jessie lac at smartwheels:~$ cat /proc/version Linux version 3.16.0-4-amd64 (debian-kernel at lists.debian.org) (gcc version 4.8.4 (Debian 4.8.4-1) ) #1 SMP Debian 3.16.7-ckt9-2 (2015-04-13) lac at smartwheels:~$ python3 --version Python 3.4.3+ I have the lastest version of libpython3.4-testsuite installed. lac at smartwheels:~$ apt-cache policy libpython3.4-testsuite libpython3.4-testsuite: Installed: 3.4.3-8 Candidate: 3.4.3-8 Version table: *** 3.4.3-8 0 500 http://ftp.se.debian.org/debian/ unstable/main amd64 Packages 500 http://ftp.debian.org/debian/ unstable/main amd64 Packages 100 /var/lib/dpkg/status This is a brand new terminal window, i.e. I am not sitting in a virtualenv that I have completely forgotten about. But I still get: lac at smartwheels:~$ python3 -m test -ugui test_tk test_ttk_guionly test_idle /usr/bin/python3: Error while finding spec for 'test.__main__' (: bad magic number in 'test': b'\x03\xf3\r\n'); 'test' is a package and cannot be directly executed Now I am very puzzled. What else could I be missing to cause this? Laura From __peter__ at web.de Fri Aug 7 09:06:41 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 07 Aug 2015 15:06:41 +0200 Subject: Linux users: please run gui tests References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> Message-ID: Laura Creighton wrote: > In a message of Fri, 07 Aug 2015 19:51:51 +1000, Chris Angelico writes: >>On Fri, Aug 7, 2015 at 7:15 PM, Peter Otten <__peter__ at web.de> wrote: >>> By default Debian doesn't install the test suite -- that's why you >>> cannot run it ;) >>> >>> Install it with >>> >>> $ sudo apt-get install libpython3.4-testsuite >>> >>> and then try again. >> >>Which makes it work fine on my system. >> >>ChrisA > > Not here. > > I'm running debian unstable (jessie) > I've already got libpython3.4-testsuite installed, and I cannot run > the tests. > > lac at smartwheels:~$ lsb_release -a > LSB Version: > core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-3.0-noarch:core-3.1- amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:core-4.0- amd64:core-4.0-noarch:core-4.1-amd64:core-4.1-noarch:security-4.0- amd64:security-4.0-noarch:security-4.1-amd64:security-4.1-noarch > Distributor ID: Debian > Description: Debian GNU/Linux 8.0 (jessie) > Release: 8.0 > Codename: jessie > > lac at smartwheels:~$ cat /proc/version > Linux version 3.16.0-4-amd64 (debian-kernel at lists.debian.org) > (gcc version 4.8.4 (Debian 4.8.4-1) ) #1 SMP Debian 3.16.7-ckt9-2 > (2015-04-13) > > lac at smartwheels:~$ python3 --version > Python 3.4.3+ > > I have the lastest version of libpython3.4-testsuite installed. > lac at smartwheels:~$ apt-cache policy libpython3.4-testsuite > libpython3.4-testsuite: > Installed: 3.4.3-8 > Candidate: 3.4.3-8 > Version table: > *** 3.4.3-8 0 > 500 http://ftp.se.debian.org/debian/ unstable/main amd64 Packages > 500 http://ftp.debian.org/debian/ unstable/main amd64 Packages > 100 /var/lib/dpkg/status > > This is a brand new terminal window, i.e. I am not sitting in a virtualenv > that I have completely forgotten about. > > But I still get: > lac at smartwheels:~$ python3 -m test -ugui test_tk test_ttk_guionly > test_idle /usr/bin/python3: Error while finding spec for 'test.__main__' > (: bad magic number in 'test': b'\x03\xf3\r\n'); > 'test' is a package and cannot be directly executed > > Now I am very puzzled. What else could I be missing to cause this? I can provoke something similar with $ touch test.py $ python -c import\ test $ rm test.py $ python3 -m test -ugui test_tk /usr/bin/python3: bad magic number in 'test': b'\x03\xf3\r\n' >From that I'd conclude that your python3 sees a leftover python2 pyc instead of the actual test package. Have a look at your working directory or PYTHONPATH. From ahlusar.ahluwalia at gmail.com Fri Aug 7 09:08:05 2015 From: ahlusar.ahluwalia at gmail.com (Saran Ahluwalia) Date: Fri, 7 Aug 2015 09:08:05 -0400 Subject: GOTCHA with list comprehension In-Reply-To: References: <87wpxacdnr.fsf@elektro.pacujo.net> Message-ID: @ChrisA You, my friend, certainly put the nail in the coffin! Sent from my iPhone > On Aug 5, 2015, at 5:52 AM, Chris Angelico wrote: > >> On Wed, Aug 5, 2015 at 7:01 PM, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> You can chain 'for' and 'if' clauses as much as you like, and they >>> behave exactly the way you'd expect. >> >> How do you know what I'd expect? >> >> I wouldn't know what to expect myself. > > A list comprehension can always be unwound into statement form. [1] For example: > > squares = [n*n for n in range(10)] > > can be unwound into: > > squares = [] > for n in range(10): > squares.append(n*n) > > You simply take the expression at the beginning and put that into the > append() method call, and then the rest become statements. Here's a > filtered version: > > odd_squares = [n*n for n in range(20) if n%2] > > Which becomes: > > odd_squares = [] > for n in range(20): > if n%2: > odd_squares.append(n*n) > > So what would you expect nested 'if' clauses to do? Well, they become > nested 'if' statements: > > primes = [n for n in range(2,24) if n%2 if n%3] > > primes = [] > for n in range(2,24): > if n%2: > if n%3: > primes.append(n) > > What if we have multiple 'for' loops? Same thing! > > ways_to_get_seven = [(a,b) for a in range(1,7) for b in range(1,7) if a+b==7] > > ways_to_get_seven = [] > for a in range(1,7): > for b in range(1,7): > if a+b==7: > ways_to_get_seven.append((a,b)) > > No matter what combination of 'if' and 'for' you use, it can be > unwound like this, and it'll always behave the same way. Not sure what > to expect? Follow the simple rules of unwinding, and then read the > code that way. > > Of course, if you don't know how to predict what the statement form > will do, then you won't understand what the comprehension will do. But > that's not the comprehension's fault. > > peculiar = [a*x*x+b*x+c for a in range(1,10) for b in range(2,30) for > c in range(-3,5) if b*b-4*a*c>=0 if (-b+math.sqrt(b*b-4*a*c))/2/a>0 > for x in (x*.01 for x in range(-500,500))] > > I suppose you could graph that. Or something. But that's just bad > code, don't blame the list comp for that... > > ChrisA > > [1] To be technically correct, this unwinding should be done in a > nested function, which you then call. There are some other minor > technicalities too. But it's pretty much this. > -- > https://mail.python.org/mailman/listinfo/python-list From lac at openend.se Fri Aug 7 09:46:21 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 07 Aug 2015 15:46:21 +0200 Subject: Linux users: please run gui tests In-Reply-To: Message from Peter Otten <__peter__@web.de> of "Fri, 07 Aug 2015 15:06:41 +0200." References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> Message-ID: <201508071346.t77DkL2t031696@fido.openend.se> In a message of Fri, 07 Aug 2015 15:06:41 +0200, Peter Otten writes: >$ touch test.py >$ python -c import\ test >$ rm test.py >$ python3 -m test -ugui test_tk >/usr/bin/python3: bad magic number in 'test': b'\x03\xf3\r\n' > >>From that I'd conclude that your python3 sees a leftover python2 pyc instead >of the actual test package. Have a look at your working directory or >PYTHONPATH. Right you are. Thank you. lac at smartwheels:~$ python3 -m test -ugui test_tk test_ttk_guionly test_idle [1/3] test_tk test test_tk failed -- multiple errors occurred; run in verbose mode for details [2/3/1] test_ttk_guionly [3/3/1] test_idle 2 tests OK. 1 test failed: test_tk running python3 -v -m test -ugui test_tk 2>test_tk.out produces a whole lot of output. I put the file up here. http://www2.openend.se/~lac/test_tk.out But I don't think there is anything useful in it. grepping the file for 'failed' only gives you the same old est test_tk failed -- multiple errors occurred; run in verbose mode for details What would you (Terry) like me to do now? Laura From emile at fenx.com Fri Aug 7 09:48:32 2015 From: emile at fenx.com (Emile van Sebille) Date: Fri, 7 Aug 2015 06:48:32 -0700 Subject: Python Scheduling In-Reply-To: References: Message-ID: On 8/6/2015 11:06 AM, sairam kumar wrote: > Hi Experts, > > I am Automating some repetitive works through Sikuli and Python > scripting languages.I have multiple workflows.i need to schedule this > script for every two hours.can anyone guide me how to schedule the scripts > for every two hours. > > is there any way to schedule the python programming through Task scheduler > in windows platform. > The windows task scheduler works fine -- have you tried it? Emile From rogerh906 at gmail.com Fri Aug 7 10:08:23 2015 From: rogerh906 at gmail.com (rogerh906 at gmail.com) Date: Fri, 7 Aug 2015 07:08:23 -0700 (PDT) Subject: Python speed Message-ID: <2261c8c6-77ba-453d-9205-0a922fa67c81@googlegroups.com> Can anyone compare PyNum calculation speed to Fortran? This is for a number crunching program working with large files. Roger From lac at openend.se Fri Aug 7 10:17:59 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 07 Aug 2015 16:17:59 +0200 Subject: Python Scheduling In-Reply-To: Message from Emile van Sebille of "Fri, 07 Aug 2015 06:48:32 -0700." References: Message-ID: <201508071417.t77EHxla005652@fido.openend.se> In a message of Fri, 07 Aug 2015 06:48:32 -0700, Emile van Sebille writes: >On 8/6/2015 11:06 AM, sairam kumar wrote: >> Hi Experts, >> >> I am Automating some repetitive works through Sikuli and Python >> scripting languages.I have multiple workflows.i need to schedule this >> script for every two hours.can anyone guide me how to schedule the scripts >> for every two hours. >> >> is there any way to schedule the python programming through Task scheduler >> in windows platform. >> > >The windows task scheduler works fine -- have you tried it? > >Emile I think his problem is that he wants a way to do this that doesn't involve having a human being sitting at a console using a gui to communicate with the task scheduler, but I could be wrong about this. Laura From __peter__ at web.de Fri Aug 7 11:34:54 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 07 Aug 2015 17:34:54 +0200 Subject: Linux users: please run gui tests References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> <201508071346.t77DkL2t031696@fido.openend.se> Message-ID: Laura Creighton wrote: > In a message of Fri, 07 Aug 2015 15:06:41 +0200, Peter Otten writes: >>$ touch test.py >>$ python -c import\ test >>$ rm test.py >>$ python3 -m test -ugui test_tk >>/usr/bin/python3: bad magic number in 'test': b'\x03\xf3\r\n' >> >>>From that I'd conclude that your python3 sees a leftover python2 pyc >>>instead >>of the actual test package. Have a look at your working directory or >>PYTHONPATH. > > Right you are. Thank you. > > lac at smartwheels:~$ python3 -m test -ugui test_tk test_ttk_guionly > test_idle > [1/3] test_tk > test test_tk failed -- multiple errors occurred; run in verbose mode for > details > [2/3/1] test_ttk_guionly > [3/3/1] test_idle > 2 tests OK. > 1 test failed: > test_tk > > running python3 -v -m test -ugui test_tk 2>test_tk.out produces a whole > lot of output. > > I put the file up here. > http://www2.openend.se/~lac/test_tk.out > > But I don't think there is anything useful in it. grepping the file > for 'failed' only gives you the same old > est test_tk failed -- multiple errors occurred; run in verbose mode for > details > > What would you (Terry) like me to do now? Run $ python3 -m test -ugui -v test_tk (That way the unittest framework will see the -v option) Note that there are lines like # possible namespace for /home/lac/src/accounting/test in your python3 -v output that indicate that there may still be too much in your PYTHONPATH. From emile at fenx.com Fri Aug 7 11:37:39 2015 From: emile at fenx.com (Emile van Sebille) Date: Fri, 7 Aug 2015 08:37:39 -0700 Subject: Python Scheduling In-Reply-To: <201508071417.t77EHxla005652@fido.openend.se> References: <201508071417.t77EHxla005652@fido.openend.se> Message-ID: On 8/7/2015 7:17 AM, Laura Creighton wrote: > In a message of Fri, 07 Aug 2015 06:48:32 -0700, Emile van Sebille writes: >> On 8/6/2015 11:06 AM, sairam kumar wrote: >>> Hi Experts, >>> >>> I am Automating some repetitive works through Sikuli and Python >>> scripting languages.I have multiple workflows.i need to schedule this >>> script for every two hours.can anyone guide me how to schedule the scripts >>> for every two hours. >>> >>> is there any way to schedule the python programming through Task scheduler >>> in windows platform. >>> >> >> The windows task scheduler works fine -- have you tried it? >> >> Emile > > I think his problem is that he wants a way to do this that doesn't > involve having a human being sitting at a console using a gui to communicate > with the task scheduler, but I could be wrong about this. In that case, 'at' provides a command line interface for the windows task scheduler... Emile From malladisivaramakrishna88 at gmail.com Fri Aug 7 11:59:45 2015 From: malladisivaramakrishna88 at gmail.com (malladisivaramakrishna88 at gmail.com) Date: Fri, 7 Aug 2015 08:59:45 -0700 (PDT) Subject: Python Developer- Houston, TX Message-ID: Hi, Hope you are doing well !!! My name is Siva and I'm a recruiter at TheAppliedthought , a global staffing and IT consulting company. Please find the below job description which may suits any of your consultants who are available in market or who are looking for change, please send me latest updated resume along with contact details and expected hourly rate to my email id siva at theappliedthought.com or you can reach me on 407-574-7610. Position: Open Stack Developer Location: Houston, TX Duration: Long Term Job Description 6+ years of experience with Linux/UNIX Systems Administration o 2+ years of Openstack Experience o Hypervisor KVM, BIOS, Firmware update o Storage Technologies (NAS, SAN & Cloud Storage) o Experience with configuration management tools (Chef expert!!) o Analytical problem-solving and conceptual skills o Strong scripting and/or development chops (Ruby, Python, Bash, Perl) o Experience with database technologies (MySQL, Percona, MongoDB) o Experience with automation (Chef etc.) and monitoring (Nagios, etc.) technologies in production setting o Experience with networking technologies including TCP/IP VPN DNS routing firewalls VLAN. o Excellent communication skills o Excellent team player With Regards & Wishes, SivaRamakrishna.M| Executive-Talent Acquisition & Bench Sales Email: siva at theappliedthought.com | Gtalk/IM: malladisivaramakrishna88 Phone: 407-574-7610 | Fax: 407-641-8184 820 West Lake Mary Blvd, Suite 202, Sanford, FL 32773 From lab at pacbell.net Fri Aug 7 12:23:32 2015 From: lab at pacbell.net (20/20 Lab) Date: Fri, 07 Aug 2015 09:23:32 -0700 Subject: Linux users: please run gui tests In-Reply-To: References: Message-ID: <55C4DB84.9070104@pacbell.net> On 08/06/2015 07:07 PM, Terry Reedy wrote: > Python has an extensive test suite run after each 'batch' of commits > on a variety of buildbots. However, the Linux buildbots all (AFAIK) > run 'headless', with gui's disabled. Hence the following > test_tk test_ttk_guionly test_idle > (and on 3.5, test_tix, but not important) > are skipped either in whole or in part. > > We are planning on adding the use of tkinter.ttk to Idle after the > 3.5.0 release, but a couple of other core developers have expressed > concern about the reliability of tkinter.ttk on Linux. > > There is also an unresolved issue where test_ttk hung on Ubuntu Unity > 3 years ago. https://bugs.python.org/issue14799 > > I would appreciate it if some people could run the linux version of > py -3.4 -m test -ugui test_tk test_ttk_guionly test_idle > (or 3.5). I guess this means 'python3 for the executable. > > and report here python version, linux system, and result. > Alteration of environment and locale is a known issue, skip that. > $ uname -a Linux term 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux $ python3 -m test -ugui test_tk test_ttk_guionly test_idle [1/3] test_tk [2/3] test_ttk_guionly [3/3] test_idle All 3 tests OK. From pkpearson at nowhere.invalid Fri Aug 7 12:48:12 2015 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 7 Aug 2015 16:48:12 GMT Subject: How to use regex (re) References: <306503ec-4052-4438-b778-781797f9941a@googlegroups.com> Message-ID: On Thu, 6 Aug 2015 13:06:36 -0700 (PDT), PK Khatri wrote: > I have a following script which extracts xyz.tgz and outputs to a > folder which contains several sub-folders and files. > > source_dir = "c:\\TEST" > dest_dir = "c:\\TEST" > for src_name in glob.glob(os.path.join(source_dir, '*.tgz')): > base = os.path.basename(src_name) > dest_name = os.path.join(dest_dir, base[:-4]) > with tarfile.open(src_name, 'r') as infile: > infile.extractall(dest_dir) > > When above script is ran, the output is a single directory within that > directory the structure looks like this: > > folder_1 > folder_2 > folder_n > file_1 > file_2 > file_n > > In these folder, there are sub-folders and files. Among those file > there are some data i am interested in to search and output to a file. > > For eg. Among the folders there is a file called > **'localcli_network-ip-neighbor-list.txt**' which contains IP > address(s) which I would like to output to a file. Are you asking how to determine whether the string "localcli_network-ip-neighbor-list.txt" appears in a filename? If so, the logical expression "localcli_network-ip-neighbor-list.txt" in filename will do the job. -- To email me, substitute nowhere->runbox, invalid->com. From beliavsky at aol.com Fri Aug 7 12:57:26 2015 From: beliavsky at aol.com (beliavsky at aol.com) Date: Fri, 7 Aug 2015 09:57:26 -0700 (PDT) Subject: Python speed In-Reply-To: <2261c8c6-77ba-453d-9205-0a922fa67c81@googlegroups.com> References: <2261c8c6-77ba-453d-9205-0a922fa67c81@googlegroups.com> Message-ID: <04b7cdd0-1eb0-4378-9d14-38e97b4456a7@googlegroups.com> On Friday, August 7, 2015 at 10:08:37 AM UTC-4, roge... at gmail.com wrote: > Can anyone compare PyNum calculation speed to Fortran? > > This is for a number crunching program working with large files. > > Roger Did you mean NumPy? It depends on the program. Here are two posts that compared speeds. Comparing Python, NumPy, Matlab, Fortran, etc. (2009) https://modelingguru.nasa.gov/docs/DOC-1762 Optimizing Python in the Real World: NumPy, Numba, and the NUFFT (2015) https://jakevdp.github.io/blog/2015/02/24/optimizing-python-with-numpy-and-numba/ From lac at openend.se Fri Aug 7 13:01:12 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 07 Aug 2015 19:01:12 +0200 Subject: Linux users: please run gui tests In-Reply-To: Message from Peter Otten <__peter__@web.de> of "Fri, 07 Aug 2015 17:34:54 +0200." References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> <201508071346.t77DkL2t031696@fido.openend.se> Message-ID: <201508071701.t77H1Csn004579@fido.openend.se> In a message of Fri, 07 Aug 2015 17:34:54 +0200, Peter Otten writes: >Run > >$ python3 -m test -ugui -v test_tk > >(That way the unittest framework will see the -v option) Aha, I didn't understand that. Thank you. >Note that there are lines like > ># possible namespace for /home/lac/src/accounting/test > >in your python3 -v output that indicate that there may still be too much in >your PYTHONPATH. It's now "" for this test. I get 3 failures, as follows (I trimmed the rest of the ok ones). = CPython 3.4.3+ (default, Jul 28 2015, 13:17:50) [GCC 4.9.3] == Linux-3.16.0-4-amd64-x86_64-with-debian-stretch-sid little-endian == hash algorithm: siphash24 64bit == /tmp/test_python_7974 Testing with flags: sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1, isolated=0) test_default (tkinter.test.test_tkinter.test_variables.TestBooleanVar) ... FAIL test_get (tkinter.test.test_tkinter.test_variables.TestBooleanVar) ... FAIL test_set (tkinter.test.test_tkinter.test_variables.TestBooleanVar) ... FAIL ====================================================================== FAIL: test_default (tkinter.test.test_tkinter.test_variables.TestBooleanVar) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python3.4/tkinter/test/test_tkinter/test_variables.py", line 163, in test_default self.assertIs(v.get(), False) AssertionError: 0 is not False ====================================================================== FAIL: test_get (tkinter.test.test_tkinter.test_variables.TestBooleanVar) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python3.4/tkinter/test/test_tkinter/test_variables.py", line 167, in test_get self.assertIs(v.get(), True) AssertionError: 1 is not True ====================================================================== FAIL: test_set (tkinter.test.test_tkinter.test_variables.TestBooleanVar) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python3.4/tkinter/test/test_tkinter/test_variables.py", line 186, in test_set self.assertEqual(self.root.globalgetvar("name"), true) AssertionError: 42 != 1 ---------------------------------------------------------------------- Ran 660 tests in 3.901s FAILED (failures=3) 1 test failed: test_tk From sohcahtoa82 at gmail.com Fri Aug 7 13:16:14 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Fri, 7 Aug 2015 10:16:14 -0700 (PDT) Subject: except block isn't catching exception In-Reply-To: References: <48587161-1bd6-47e4-b2c9-7a37c60a59e5@googlegroups.com> Message-ID: On Thursday, August 6, 2015 at 5:46:19 PM UTC-7, Chris Angelico wrote: > On Fri, Aug 7, 2015 at 10:34 AM, wrote: > > Despite my "except KeyboardInterrupt", the KeyboardInterrupt forced by the thread.interrupt_main() in the worker thread isn't being caught. > > > > Other things worth noting is that the exception takes about 3 seconds after the call to thread.interrupt_main(). It appears to not actually happen until the sock.accept() times out. If the call to sock.settimeout(5) is removed, the KeyboardInterrupt never appears and flow is still blocked on the sock.accept(). > > > > My Python version is 2.7.3. I know its out of date, but I don't really have a choice. > > As far as I know, the only effect of thread.interrupt_main() is to set > a flag saying "Hey main thread, next time you go checking for these > things, there's a KeyboardInterrupt waiting for you". It doesn't > actually send an OS-level signal, which means it cannot interrupt a > blocking call. So you have a few choices: > > 1) Shorten the timeout on sock.accept() to an (if you'll excuse the > pun) acceptable delay, and then simply check a flag. Something like > this: > > interrupt = False > while not interrupt: > try: > connection, _ = sock.accept() > except socket.timeout: > # On timeout, check flag and keep sleeping > pass > > If you wish to also have an actual timeout, you could monitor that separately. > > 2) Instead of blocking on sock.accept directly, have another event > which the other thread can raise, which will wake the main thread. You > could use select.select() for this. > > 3) Bury the details of select.select() away behind a nice framework > like asyncio, merge your two threads, and run everything through a > back-end event loop. > > 4) Use separate processes, and signal the interrupt using an OS-level > notification (on Unix systems, SIGINT; on Windows, there's an > equivalent called BreakSignal or something). This will break out of > the underlying system call that handles accept(). > > thread.interrupt_main() is similar to just setting a global that you > periodically check, except that the periodic check is handled for you > by the system. That's really all. > > ChrisA I'll probably go for the first solution. It's the simplest, and simple is usually good. In my application, there aren't going to be any consequences for the main thread not unblocking *immediately* when a worker thread requests it. Though I still doesn't understand why the exception isn't caught when I'm explicitly trying to catch it. I even tried changing the try/except block to this: try: connection, _ = sock.accept() except KeyboardInterrupt: print 'KeyboardInterrupt caught!' except socket.timeout: print 'Socket timeout caught!' except: print 'other exception caught!' finally: print 'finally!' The result prints: Interrupting main main interrupted! finally! Traceback (most recent call last): File "exception_test.py", line 23, in connection, _ = sock.accept() KeyboardInterrupt From lac at openend.se Fri Aug 7 13:17:37 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 07 Aug 2015 19:17:37 +0200 Subject: Python speed In-Reply-To: Message from beliavsky--- via Python-list of "Fri, 07 Aug 2015 09:57:26 -0700." <04b7cdd0-1eb0-4378-9d14-38e97b4456a7@googlegroups.com> References: <2261c8c6-77ba-453d-9205-0a922fa67c81@googlegroups.com><04b7cdd0-1eb0-4378-9d14-38e97b4456a7@googlegroups.com> Message-ID: <201508071717.t77HHb65007813@fido.openend.se> In a message of Fri, 07 Aug 2015 09:57:26 -0700, beliavsky--- via Python-list w rites: >On Friday, August 7, 2015 at 10:08:37 AM UTC-4, roge... at gmail.com wrote: >> Can anyone compare PyNum calculation speed to Fortran? >> >> This is for a number crunching program working with large files. >> >> Roger And for speed you may be better off with PyPy than with NumPy http://speed.pypy.org/timeline/ but, as is always the case when measuring the speed of things, 'it all depends on what you are doing'. Do you need to link to existing Fortran or C libraries? If the answer is no, and you really only are doing crunching, and your crunching is done in loops which run for a significant amount of time -- then PyPy is generally faster than Fortran. If you are spending most of your time in matplotlib graphing your results, you will be unhappy with PyPy performance. pypy-dev at python.org is a better place to discuss performance of PyPy, though while http://mail.scipy.org/mailman/listinfo/numpy-discussion is a better place to discuss numpy. scipy.org has been down all day, alas. But the Americans should be awake now and dealing with it. Laura From steve at pearwood.info Fri Aug 7 13:27:04 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 08 Aug 2015 03:27:04 +1000 Subject: Which Python implementation am I using? Message-ID: <55c4ea68$0$1667$c3e8da3$5496439d@news.astraweb.com> I have a need to determine which Python implementation is running. Starting from Python 2.6, we have platform.python_implemention() which (at least in principle) will do the right thing. However, for my sins, I also need to support 2.4 and 2.5. I have come up with this function to determine the Python implementation, using platform.python_implementation when available, and if not, by trying to detect the implementation indirectly. import sys, platform def implementation(): """Return the Python implementation.""" def jython(): t = platform.java_ver() return (t and t[0]) or ('java' in sys.platform.lower()) def ironpython(): if sys.platform == 'cli': # Common Language Infrastructure == .Net or Mono. return True return 'ironpython' in sys.version.lower() try: return platform.python_implementation() except ValueError: # Work around a bug in some versions of IronPython. if ironpython(): return 'ironpython' raise except AttributeError: # Python is too old! Probably 2.4 or 2.5. for func in (jython, ironpython): if func(): return func.__name__ # Otherwise, it's too hard to tell. Return a default. return 'python' Is this the best way to detect Jython and IronPython when python_implementation isn't available? How about PyPy, Stackless, or others? Is there a definitive test (other than python_implementation) for CPython itself? I'd like to detect that specifically, and leave the default python-with-no-c for those cases where I really am running some unknown Python implementation. Tests should be relatively lightweight, if possible. Thanks in advance, -- Steven From ned at nedbatchelder.com Fri Aug 7 14:16:12 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 7 Aug 2015 11:16:12 -0700 (PDT) Subject: Which Python implementation am I using? In-Reply-To: <55c4ea68$0$1667$c3e8da3$5496439d@news.astraweb.com> References: <55c4ea68$0$1667$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, August 7, 2015 at 1:27:17 PM UTC-4, Steven D'Aprano wrote: > Is this the best way to detect Jython and IronPython when > python_implementation isn't available? > > How about PyPy, Stackless, or others? > I've been told that the canonical test for PyPy is: '__pypy__' in sys.builtin_module_names This is the test that coverage.py uses. --Ned. From appthought1 at gmail.com Fri Aug 7 15:09:03 2015 From: appthought1 at gmail.com (appthought1 at gmail.com) Date: Fri, 7 Aug 2015 12:09:03 -0700 (PDT) Subject: Urgent requirement for Python Developer Message-ID: <369c597d-b2c4-4169-825a-1b5fd941b46c@googlegroups.com> Hi, Hope you are doing well !!! My name is Siva and I'm a recruiter at TheAppliedthought , a global staffing and IT consulting company. Please find the below job description which may suits any of your consultants who are available in market or who are looking for change, please send me latest updated resume along with contact details and expected hourly rate to my email id siva at theappliedthought.com or you can reach me on 407-574-7610. Position: Python Developer Location: Houston, TX Duration: Long Term Job Description * 6+ years of experience with Linux/UNIX Systems Administration * 2+ years of Openstack Experience * Hypervisor KVM, BIOS, Firmware update * Storage Technologies (NAS, SAN & Cloud Storage) * Experience with configuration management tools (Chef expert!!) * Analytical problem-solving and conceptual skills * Strong scripting and/or development chops (Ruby, Python, Bash, Perl) * Experience with database technologies (MySQL, Percona, MongoDB) * Experience with automation (Chef etc.) and monitoring (Nagios, etc.) technologies in production setting * Experience with networking technologies including TCP/IP VPN DNS routing firewalls VLAN. * Excellent communication skills * Excellent team player Thanks & Regards Siva Executive-Talent Acquisition & Bench Sales Email: siva at theappliedthought.com IM: malladi sivaramakrishna88 Phone: 407-574-7610 Fax: 407-641-8184 From __peter__ at web.de Fri Aug 7 15:13:02 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 07 Aug 2015 21:13:02 +0200 Subject: Linux users: please run gui tests References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> <201508071346.t77DkL2t031696@fido.openend.se> <201508071701.t77H1Csn004579@fido.openend.se> Message-ID: Laura Creighton wrote: > In a message of Fri, 07 Aug 2015 17:34:54 +0200, Peter Otten writes: >>Run >> >>$ python3 -m test -ugui -v test_tk >> >>(That way the unittest framework will see the -v option) > > Aha, I didn't understand that. Thank you. > >>Note that there are lines like >> >># possible namespace for /home/lac/src/accounting/test >> >>in your python3 -v output that indicate that there may still be too much >>in your PYTHONPATH. > > It's now "" for this test. > > I get 3 failures, as follows (I trimmed the rest of the ok ones). > > = CPython 3.4.3+ (default, Jul 28 2015, 13:17:50) [GCC 4.9.3] > == Linux-3.16.0-4-amd64-x86_64-with-debian-stretch-sid little-endian > == hash algorithm: siphash24 64bit > == /tmp/test_python_7974 > Testing with flags: sys.flags(debug=0, inspect=0, interactive=0, > optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, > ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, > hash_randomization=1, isolated=0) > > test_default (tkinter.test.test_tkinter.test_variables.TestBooleanVar) ... > FAIL test_get (tkinter.test.test_tkinter.test_variables.TestBooleanVar) > ... FAIL test_set > (tkinter.test.test_tkinter.test_variables.TestBooleanVar) ... FAIL > > ====================================================================== > FAIL: test_default > (tkinter.test.test_tkinter.test_variables.TestBooleanVar) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/usr/lib/python3.4/tkinter/test/test_tkinter/test_variables.py", > line 163, in test_default > self.assertIs(v.get(), False) > AssertionError: 0 is not False > > ====================================================================== > FAIL: test_get (tkinter.test.test_tkinter.test_variables.TestBooleanVar) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/usr/lib/python3.4/tkinter/test/test_tkinter/test_variables.py", > line 167, in test_get > self.assertIs(v.get(), True) > AssertionError: 1 is not True > > ====================================================================== > FAIL: test_set (tkinter.test.test_tkinter.test_variables.TestBooleanVar) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/usr/lib/python3.4/tkinter/test/test_tkinter/test_variables.py", > line 186, in test_set > self.assertEqual(self.root.globalgetvar("name"), true) > AssertionError: 42 != 1 > > ---------------------------------------------------------------------- > Ran 660 tests in 3.901s > > FAILED (failures=3) > 1 test failed: > test_tk test_set() was introduced in a bugfix http://bugs.python.org/issue15133 https://hg.python.org/cpython/rev/117f45749359/ that I don't have on my machine (up-to-date Linux Mint 17). When I download https://hg.python.org/cpython/file/117f45749359/Lib/tkinter/test/test_tkinter/test_variables.py and manually run that file I get errors similar to those you are reporting: $ python3 test_variables.py | grep -v ok$ test_default (__main__.TestBooleanVar) ... FAIL test_get (__main__.TestBooleanVar) ... FAIL test_invalid_value_domain (__main__.TestBooleanVar) ... FAIL test_set (__main__.TestBooleanVar) ... FAIL ====================================================================== FAIL: test_default (__main__.TestBooleanVar) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_variables.py", line 163, in test_default self.assertIs(v.get(), False) AssertionError: 0 is not False ====================================================================== FAIL: test_get (__main__.TestBooleanVar) Traceback (most recent call last): ---------------------------------------------------------------------- Traceback (most recent call last): File "test_variables.py", line 167, in test_get self.assertIs(v.get(), True) AssertionError: 1 is not True ====================================================================== File "test_variables.py", line 212, in FAIL: test_invalid_value_domain (__main__.TestBooleanVar) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_variables.py", line 196, in test_invalid_value_domain v.set("value") AssertionError: TclError not raised ====================================================================== FAIL: test_set (__main__.TestBooleanVar) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_variables.py", line 184, in test_set self.assertEqual(self.root.globalgetvar("name"), false) AssertionError: '0' != 0 ---------------------------------------------------------------------- Ran 22 tests in 0.098s FAILED (failures=4) run_unittest(*tests_gui) File "/usr/lib/python3.4/test/support/__init__.py", line 1719, in run_unittest _run_suite(suite) File "/usr/lib/python3.4/test/support/__init__.py", line 1694, in _run_suite raise TestFailed(err) test.support.TestFailed: multiple errors occurred $ This leads me to believe that your tests and the tkinter shared library may not match. Does $ python3 -c 'import _tkinter; print(_tkinter)' show something suspicious? From rogerh906 at gmail.com Fri Aug 7 15:30:16 2015 From: rogerh906 at gmail.com (rogerh906 at gmail.com) Date: Fri, 7 Aug 2015 12:30:16 -0700 (PDT) Subject: Python speed In-Reply-To: <2261c8c6-77ba-453d-9205-0a922fa67c81@googlegroups.com> References: <2261c8c6-77ba-453d-9205-0a922fa67c81@googlegroups.com> Message-ID: <051b46fe-83a7-4607-8f68-ff94df9c1ff5@googlegroups.com> On Friday, August 7, 2015 at 8:08:37 AM UTC-6, roge... at gmail.com wrote: > Can anyone compare PyNum calculation speed to Fortran? > > This is for a number crunching program working with large files. > > Roger Thanks for answering. This will help a lot. Roger From lac at openend.se Fri Aug 7 16:35:54 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 07 Aug 2015 22:35:54 +0200 Subject: Linux users: please run gui tests In-Reply-To: Message from Peter Otten <__peter__@web.de> of "Fri, 07 Aug 2015 21:13:02 +0200." References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> <201508071346.t77DkL2t031696@fido.openend.se> <201508071701.t77H1Csn004579@fido.openend.se> Message-ID: <201508072035.t77KZscG013517@fido.openend.se> In a message of Fri, 07 Aug 2015 21:13:02 +0200, Peter Otten writes: >test_set() was introduced in a bugfix > >http://bugs.python.org/issue15133 >https://hg.python.org/cpython/rev/117f45749359/ > >that I don't have on my machine (up-to-date Linux Mint 17). When I download > >https://hg.python.org/cpython/file/117f45749359/Lib/tkinter/test/test_tkinter/test_variables.py > >and manually run that file I get errors similar to those you are reporting: > >$ python3 test_variables.py | grep -v ok$ >test_default (__main__.TestBooleanVar) ... FAIL >test_get (__main__.TestBooleanVar) ... FAIL >test_invalid_value_domain (__main__.TestBooleanVar) ... FAIL >test_set (__main__.TestBooleanVar) ... FAIL >This leads me to believe that your tests and the tkinter shared library may >not match. Does > >$ python3 -c 'import _tkinter; print(_tkinter)' >dynload/_tkinter.cpython-34m-x86_64-linux-gnu.so'> > >show something suspicious? lac at smartwheels:~$ python3 -c 'import _tkinter; print(_tkinter)' Laura From db3l.net at gmail.com Fri Aug 7 16:53:02 2015 From: db3l.net at gmail.com (David Bolen) Date: Fri, 07 Aug 2015 16:53:02 -0400 Subject: Linux users: please run gui tests References: Message-ID: Terry Reedy writes: > and report here python version, linux system, and result. > Alteration of environment and locale is a known issue, skip that. Using source builds on my slave (bolen-ubuntu): Linux buildbot-ubuntu 4.1.0-x86_64-linode59 #1 SMP Mon Jun 22 10:39:23 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux NOTE: This is a 32-bit userspace system, just with a 64-bit kernel Python 3.6.0a0 (default:e56893df8e76, Aug 7 2015, 16:36:30) [GCC 4.8.4] on linux [1/3] test_tk [2/3] test_ttk_guionly [3/3] test_idle All 3 tests OK. Python 3.5.0b4+ (3.5:b9a0165a3de8, Aug 7 2015, 16:21:51) [GCC 4.8.4] on linux [1/3] test_tk [2/3] test_ttk_guionly [3/3] test_idle All 3 tests OK. Python 3.4.3+ (3.4:f5069e6e4229, Aug 7 2015, 16:38:53) [GCC 4.8.4] on linux [1/3] test_tk [2/3] test_ttk_guionly [3/3] test_idle All 3 tests OK. I have also adjusted the slave to run under Xvfb so the tests should be included going forward. -- David From auriocus at gmx.de Fri Aug 7 17:26:46 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 07 Aug 2015 23:26:46 +0200 Subject: Python speed In-Reply-To: References: <2261c8c6-77ba-453d-9205-0a922fa67c81@googlegroups.com><04b7cdd0-1eb0-4378-9d14-38e97b4456a7@googlegroups.com> Message-ID: Am 07.08.2015 um 19:17 schrieb Laura Creighton: > you > really only are doing crunching, and your crunching is done > in loops which run for a significant amount of time -- then PyPy > is generally faster than Fortran. PyPy faster than Fortran in a tight number-crunching loop? Sorry I find this very hard to believe. I could accept that PyPy can match the speed of Fortran in these cases, but exceeding seems highly unlikely. Was it a mistake, or do you have a reference that shows how PyPy can be faster than Fortran? I agree with the rest what you have said. Christian From lac at openend.se Fri Aug 7 18:01:53 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 08 Aug 2015 00:01:53 +0200 Subject: Python speed In-Reply-To: Message from Christian Gollwitzer of "Fri, 07 Aug 2015 23:26:46 +0200." References: <2261c8c6-77ba-453d-9205-0a922fa67c81@googlegroups.com><04b7cdd0-1eb0-4378-9d14-38e97b4456a7@googlegroups.com> Message-ID: <201508072201.t77M1r1H030241@fido.openend.se> In a message of Fri, 07 Aug 2015 23:26:46 +0200, Christian Gollwitzer writes: >Am 07.08.2015 um 19:17 schrieb Laura Creighton: >> you >> really only are doing crunching, and your crunching is done >> in loops which run for a significant amount of time -- then PyPy >> is generally faster than Fortran. > >PyPy faster than Fortran in a tight number-crunching loop? Sorry I find >this very hard to believe. I could accept that PyPy can match the speed >of Fortran in these cases, but exceeding seems highly unlikely. Was it a >mistake, or do you have a reference that shows how PyPy can be faster >than Fortran? > >I agree with the rest what you have said. > > Christian My apologies -- I went and looked it up, and it seems that the person who reported this got taught how to vectorise his Fortran code and some other tricks, and now his Fortran code runs between 2.5 and 3 times faster than PyPy for his numberical benchmarks. I seem to have got the initial news, and never heard about the correction .... Thank you for bringing this up. Laura From lac at openend.se Fri Aug 7 19:03:19 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 08 Aug 2015 01:03:19 +0200 Subject: Which Python implementation am I using? In-Reply-To: Message from "Steven D'Aprano" of "Sat, 08 Aug 2015 03:27:04 +1000." <55c4ea68$0$1667$c3e8da3$5496439d@news.astraweb.com> References: <55c4ea68$0$1667$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201508072303.t77N3JoG009766@fido.openend.se> In a message of Sat, 08 Aug 2015 03:27:04 +1000, "Steven D'Aprano" writes: > > def jython(): > t = platform.java_ver() > return (t and t[0]) or ('java' in sys.platform.lower()) Around here if we cannot find platform.python_implemention() we just look for sys.platform.startswith('java') Are there any cases where you need platform.java_ver() ? I don't know about IronPython >How about PyPy, Stackless, or others? PyPy has platform.python_implementation these days as well. If you cannot find it, look for '__pypy__' in sys.builtin_module_names For detecting Stackless my PYTHONSTARTUP just tries to import stackless. Detecting Cygwin may be important for you. It's a real mess. platform.system usually gives you stuff like: CYGWIN_NT-5.1 but, alas, sometimes it just gives you 'Windows'. os.name sometimes gives you 'nt' -- but sometimes it gives you 'posix'. I've played whack-a-mole with this one for a while, and still don't like any of our solutions. And the customer threw out his windows systems and replaced them with Macs, so the problem now is moot for me. Laura From invalid at invalid.invalid Fri Aug 7 19:57:54 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 7 Aug 2015 23:57:54 +0000 (UTC) Subject: Python speed References: <2261c8c6-77ba-453d-9205-0a922fa67c81@googlegroups.com> Message-ID: On 2015-08-07, rogerh906 at gmail.com wrote: > Can anyone compare PyNum calculation speed to Fortran? > > This is for a number crunching program working with large files. Well I can tell you how the numerical analysis and data visualization programs _I_ use to write would compare to Fortran: The Python programs were infinitely faster than Fortran because the probability I could have gotten equivelent Fortran programs to work before the data became moot was pretty much zero. On a more serious note, almost all of the heavy lifting in the programs I wrote (array operations, curve fitting, Delaunay triangulation, etc.) was all done by libraries written in Fortan and C. So I doubt the difference between Fortran and Python would have mattered (assuming I _could_ have written equivalent programs in Fortran). -- Grant From tjreedy at udel.edu Fri Aug 7 20:40:27 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 7 Aug 2015 20:40:27 -0400 Subject: Linux users: please run gui tests In-Reply-To: References: Message-ID: On 8/6/2015 11:46 PM, Grant Edwards wrote: > In both cases, some small, yellow windows flash briefly on the screen. I should have warned about this ;-). Gui tests mean 'actually flash stuff on screen', which is why they do not get run. -- Terry Jan Reedy From tjreedy at udel.edu Fri Aug 7 20:42:02 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 7 Aug 2015 20:42:02 -0400 Subject: Linux users: please run gui tests In-Reply-To: <85y4hnj0xg.fsf@benfinney.id.au> References: <85y4hnj0xg.fsf@benfinney.id.au> Message-ID: On 8/6/2015 10:18 PM, Ben Finney wrote: > Terry Reedy writes: > >> I would appreciate it if some people could run the linux version of >> py -3.4 -m test -ugui test_tk test_ttk_guionly test_idle >> (or 3.5). I guess this means 'python3 for the executable. > > Could you verify exactly what is the command to run? Sorry, py.exe is Windows (and Mac?) only. Replace 'py -3.4' with the linux equivalent 'python3'. -- Terry Jan Reedy From tjreedy at udel.edu Fri Aug 7 21:04:26 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 7 Aug 2015 21:04:26 -0400 Subject: Linux users: please run gui tests In-Reply-To: <201508071701.t77H1Csn004579@fido.openend.se> References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> <201508071346.t77DkL2t031696@fido.openend.se> <201508071701.t77H1Csn004579@fido.openend.se> Message-ID: On 8/7/2015 1:01 PM, Laura Creighton wrote: > In a message of Fri, 07 Aug 2015 17:34:54 +0200, Peter Otten writes: >> Run >> >> $ python3 -m test -ugui -v test_tk >> >> (That way the unittest framework will see the -v option) > > Aha, I didn't understand that. Thank you. > >> Note that there are lines like >> >> # possible namespace for /home/lac/src/accounting/test >> >> in your python3 -v output that indicate that there may still be too much in >> your PYTHONPATH. > > It's now "" for this test. > > I get 3 failures, as follows (I trimmed the rest of the ok ones). > > = CPython 3.4.3+ (default, Jul 28 2015, 13:17:50) [GCC 4.9.3] > == Linux-3.16.0-4-amd64-x86_64-with-debian-stretch-sid little-endian > == hash algorithm: siphash24 64bit > == /tmp/test_python_7974 > Testing with flags: sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1, isolated=0) > > test_default (tkinter.test.test_tkinter.test_variables.TestBooleanVar) ... FAIL > test_get (tkinter.test.test_tkinter.test_variables.TestBooleanVar) ... FAIL > test_set (tkinter.test.test_tkinter.test_variables.TestBooleanVar) ... FAIL > > ====================================================================== > FAIL: test_default (tkinter.test.test_tkinter.test_variables.TestBooleanVar) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/usr/lib/python3.4/tkinter/test/test_tkinter/test_variables.py", line 163, in test_default > self.assertIs(v.get(), False) > AssertionError: 0 is not False > > ====================================================================== > FAIL: test_get (tkinter.test.test_tkinter.test_variables.TestBooleanVar) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/usr/lib/python3.4/tkinter/test/test_tkinter/test_variables.py", line 167, in test_get > self.assertIs(v.get(), True) > AssertionError: 1 is not True > > ====================================================================== > FAIL: test_set (tkinter.test.test_tkinter.test_variables.TestBooleanVar) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/usr/lib/python3.4/tkinter/test/test_tkinter/test_variables.py", line 186, in test_set > self.assertEqual(self.root.globalgetvar("name"), true) > AssertionError: 42 != 1 > > ---------------------------------------------------------------------- > Ran 660 tests in 3.901s > > FAILED (failures=3) > 1 test failed: > test_tk The only thing I found on the tracker is https://bugs.python.org/issue20067 I suspect that this is more an issue with the tests, which are somewhat new, than tkinter itself. In any case, my personal concern is whether adding ttk to Idle creates a problem, and those two tests passes. Thank you for trying. -- Terry Jan Reedy From tjreedy at udel.edu Fri Aug 7 21:10:03 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 7 Aug 2015 21:10:03 -0400 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: <55C4969D.2010005@outlook.com> References: <55C37EBC.3020604@outlook.com> <55C4969D.2010005@outlook.com> Message-ID: On 8/7/2015 7:29 AM, tjohnson wrote: > On 8/6/2015 7:31 PM, Terry Reedy wrote: >> On 8/6/2015 11:35 AM, Timothy Johnson wrote: >> >>> problems because it works well for that. Most of the time I use PyDev >>> and Notepad++ to edit Python code, but if more features were added to >>> Idle I would consider using it more. >> >> What 1 or 2 features would you most like to see? >> > Practically, I'd say a line number margin Patch is mostly done but I need to review (sooner than later). > and right edge indicator. Do you mean at column 80 or something? > Theoretically, a tabbed editor *Many* people want this. I think this should be the highest priority new big feature. > and dockable interpreter pane. Please explain. -- Terry Jan Reedy From tjreedy at udel.edu Fri Aug 7 21:16:41 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 7 Aug 2015 21:16:41 -0400 Subject: Linux users: please run gui tests In-Reply-To: References: Message-ID: On 8/6/2015 10:07 PM, Terry Reedy wrote: > Python has an extensive test suite run after each 'batch' of commits on > a variety of buildbots. However, the Linux buildbots all (AFAIK) run > 'headless', with gui's disabled. Hence the following > test_tk test_ttk_guionly test_idle > (and on 3.5, test_tix, but not important) > are skipped either in whole or in part. > > We are planning on adding the use of tkinter.ttk to Idle after the 3.5.0 > release, but a couple of other core developers have expressed concern > about the reliability of tkinter.ttk on Linux. > > There is also an unresolved issue where test_ttk hung on Ubuntu Unity 3 > years ago. https://bugs.python.org/issue14799 > > I would appreciate it if some people could run the linux version of > py -3.4 -m test -ugui test_tk test_ttk_guionly test_idle > (or 3.5). I guess this means 'python3 for the executable. > > and report here python version, linux system, and result. > Alteration of environment and locale is a known issue, skip that. I should have mentioned the flashing boxes... Anyway, 6 people have run these so far on a variety of common systems: Debian Wheezy, Debian Jessie, Mint, Gentoo, openSUSE, and Ubuntu. One ttk test failed once but passed on retry. Three obscure tk tests failed on another system. On the same system, though, the ttk and (incomplete) idle tests passed. Conclusion: I should not worry about ttk on Linux. Thank you all for helping. -- Terry Jan Reedy From tjreedy at udel.edu Fri Aug 7 21:25:21 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 7 Aug 2015 21:25:21 -0400 Subject: Linux users: please run gui tests In-Reply-To: <201508071701.t77H1Csn004579@fido.openend.se> References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> <201508071346.t77DkL2t031696@fido.openend.se> <201508071701.t77H1Csn004579@fido.openend.se> Message-ID: On 8/7/2015 1:01 PM, Laura Creighton wrote: > ====================================================================== > FAIL: test_get (tkinter.test.test_tkinter.test_variables.TestBooleanVar) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/usr/lib/python3.4/tkinter/test/test_tkinter/test_variables.py", line 167, in test_get > self.assertIs(v.get(), True) > AssertionError: 1 is not True https://bugs.python.org/issue15601 was about this very test failure. The failure only occurred with tk 8.4. What tk version do you have? (Easily found, for instance, in Idle -> Help -> About Idle. (python3 -m idlelib should start idle). -- Terry Jan Reedy From tjreedy at udel.edu Fri Aug 7 21:38:37 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 7 Aug 2015 21:38:37 -0400 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: Message-ID: On 8/6/2015 9:14 PM, Dennis Lee Bieber wrote: > On Wed, 5 Aug 2015 21:06:31 -0400, Terry Reedy declaimed > the following: > >> There have been discussions, such as today on Idle-sig , about who uses >> Idle and who we should design it for. If you use Idle in any way, or >> know of or teach classes using Idle, please answer as many of the >> questions below as you are willing, and as are appropriate >> > If you only take responses from people who already use Idle, you may be > selecting against some of the more critical responses. The main issue is who, other than highschool or college students, use it. With 35 years of experience, you are not the target audience. I am unusual in not having switched. In you situation, I well might have. "What's wrong with Idle' or 'Why don't you use Idle' or 'How can Idle be improved' would be another survey. I am not asking that too much because there are already over a 120 issues to work on. (But note, Idle is 60 xyz.py modules, which is 2 issues per module, whereas there are more than that for the stdlib as a whole. I am aware that issues per 1000 lines would be a better comparison.) > I find Idle somewhat clunky looking, We are going to add the better looking ttk widgets as an option, but that will have least effect on Windows. > with some GUI behaviors that just don't feel natural to me. We are reviewing these within the confines of what tk can do on each platform. Thank you for your response. -- Terry Jan Reedy From tandrewjohnson at outlook.com Fri Aug 7 21:41:10 2015 From: tandrewjohnson at outlook.com (tjohnson) Date: Fri, 7 Aug 2015 21:41:10 -0400 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: <55C37EBC.3020604@outlook.com> <55C4969D.2010005@outlook.com> Message-ID: <55C55E36.2020501@outlook.com> On 8/7/2015 9:10 PM, Terry Reedy wrote: > On 8/7/2015 7:29 AM, tjohnson wrote: >> On 8/6/2015 7:31 PM, Terry Reedy wrote: >>> On 8/6/2015 11:35 AM, Timothy Johnson wrote: >>> >>>> problems because it works well for that. Most of the time I use PyDev >>>> and Notepad++ to edit Python code, but if more features were added to >>>> Idle I would consider using it more. >>> >>> What 1 or 2 features would you most like to see? >>> >> Practically, I'd say a line number margin > > Patch is mostly done but I need to review (sooner than later). > Great. >> and right edge indicator. > > Do you mean at column 80 or something? > Yes, exactly. >> Theoretically, a tabbed editor > > *Many* people want this. I think this should be the highest priority > new big feature. > I agree. > > and dockable interpreter pane. > > Please explain. > Currently the interpreter is shown in a separate floating window. If it was dockable, it could also be placed in the same window as the text editor but separated by a splitter. Examples: wxPython AUI panes, Firefox bookmarks pane > From tandrewjohnson at outlook.com Fri Aug 7 21:41:10 2015 From: tandrewjohnson at outlook.com (tjohnson) Date: Fri, 7 Aug 2015 21:41:10 -0400 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: <55C37EBC.3020604@outlook.com> <55C4969D.2010005@outlook.com> Message-ID: On 8/7/2015 9:10 PM, Terry Reedy wrote: > On 8/7/2015 7:29 AM, tjohnson wrote: >> On 8/6/2015 7:31 PM, Terry Reedy wrote: >>> On 8/6/2015 11:35 AM, Timothy Johnson wrote: >>> >>>> problems because it works well for that. Most of the time I use PyDev >>>> and Notepad++ to edit Python code, but if more features were added to >>>> Idle I would consider using it more. >>> >>> What 1 or 2 features would you most like to see? >>> >> Practically, I'd say a line number margin > > Patch is mostly done but I need to review (sooner than later). > Great. >> and right edge indicator. > > Do you mean at column 80 or something? > Yes, exactly. >> Theoretically, a tabbed editor > > *Many* people want this. I think this should be the highest priority > new big feature. > I agree. > > and dockable interpreter pane. > > Please explain. > Currently the interpreter is shown in a separate floating window. If it was dockable, it could also be placed in the same window as the text editor but separated by a splitter. Examples: wxPython AUI panes, Firefox bookmarks pane > From rosuav at gmail.com Fri Aug 7 22:44:31 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 8 Aug 2015 12:44:31 +1000 Subject: except block isn't catching exception In-Reply-To: References: <48587161-1bd6-47e4-b2c9-7a37c60a59e5@googlegroups.com> Message-ID: On Sat, Aug 8, 2015 at 3:16 AM, wrote: > > Though I still doesn't understand why the exception isn't caught when I'm explicitly trying to catch it. I even tried changing the try/except block to this: > > try: > connection, _ = sock.accept() > except KeyboardInterrupt: > print 'KeyboardInterrupt caught!' > except socket.timeout: > print 'Socket timeout caught!' > except: > print 'other exception caught!' > finally: > print 'finally!' > > The result prints: > > Interrupting main > main interrupted! > finally! The exception isn't happening inside sock.accept(), as I explained. So you can't catch it there. ChrisA From no.email at nospam.invalid Fri Aug 7 23:20:33 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 07 Aug 2015 20:20:33 -0700 Subject: Who uses IDLE -- please answer if you ever do, know, or teach References: <55C37EBC.3020604@outlook.com> <55C4969D.2010005@outlook.com> Message-ID: <87fv3uihz2.fsf@jester.gateway.sonic.net> tjohnson writes: > Currently the interpreter is shown in a separate floating window. If > it was dockable, it could also be placed in the same window as the > text editor but separated by a splitter. Dockable would be nice but the split window is ok with me. What I wish is that Control-N in the interpreter window (or maybe some newly assigned hotkey) would launch a Python editing window instead of a text window. Better still, have it already editing a temp file so that I can immediately type code and hit F5 and run it, without the "Save as" dance. Also the "save on close" dialog buttons should say "save" and "don't save" instead of "yes" and "no". Lots of programs have dialogs like that and the senses keep differing so it's easy to misread the prompt. From 4kir4.1i at gmail.com Fri Aug 7 23:45:16 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Sat, 08 Aug 2015 06:45:16 +0300 Subject: Who uses IDLE -- please answer if you ever do, know, or teach References: Message-ID: <87egjezbn7.fsf@gmail.com> Terry Reedy writes: > There have been discussions, such as today on Idle-sig , about who > uses Idle and who we should design it for. If you use Idle in any > way, or know of or teach classes using Idle, please answer as many of > the questions below as you are willing, and as are appropriate > Running Python scripts in Windows console that may produce Unicode output is a worth-mentioning use-case [1] (as you might know) i.e., if you run: T:\> py print_unicode.py and get the error: UnicodeEncodeError: 'charmap' codec can't encode character '...' then a workaround that works out of the box is to run: T:\> py -m idlelib -r print_unicode.py that can display Unicode (BMP) output in IDLE. [1] http://stackoverflow.com/questions/28521944/python3-print-unicode-to-windows-xp-console-encode-cp437 From orgnut at yahoo.com Fri Aug 7 23:58:02 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Fri, 07 Aug 2015 20:58:02 -0700 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: References: Message-ID: On 08/05/2015 06:06 PM, Terry Reedy wrote: [snip] > 0. Classes where Idle is used: > Where? > Level? > None > Idle users: > > 1. Are you > grade school (1=12)? > undergraduate (Freshman-Senior)? > post-graduate (from whatever)? > Some college, but didn't complete. Never had any CS or programming courses. > 2. Are you > beginner (1st class, maybe 2nd depending on intensity of first)? > post-beginner? > post-beginner (and self-taught) > 3. With respect to programming, are you > amateur (unpaid) > professional (paid for programming) > amateur My situation: Amateur/hobbyist programmer. (Retired from electronics industries.) My programming needs are very modest -- mostly simple utilities for my own use. In the past used C extensively, C++ some. But after I found Python I haven't looked back. Programming environment: Linux Mint (hate Windows!). Using simple editor (usually gedit) and a terminal window, but I usually have Idle running (minimized) to be able to quickly check syntax, run help(...), etc. I rarely use it for actual programming. One minor complaint about Idle: In the interactive mode the auto-indent uses a tab character which the display expands to 8-character columns. This large indent is annoying. The editor mode can be set for smaller indents but the interactive mode can't -- at least I haven't found how if it is possible. -=- Larry -=- From piseema at gmail.com Fri Aug 7 23:58:05 2015 From: piseema at gmail.com (PK Khatri) Date: Fri, 7 Aug 2015 20:58:05 -0700 (PDT) Subject: How to use regex (re) In-Reply-To: References: <306503ec-4052-4438-b778-781797f9941a@googlegroups.com> Message-ID: <3b01d487-2f06-4af7-b6f2-3405f8dcd460@googlegroups.com> On Friday, August 7, 2015 at 9:48:35 AM UTC-7, Peter Pearson wrote: > On Thu, 6 Aug 2015 13:06:36 -0700 (PDT), PK Khatri wrote: > > I have a following script which extracts xyz.tgz and outputs to a > > folder which contains several sub-folders and files. > > > > source_dir = "c:\\TEST" > > dest_dir = "c:\\TEST" > > for src_name in glob.glob(os.path.join(source_dir, '*.tgz')): > > base = os.path.basename(src_name) > > dest_name = os.path.join(dest_dir, base[:-4]) > > with tarfile.open(src_name, 'r') as infile: > > infile.extractall(dest_dir) > > > > When above script is ran, the output is a single directory within that > > directory the structure looks like this: > > > > folder_1 > > folder_2 > > folder_n > > file_1 > > file_2 > > file_n > > > > In these folder, there are sub-folders and files. Among those file > > there are some data i am interested in to search and output to a file. > > > > For eg. Among the folders there is a file called > > **'localcli_network-ip-neighbor-list.txt**' which contains IP > > address(s) which I would like to output to a file. > > Are you asking how to determine whether the string > "localcli_network-ip-neighbor-list.txt" appears in a filename? > If so, the logical expression > > "localcli_network-ip-neighbor-list.txt" in filename > > will do the job. > > -- > To email me, substitute nowhere->runbox, invalid->com. Thanks Peter. From rosuav at gmail.com Sat Aug 8 00:11:36 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 8 Aug 2015 14:11:36 +1000 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: <87egjezbn7.fsf@gmail.com> References: <87egjezbn7.fsf@gmail.com> Message-ID: On Sat, Aug 8, 2015 at 1:45 PM, Akira Li <4kir4.1i at gmail.com> wrote: > then a workaround that works out of the box is to run: > > T:\> py -m idlelib -r print_unicode.py > > that can display Unicode (BMP) output in IDLE. But sadly, *only* the BMP. That's enough for most modern languages, but it's by no means all of Unicode. I'm told there are plans in the works for improving Tcl and Tk, which tkinter and thus Idle could then take advantage of, but for the time being, we're stuck on sixteen bit characters in Idle. :( ChrisA From lac at openend.se Sat Aug 8 02:35:59 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 08 Aug 2015 08:35:59 +0200 Subject: Linux users: please run gui tests In-Reply-To: Message from Terry Reedy of "Fri, 07 Aug 2015 21:04:26 -0400." References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> <201508071346.t77DkL2t031696@fido.openend.se> <201508071701.t77H1Csn004579@fido.openend.se> Message-ID: <201508080635.t786ZxnD032016@fido.openend.se> I forgot to mention that I am running OpenBox as a window manager, so if this is a problem with ubuntu Unity, then so far we don't seem to have any Unity users running these tests. Laura From lac at openend.se Sat Aug 8 02:40:04 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 08 Aug 2015 08:40:04 +0200 Subject: Linux users: please run gui tests In-Reply-To: Message from Terry Reedy of "Fri, 07 Aug 2015 21:25:21 -0400." References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> <201508071346.t77DkL2t031696@fido.openend.se> <201508071701.t77H1Csn004579@fido.openend.se> Message-ID: <201508080640.t786e4QU000440@fido.openend.se> In a message of Fri, 07 Aug 2015 21:25:21 -0400, Terry Reedy writes: >was about this very test failure. The failure only occurred with tk >8.4. What tk version do you have? (Easily found, for instance, in Idle >-> Help -> About Idle. (python3 -m idlelib should start idle). > >-- >Terry Jan Reedy Tk version 8.6.4 Laura From ian.g.kelly at gmail.com Sat Aug 8 02:56:43 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 8 Aug 2015 00:56:43 -0600 Subject: except block isn't catching exception In-Reply-To: References: <48587161-1bd6-47e4-b2c9-7a37c60a59e5@googlegroups.com> Message-ID: On Fri, Aug 7, 2015 at 8:44 PM, Chris Angelico wrote: > The exception isn't happening inside sock.accept(), as I explained. So > you can't catch it there. Where does the exception happen then? Your explanation only covered why the blocking call cannot be interrupted by it, not why the exception isn't simply raised when the blocking call finishes. I played around with this and found that if the try...except chain is wrapped in another outer try statement, then the KeyboardInterrupt exception does get caught by the outer exception handler as one might expect. For the inner try statement though, neither any except block nor the else block is executed, just the finally block. I didn't know until now that was even possible. The language reference mentions this in regard to the try statement: """ If the evaluation of an expression in the header of an except clause raises an exception, the original search for a handler is canceled and a search starts for the new exception in the surrounding code and on the call stack (it is treated as if the entire try statement raised the exception). """ So my theory as to what's going on here is that sock.accept raises a socket.timeout exception, but then the KeyboardInterrupt is raised before the first except block even begins to check the exception type, and so it's treated as if the "entire try statement" raised KeyboardInterrupt. Hence it can't be caught there, but only in an outer try statement. Whatever the reason, it definitely seems to be an interesting corner case. From rosuav at gmail.com Sat Aug 8 03:08:25 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 8 Aug 2015 17:08:25 +1000 Subject: except block isn't catching exception In-Reply-To: References: <48587161-1bd6-47e4-b2c9-7a37c60a59e5@googlegroups.com> Message-ID: On Sat, Aug 8, 2015 at 4:56 PM, Ian Kelly wrote: > On Fri, Aug 7, 2015 at 8:44 PM, Chris Angelico wrote: >> The exception isn't happening inside sock.accept(), as I explained. So >> you can't catch it there. > > Where does the exception happen then? Your explanation only covered > why the blocking call cannot be interrupted by it, not why the > exception isn't simply raised when the blocking call finishes. > I'm not sure there's anything in the language spec about it; at least, I can't find it. But the last time I was digging in the Python/C API, there was a caveat that KeyboardInterrupt was raised *at some point after* Ctrl-C was hit - a flag gets set, and after every N bytecode instructions, the flag is checked, and then the signal gets raised. It might happen on only some platforms, and I can't even find back the page I was looking at when I read that. Maybe someone else knows? ChrisA From __peter__ at web.de Sat Aug 8 03:53:45 2015 From: __peter__ at web.de (Peter Otten) Date: Sat, 08 Aug 2015 09:53:45 +0200 Subject: Linux users: please run gui tests References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> <201508071346.t77DkL2t031696@fido.openend.se> <201508071701.t77H1Csn004579@fido.openend.se> <201508072035.t77KZscG013517@fido.openend.se> Message-ID: Laura Creighton wrote: >>This leads me to believe that your tests and the tkinter shared library >>may not match. Does >> >>$ python3 -c 'import _tkinter; print(_tkinter)' >>>dynload/_tkinter.cpython-34m-x86_64-linux-gnu.so'> >> >>show something suspicious? > > lac at smartwheels:~$ python3 -c 'import _tkinter; print(_tkinter)' > '/usr/lib/python3.4/lib-dynload/_tkinter.cpython-34m-x86_64-linux-gnu.so'> I hate to say it, but at the moment I'm out of ideas on what to investigate. From cs at zip.com.au Sat Aug 8 04:11:48 2015 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 8 Aug 2015 18:11:48 +1000 Subject: except block isn't catching exception In-Reply-To: References: Message-ID: <20150808081148.GA82462@cskk.homeip.net> On 08Aug2015 17:08, Chris Angelico wrote: >On Sat, Aug 8, 2015 at 4:56 PM, Ian Kelly wrote: >> On Fri, Aug 7, 2015 at 8:44 PM, Chris Angelico wrote: >>> The exception isn't happening inside sock.accept(), as I explained. So >>> you can't catch it there. >> >> Where does the exception happen then? Your explanation only covered >> why the blocking call cannot be interrupted by it, not why the >> exception isn't simply raised when the blocking call finishes. > >I'm not sure there's anything in the language spec about it; at least, >I can't find it. But the last time I was digging in the Python/C API, >there was a caveat that KeyboardInterrupt was raised *at some point >after* Ctrl-C was hit - a flag gets set, and after every N bytecode >instructions, the flag is checked, and then the signal gets raised. It >might happen on only some platforms, and I can't even find back the >page I was looking at when I read that. Maybe someone else knows? From: https://docs.python.org/3/library/signal.html#execution-of-python-signal-handlers we have: A Python signal handler does not get executed inside the low-level (C) signal handler. Instead, the low-level signal handler sets a flag which tells the virtual machine to execute the corresponding Python signal handler at a later point(for example at the next bytecode instruction). and in the next section "Signals and threads" it says: Python signal handlers are always executed in the main Python thread, even if the signal was received in another thread. Cheers, Cameron Simpson Meddle not in the affairs of dragons, for you are crunchy and good with ketchup. From rosuav at gmail.com Sat Aug 8 04:17:13 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 8 Aug 2015 18:17:13 +1000 Subject: except block isn't catching exception In-Reply-To: <20150808081148.GA82462@cskk.homeip.net> References: <20150808081148.GA82462@cskk.homeip.net> Message-ID: On Sat, Aug 8, 2015 at 6:11 PM, Cameron Simpson wrote: > From: > > > https://docs.python.org/3/library/signal.html#execution-of-python-signal-handlers > > we have: > > A Python signal handler does not get executed inside the low-level (C) > signal handler. Instead, the low-level signal handler sets a flag which > tells the virtual machine to execute the corresponding Python signal > handler at a later point(for example at the next bytecode instruction). Ah, thanks. Most importantly, though: Is there anything in the *language spec*, or is this a CPython implementation detail? ChrisA From Cecil at decebal.nl Sat Aug 8 04:41:39 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sat, 08 Aug 2015 10:41:39 +0200 Subject: python-matplotlib changes very often? Message-ID: <87wpx6dvek.fsf@Equus.decebal.nl> On openSUSE I see python-matplotlib updated very often. Sometimes more as once a week. It is also not very small (almost 40 MB). Is there a reason for this, or is there a problem at SUSE? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From cs at zip.com.au Sat Aug 8 05:02:59 2015 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 8 Aug 2015 19:02:59 +1000 Subject: except block isn't catching exception In-Reply-To: References: Message-ID: <20150808090259.GA92450@cskk.homeip.net> On 08Aug2015 18:17, Chris Angelico wrote: >On Sat, Aug 8, 2015 at 6:11 PM, Cameron Simpson wrote: >> From: >> >> >> https://docs.python.org/3/library/signal.html#execution-of-python-signal-handlers >> >> we have: >> >> A Python signal handler does not get executed inside the low-level (C) >> signal handler. Instead, the low-level signal handler sets a flag which >> tells the virtual machine to execute the corresponding Python signal >> handler at a later point(for example at the next bytecode instruction). > >Ah, thanks. Most importantly, though: Is there anything in the >*language spec*, or is this a CPython implementation detail? Signals aren't part of the language spec, surely? Though part of the stdlib clearly. I'd say the above text from the signal module doco was written from the viewport of CPython, though it is loose enough in terminology (==> allows freedom to implementors) to read like generic Python spec than CPython detail. The other bit of text I quoted: Python signal handlers are always executed in the main Python thread, even if the signal was received in another thread. also reads like specification. No, I can't prove any of this. It is just how I read the signal module documentation. Cheers, Cameron Simpson No good deed shall go unpunished! - David Wood From lac at openend.se Sat Aug 8 05:17:25 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 08 Aug 2015 11:17:25 +0200 Subject: python-matplotlib changes very often? In-Reply-To: Message from Cecil Westerhof of "Sat, 08 Aug 2015 10:41:39 +0200." <87wpx6dvek.fsf@Equus.decebal.nl> References: <87wpx6dvek.fsf@Equus.decebal.nl> Message-ID: <201508080917.t789HP24031177@fido.openend.se> In a message of Sat, 08 Aug 2015 10:41:39 +0200, Cecil Westerhof writes: >On openSUSE I see python-matplotlib updated very often. Sometimes more >as once a week. It is also not very small (almost 40 MB). Is there a >reason for this, or is there a problem at SUSE? > >-- >Cecil Westerhof >Senior Software Engineer >LinkedIn: http://www.linkedin.com/in/cecilwesterhof >-- >https://mail.python.org/mailman/listinfo/python-list Debian isn't sending me updates that often, but the matplotlib folks are quite busy. https://github.com/matplotlib/matplotlib/pulse Laura From toddrjen at gmail.com Sat Aug 8 08:39:53 2015 From: toddrjen at gmail.com (Todd) Date: Sat, 8 Aug 2015 14:39:53 +0200 Subject: python-matplotlib changes very often? In-Reply-To: <87wpx6dvek.fsf@Equus.decebal.nl> References: <87wpx6dvek.fsf@Equus.decebal.nl> Message-ID: On Aug 8, 2015 10:46, "Cecil Westerhof" wrote: > > On openSUSE I see python-matplotlib updated very often. Sometimes more > as once a week. It is also not very small (almost 40 MB). Is there a > reason for this, or is there a problem at SUSE? I assume you are using tumbleweed and/or devel:languages:python? matplotlib has quite a few dependencies, and many of those have dependencies of their own. Whenever a dependency of a package is updated the open build service openSUSE uses for packaging the package is also updated. So it isn't really matplotlib getting updates, but rather the packages it depends on (or packages they depend on, and so on). And none of those are updated very often, there are just a lot if them. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Cecil at decebal.nl Sat Aug 8 08:51:47 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sat, 08 Aug 2015 14:51:47 +0200 Subject: python-matplotlib changes very often? References: <87wpx6dvek.fsf@Equus.decebal.nl> Message-ID: <87si7udjto.fsf@Equus.decebal.nl> On Saturday 8 Aug 2015 11:17 CEST, Laura Creighton wrote: > In a message of Sat, 08 Aug 2015 10:41:39 +0200, Cecil Westerhof > writes: >> On openSUSE I see python-matplotlib updated very often. Sometimes >> more as once a week. It is also not very small (almost 40 MB). Is >> there a reason for this, or is there a problem at SUSE? >> >> -- >> Cecil Westerhof >> Senior Software Engineer >> LinkedIn: http://www.linkedin.com/in/cecilwesterhof >> -- >> https://mail.python.org/mailman/listinfo/python-list > > Debian isn't sending me updates that often, but the matplotlib folks > are quite busy. https://github.com/matplotlib/matplotlib/pulse Well, I should not be to concerned with it then I suppose. ;-) But using patch files would clearly be an improvement I think. But nothing to be bash the people at SUSE over, -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From lac at openend.se Sat Aug 8 11:41:20 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 08 Aug 2015 17:41:20 +0200 Subject: Linux users: please run gui tests In-Reply-To: Message from Laura Creighton of "Sat, 08 Aug 2015 08:40:04 +0200." <201508080640.t786e4QU000440@fido.openend.se> References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> <201508071346.t77DkL2t031696@fido.openend.se> <201508071701.t77H1Csn004579@fido.openend.se><201508080640.t786e4QU000440@fido.openend.se> Message-ID: <201508081541.t78FfKLw008114@fido.openend.se> Ok, I moved to debian unstable (stretch/sid) lac at smartwheels:~$ lsb_release -a LSB Version: core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-3.0-noarch:core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:core-4.0-amd64:core-4.0-noarch:core-4.1-amd64:core-4.1-noarch:security-4.0-amd64:security-4.0-noarch:security-4.1-amd64:security-4.1-noarch Distributor ID: Debian Description: Debian GNU/Linux unstable (sid) Release: unstable Codename: sid I still get the same 3 errors. Laura From lac at openend.se Sat Aug 8 13:20:26 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 08 Aug 2015 19:20:26 +0200 Subject: Linux users: please run gui tests In-Reply-To: Message from Laura Creighton of "Sat, 08 Aug 2015 17:41:20 +0200." <201508081541.t78FfKLw008114@fido.openend.se> References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> <201508071346.t77DkL2t031696@fido.openend.se> <201508071701.t77H1Csn004579@fido.openend.se><201508080640.t786e4QU000440@fido.openend.se><201508081541.t78FfKLw008114@fido.openend.se> Message-ID: <201508081720.t78HKQ2F028163@fido.openend.se> Tried this on a different debian unstable system. lac at fido:~$ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux unstable (sid) Release: unstable Codename: sid lac at fido:~$ Same 3 errors. (So it is not just me.) Laura From laurent.pointal at free.fr Sat Aug 8 13:59:09 2015 From: laurent.pointal at free.fr (Laurent Pointal) Date: Sat, 08 Aug 2015 19:59:09 +0200 Subject: Who uses IDLE -- please answer if you ever do, know, or teach References: Message-ID: <55c6436d$0$3050$426a74cc@news.free.fr> Terry Reedy wrote: > There have been discussions, such as today on Idle-sig , about who uses > Idle and who we should design it for. If you use Idle in any way, or > know of or teach classes using Idle, please answer as many of the > questions below as you are willing, and as are appropriate I think they take a look at idlex http://idlex.sourceforge.net/ > Private answers are welcome. They will be deleted as soon as they are > tallied (without names). > > I realized that this list is a biased sample of the universe of people > who have studied Python at least, say, a month. But biased data should > be better than my current vague impressions. > > 0. Classes where Idle is used: > Where? IUT Orsay, Mesures Physiques, for teaching Python as programming language. > Level? Graduate (post-Bac in france) > Idle users: > > 1. Are you > grade school (1=12)? (sorry, I dont know correspondance in france) > undergraduate (Freshman-Senior)? > post-graduate (from whatever)? I'm senior developer. > 2. Are you > beginner (1st class, maybe 2nd depending on intensity of first)? > post-beginner? Post-beginner. > 3. With respect to programming, are you > amateur (unpaid) > professional (paid for programming) Pro. From marko at pacujo.net Sat Aug 8 17:27:00 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 09 Aug 2015 00:27:00 +0300 Subject: Devanagari int literals [was Re: Should non-security 2.7 bugs be fixed?] References: <7083e494-6192-4acb-aea9-216d858171bc@googlegroups.com> <55ab2b57$0$1664$c3e8da3$5496439d@news.astraweb.com> <76252f32-64e9-405b-84a2-996200a6fa6f@googlegroups.com> <87twsxj2ot.fsf@elektro.pacujo.net> <55ae2171$0$1646$c3e8da3$5496439d@news.astraweb.com> <87h9oxixwy.fsf@elektro.pacujo.net> Message-ID: <87614po4ij.fsf@elektro.pacujo.net> Marko Rauhamaa : > Steven D'Aprano : > >> The contemporary standard approach is from Zermelo-Fraenkel set >> theory: define 0 as the empty set, and the successor to n as the >> union of n and the set containing n: >> >> 0 = {} (the empty set) >> n + 1 = n ? {n} > > That definition barely captures the essence of what a number *is*. In > fact, there have been different formulations of natural numbers. Rehashing this old discussion. I ran into this wonderful website: It is an absolute treasure for those of us who hate handwaving in math textbooks. The database of computer-checked theorems proves everything starting from the very bottom. An interesting, recurring dividing line among the proofs is a layer of "provable" axioms. For example, this proof http://at.metamath.org/mpeuni/2p2e4.html (for "? (2 + 2) = 4") references the axiom (): ? 1 ? ? The axiom is "justified by" a set-theoretic theorem: Description: 1 is a complex number. Axiom 2 of 22 for real and complex numbers, derived from ZF set theory. This construction-dependent theorem should not be referenced directly; instead, use ax-1cn 7963. In other words, since there is no canonical way to define numbers in set theory, Metamath insulates its proofs from a particular definition by circumscribing numbers with construction-independent axioms. Anyway, ob. Python reference: Using the design ideas implemented in Metamath, Raph Levien has implemented what might be the smallest proof checker in the world, mmverify.py, at only 500 lines of Python code. Marko From random832 at fastmail.us Sat Aug 8 23:50:31 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Sat, 08 Aug 2015 23:50:31 -0400 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: <55c6436d$0$3050$426a74cc@news.free.fr> References: <55c6436d$0$3050$426a74cc@news.free.fr> Message-ID: <1439092231.1184057.351348481.57017E86@webmail.messagingengine.com> On Sat, Aug 8, 2015, at 13:59, Laurent Pointal wrote: > > Level? > > Graduate (post-Bac in france) Yours or your students? > > 1. Are you > > grade school (1=12)? > > (sorry, I dont know correspondance in france) Grade 12 refers to 17-18 year old students, each grade is one year. > > undergraduate (Freshman-Senior)? > > post-graduate (from whatever)? > > I'm senior developer. Freshman, Sophomore, Junior, and Senior conventionally refer to each of the years of a conventional four-year bachelor's degree at a university (Also to grades 9-12 in high school, but in context that seems not to be what's meant here). From Dwight at GoldWinde.com Sun Aug 9 00:08:57 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Sun, 09 Aug 2015 12:08:57 +0800 Subject: Is Django the way to go for a newbie? Message-ID: I am both new to Python and I haven?t even touched Django yet. I understand I that I need Django or something like it to develop my website. >From what I have read, Python and Django somewhat go together. Is that true? Or is there another development platform better for someone like me than Django? Any and all feedback or questions are much appreciated. BIG SMILE... Always, Dwight www.3forliving.key.to (video playlist on YouTube) www.couragebooks.key.to (all my books on Amazon) -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Aug 9 00:44:40 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 9 Aug 2015 14:44:40 +1000 Subject: Is Django the way to go for a newbie? In-Reply-To: References: Message-ID: On Sun, Aug 9, 2015 at 2:08 PM, Dwight GoldWinde wrote: > I am both new to Python and I haven?t even touched Django yet. > > I understand I that I need Django or something like it to develop my > website. > > From what I have read, Python and Django somewhat go together. > > Is that true? > > Or is there another development platform better for someone like me than > Django? Django is quite big and powerful, but if your needs are simple, you could consider something a bit simpler. I've used Flask for a couple of web sites, and have worked with a number of students who've used it successfully. My recommendation: Learn Python first, and worry about web frameworks later. Once you have the basics of the language under your belt, you'll be better able to judge what works and what doesn't for the web site you're trying to build. Do you have a background in other programming languages, or are you new to programming as a whole? ChrisA From Dwight at GoldWinde.com Sun Aug 9 01:10:30 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Sun, 09 Aug 2015 13:10:30 +0800 Subject: Is Django the way to go for a newbie? In-Reply-To: References: Message-ID: Thank you, Chris! Good input. I was a computer software consulting for 20 years, ending in 1987, whrn I changed my career to life coaching (which I have now done happily for 28 years). So now I going back to learn a new language freshly (much different than COBOL and BASIC!). I am working on a long-term project to create an ?automated life coaching? website. BIG SMILE... Always, Dwight www.3forliving.key.to (video playlist on YouTube) www.couragebooks.key.to (all my books on Amazon) On 8/9/15, 12:44 PM, "Chris Angelico" wrote: >On Sun, Aug 9, 2015 at 2:08 PM, Dwight GoldWinde >wrote: >> I am both new to Python and I haven?t even touched Django yet. >> >> I understand I that I need Django or something like it to develop my >> website. >> >> From what I have read, Python and Django somewhat go together. >> >> Is that true? >> >> Or is there another development platform better for someone like me than >> Django? > >Django is quite big and powerful, but if your needs are simple, you >could consider something a bit simpler. I've used Flask for a couple >of web sites, and have worked with a number of students who've used it >successfully. > >My recommendation: Learn Python first, and worry about web frameworks >later. Once you have the basics of the language under your belt, >you'll be better able to judge what works and what doesn't for the web >site you're trying to build. > >Do you have a background in other programming languages, or are you >new to programming as a whole? > >ChrisA >-- >https://mail.python.org/mailman/listinfo/python-list From Dwight at GoldWinde.com Sun Aug 9 01:45:04 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Sun, 09 Aug 2015 13:45:04 +0800 Subject: Importing is partially working... Message-ID: I am trying to import and function. The function (humprint) is defined in a .py module inside the same folder as the executing code. I am put traces in the Functions.py module to show that it works okay there (Python 3.4). Here is the code of the Functions.py module: try: print (callable(humprint)) except NameError: print ('humprint not defined') def humprint (sentence): import random import time import sys for char in sentence: sys.stdout.write (char) sys.stdout.flush () part_second = random.randint(1, 100) / 400 time.sleep(part_second) # delays for x seconds print (callable(humprint)) sentence = 'Testing humprint inside of the same module' humprint (sentence) And here is the code for the calling module: name = 'Jim' coach = 'Dwight' import importlib sentence = 'Hi, there, ' + name + '. My name is ' + coach + '. I will be your coach today.' from Functions.py import humprint humprint (sentence) And here are the results of running the calling module: humprint not defined True Testing humprint inside of the same moduleTraceback (most recent call last): File "", line 2218, in _find_and_load_unlocked AttributeError: 'module' object has no attribute '__path__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "Intro.py", line 5, in from Functions.py import humprint ImportError: No module named 'Functions.py'; 'Functions' is not a package So, it seems like it is accessing the module, but not the function? Please advise! With appreciation?. BIG SMILE... Always, Dwight www.3forliving.key.to (video playlist on YouTube) www.couragebooks.key.to (all my books on Amazon) -------------- next part -------------- An HTML attachment was scrubbed... URL: From lac at openend.se Sun Aug 9 02:23:23 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 09 Aug 2015 08:23:23 +0200 Subject: Is Django the way to go for a newbie? In-Reply-To: Message from Dwight GoldWinde of "Sun, 09 Aug 2015 12:08:57 +0800." References: Message-ID: <201508090623.t796NNpw016997@fido.openend.se> There are lots of Web Frameworks. https://wiki.python.org/moin/WebFrameworks lists some of them. I wouldn't place too much faith in the classification of some as 'Popular' and others as 'Regarded as Less Popular' -- I keep getting the itch to put a wikipedia style footnote (by whom) -- in my corner of the world Zope 2 and Pylons are very popular, and Pyramid which is the successor to Pylons is rather more popular than either. All 3 of them are more popular around here than web2py (which is also popular, just not at much) and I don't know anybody who is using Turbogears at all. (Pyramid is listed under the 'non full stack frameworks' but if I had been making the list it would be under full stack; maybe the list got made when Pyramid was more incomplete.) The most important consideration when choosing a web framework is whether you have somebody local who can help you, in person, with the thing. If you have such a person, and they prefer a certain Framework, go for that one. Otherwise there really isn't a thing to do but build a small example and see how you like it. Because they actually play quite differently. They are designed by people to make things most convenient for the way they like to work, to expose the complexity that they want control over and hide the stuff they don't. This means, for instance that the very things that web2py lovers like the best about their framework is precisely what the people who dislike web2py hate about it -- and the same is true for Django, and all down the list. Remember that the people who love Django (for instance) are all quite happy to write blog posts about their happiness, while the people who find writing Django code most unpleasant don't tend to talk about it. They just find something they like better, and use it. You will be happiest with the one that fits your brain best, but alas it is hard to know what that will be before you try it. But there is one major split you probably know about yourself when figuring out what to try first. If you are the sort of person who takes great comfort from the knowledge that 'all the batteries are included' and that you will never _outgrow_ your framework, should you need to do some new thing with it, the components will already be there, then you will prefer a full stack framework. The disadvantage in using a comprehensive framework like that is that you will have much less flexibility in how you do things -- you will have to do Django things the Django way, and web2py things the web2py way, etc. And things will be much more complicated. But if you are naturally inclined towards comprehensive solutions, start playing with the Full Stack Frameworks. If you throw up your hands and say 'this is all too complicated!' you can then try something simpler. If, on the other hand, your natural inclination is to dislike comprehensive solutions because you always want to go after the _simplest_ thing that can work, then you should start playing with Micro frameworks. And if you throw up your hands saying 'But this thing barely has support for anything! I don't want to have to write my own , , and ' then you can try something more comprehensive. Sorry not to be more helpful, but this is very much one of the cases where 'it depends' and it very much 'depends on you'. Laura From pierre.quentel at gmail.com Sun Aug 9 05:06:50 2015 From: pierre.quentel at gmail.com (Pierre Quentel) Date: Sun, 9 Aug 2015 02:06:50 -0700 (PDT) Subject: Iterators membership testing Message-ID: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> The documentation at https://docs.python.org/3.5/reference/expressions.html#not-in says : "For user-defined classes which do not define __contains__() but do define __iter__(), x in y is true if some value z with x == z is produced while iterating over y. If an exception is raised during the iteration, it is as if in raised that exception." However, if I define a class with class A: def __init__(self, x): self.x = x self.counter = -1 def __iter__(self): return self def __next__(self): self.counter += 1 if self.counter >= self.x: raise StopIteration return self.counter and test for membership with iterator = A(10) for i in iterator: assert i in iterator, '%s not found' %i I get an assertion error. Setting a trace on __next__ suggests that for membership testing, the interpreter consumes the iterator until the searched value is found (or until exhaustion), then it resumes iteration at this point. For instance : >>> iterator = A(10) >>> for i in iterator: ... print(i) ... assert i+1 in iterator ... 0 2 4 6 8 >>> If this is correct, should the documentation mention it ? From rosuav at gmail.com Sun Aug 9 05:24:38 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 9 Aug 2015 19:24:38 +1000 Subject: Iterators membership testing In-Reply-To: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> References: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> Message-ID: On Sun, Aug 9, 2015 at 7:06 PM, Pierre Quentel wrote: > "For user-defined classes which do not define __contains__() but do define > __iter__(), x in y is true if some value z with x == z is produced while > iterating over y. If an exception is raised during the iteration, it is as if > in raised that exception." > > ... > I get an assertion error. Setting a trace on __next__ suggests that for > membership testing, the interpreter consumes the iterator until the searched > value is found (or until exhaustion), then it resumes iteration at this point. That's exactly right. The only way for the interpreter to handle 'in' on an iterator is something like this: def contains(iter, obj): for val in iter: if val == obj: return True return False That's what the docs describe. So what you have is something like this: for i in iterator: for j in iterator: if i == j: break else: assert False, '%s not found' %i You're dragging values from the same iterator, so you're consuming it as part of your membership test. You can do this kind of thing: >>> 5 in A(10) True but if you've already consumed a few values, those won't be in the iterator any more: >>> x = A(10) >>> next(x) 0 >>> next(x) 1 >>> next(x) 2 >>> next(x) 3 >>> 2 in x False This is simply how iterators work. They're very different from repeatable iterables like lists or range objects, where you _can_ test for membership that way: >>> x = [10,20,30] >>> for i in x: assert i in x ... >>> x = iter([10,20,30]) >>> for i in x: assert i in x ... Traceback (most recent call last): File "", line 1, in AssertionError Note that I _could_ create a list that would pass this assertion, simply by duplicating every value: >>> x = iter([10,10,20,20,30,30]) >>> for i in x: assert i in x ... But it's iterating only three times here, and the 'in' check is consuming the other three values. Once your A(10) has yielded some value, it will never yield it again, so the assertion can never pass. Does that explain matters? ChrisA From pierre.quentel at gmail.com Sun Aug 9 05:55:59 2015 From: pierre.quentel at gmail.com (Pierre Quentel) Date: Sun, 9 Aug 2015 02:55:59 -0700 (PDT) Subject: Iterators membership testing In-Reply-To: References: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> Message-ID: Le dimanche 9 ao?t 2015 11:25:17 UTC+2, Chris Angelico a ?crit?: > On Sun, Aug 9, 2015 at 7:06 PM, Pierre Quentel wrote: > > "For user-defined classes which do not define __contains__() but do define > > __iter__(), x in y is true if some value z with x == z is produced while > > iterating over y. If an exception is raised during the iteration, it is as if > > in raised that exception." > > > > ... > > I get an assertion error. Setting a trace on __next__ suggests that for > > membership testing, the interpreter consumes the iterator until the searched > > value is found (or until exhaustion), then it resumes iteration at this point. > > That's exactly right. The only way for the interpreter to handle 'in' > on an iterator is something like this: > > def contains(iter, obj): > for val in iter: > if val == obj: return True > return False > > That's what the docs describe. So what you have is something like this: > > for i in iterator: > for j in iterator: > if i == j: break > else: > assert False, '%s not found' %i > > You're dragging values from the same iterator, so you're consuming it > as part of your membership test. You can do this kind of thing: > > >>> 5 in A(10) > True > > but if you've already consumed a few values, those won't be in the > iterator any more: > > >>> x = A(10) > >>> next(x) > 0 > >>> next(x) > 1 > >>> next(x) > 2 > >>> next(x) > 3 > >>> 2 in x > False > > This is simply how iterators work. They're very different from > repeatable iterables like lists or range objects, where you _can_ test > for membership that way: > > >>> x = [10,20,30] > >>> for i in x: assert i in x > ... > >>> x = iter([10,20,30]) > >>> for i in x: assert i in x > ... > Traceback (most recent call last): > File "", line 1, in > AssertionError > > Note that I _could_ create a list that would pass this assertion, > simply by duplicating every value: > > >>> x = iter([10,10,20,20,30,30]) > >>> for i in x: assert i in x > ... > > But it's iterating only three times here, and the 'in' check is > consuming the other three values. Once your A(10) has yielded some > value, it will never yield it again, so the assertion can never pass. > > Does that explain matters? > > ChrisA Thanks for the explanation. I understand that an iterator can't test membership any other way, but I'm still worried about how the documentation explains it. Reading it, I naively expected that an iterator which produces the integer 0 such as the one included in my post would say that "0 in iterator" is True, because "some value z with 0 == z is produced while iterating over y". Shouldn't it be more clear if the documentation said something like : "For user-defined classes which do not define __contains__() but do define __iter__(), x in y consumes the iterator y until some value z with x == z is produced" ? From rosuav at gmail.com Sun Aug 9 06:13:13 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 9 Aug 2015 20:13:13 +1000 Subject: Iterators membership testing In-Reply-To: References: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> Message-ID: On Sun, Aug 9, 2015 at 7:55 PM, Pierre Quentel wrote: > Thanks for the explanation. I understand that an iterator can't test membership any other way, but I'm still worried about how the documentation explains it. Reading it, I naively expected that an iterator which produces the integer 0 such as the one included in my post would say that "0 in iterator" is True, because "some value z with 0 == z is produced while iterating over y". > > Shouldn't it be more clear if the documentation said something like : "For user-defined classes which do not define __contains__() but do define __iter__(), x in y consumes the iterator y until some value z with x == z is produced" ? > Consuming the iterator is implicit in the description, because the only way to iterate over an iterator is to call next() on it, which consumes values. But the description covers all *iterables*, and the caveat applies only to *iterators*. Compare: class A: def __init__(self, x): self.x = x def __iter__(self): counter = -1 while counter < self.x: counter += 1 yield counter This is the same code as you had, except that it's an iterable that returns a _different_ object, and thus is not itself an iterator (in this case, A().__iter__() returns a generator object). Note the similarity of code to your example, and how easy it is to convert your code to be a generator and make it reiterable. Now let's do that membership test: >>> iterable = A(10) >>> for i in iterable: ... assert i in iterable ... No error. We can repeatedly iterate over this generator factory, and each iteration starts a new instance of the generator, which thus contains all the same values. Adding a print() will show that every number is indeed iterated over. The trap you're seeing here is that iterating over an iterator always consumes it, but mentally, you're expecting this to be iterating over a new instance of the same sequence. That's perfectly understandable, but due to the extreme flexibility of the iterator and iterable protocols, there's no way for the interpreter to say anything different. Make your object reiterable, and then it'll behave the way your brain is expecting... but the docs aren't incorrect here. ChrisA From pierre.quentel at gmail.com Sun Aug 9 07:00:42 2015 From: pierre.quentel at gmail.com (Pierre Quentel) Date: Sun, 9 Aug 2015 04:00:42 -0700 (PDT) Subject: Iterators membership testing In-Reply-To: References: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> Message-ID: <09cb3411-be3b-4875-9042-af96c7f63504@googlegroups.com> > The trap you're seeing here is that iterating over an iterator always > consumes it, but mentally, you're expecting this to be iterating over > a new instance of the same sequence. No, I just tried to apply what I read in the docs : 1. I have y = A(10) which is an instance of a class which does not define __contains__ but does define __iter__ 2. The value z = 0 is produced while iterating over y. 3. The sentence "x in y is true if some value z with x == z is produced while iterating over y" lead me to think that "0 in y" would be true. From rosuav at gmail.com Sun Aug 9 07:10:25 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 9 Aug 2015 21:10:25 +1000 Subject: Iterators membership testing In-Reply-To: <09cb3411-be3b-4875-9042-af96c7f63504@googlegroups.com> References: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> <09cb3411-be3b-4875-9042-af96c7f63504@googlegroups.com> Message-ID: On Sun, Aug 9, 2015 at 9:00 PM, Pierre Quentel wrote: >> The trap you're seeing here is that iterating over an iterator always >> consumes it, but mentally, you're expecting this to be iterating over >> a new instance of the same sequence. > > No, I just tried to apply what I read in the docs : > > 1. I have y = A(10) which is an instance of a class which does not define __contains__ but does define __iter__ > > 2. The value z = 0 is produced while iterating over y. > > 3. The sentence "x in y is true if some value z with x == z is produced while iterating over y" lead me to think that "0 in y" would be true. You're almost right. The significance here is that once you've partially iterated over y, the value z will not be produced while iterating over y - so *at that point in time*, y does not contain z. Iterators (non-infinite ones, at least) shrink over time, so the set of objects they contain will shrink. ChrisA From lac at openend.se Sun Aug 9 07:30:38 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 09 Aug 2015 13:30:38 +0200 Subject: Iterators membership testing In-Reply-To: Message from Chris Angelico of "Sun, 09 Aug 2015 20:13:13 +1000." References: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> Message-ID: <201508091130.t79BUcE9011366@fido.openend.se> Maybe add something about this here? https://docs.python.org/2/tutorial/classes.html#iterators Laura From tim at thechases.com Sun Aug 9 09:09:17 2015 From: tim at thechases.com (Tim Chase) Date: Sun, 9 Aug 2015 08:09:17 -0500 Subject: Iterators membership testing In-Reply-To: References: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> Message-ID: <20150809080917.2c87f22f@bigbox.christie.dr> On 2015-08-09 19:24, Chris Angelico wrote: > That's exactly right. The only way for the interpreter to handle > 'in' on an iterator is something like this: > > def contains(iter, obj): > for val in iter: > if val == obj: return True > return False Which can nicely be written as any(i == obj for obj in iter) The addition of any/all initially struck me as a "why?! this is so easy to write in-line" moment, only to find myself using them all() the time. :-) The code-intention becomes so much clearer. Even back-ported them to 2.4 code that I maintain. -tkc From python.list at tim.thechases.com Sun Aug 9 09:09:51 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 9 Aug 2015 08:09:51 -0500 Subject: Iterators membership testing In-Reply-To: References: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> Message-ID: <20150809080951.44bbd4e9@bigbox.christie.dr> On 2015-08-09 19:24, Chris Angelico wrote: > That's exactly right. The only way for the interpreter to handle > 'in' on an iterator is something like this: > > def contains(iter, obj): > for val in iter: > if val == obj: return True > return False Which can nicely be written as any(i == obj for obj in iter) The addition of any/all initially struck me as a "why?! this is so easy to write in-line" moment, only to find myself using them all() the time. :-) The code-intention becomes so much clearer. Even back-ported them to 2.4 code that I maintain. -tkc From rosuav at gmail.com Sun Aug 9 09:11:20 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 9 Aug 2015 23:11:20 +1000 Subject: Iterators membership testing In-Reply-To: <20150809080917.2c87f22f@bigbox.christie.dr> References: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> <20150809080917.2c87f22f@bigbox.christie.dr> Message-ID: On Sun, Aug 9, 2015 at 11:09 PM, Tim Chase wrote: > On 2015-08-09 19:24, Chris Angelico wrote: >> That's exactly right. The only way for the interpreter to handle >> 'in' on an iterator is something like this: >> >> def contains(iter, obj): >> for val in iter: >> if val == obj: return True >> return False > > Which can nicely be written as > > any(i == obj for obj in iter) Indeed it can, although I'm not sure whether it'd just have been another step in the explanation :) Whether or not that makes perfect sense depends on the reader. ChrisA From breamoreboy at yahoo.co.uk Sun Aug 9 09:45:20 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 9 Aug 2015 14:45:20 +0100 Subject: Iterators membership testing In-Reply-To: References: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> <20150809080917.2c87f22f@bigbox.christie.dr> Message-ID: On 09/08/2015 14:11, Chris Angelico wrote: > On Sun, Aug 9, 2015 at 11:09 PM, Tim Chase wrote: >> On 2015-08-09 19:24, Chris Angelico wrote: >>> That's exactly right. The only way for the interpreter to handle >>> 'in' on an iterator is something like this: >>> >>> def contains(iter, obj): >>> for val in iter: >>> if val == obj: return True >>> return False >> >> Which can nicely be written as >> >> any(i == obj for obj in iter) > > Indeed it can, although I'm not sure whether it'd just have been > another step in the explanation :) Whether or not that makes perfect > sense depends on the reader. > > ChrisA > This one probably won't make make sense to most readers. any("Australian batsmen scored any() runs recently?") See also http://www.cricketcountry.com/photos/photo-england-supporters-sell-hardly-used-australian-bats-314378 :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Sun Aug 9 09:49:27 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 9 Aug 2015 14:49:27 +0100 Subject: Iterators membership testing In-Reply-To: <201508091130.t79BUcE9011366@fido.openend.se> References: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> <201508091130.t79BUcE9011366@fido.openend.se> Message-ID: On 09/08/2015 12:30, Laura Creighton wrote: > Maybe add something about this here? > https://docs.python.org/2/tutorial/classes.html#iterators > > Laura > Better still https://docs.python.org/3/tutorial/classes.html#iterators -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rogerh906 at gmail.com Sun Aug 9 10:10:50 2015 From: rogerh906 at gmail.com (rogerh906 at gmail.com) Date: Sun, 9 Aug 2015 07:10:50 -0700 (PDT) Subject: Pipes Message-ID: Just learning Python and have a question. Is it possible for Python to pass information to another program (in Windows), wait for that program to finish and then resume operating? It's called a pipe in Unix systems. Thanks, Roger From rustompmody at gmail.com Sun Aug 9 12:29:06 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 9 Aug 2015 09:29:06 -0700 (PDT) Subject: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?] In-Reply-To: <87614po4ij.fsf@elektro.pacujo.net> References: <7083e494-6192-4acb-aea9-216d858171bc@googlegroups.com> <55ab2b57$0$1664$c3e8da3$5496439d@news.astraweb.com> <76252f32-64e9-405b-84a2-996200a6fa6f@googlegroups.com> <87twsxj2ot.fsf@elektro.pacujo.net> <55ae2171$0$1646$c3e8da3$5496439d@news.astraweb.com> <87h9oxixwy.fsf@elektro.pacujo.net> <87614po4ij.fsf@elektro.pacujo.net> Message-ID: On Sunday, August 9, 2015 at 2:57:20 AM UTC+5:30, Marko Rauhamaa wrote: > Marko Rauhamaa : > > > Steven D'Aprano : > > > >> The contemporary standard approach is from Zermelo-Fraenkel set > >> theory: define 0 as the empty set, and the successor to n as the > >> union of n and the set containing n: > >> > >> 0 = {} (the empty set) > >> n + 1 = n ? {n} > > > > That definition barely captures the essence of what a number *is*. In > > fact, there have been different formulations of natural numbers. > > Rehashing this old discussion. I ran into this wonderful website: > > Attention you Hilbertian! G?delian here ? http://blog.languager.org/2015/07/cs-history-2.html :-) Thanks for that link. Need to study it carefully From ian.g.kelly at gmail.com Sun Aug 9 13:13:41 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 9 Aug 2015 11:13:41 -0600 Subject: Pipes In-Reply-To: References: Message-ID: On Sun, Aug 9, 2015 at 8:10 AM, wrote: > Just learning Python and have a question. > > Is it possible for Python to pass information to another program (in Windows), wait for that program to finish and then resume operating? > > It's called a pipe in Unix systems. Yes, pipes can also be used in Windows. In Python, use the subprocess module for this. From rogerh906 at gmail.com Sun Aug 9 13:39:08 2015 From: rogerh906 at gmail.com (rogerh906 at gmail.com) Date: Sun, 9 Aug 2015 10:39:08 -0700 (PDT) Subject: Pipes In-Reply-To: References: Message-ID: <269a4bf7-cbf1-4262-86ad-c6ada3d99d58@googlegroups.com> On Sunday, August 9, 2015 at 8:11:18 AM UTC-6, roge... at gmail.com wrote: > Just learning Python and have a question. > > Is it possible for Python to pass information to another program (in Windows), wait for that program to finish and then resume operating? > > It's called a pipe in Unix systems. > > Thanks, > > Roger Where can I find out about this? It's not mentioned in my "Introduction to Python" book. Roger From torriem at gmail.com Sun Aug 9 13:41:39 2015 From: torriem at gmail.com (Michael Torrie) Date: Sun, 09 Aug 2015 11:41:39 -0600 Subject: Is Django the way to go for a newbie? In-Reply-To: References: Message-ID: <55C790D3.3040906@gmail.com> On 08/08/2015 10:08 PM, Dwight GoldWinde wrote: > I am both new to Python and I haven?t even touched Django yet. > > I understand I that I need Django or something like it to develop my > website. > > From what I have read, Python and Django somewhat go together. > > Is that true? > > Or is there another development platform better for someone like me than > Django? > > Any and all feedback or questions are much appreciated. Web development is very a very hard problem, largely because it involves quite a few different domain-specific languages that you have to be proficient in. It's not just a matter of Python and Django. You must also have a good working knowledge of html, css, javascript, SQL (or some other database engine, and even though Django abstracts the database somewhat), and how they all interconnect and interact with each other. So at this stage of the game, get some Python experience. Then mess with html, css, javascript on their own (static pages). After than then you'll be ready to add Django to the mix and also get some basic database experience. And judging by how much custom web applications cost these days, once you've mastered all this, you'll be in a position to make a lot of money. Not joking either! Web developers are some of the smartest people I know, and in the highest demand, because they work so well with such complex systems. In this area, node.js is getting very popular. I don't care much for javascript but using it on the server as well as the web browser itself reduced the number of languages you have to know by one. > BIG SMILE... "Just relax and let the hooks do their work." From ian.g.kelly at gmail.com Sun Aug 9 13:52:13 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 9 Aug 2015 11:52:13 -0600 Subject: Pipes In-Reply-To: <269a4bf7-cbf1-4262-86ad-c6ada3d99d58@googlegroups.com> References: <269a4bf7-cbf1-4262-86ad-c6ada3d99d58@googlegroups.com> Message-ID: On Sun, Aug 9, 2015 at 11:39 AM, wrote: > Where can I find out about this? It's not mentioned in my "Introduction to Python" book. The Python documentation at docs.python.org are an important resource, and in particular the subprocess module is covered at https://docs.python.org/3/library/subprocess.html. From rogerh906 at gmail.com Sun Aug 9 13:55:36 2015 From: rogerh906 at gmail.com (rogerh906 at gmail.com) Date: Sun, 9 Aug 2015 10:55:36 -0700 (PDT) Subject: Pipes In-Reply-To: References: Message-ID: <3bf7a462-2c70-4e53-bfc6-86b5acb9f5f8@googlegroups.com> On Sunday, August 9, 2015 at 8:11:18 AM UTC-6, roge... at gmail.com wrote: > Just learning Python and have a question. > > Is it possible for Python to pass information to another program (in Windows), wait for that program to finish and then resume operating? > > It's called a pipe in Unix systems. > > Thanks, > > Roger Nevermind, I found it. Thanks for the pointer. But WOW! Python is described as an easy to learn language. I don't think so! Roger From breamoreboy at yahoo.co.uk Sun Aug 9 14:34:48 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 9 Aug 2015 19:34:48 +0100 Subject: Pipes In-Reply-To: References: <269a4bf7-cbf1-4262-86ad-c6ada3d99d58@googlegroups.com> Message-ID: On 09/08/2015 18:52, Ian Kelly wrote: > On Sun, Aug 9, 2015 at 11:39 AM, wrote: >> Where can I find out about this? It's not mentioned in my "Introduction to Python" book. > > The Python documentation at docs.python.org are an important resource, > and in particular the subprocess module is covered at > https://docs.python.org/3/library/subprocess.html. > Just a tip aimed at everybody. If you go to the main page here https://docs.python.org/3/ up in the top right corner it says "modules | index". The former is for all modules in the standard library, the latter is the general index for everything in all of the docs. Both of them are a real time saver. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From emile at fenx.com Sun Aug 9 14:51:44 2015 From: emile at fenx.com (Emile van Sebille) Date: Sun, 9 Aug 2015 11:51:44 -0700 Subject: Pipes In-Reply-To: <3bf7a462-2c70-4e53-bfc6-86b5acb9f5f8@googlegroups.com> References: <3bf7a462-2c70-4e53-bfc6-86b5acb9f5f8@googlegroups.com> Message-ID: On 8/9/2015 10:55 AM, rogerh906 at gmail.com wrote: > On Sunday, August 9, 2015 at 8:11:18 AM UTC-6, roge... at gmail.com wrote: >> Just learning Python and have a question. >> >> Is it possible for Python to pass information to another program >>(in Windows), wait for that program to finish and then resume operating? >> >> It's called a pipe in Unix systems. >> >> Thanks, >> >> Roger > > Nevermind, I found it. Thanks for the pointer. But WOW! Python is described > as an easy to learn language. I don't think so! Well, 2.7 only has 31 keywords most of which are easily understood[1], as is the enforced indentation structure. Also, pipes and interprocess communications aren't usually CS101 level classes. The libraries are where things get interesting and where you should focus your attention. https://docs.python.org/2/library/ is the official docs, but effbot's guide, while old, is not entirely obsolete and still provides a nice overview of things. See http://effbot.org/zone/librarybook-index.htm Emile [1] and del from not while as elif global or with assert else if pass yield break except import print class exec in raise continue finally is return def for lambda try From alister.nospam.ware at ntlworld.com Sun Aug 9 14:55:24 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Sun, 9 Aug 2015 18:55:24 +0000 (UTC) Subject: Pipes References: <3bf7a462-2c70-4e53-bfc6-86b5acb9f5f8@googlegroups.com> Message-ID: On Sun, 09 Aug 2015 10:55:36 -0700, rogerh906 wrote: > On Sunday, August 9, 2015 at 8:11:18 AM UTC-6, roge... at gmail.com wrote: >> Just learning Python and have a question. >> >> Is it possible for Python to pass information to another program (in >> Windows), wait for that program to finish and then resume operating? >> >> It's called a pipe in Unix systems. >> >> Thanks, >> >> Roger > > Nevermind, I found it. Thanks for the pointer. But WOW! Python is > described as an easy to learn language. I don't think so! > > Roger that depends on what you are comparing it to. I used to be an assembler programmer on on 8 bit micros so I believe i have a reasonable programming background & found python much easier to learn than for example C. -- And on the seventh day, He exited from append mode. From PointedEars at web.de Sun Aug 9 15:39:27 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sun, 09 Aug 2015 21:39:27 +0200 Subject: Is Django the way to go for a newbie? References: Message-ID: <1794184.sQQE973R46@PointedEars.de> Michael Torrie wrote: > Web development is very a very hard problem, largely because it involves > quite a few different domain-specific languages that you have to be > proficient in. I, professional Web developer, will not comment on that :) > It's not just a matter of Python and Django. You must also have a good > working knowledge of html, css, javascript, SQL (or ^^^^^^^^^^^^^^^^^^^^^ This is a common mistake and it has been repeated twice in your posting (so it is unlikely to be a typo). Therefore, allow me to "nitpick" on it again: It is _HTML_ (HyperText Markup Language), _CSS_ (Cascading Style-Sheets) and _JavaScript_? (not an acronym). Why you would write those three names in all-lowercase, but not ?sql? (which would equally be wrong since it is an abbreviation for ?Structured Query Language?) is truly beyond me. How did you get this idea? _____ ? Contrary to popular belief, ?JavaScript? does not encompass only one programming language, and there are ECMAScript implementations (in Web browsers and elsewhere) that did not, and marketing aside, still do not, contain the ?JavaScript? trademark. See for details. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From breamoreboy at yahoo.co.uk Sun Aug 9 17:18:39 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 9 Aug 2015 22:18:39 +0100 Subject: Pipes In-Reply-To: <2nefsaleec1b20kur4mbt5jat3eafh2f3n@4ax.com> References: <3bf7a462-2c70-4e53-bfc6-86b5acb9f5f8@googlegroups.com> <2nefsaleec1b20kur4mbt5jat3eafh2f3n@4ax.com> Message-ID: On 09/08/2015 21:43, Dennis Lee Bieber wrote: > On Sun, 9 Aug 2015 10:55:36 -0700 (PDT), rogerh906 at gmail.com declaimed the > following: > >> >> Nevermind, I found it. Thanks for the pointer. But WOW! Python is described as an easy to learn language. I don't think so! >> > It is... The Language Reference Manual is only some 70 or so pages (I > haven't counted the later versions; probably grew to 100 behind my back). > > But the LIBRARIES that do all the nice things for you so you don't have > program the stuff from scratch may take some time to get familiar. > I assume that by LIBRARIES you mean the stdlib? Once you've mastered all of them, a couple of hundred at most which shouldn't take more than a few minutes, it shouldn't take too very much longer to get to grips with the 64337 packages listed on pypi alone. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From cs at zip.com.au Sun Aug 9 18:27:25 2015 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 10 Aug 2015 08:27:25 +1000 Subject: Pipes In-Reply-To: <3bf7a462-2c70-4e53-bfc6-86b5acb9f5f8@googlegroups.com> References: <3bf7a462-2c70-4e53-bfc6-86b5acb9f5f8@googlegroups.com> Message-ID: <20150809222725.GA35504@cskk.homeip.net> On 09Aug2015 10:55, rogerh906 at gmail.com wrote: >But WOW! Python is described as an easy to learn language. I don't think so! The language itself is pretty compact and expressive. You also need to gain some familarity with the standard library that comes with it. That has lots of stuff. "subprocess" is part of the library. I'm not sure what metric you're using here for "easy to learn". Cheers, Cameron Simpson From gary719_list1 at verizon.net Sun Aug 9 19:25:16 2015 From: gary719_list1 at verizon.net (Gary Roach) Date: Sun, 09 Aug 2015 16:25:16 -0700 Subject: Is Django the way to go for a newbie? In-Reply-To: References: Message-ID: <55C7E15C.6070003@verizon.net> On 08/08/2015 09:08 PM, Dwight GoldWinde wrote: > I am both new to Python and I haven?t even touched Django yet. > > I understand I that I need Django or something like it to develop my > website. > > From what I have read, Python and Django somewhat go together. > > Is that true? > > Or is there another development platform better for someone like me > than Django? > > Any and all feedback or questions are much appreciated. > > BIG SMILE... > > Always, Dwight > > > www.3forliving.key.to (video playlist on YouTube) > www.couragebooks.key.to (all my books on Amazon) > > > > I'm also somewhat of a newbie but seem to be a little further down the road than you are. So hear is some advise from someone with recent bruises. The advise to learn python first is a very good piece of advice. I tried Postgresql and Django first and got bogged down just about the time that I was starting to get past the setup phase. You might try "Learning Python The Hard Way". It's working for me. Django v.s. other frameworks. It depends on what you want to do. I'm working on a data archiving project so the fact that Dango was / is developed by a couple of newspaper journalists fits well with my project. This may not be true for you. I will say that once you set the system up you will probably never see the sql database again. A very good thing. What ever you do set up virtualenv and vertualenvwrapper. Not only will this keep you project code away from the rest of your system, it will allow you to run different versions of software simultaneously. (Note: Unless you are using SQLite your database engine will be installed globally. Everything else inside the wrapper using pip.) There are a lot of scripting languages out there and everyone has a favorite. No matter what Python strikes me as being a good choice. You will need some kind of an Integrated Development Environment (IDE). I happen to like Ninja-Ide. (Don't everyone start throwing rocks. We all have our favorites. An no, I haven't checked them all out.) This is my first programming in some years too. I use to be a whiz at fortran, C and Xbase but haven't done anything since I retired. Good luck Gary R -------------- next part -------------- An HTML attachment was scrubbed... URL: From laurent.pointal at free.fr Sun Aug 9 20:24:08 2015 From: laurent.pointal at free.fr (Laurent Pointal) Date: Mon, 10 Aug 2015 02:24:08 +0200 Subject: Who uses IDLE -- please answer if you ever do, know, or teach References: <55c6436d$0$3050$426a74cc@news.free.fr> Message-ID: <55c7ef29$0$3321$426a74cc@news.free.fr> random832 at fastmail.us wrote: > On Sat, Aug 8, 2015, at 13:59, Laurent Pointal wrote: >> > Level? >> >> Graduate (post-Bac in france) > > Yours or your students? My students. > >> > 1. Are you >> > grade school (1=12)? >> >> (sorry, I dont know correspondance in france) > > Grade 12 refers to 17-18 year old students, each grade is one year. Ok, students are at grade 12 (some at 13 after a failure in another cursus). >> > undergraduate (Freshman-Senior)? >> > post-graduate (from whatever)? >> >> I'm senior developer. > > Freshman, Sophomore, Junior, and Senior conventionally refer to each of > the years of a conventional four-year bachelor's degree at a university > (Also to grades 9-12 in high school, but in context that seems not to be > what's meant here). Oups, students are mainly beginners (but some algorithmic is being introduced in their previous pre-bachelor schools years, so we may see more experienced students). The choice of IDLE is related to its standard installation with Python (at least on Windows, and easily available on Linux / MacOSX). But, would appreciate some enhancements as seen in discussions (ex. typical example is line numbering). A+ Laurent. From crk at godblessthe.us Sun Aug 9 20:44:56 2015 From: crk at godblessthe.us (Clayton Kirkwood) Date: Sun, 9 Aug 2015 17:44:56 -0700 Subject: Pipes In-Reply-To: <2nefsaleec1b20kur4mbt5jat3eafh2f3n@4ax.com> References: <3bf7a462-2c70-4e53-bfc6-86b5acb9f5f8@googlegroups.com> <2nefsaleec1b20kur4mbt5jat3eafh2f3n@4ax.com> Message-ID: <048e01d0d305$ca953e20$5fbfba60$@godblessthe.us> > -----Original Message----- > From: Python-list [mailto:python-list- > bounces+crk=godblessthe.us at python.org] On Behalf Of Dennis Lee Bieber > Sent: Sunday, August 09, 2015 1:43 PM > To: python-list at python.org > Subject: Re: Pipes > > On Sun, 9 Aug 2015 10:55:36 -0700 (PDT), rogerh906 at gmail.com declaimed > the > following: > > > > >Nevermind, I found it. Thanks for the pointer. But WOW! Python is > described as an easy to learn language. I don't think so! > > > It is... The Language Reference Manual is only some 70 or so pages (I > haven't counted the later versions; probably grew to 100 behind my back). > > But the LIBRARIES that do all the nice things for you so you don't have > program the stuff from scratch may take some time to get familiar. But there is nothing non-cryptic and orderly that I have found that lists out various modules and packages. If you know the module, it generally gives most of the information, but if you don't know the module name or function capability, you're lost. It would be nice to have a 'if you want to do this, look at these packages'. You have a language ref that defines the basics but gives very little insight. Take list comprehension. As described in the language ref and given tutotial, you get maybe a paragraph of what it is, but there was no definition of what the brackets were for or how the comprehension worked and maybe you get one or two examples, but you're still left with what is it. Is there an up to date book on 3.x even. Every book seems to be from 2006 or so. Clayton > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list From cs at zip.com.au Sun Aug 9 21:09:30 2015 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 10 Aug 2015 11:09:30 +1000 Subject: Pipes In-Reply-To: <048e01d0d305$ca953e20$5fbfba60$@godblessthe.us> References: <048e01d0d305$ca953e20$5fbfba60$@godblessthe.us> Message-ID: <20150810010930.GA652@cskk.homeip.net> On 09Aug2015 17:44, Clayton Kirkwood wrote: >But there is nothing non-cryptic and orderly that I have found that lists >out various modules and packages. If you know the module, it generally gives >most of the information, but if you don't know the module name or function >capability, you're lost. Mark has already mentioned these: https://docs.python.org/3/py-modindex.html https://docs.python.org/3/genindex.html I use the index a lot, especially if I have a (probable) method name. >It would be nice to have a 'if you want to do this, >look at these packages'. There is also a search here: https://docs.python.org/3/ which has some utility. Note you need to wait for it to load the results. I just tried searching for "pipe". Admittedly "subprocess.PIPE" is the very last thing listed, but still, it is there. >You have a language ref that defines the basics but >gives very little insight. Take list comprehension. As described in the >language ref and given tutotial, you get maybe a paragraph of what it is, >but there was no definition of what the brackets were for or how the >comprehension worked and maybe you get one or two examples, but you're still >left with what is it. It is like a for loop, but you know that by now. >Is there an up to date book on 3.x even. Every book seems to be from 2006 or >so. Not sure, sorry. Cheers, Cameron Simpson From Dwight at GoldWinde.com Sun Aug 9 21:22:03 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Mon, 10 Aug 2015 09:22:03 +0800 Subject: Is Django the way to go for a newbie? In-Reply-To: <201508090623.t796NNpw016997@fido.openend.se> References: <201508090623.t796NNpw016997@fido.openend.se> Message-ID: Wow?such a generous response. Thank you, Laura! Based upon your feedback, I did some additional investigation and decided to go with Django. One of the reasons is that it?s got everything in the package. For example, I won?t have to go outside of Django for my database needs. And, although my website will be simple to start, it will grow in sophistication over the years. Thank you, again! BIG SMILE... Always, Dwight www.3forliving.key.to (video playlist on YouTube) www.couragebooks.key.to (all my books on Amazon) On 8/9/15, 2:23 PM, "Laura Creighton" wrote: >There are lots of Web Frameworks. >https://wiki.python.org/moin/WebFrameworks > >lists some of them. > >I wouldn't place too much faith in the classification of some as >'Popular' and others as 'Regarded as Less Popular' -- I keep getting >the itch to put a wikipedia style footnote (by whom) -- in my corner of >the world Zope 2 and Pylons are very popular, and Pyramid which is the >successor to Pylons is rather more popular than either. All 3 of them >are more popular around here than web2py (which is also popular, just >not at much) and I don't know anybody who is using Turbogears at all. >(Pyramid is listed under the 'non full stack frameworks' but if I had >been making the list it would be under full stack; maybe the list >got made when Pyramid was more incomplete.) > >The most important consideration when choosing a web framework is >whether you have somebody local who can help you, in person, with >the thing. If you have such a person, and they prefer a certain >Framework, go for that one. > >Otherwise there really isn't a thing to do but build a small example >and see how you like it. Because they actually play quite differently. >They are designed by people to make things most convenient for the way >they like to work, to expose the complexity that they want control over >and hide the stuff they don't. This means, for instance that the very >things that web2py lovers like the best about their framework is >precisely what the people who dislike web2py hate about it -- and >the same is true for Django, and all down the list. Remember that >the people who love Django (for instance) are all quite happy to >write blog posts about their happiness, while the people who find >writing Django code most unpleasant don't tend to talk about it. >They just find something they like better, and use it. > >You will be happiest with the one that fits your brain best, but alas >it is hard to know what that will be before you try it. But there is >one major split you probably know about yourself when figuring out >what to try first. If you are the sort of person who takes great >comfort from the knowledge that 'all the batteries are included' and >that you will never _outgrow_ your framework, should you need to do >some new thing with it, the components will already be there, then you >will prefer a full stack framework. The disadvantage in using a >comprehensive framework like that is that you will have much less >flexibility in how you do things -- you will have to do Django things >the Django way, and web2py things the web2py way, etc. And things >will be much more complicated. But if you are naturally inclined >towards comprehensive solutions, start playing with the Full Stack >Frameworks. If you throw up your hands and say 'this is all too >complicated!' you can then try something simpler. > >If, on the other hand, your natural inclination is to dislike >comprehensive >solutions because you always want to go after the _simplest_ thing that >can work, then you should start playing with Micro frameworks. And >if you throw up your hands saying 'But this thing barely has support >for anything! I don't want to have to write my own , , >and ' then you can try something more comprehensive. > >Sorry not to be more helpful, but this is very much one of the cases >where 'it depends' and it very much 'depends on you'. > >Laura > From rosuav at gmail.com Sun Aug 9 21:27:49 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 10 Aug 2015 11:27:49 +1000 Subject: Is Django the way to go for a newbie? In-Reply-To: <55C790D3.3040906@gmail.com> References: <55C790D3.3040906@gmail.com> Message-ID: On Mon, Aug 10, 2015 at 3:41 AM, Michael Torrie wrote: > Web development is very a very hard problem, largely because it involves > quite a few different domain-specific languages that you have to be > proficient in... > > In this area, node.js is getting very popular. I don't care much for > javascript but using it on the server as well as the web browser itself > reduced the number of languages you have to know by one. There's another thing you absolutely have to know when you do web development, and that's i18n. This is why I don't recommend Node.js for server-side work - because Python's Unicode support is better than JS's. Stick with Python (and avoid Python 2 on Windows) and you get great Unicode support. Do anything in JavaScript/ECMAScript and you get UTF-16 as the official representation. What's the length of the string "Hello, world"? >>> len("Hello, world") 12 > "Hello, world".length 12 So far, so good. What if those weren't ASCII characters? >>> len("?????, ?????") 12 (That's Python 3. In Python 2, you'd need to put a u"" prefix on the string, but it's otherwise the same, modulo the Windows narrow-build issue.) > "?????, ?????".length 22 ECMAScript stipulates that strings are not codepoints, but UTF-16 code units, so whenever you work with astral characters (which includes a lot of emoticons, Chinese characters, and other symbols that your end users *will* use), they'll get things wrong. The length of the string counts astral characters twice; indexing/slicing can take half of a character; any manipulation at all could corrupt your data. So, use Python for all your text processing. Life's better that way. ChrisA From rogerh906 at gmail.com Sun Aug 9 22:55:41 2015 From: rogerh906 at gmail.com (Roger Hunter) Date: Sun, 9 Aug 2015 20:55:41 -0600 Subject: Pipes In-Reply-To: <20150809222725.GA35504@cskk.homeip.net> References: <3bf7a462-2c70-4e53-bfc6-86b5acb9f5f8@googlegroups.com> <20150809222725.GA35504@cskk.homeip.net> Message-ID: I agree that some of Python is simple but the description of subprocess is certainly not. I spent much of my working career using Fortran and TrueBasic on mainframes. I'd like programming to be more like holding a discussion to the computer in English instead of Sanscrit. Roger On Sun, Aug 9, 2015 at 4:27 PM, Cameron Simpson wrote: > On 09Aug2015 10:55, rogerh906 at gmail.com wrote: > >> But WOW! Python is described as an easy to learn language. I don't think >> so! >> > > The language itself is pretty compact and expressive. You also need to > gain some familarity with the standard library that comes with it. That has > lots of stuff. "subprocess" is part of the library. > > I'm not sure what metric you're using here for "easy to learn". > > Cheers, > Cameron Simpson > -------------- next part -------------- An HTML attachment was scrubbed... URL: From torque.india at gmail.com Sun Aug 9 23:25:10 2015 From: torque.india at gmail.com (OmPs) Date: Mon, 10 Aug 2015 08:55:10 +0530 Subject: Parsing data from text file to python Message-ID: Hi All, Please accept my apologies, if this similar question has been asked earlier, I tried to search over the stack network and googled but couldn't find relevant information, partly may be because I may not be able to search effectively. I have built a contact form which sends me email for every user registration My question is more related to parsing some text data into csv format. and I have received multiple users information in my mail box which I had copied into a text file. The data looks like below. Name: testuser2 Email: testuser2 at gmail.com Cluster Name: o b Contact No.: 12346971239 Coming: Yes Name: testuser3 Email: testuser3 at gmail.com Cluster Name: Mediternea Contact No.: 9121319107 Coming: Yes Name: testuser4 Email: tuser4 at yahoo.com Cluster Name: Mediterranea Contact No.: 7892174896 Coming: Yes Name: tuser5 Email: tuserner5 at gmail.com Cluster Name: River Retreat A Contact No.: 7583450912 Coming: Yes Members Participating: 2 Name: Test User Email: testuser at yahoo.co.in Cluster Name: RD Contact No.: 09833123445 Coming: Yes Members Participating: 2 As can see the data contains some common fields and some fields which are not present, I am looking for solution/suggestion on how I can parse this data so under the heading Name, I will collect the name information under that column, and similarly for other, the data with title "Members Participating" I can just pick the nos and add it into excel sheet under the same heading, incase for the user this information is not present, it can just go blank. Stackoverflow link to this question: http://stackoverflow.com/questions/31911191/parsing-data-from-text-file-to-python Regards, Om Prakash Singh Live Curious -------------- next part -------------- An HTML attachment was scrubbed... URL: From lac at openend.se Mon Aug 10 00:06:38 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 10 Aug 2015 06:06:38 +0200 Subject: Parsing data from text file to python In-Reply-To: Message from OmPs of "Mon, 10 Aug 2015 08:55:10 +0530." References: Message-ID: <201508100406.t7A46cxu009784@fido.openend.se> In a message of Mon, 10 Aug 2015 08:55:10 +0530, OmPs writes: >I have built a contact form which sends me email for every user >registration My question is more related to parsing some text data into csv >format. Your contact form should be able to produce csv files for you, rather than producing plain text which you then parse. Did you write the code for the form? In which case can we see it? Laura From cs at zip.com.au Mon Aug 10 00:52:14 2015 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 10 Aug 2015 14:52:14 +1000 Subject: Pipes In-Reply-To: References: Message-ID: <20150810045214.GA3031@cskk.homeip.net> On 09Aug2015 20:55, Roger Hunter wrote: >I agree that some of Python is simple but the description of subprocess is >certainly not. It depends, to a degree. Subprocess embodies, in a fairly portable way, the mechanisms for starting an external command and connecting to it, and has a few convenience routes for the common cases of that interaction, such as the check-call() function. It does expect the user to have some familarity with pipes and the whole "process" model, and describes what it offers. If you want to make pipelines or do other higher level things built on subprocesses then either your should use subprocess to assemble that pipeline yourself (which is not incredibly hard, but I would hardly call trivial and convenient) or reach for a third party wrapper aimed at larger goals than subprocess' "single external process" focus. For example, the "sarge" module: http://sarge.readthedocs.org/en/latest/index.html It is not part of the standard library, but it is available from PyPI: https://pypi.python.org/pypi/sarge/ which makes fetching and installing it very easy. There are doubtless other libraries written to similarly ease more complicated subprocess-based operations. Using PyPI's search field with the word "subprocess" lists many many modules, several of which might be suited to specific goals. >I spent much of my working career using Fortran and TrueBasic on mainframes. Did either make spawning subcommands and collecting their output, or passing them some input, easy? >I'd like programming to be more like holding a discussion to the computer >in English instead of Sanscrit. Actually, Python is far far more like English pseudocode than most other languages in my experience. And a much better attempt than other "let the user write plain English" attempts like COBOL or SQL (less proselike, but definitely of that aim). There is of course Elisa :-) https://pypi.python.org/pypi/babbler/ Though it isn't programming... Cheers, Cameron Simpson My computer always does exactly what I tell it to do but sometimes I have trouble finding out what it was that I told it to do. - Dick Wexelblat From rosuav at gmail.com Mon Aug 10 06:11:15 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 10 Aug 2015 20:11:15 +1000 Subject: Importing is partially working... In-Reply-To: References: Message-ID: On Sun, Aug 9, 2015 at 3:45 PM, Dwight GoldWinde wrote: > name = 'Jim' > coach = 'Dwight' > import importlib > sentence = 'Hi, there, ' + name + '. My name is ' + coach + '. I will be > your coach today.' > from Functions.py import humprint > humprint (sentence) > > Traceback (most recent call last): > > File "Intro.py", line 5, in > > from Functions.py import humprint > > ImportError: No module named 'Functions.py'; 'Functions' is not a package > > > > So, it seems like it is accessing the module, but not the function? You're almost there! But in Python, you don't import something from a specific file - you import from a module, and the Python interpreter is free to locate that file anywhere that it can. It might be implemented in C, and be stored in Functions.so (on Unix-like systems) or Functions.dll (on Windows); it might be precompiled and loaded from Functions.pyc; it might come from a zip file, or some other form of special import source. So all you say is: from Functions import humprint and Python does the rest. Yep, that's all the change you need, and your code will most likely work. (I haven't tested it, but it'll probably work.) Have fun! ChrisA From memilanuk at gmail.com Mon Aug 10 06:19:36 2015 From: memilanuk at gmail.com (memilanuk) Date: Mon, 10 Aug 2015 03:19:36 -0700 Subject: Who uses IDLE -- please answer if you ever do, know, or teach In-Reply-To: <55C4969D.2010005@outlook.com> References: <55C37EBC.3020604@outlook.com> <55C4969D.2010005@outlook.com> Message-ID: On 08/07/2015 04:29 AM, tjohnson wrote: > On 8/6/2015 7:31 PM, Terry Reedy wrote: >> >> What 1 or 2 features would you most like to see? >> > Practically, I'd say a line number margin and right edge indicator. > > Theoretically, a tabbed editor and dockable interpreter pane. YES!!! and yes to the above. Some built-in support for style/syntax checking i.e. PEP8, pylint would be very nice (in my mind) for helping new users understand where some of the problems are in their code. Maybe not enabled by default, but available in the options for those who want it. -- Shiny! Let's be bad guys. Reach me @ memilanuk (at) gmail dot com From rosuav at gmail.com Mon Aug 10 06:50:39 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 10 Aug 2015 20:50:39 +1000 Subject: Pipes In-Reply-To: References: <3bf7a462-2c70-4e53-bfc6-86b5acb9f5f8@googlegroups.com> <20150809222725.GA35504@cskk.homeip.net> Message-ID: On Mon, Aug 10, 2015 at 12:55 PM, Roger Hunter wrote: > I agree that some of Python is simple but the description of subprocess is > certainly not. That's because spawning subprocesses is a complicated thing to do - or rather, it's a simple thing to do, but with a large number of options. This is particularly true when you want (a) security, (b) performance, (c) flexibility, and (d) convenience/simplicity in your code, as you basically can't have all of them at once. Compare other modern languages and how they go about spawning processes; chances are you'll see stuff about chroot, standard streams, environment, uid/gid, priority, file descriptors, resource limits, whether it uses a shell, and stuff like that. Python handles all of those using keyword arguments; Pike lets you provide an options mapping; I'm guessing Node.js has you provide an object with key/value pairs to configure it; whatever your language, whatever your framework, these features require a bit of complexity. Python *is* simple. As languages go, Python has far fewer edge cases and detaily bits than most. But you can't get away from the inherent complexity of computers... fortunately, Python puts most of that into its standard library, so you can follow the standard lookup rules and function calling conventions to figure out what's going on. Of course, simplicity isn't all there is to making a good language. Ook has just three tokens (used in pairs, making eight effective opcodes), but that doesn't make it easy to use. ChrisA From billy.earney at gmail.com Mon Aug 10 07:51:18 2015 From: billy.earney at gmail.com (Billy Earney) Date: Mon, 10 Aug 2015 06:51:18 -0500 Subject: pyjs - a compiler from Python to JavaScript In-Reply-To: References: Message-ID: Uri, It has been a few years since I have messed with py2js. Have you checked out brython? http://brython.info It supports javascript libraries such as jQuery, raphael.js, etc. Billy On Fri, Aug 7, 2015 at 6:00 AM, Uri Even-Chen wrote: > To Python developers, > > Are you familiar with pyjs ? I saw the website and I > see that the latest stable release is from May 2012. Is it possible to use > pyjs to compile Python to JavaScript? Which versions of Python are > supported? Are versions 2.7 and 3.4 supported? And is it possible to use > Django (in the client side) and JavaScript frameworks such as jQuery, > jQuery UI and jQuery plugins together with pyjs? > > Thanks, > Uri. > > *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 > Email: uri at speedy.net > Website: http://www.speedysoftware.com/uri/en/ > > > > > Speedypedia in Hebrew and English > > > -- > https://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From PointedEars at web.de Mon Aug 10 07:58:24 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Mon, 10 Aug 2015 13:58:24 +0200 Subject: Is Django the way to go for a newbie? References: <55C790D3.3040906@gmail.com> Message-ID: <7619054.rZZqoS0ge9@PointedEars.de> Chris Angelico wrote: > There's another thing you absolutely have to know when you do web > development, and that's i18n. This is why I don't recommend Node.js > for server-side work - because Python's Unicode support is better than > JS's. Your posting shows again that your knowledge of "JS" is full of gaps at best, so you should refrain from making bold statements about "it" and making design decisions and recommendations based on that. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From rosuav at gmail.com Mon Aug 10 08:57:10 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 10 Aug 2015 22:57:10 +1000 Subject: Is Django the way to go for a newbie? In-Reply-To: <7619054.rZZqoS0ge9@PointedEars.de> References: <55C790D3.3040906@gmail.com> <7619054.rZZqoS0ge9@PointedEars.de> Message-ID: On Mon, Aug 10, 2015 at 9:58 PM, Thomas 'PointedEars' Lahn wrote: > Chris Angelico wrote: > >> There's another thing you absolutely have to know when you do web >> development, and that's i18n. This is why I don't recommend Node.js >> for server-side work - because Python's Unicode support is better than >> JS's. > > Your posting shows again that your knowledge of "JS" is full of gaps at > best, so you should refrain from making bold statements about "it" and > making design decisions and recommendations based on that. Do please enlighten me! Tell me how Node changes the underlying ECMAScript specification and gives true Unicode support. In particular, I would expect the length of a string to be based on either code points or combining character sequences, and indexing (including slicing) should be based on the same thing. It should not be possible to split a character during iteration over a string. (Whether you iterate over "e?" as a single character or as two (U+0065 U+0301) is a matter of debate, and I'd accept both answers as correct.) ChrisA From breamoreboy at yahoo.co.uk Mon Aug 10 09:44:27 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 10 Aug 2015 14:44:27 +0100 Subject: Pipes In-Reply-To: References: <3bf7a462-2c70-4e53-bfc6-86b5acb9f5f8@googlegroups.com> <20150809222725.GA35504@cskk.homeip.net> Message-ID: On 10/08/2015 03:55, Roger Hunter wrote: > I agree that some of Python is simple but the description of subprocess > is certainly not. > > I spent much of my working career using Fortran and TrueBasic on mainframes. That's good. It means that you were probably taught to read and write from left to right *AND* from top to bottom. Would you like to keep to that convention here please as it makes following long threads much easier, thank you. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rogerh906 at gmail.com Mon Aug 10 10:05:58 2015 From: rogerh906 at gmail.com (rogerh906 at gmail.com) Date: Mon, 10 Aug 2015 07:05:58 -0700 (PDT) Subject: Pipes In-Reply-To: References: <3bf7a462-2c70-4e53-bfc6-86b5acb9f5f8@googlegroups.com> <20150809222725.GA35504@cskk.homeip.net> Message-ID: <0436295b-bf99-4956-b24e-a6dcd78e161e@googlegroups.com> On Monday, August 10, 2015 at 7:45:28 AM UTC-6, Mark Lawrence wrote: > On 10/08/2015 03:55, Roger Hunter wrote: > > I agree that some of Python is simple but the description of subprocess > > is certainly not. > > > > I spent much of my working career using Fortran and TrueBasic on mainframes. > > That's good. It means that you were probably taught to read and write > from left to right *AND* from top to bottom. Would you like to keep to > that convention here please as it makes following long threads much > easier, thank you. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence Sorry Mark, I don't know how these posts came out backward. I didn't do it. Roger From breamoreboy at yahoo.co.uk Mon Aug 10 10:36:24 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 10 Aug 2015 15:36:24 +0100 Subject: Pipes In-Reply-To: <0436295b-bf99-4956-b24e-a6dcd78e161e@googlegroups.com> References: <3bf7a462-2c70-4e53-bfc6-86b5acb9f5f8@googlegroups.com> <20150809222725.GA35504@cskk.homeip.net> <0436295b-bf99-4956-b24e-a6dcd78e161e@googlegroups.com> Message-ID: On 10/08/2015 15:05, rogerh906 at gmail.com wrote: > On Monday, August 10, 2015 at 7:45:28 AM UTC-6, Mark Lawrence wrote: >> On 10/08/2015 03:55, Roger Hunter wrote: >>> I agree that some of Python is simple but the description of subprocess >>> is certainly not. >>> >>> I spent much of my working career using Fortran and TrueBasic on mainframes. >> >> That's good. It means that you were probably taught to read and write >> from left to right *AND* from top to bottom. Would you like to keep to >> that convention here please as it makes following long threads much >> easier, thank you. >> >> -- >> My fellow Pythonistas, ask not what our language can do for you, ask >> what you can do for our language. >> >> Mark Lawrence > > Sorry Mark, I don't know how these posts came out backward. I didn't do it. > > Roger > Nothing to worry about. It's mostly a result of people so used to M$ Outlook in a business environment that they don't stop to think about it. On short threads it's not a problem, but some Python related threads can run into hundreds of entries, all being bounced backwards and forwards between umpteen different technologies. Try reading those if they're all top posted, complete nightmare. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From python at mrabarnett.plus.com Mon Aug 10 11:48:59 2015 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 10 Aug 2015 16:48:59 +0100 Subject: Importing is partially working... In-Reply-To: References: Message-ID: <55C8C7EB.6020401@mrabarnett.plus.com> On 2015-08-10 11:11, Chris Angelico wrote: > On Sun, Aug 9, 2015 at 3:45 PM, Dwight GoldWinde wrote: >> name = 'Jim' >> coach = 'Dwight' >> import importlib >> sentence = 'Hi, there, ' + name + '. My name is ' + coach + '. I will be >> your coach today.' >> from Functions.py import humprint >> humprint (sentence) >> >> Traceback (most recent call last): >> >> File "Intro.py", line 5, in >> >> from Functions.py import humprint >> >> ImportError: No module named 'Functions.py'; 'Functions' is not a package >> >> >> >> So, it seems like it is accessing the module, but not the function? > > You're almost there! But in Python, you don't import something from a > specific file - you import from a module, and the Python interpreter > is free to locate that file anywhere that it can. It might be > implemented in C, and be stored in Functions.so (on Unix-like systems) > or Functions.dll (on Windows); it might be precompiled and loaded from > Functions.pyc; it might come from a zip file, or some other form of > special import source. So all you say is: > On Windows, the extension for Python extension DLLs is ".pyd". > from Functions import humprint > > and Python does the rest. Yep, that's all the change you need, and > your code will most likely work. (I haven't tested it, but it'll > probably work.) > From rosuav at gmail.com Mon Aug 10 12:08:54 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Aug 2015 02:08:54 +1000 Subject: Importing is partially working... In-Reply-To: <55C8C7EB.6020401@mrabarnett.plus.com> References: <55C8C7EB.6020401@mrabarnett.plus.com> Message-ID: On Tue, Aug 11, 2015 at 1:48 AM, MRAB wrote: >> You're almost there! But in Python, you don't import something from a >> specific file - you import from a module, and the Python interpreter >> is free to locate that file anywhere that it can. It might be >> implemented in C, and be stored in Functions.so (on Unix-like systems) >> or Functions.dll (on Windows); it might be precompiled and loaded from >> Functions.pyc; it might come from a zip file, or some other form of >> special import source. So all you say is: >> > On Windows, the extension for Python extension DLLs is ".pyd". Or that. I haven't built any Python extensions in, well, ever, and haven't even deployed other people's in years, so I'm a bit rusty. Anyway, point is you don't have to care where it actually comes from. The one thing that I do kinda miss in Python is an easy way to "shadow and pull in the original" - to create something earlier in the search path, but then have that file get a reference to "the module that would have been loaded if I hadn't been here". It's not often you want it, but quite frankly, I don't know how I'd spell it at all. There probably is a way, but I've no idea what it is... ChrisA From ian.g.kelly at gmail.com Mon Aug 10 12:40:58 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 10 Aug 2015 10:40:58 -0600 Subject: pyjs - a compiler from Python to JavaScript In-Reply-To: References: Message-ID: On Fri, Aug 7, 2015 at 5:00 AM, Uri Even-Chen wrote: > > Are you familiar with pyjs? I saw the website and I see that the latest stable release is from May 2012. Is it possible to use pyjs to compile Python to JavaScript? Which versions of Python are supported? Are versions 2.7 and 3.4 supported? And is it possible to use Django (in the client side) and JavaScript frameworks such as jQuery, jQuery UI and jQuery plugins together with pyjs? And if you check the commit history on GitHub, there are only two commits in the past year. The project was hijacked (i.e. forked plus "we're taking the domain name and the mailing list too") a few years ago (also in May 2012, I think not coincidentally), and that sadly seems to have slowly killed the development momentum on the project. I'm not really familiar with the space, but I tend to hear good things about Brython. PyPy.js and Skulpt are other alternatives. However, I think that all of these are implementations of Python in Javascript, not Python to Javascript compilers. From yasoobkhld at gmail.com Mon Aug 10 15:55:51 2015 From: yasoobkhld at gmail.com (Yasoob Khalid) Date: Mon, 10 Aug 2015 12:55:51 -0700 (PDT) Subject: Calling Out All Python Programmer in Pakistan Message-ID: <9b04f552-9989-483e-8cc0-67a6480af36e@googlegroups.com> Hi there guys! I am Yasoob. I am one of the guys behind python.org.pk We are trying to organize a local meetup in Lahore but having a hard time finding members. Kindly let me know if you live in Lahore, Pakistan and would be interested in a meetup. If any of your friends would be interested in a meetup as well then kindly share this post with him as well. Kind regards, Muhammad Yasoob Ullah Khalid yasoob.khld at gmail.com Python Tips From edgrsprj at ix.netcom.com Mon Aug 10 16:43:26 2015 From: edgrsprj at ix.netcom.com (E.D.G.) Date: Mon, 10 Aug 2015 15:43:26 -0500 Subject: Pipes In-Reply-To: References: Message-ID: <2ZWdnZJUbYdxkVTInZ2dnUU7-I-dnZ2d@earthlink.com> wrote in message news:d6a3dfe4-8389-463b-ac66-a93f14a91a5e at googlegroups.com... > Just learning Python and have a question. Posted by E.D.G. on August 10, 2015 Roger's original post is largely a continuation of my July 25, 2015 posting regarding "Python Questions." His post does not actually explain what the general goal is here. So I will explain it once again. It has been my experience that researchers, particularly scientists, need to have some versatile and powerful programming language available that is compatible with the Windows operating system. The language needs to make certain resources available to the researchers. And in some form it should ultimately be compatible with other operating systems. Among the needed resources would be the ability to open and close files, read from and write to files, open "pipes" to other Windows programs, execute system or shell commands, read and respond to keyboard key presses, send text etc. to a running Windows program such as Notepad.exe and have it printed on the screen, and read and write to the Windows clipboard. Other important resources would be the ability to perform rapid calculations and the ability to generate plots that could display on the screen and also be saved as .png files etc. The language also has to have the ability to be "cloned." That means that it could be stored in some directory that could be copied from one computer to another. And programs written with that language would then run on the new computer. One person responding to my own earlier post stated that this is possible with Python. There are not too many programming languages that can do all of those things. Perl and probably Fortran will. But we could not get simple questions answered regarding how to do specific things such as open a "pipe" to a running Windows program. And there are two versions of Fortran, gfortran and F95 that we looked at. And we could not decided which one would work better. Python apparently also provides all of the necessary resources. And as all of these posts demonstrate, it has the major advantage in that when a question gets asked in the Python newsgroup, there is usually an answer. It will likely be up to Roger to decide if we will go with gfortran or Python since he does most of the actual computer program code development. Even though he prefers True Basic, I explained that we can't continue to use it. For example, with the versions we have been using, when it is waiting for a key to be pressed it is using 100% of the processor time. Perl and Fortran and probably Python just "go to sleep" while they are waiting for the Enter key to be pressed. They largely stop using the processor. The following is an example of how it can be important for researchers to have a powerful and versatile programming language available: I needed a program that could generate data regarding the locations of the sun and the moon in the sky in response to specific times entered. Roger developed the basic equations with some help from another researcher. And that took a while. But it probably took a full six months for us to compare notes by E-mail and get the program into a final form that people could download for free use. That is just too much time. Researchers need to be able to do things such as create simple charts etc. without spending months or years learning some programming language or comparing notes with one another. So, an entire Python directory that made that possible and that had clear instructions for how to open and close files and create "pipes" etc. would get the job done. If Roger wants to use Python then we might use the ActiveState version and then build those various resources into it. It reportedly installs in a Windows environment without problems. And I myself have used the ActiveState versions of Perl for quite a few years with a considerable amount of success. This assumes that the ActiveState version of Python can be taught to do fast calculations and to generate charts. If that does not look possible or easy then we will probably try one of the available scientific versions of Python. Would researchers then put professional Python programmers "out of business?" The answer is probably just the opposite. Researchers want to do research and not write computer programs. And if they can do at least some programming themselves then it makes it easier for them to work with professional programmers and explain what needs to be done. They are then more inclined to work with the programmers. And they won't have to compare notes with them for six months just to get a relatively simple task completed. Regards to all, E.D.G. From appthought1 at gmail.com Mon Aug 10 17:24:24 2015 From: appthought1 at gmail.com (appthought1 at gmail.com) Date: Mon, 10 Aug 2015 14:24:24 -0700 (PDT) Subject: Python Developer- Houston, TX Message-ID: <6c833463-41f3-4e1d-b5a7-fe069799c0eb@googlegroups.com> Hi, Hope you are doing well !!! My name is Siva and I'm a recruiter at TheAppliedthought , a global staffing and IT consulting company. Please find the below job description which may suits any of your consultants who are available in market or who are looking for change, please send me latest updated resume along with contact details and expected hourly rate to my email id siva at theappliedthought.com or you can reach me on 407-574-7610. Position: Python Developer Location: Houston, TX Duration: Long Term Job Description * 6+ years of experience with Linux/UNIX Systems Administration * 2+ years of Openstack Experience * Hypervisor KVM, BIOS, Firmware update * Storage Technologies (NAS, SAN & Cloud Storage) * Experience with configuration management tools (Chef expert!!) * Analytical problem-solving and conceptual skills * Strong scripting and/or development chops (Ruby, Python, Bash, Perl) * Experience with database technologies (MySQL, Percona, MongoDB) * Experience with automation (Chef etc.) and monitoring (Nagios, etc.) technologies in production setting * Experience with networking technologies including TCP/IP VPN DNS routing firewalls VLAN. * Excellent communication skills * Excellent team player Thanks & Regards Siva Executive-Talent Acquisition & Bench Sales Email: siva at theappliedthought.com IM: malladi sivaramakrishna88 Phone: 407-574-7610 Fax: 407-641-8184 From larry.martell at gmail.com Mon Aug 10 17:30:22 2015 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 10 Aug 2015 15:30:22 -0600 Subject: Python Developer- Houston, TX In-Reply-To: <6c833463-41f3-4e1d-b5a7-fe069799c0eb@googlegroups.com> References: <6c833463-41f3-4e1d-b5a7-fe069799c0eb@googlegroups.com> Message-ID: Can this be done remotely or only on-site? On Mon, Aug 10, 2015 at 3:24 PM, wrote: > Hi, > Hope you are doing well !!! > My name is Siva and I'm a recruiter at TheAppliedthought , a global staffing and IT consulting company. > Please find the below job description which may suits any of your consultants who are available in market or who are looking for change, please send me latest updated resume along with contact details and expected hourly rate to my email id siva at theappliedthought.com or you can reach me on 407-574-7610. > Position: Python Developer > Location: Houston, TX > Duration: Long Term > Job Description > * 6+ years of experience with Linux/UNIX Systems Administration > * 2+ years of Openstack Experience > * Hypervisor KVM, BIOS, Firmware update > * Storage Technologies (NAS, SAN & Cloud Storage) > * Experience with configuration management tools (Chef expert!!) > * Analytical problem-solving and conceptual skills > * Strong scripting and/or development chops (Ruby, Python, Bash, Perl) > * Experience with database technologies (MySQL, Percona, MongoDB) > * Experience with automation (Chef etc.) and monitoring (Nagios, etc.) technologies in production setting > * Experience with networking technologies including TCP/IP VPN DNS routing firewalls VLAN. > * Excellent communication skills > * Excellent team player > Thanks & Regards > Siva > Executive-Talent Acquisition & Bench Sales > Email: siva at theappliedthought.com > IM: malladi sivaramakrishna88 > Phone: 407-574-7610 > Fax: 407-641-8184 > -- > https://mail.python.org/mailman/listinfo/python-list From emile at fenx.com Mon Aug 10 17:43:33 2015 From: emile at fenx.com (Emile van Sebille) Date: Mon, 10 Aug 2015 14:43:33 -0700 Subject: Python Developer- Houston, TX In-Reply-To: <6c833463-41f3-4e1d-b5a7-fe069799c0eb@googlegroups.com> References: <6c833463-41f3-4e1d-b5a7-fe069799c0eb@googlegroups.com> Message-ID: On 8/10/2015 2:24 PM, appthought1 at gmail.com wrote: > Hi, > Hope you are doing well !!! > My name is Siva and I'm a recruiter at TheAppliedthought , a global staffing and IT consulting company. You really shouldn't post job offerings on this list. Please use the Python Job Board at https://www.python.org/community/jobs/howto/ next time. Emile From breamoreboy at yahoo.co.uk Mon Aug 10 17:59:48 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 10 Aug 2015 22:59:48 +0100 Subject: Pipes In-Reply-To: <2ZWdnZJUbYdxkVTInZ2dnUU7-I-dnZ2d@earthlink.com> References: <2ZWdnZJUbYdxkVTInZ2dnUU7-I-dnZ2d@earthlink.com> Message-ID: On 10/08/2015 21:43, E.D.G. wrote: > wrote in message > news:d6a3dfe4-8389-463b-ac66-a93f14a91a5e at googlegroups.com... >> Just learning Python and have a question. > Other important resources would be the ability to perform rapid > calculations and the ability to generate plots that could display on the > screen and also be saved as .png files etc. numpy and matplotlib are the leaders here. > > The language also has to have the ability to be "cloned." That > means that it could be stored in some directory that could be copied > from one computer to another. And programs written with that language > would then run on the new computer. One person responding to my own > earlier post stated that this is possible with Python. Certainly. In your position I think the easiest option is to have Python installed on all your machines and simply copy your programs aka scripts from machine to machine. I suppose it all depends on how easy it is to bribe your admin people!!! > > Python apparently also provides all of the necessary resources. > And as all of these posts demonstrate, it has the major advantage in > that when a question gets asked in the Python newsgroup, there is > usually an answer. No "usually" about it :) > I needed a program that could generate data regarding the > locations of the sun and the moon in the sky in response to specific > times entered. Roger developed the basic equations with some help from > another researcher. And that took a while. But it probably took a full > six months for us to compare notes by E-mail and get the program into a > final form that people could download for free use. > That is just too much time. Researchers need to be able to do > things such as create simple charts etc. without spending months or > years learning some programming language or comparing notes with one > another. So, an entire Python directory that made that possible and > that had clear instructions for how to open and close files and create > "pipes" etc. would get the job done. http://ipython.org/notebook.html could be what you're looking for here, both for your collaboration rather than comparing notes by email, and for actually producing your output. > > If Roger wants to use Python then we might use the ActiveState > version and then build those various resources into it. It reportedly > installs in a Windows environment without problems. And I myself have > used the ActiveState versions of Perl for quite a few years with a > considerable amount of success. > > This assumes that the ActiveState version of Python can be taught > to do fast calculations and to generate charts. If that does not look > possible or easy then we will probably try one of the available > scientific versions of Python. Anaconda always comes up in this area, with numpy, ipython and matplotlib included in the distibution, see http://docs.continuum.io/anaconda/index > > Would researchers then put professional Python programmers "out > of business?" No, they'll work perfectly happily side by side. If you're not already aware then scipy http://www.scipy.org/ should be pointed out, as well as pypi https://pypi.python.org/pypi which currently holds 64383 packages. Heck, I almost forgot pythonlibs http://www.lfd.uci.edu/~gohlke/pythonlibs/ which is a godsend if you haven't got Visual Studio and don't want to install it. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From larry at hastings.org Mon Aug 10 20:26:18 2015 From: larry at hastings.org (Larry Hastings) Date: Mon, 10 Aug 2015 17:26:18 -0700 Subject: [RELEASED] Python 3.5.0rc1 is now available Message-ID: <55C9412A.5030003@hastings.org> On behalf of the Python development community and the Python 3.5 release team, I'm relieved to announce the availability of Python 3.5.0rc1, also known as Python 3.5.0 Release Candidate 1. Python 3.5 has now entered "feature freeze". By default new features may no longer be added to Python 3.5. This is a preview release, and its use is not recommended for production settings. You can find Python 3.5.0rc1 here: https://www.python.org/downloads/release/python-350rc1/ Windows and Mac users: please read the important platform-specific "Notes on this release" section near the end of that page. Happy hacking, /arry From larry at hastings.org Mon Aug 10 20:55:40 2015 From: larry at hastings.org (Larry Hastings) Date: Mon, 10 Aug 2015 17:55:40 -0700 Subject: Sorry folks, minor hiccup for Python 3.5.0rc1 Message-ID: <55C9480C.20409@hastings.org> I built the source tarballs with a slightly-out-of-date tree. We slipped the release by a day to get two fixes in, but the tree I built from didn't have those two fixes. I yanked the tarballs off the release page as soon as I suspected something. I'm rebuilding the tarballs and the docs now. If you grabbed the tarball as soon as it appeared, it's slightly out of date, please re-grab. Sorry for the palaver, //arry/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From larry at hastings.org Mon Aug 10 20:56:26 2015 From: larry at hastings.org (Larry Hastings) Date: Mon, 10 Aug 2015 17:56:26 -0700 Subject: Sorry folks, minor hiccup for Python 3.5.0rc1 In-Reply-To: <55C9480C.20409@hastings.org> References: <55C9480C.20409@hastings.org> Message-ID: <55C9483A.8010300@hastings.org> On 08/10/2015 05:55 PM, Larry Hastings wrote: > I yanked the tarballs off the release page as soon as I suspected > something. I'm rebuilding the tarballs and the docs now. If you > grabbed the tarball as soon as it appeared, it's slightly out of date, > please re-grab. p.s. I should have mentioned--the Mac and Windows builds should be fine. They, unlike me, updated their tree ;-) -------------- next part -------------- An HTML attachment was scrubbed... URL: From Dwight at GoldWinde.com Mon Aug 10 21:31:19 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Tue, 11 Aug 2015 09:31:19 +0800 Subject: Is Django the way to go for a newbie? In-Reply-To: <55C790D3.3040906@gmail.com> References: <55C790D3.3040906@gmail.com> Message-ID: With much appreciation, Michael? When I get to that point, I will look into learning what I need to know about html, css, javascript, and SQL. I have been a life coaching now for 28 years (and super happy with it), although I was a computer software consultant before that. I?m not really thinking of getting back into web development for pay, just for fun for a project that I am designing for creating an ?automated life coach?. Again, thank you! BIG SMILE... Always, Dwight www.3forliving.key.to (video playlist on YouTube) www.couragebooks.key.to (all my books on Amazon) On 8/10/15, 1:41 AM, "Michael Torrie" wrote: >On 08/08/2015 10:08 PM, Dwight GoldWinde wrote: >> I am both new to Python and I haven?t even touched Django yet. >> >> I understand I that I need Django or something like it to develop my >> website. >> >> From what I have read, Python and Django somewhat go together. >> >> Is that true? >> >> Or is there another development platform better for someone like me than >> Django? >> >> Any and all feedback or questions are much appreciated. > >Web development is very a very hard problem, largely because it involves >quite a few different domain-specific languages that you have to be >proficient in. It's not just a matter of Python and Django. You must >also have a good working knowledge of html, css, javascript, SQL (or >some other database engine, and even though Django abstracts the >database somewhat), and how they all interconnect and interact with each >other. So at this stage of the game, get some Python experience. Then >mess with html, css, javascript on their own (static pages). After than >then you'll be ready to add Django to the mix and also get some basic >database experience. > >And judging by how much custom web applications cost these days, once >you've mastered all this, you'll be in a position to make a lot of >money. Not joking either! Web developers are some of the smartest >people I know, and in the highest demand, because they work so well with >such complex systems. > >In this area, node.js is getting very popular. I don't care much for >javascript but using it on the server as well as the web browser itself >reduced the number of languages you have to know by one. > >> BIG SMILE... > >"Just relax and let the hooks do their work." >-- >https://mail.python.org/mailman/listinfo/python-list From Dwight at GoldWinde.com Mon Aug 10 21:49:01 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Tue, 11 Aug 2015 09:49:01 +0800 Subject: Is Django the way to go for a newbie? In-Reply-To: <55C7E15C.6070003@verizon.net> References: <55C7E15C.6070003@verizon.net> Message-ID: Thank you, Gary, for this new information. I will be looking into virtualenv and vertualenvwrapper. I thought that Django was an IDE. But, it seems that an IDE is one more thing that I need that I didn?t know I needed!? BIG SMILE... Always, Dwight www.3forliving.key.to (video playlist on YouTube) www.couragebooks.key.to (all my books on Amazon) On 08/08/2015 09:08 PM, Dwight GoldWinde wrote: > > I am both new to Python and I haven?t even touched Django yet. > > > > > I understand I that I need Django or something like it to develop my website. > > > > > From what I have read, Python and Django somewhat go together. > > > > > Is that true? > > > > > Or is there another development platform better for someone like me than > Django? > > > > > Any and all feedback or questions are much appreciated. > > > > > > BIG SMILE... > > > > > Always, Dwight > > > > > > > > www.3forliving.key.to (video playlist on > YouTube) > > www.couragebooks.key.to (all my books on > Amazon) > > > > > > > > > > I'm also somewhat of a newbie but seem to be a little further down the road than you are. So hear is some advise from someone with recent bruises. The advise to learn python first is a very good piece of advice. I tried Postgresql and Django first and got bogged down just about the time that I was starting to get past the setup phase. You might try "Learning Python The Hard Way". It's working for me. Django v.s. other frameworks. It depends on what you want to do. I'm working on a data archiving project so the fact that Dango was / is developed by a couple of newspaper journalists fits well with my project. This may not be true for you. I will say that once you set the system up you will probably never see the sql database again. A very good thing. What ever you do set up virtualenv and vertualenvwrapper. Not only will this keep you project code away from the rest of your system, it will allow you to run different versions of software simultaneously. (Note: Unless you are using SQLite your database engine will be installed globally. Everything else inside the wrapper using pip.) There are a lot of scripting languages out there and everyone has a favorite. No matter what Python strikes me as being a good choice. You will need some kind of an Integrated Development Environment (IDE). I happen to like Ninja-Ide. (Don't everyone start throwing rocks. We all have our favorites. An no, I haven't checked them all out.) This is my first programming in some years too. I use to be a whiz at fortran, C and Xbase but haven't done anything since I retired. Good luck Gary R -- https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From Dwight at GoldWinde.com Mon Aug 10 21:53:14 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Tue, 11 Aug 2015 09:53:14 +0800 Subject: Is Django the way to go for a newbie? In-Reply-To: References: <55C790D3.3040906@gmail.com> Message-ID: So many new things to look into! Chris, I now will also investigate i18n. Thank you. BIG SMILE... Always, Dwight www.3forliving.key.to (video playlist on YouTube) www.couragebooks.key.to (all my books on Amazon) On 8/10/15, 9:27 AM, "Chris Angelico" wrote: >On Mon, Aug 10, 2015 at 3:41 AM, Michael Torrie wrote: >> Web development is very a very hard problem, largely because it involves >> quite a few different domain-specific languages that you have to be >> proficient in... >> >> In this area, node.js is getting very popular. I don't care much for >> javascript but using it on the server as well as the web browser itself >> reduced the number of languages you have to know by one. > >There's another thing you absolutely have to know when you do web >development, and that's i18n. This is why I don't recommend Node.js >for server-side work - because Python's Unicode support is better than >JS's. Stick with Python (and avoid Python 2 on Windows) and you get >great Unicode support. Do anything in JavaScript/ECMAScript and you >get UTF-16 as the official representation. What's the length of the >string "Hello, world"? > >>>> len("Hello, world") >12 > >> "Hello, world".length >12 > >So far, so good. What if those weren't ASCII characters? > >>>> len("?????, ?????") >12 > >(That's Python 3. In Python 2, you'd need to put a u"" prefix on the >string, but it's otherwise the same, modulo the Windows narrow-build >issue.) > >> "?????, ?????".length >22 > >ECMAScript stipulates that strings are not codepoints, but UTF-16 code >units, so whenever you work with astral characters (which includes a >lot of emoticons, Chinese characters, and other symbols that your end >users *will* use), they'll get things wrong. The length of the string >counts astral characters twice; indexing/slicing can take half of a >character; any manipulation at all could corrupt your data. > >So, use Python for all your text processing. Life's better that way. > >ChrisA >-- >https://mail.python.org/mailman/listinfo/python-list From Dwight at GoldWinde.com Mon Aug 10 22:15:05 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Tue, 11 Aug 2015 10:15:05 +0800 Subject: Importing is partially working... In-Reply-To: References: Message-ID: Such a simple change, I wouldn?t think it would work. But it did. You suggested "from Functions import humprint? instead of "from Functions.py import humprint?. Thank you, Chris! Now I can define functions all over the place. LOL? BIG SMILE... Always, Dwight www.3forliving.key.to (video playlist on YouTube) www.couragebooks.key.to (all my books on Amazon) On 8/10/15, 6:11 PM, "Chris Angelico" wrote: >from Functions import humprint From steve at pearwood.info Mon Aug 10 22:40:42 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 11 Aug 2015 12:40:42 +1000 Subject: Importing is partially working... References: Message-ID: <55c960aa$0$1668$c3e8da3$5496439d@news.astraweb.com> On Tue, 11 Aug 2015 01:48 am, MRAB wrote: > On Windows, the extension for Python extension DLLs is ".pyd". I believe that there is a subtle difference in the entry-point depending on whether the file is named .pyd or .dll. http://effbot.org/pyfaq/is-a-pyd-file-the-same-as-a-dll.htm https://docs.python.org/2/faq/windows.html#is-a-pyd-file-the-same-as-a-dll I'm not entirely sure, but I think the only way to access a DLL proper is via cytpes (or some other third-party framework, like Boost or SWIG). To actually use "import spam" on a DLL, you have to make sure it has an initfoo() function, and declare the list of available functions somewhat differently. Oh, and according to this: https://docs.python.org/2/extending/windows.html prior to Python 2.5, spam.dll was recognised by import. That was specifically changed so that you could have a spam.dll C library and a spam.pyd interface to that library. -- Steven From breamoreboy at yahoo.co.uk Mon Aug 10 23:10:55 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 11 Aug 2015 04:10:55 +0100 Subject: Is Django the way to go for a newbie? In-Reply-To: References: <55C790D3.3040906@gmail.com> Message-ID: On 11/08/2015 02:53, Dwight GoldWinde wrote: [snipped] Pleased to see that you're getting answers, but would you please not top post here. Trying to follow long threads is particularly difficult when you have the response at the top, but have to scroll down to find what it's in response to. Thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From kmisoft at gmail.com Mon Aug 10 23:22:16 2015 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Mon, 10 Aug 2015 23:22:16 -0400 Subject: looking for standard/builtin dict-like data object Message-ID: Hi, In my code I often use my own home-brewed object for passing bunch of data between functions. Something like: class Data(object): def __init__ (self, **kwargs): self.__dict__ = kwargs .... return Data(attr1=..., attr2=..., attr3=...) Logically it works like plain dictionary but with nice result.attrX syntax on client side (instead of resut['attrX']). Overall I am pretty happy with this approach except that I need to drag Data class around my projects and import its module in every code producing data. I am curious if anybody knows similar "dummy" class located in standard libraries? I'd be glad to use it instead. Thanks, Vladimir https://itunes.apple.com/us/app/python-code-samples/id1025613117 From torriem at gmail.com Mon Aug 10 23:29:22 2015 From: torriem at gmail.com (Michael Torrie) Date: Mon, 10 Aug 2015 21:29:22 -0600 Subject: Is Django the way to go for a newbie? In-Reply-To: References: <55C7E15C.6070003@verizon.net> Message-ID: <55C96C12.8040504@gmail.com> On 08/10/2015 07:49 PM, Dwight GoldWinde wrote: > Thank you, Gary, for this new information. > > I will be looking into virtualenv and vertualenvwrapper. > > I thought that Django was an IDE. But, it seems that an IDE is one more > thing that I need that I didn?t know I needed!? Django is a programming _library_ (also called a framework) that makes web development easier/possible in Python (well it's some tools as well as a library). Basically check out the introductory documents at their website: https://www.djangoproject.com/start/ Depending on your definition of IDE, many Python programmers and Django developers don't use an IDE at all, but just a nice programmer's text editor. Many people enjoy using the commercial Sublime Text editor. Personally I use ViM. An IDE could be useful for doing web development in Django, with code completion as Django has many sub libraries and lots of APIs to remember. Do a search for Python IDEs. Some are free, some are not. From clp2 at rebertia.com Mon Aug 10 23:36:00 2015 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 10 Aug 2015 20:36:00 -0700 Subject: looking for standard/builtin dict-like data object In-Reply-To: References: Message-ID: On Mon, Aug 10, 2015 at 8:22 PM, Vladimir Ignatov wrote: > Hi, > > In my code I often use my own home-brewed object for passing bunch of > data between functions. Something like: > > class Data(object): > def __init__ (self, **kwargs): > self.__dict__ = kwargs > > .... > > return Data(attr1=..., attr2=..., attr3=...) > > Logically it works like plain dictionary but with nice result.attrX > syntax on client side (instead of resut['attrX']). Overall I am > pretty happy with this approach except that I need to drag Data class > around my projects and import its module in every code producing data. > > I am curious if anybody knows similar "dummy" class located in > standard libraries? I'd be glad to use it instead. This is commonly known as a "Bunch" class, after the Python Cookbook recipe. I don't believe there's any public version of it in the std lib, but there is a PyPI package for it: https://pypi.python.org/pypi/bunch However, if the set of attribute names is fixed and an immutable datatype is acceptable, you could use the std lib's "namedtuple" type: https://docs.python.org/3/library/collections.html#collections.namedtuple Cheers, Chris -- http://chrisrebert.com From cs at zip.com.au Mon Aug 10 23:40:49 2015 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 11 Aug 2015 13:40:49 +1000 Subject: looking for standard/builtin dict-like data object In-Reply-To: References: Message-ID: <20150811034049.GA30067@cskk.homeip.net> On 10Aug2015 23:22, Vladimir Ignatov wrote: >In my code I often use my own home-brewed object for passing bunch of >data between functions. Something like: > >class Data(object): > def __init__ (self, **kwargs): > self.__dict__ = kwargs >.... > >return Data(attr1=..., attr2=..., attr3=...) > >Logically it works like plain dictionary but with nice result.attrX >syntax on client side (instead of resut['attrX']). Overall I am >pretty happy with this approach except that I need to drag Data class >around my projects and import its module in every code producing data. I've got a base class called "O" like that: https://pypi.python.org/pypi/cs.obj/ >I am curious if anybody knows similar "dummy" class located in >standard libraries? I'd be glad to use it instead. namedtuple initialises and accesses like that: >>> from collections import namedtuple >>> Klass = namedtuple('Klass', 'a b c') >>> o1 = Klass(1,2,3) >>> o1 O(a=1, b=2, c=3) >>> o1.b 2 >>> o2 = Klass(a=1,c=3,b=2) >>> o2 O(a=1, b=2, c=3) namedtuple makes a factory for making particular flavours. And the result us a tuple, not a dict. I also thought the stdlib had some kind of "namespace" class with this kind of API, but I can't find it now:-( Cheers, Cameron Simpson Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Martin Golding, DoD #0236, martin at plaza.ds.adp.com From rustompmody at gmail.com Tue Aug 11 00:08:22 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 10 Aug 2015 21:08:22 -0700 (PDT) Subject: Is Django the way to go for a newbie? In-Reply-To: References: <55C7E15C.6070003@verizon.net> Message-ID: <6f2dc159-146b-44b8-b72e-fa34c4dc43cf@googlegroups.com> On Tuesday, August 11, 2015 at 8:59:47 AM UTC+5:30, Michael Torrie wrote: > On 08/10/2015 07:49 PM, Dwight GoldWinde wrote: > > Thank you, Gary, for this new information. > > > > I will be looking into virtualenv and vertualenvwrapper. > > > > I thought that Django was an IDE. But, it seems that an IDE is one more > > thing that I need that I didn?t know I needed!? > > Django is a programming _library_ (also called a framework) Please dont conflate library and framework. Library, framework, DSL are different approaches for solving similar problems. I personally tend to prefer DSL's, dislike frameworks and am neutral to libraries. Which is why I would tend to start with flask + template-language + ORM rather than start with a framework. Others may have for very good reasons different preferences and that is fine?. But if you say equate all these, discussion becomes a mess. ----------------- ? html + js + css is a good example of how/why the DSL approach can lead to a mess. Curl shows a better way https://en.wikipedia.org/wiki/Curl_%28programming_language%29 aside from the politics From rosuav at gmail.com Tue Aug 11 00:09:51 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Aug 2015 14:09:51 +1000 Subject: looking for standard/builtin dict-like data object In-Reply-To: <20150811034049.GA30067@cskk.homeip.net> References: <20150811034049.GA30067@cskk.homeip.net> Message-ID: On Tue, Aug 11, 2015 at 1:40 PM, Cameron Simpson wrote: > I also thought the stdlib had some kind of "namespace" class with this kind > of API, but I can't find it now:-( It does - types.SimpleNamespace(). It accepts keyword arguments, and will let you create more attributes on the fly (unlike a namedtuple). ChrisA From cs at zip.com.au Tue Aug 11 00:28:07 2015 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 11 Aug 2015 14:28:07 +1000 Subject: looking for standard/builtin dict-like data object In-Reply-To: References: Message-ID: <20150811042807.GA56342@cskk.homeip.net> On 11Aug2015 14:09, Chris Angelico wrote: >On Tue, Aug 11, 2015 at 1:40 PM, Cameron Simpson wrote: >> I also thought the stdlib had some kind of "namespace" class with this kind >> of API, but I can't find it now:-( > >It does - types.SimpleNamespace(). It accepts keyword arguments, and >will let you create more attributes on the fly (unlike a namedtuple). Yes, that's it. Thanks! Cheers, Cameron Simpson Ed Campbell's pointers for long trips: 6. *NEVER* trust anyone in a cage, if they weren't nuts they'd be on a bike like everyone else. From orgnut at yahoo.com Tue Aug 11 00:48:12 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Mon, 10 Aug 2015 21:48:12 -0700 Subject: Pipes In-Reply-To: <2ZWdnZJUbYdxkVTInZ2dnUU7-I-dnZ2d@earthlink.com> References: <2ZWdnZJUbYdxkVTInZ2dnUU7-I-dnZ2d@earthlink.com> Message-ID: On 08/10/2015 01:43 PM, E.D.G. wrote: [snip] > It has been my experience that researchers, particularly scientists, need to have some > versatile and powerful programming language available that is compatible with the Windows > operating system. The language needs to make certain resources available to the researchers. > And in some form it should ultimately be compatible with other operating systems. [snip] This is just a comment that may or may not be worthwhile... I just ran across a new O'Reilly book, Effective Computation in Physics (subtitle: Field Guide to Research with Python), ISBN: 978-1-491-90153-3. It seems to cover all the subjects you bring up, and specifically uses Python. I have only glanced through it and I'm not ready to comment on it myself -- (Aside: I was once a physics major (unfortunately unsuccessful), but that was a loooooonnngg time ago.) But quoting the blurb on the back cover... More physicists today are taking on the role of software development as part of their research, but software development isn't always easy or obvious, even for physicists. This practical book teaches essential software development skills to help you automate and accomplish nearly any aspect of research in a physics-based field. Written by two PhDs in nuclear engineering, this book includes practical examples drawn from a working knowledge of physics concepts. You'll learn now to use the Python programming language to perform everything from collecting and analyzing data to building software and publishing your results. I don't know if a book is relevant to your needs, but I thought it was worth mentioning. -=- Larry -=- From smahabole at google.com Tue Aug 11 02:28:13 2015 From: smahabole at google.com (smahabole at google.com) Date: Mon, 10 Aug 2015 23:28:13 -0700 (PDT) Subject: Flan definition collision Message-ID: <238cfbd9-6ccb-4dcf-a4ea-3de78932db02@googlegroups.com> I am importing two modules, each of which is defining flags (command line arguments) with the same name. This makes it impossible to import both the modules at once, because of flag name definition conflict. Is there any way which doesn't involve modifying the flag names in these modules? From lac at openend.se Tue Aug 11 05:07:57 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 11 Aug 2015 11:07:57 +0200 Subject: Pipes In-Reply-To: Message from "E.D.G." of "Mon, 10 Aug 2015 15:43:26 -0500." <2ZWdnZJUbYdxkVTInZ2dnUU7-I-dnZ2d@earthlink.com> References: <2ZWdnZJUbYdxkVTInZ2dnUU7-I-dnZ2d@earthlink.com> Message-ID: <201508110907.t7B97v7o024034@fido.openend.se> In a message of Mon, 10 Aug 2015 15:43:26 -0500, "E.D.G." writes: > I needed a program that could generate data regarding the locations >of the sun and the moon in the sky in response to specific times entered. >Roger developed the basic equations with some help from another researcher. >And that took a while. But it probably took a full six months for us to >compare notes by E-mail and get the program into a final form that people >could download for free use. I see a pattern here. You and Roger keep coming up with cool ideas, but neglect to check if _somebody else already had them_ and if we already have a Python package that does what you want to do. We've got, for instance, PyEphem http://rhodesmill.org/pyephem/tutorial.html and if that doesn't already do what you want, well there are other choices that astronomers are using all the time, right now. Wrapping a giu around PyEphem, if that is what you want is a job that can be measured in hours or days if you are a proficient Python programmer. > That is just too much time. Researchers need to be able to do things >such as create simple charts etc. without spending months or years learning >some programming language or comparing notes with one another. So, an >entire Python directory that made that possible and that had clear >instructions for how to open and close files and create "pipes" etc. would >get the job done. We've already got this with the Scientific Python distribution. For more than 20 years, thousands, tens of thousands of scientist-python programmers have been beavering away writing solutions to the problems you mention and others that are, as you say, deeply important to them. I am sorry that you came to this party late, but the good news is that you should be able to get what you want with a whole lot less work than you think. What you need to do is familiarise yourself with what we already got, instead of assuming that because you don't know about them, they don't exist. One of the ways to do this is to join scientific python mailing lists. **This list isn't one of them.** Scientists who use Python mostly _do not hang out here_. I'd join Scipy-Users: http://www.scipy.org/scipylib/mailing-lists.html or hang out on the freenode irc channel #scipy and tell the people both places that you are new to python and are looking for an overview of what there is out there. Maybe post the same thing to the Anaconda Google group. https://groups.google.com/a/continuum.io/forum/?fromgroups#!forum/anaconda The scientists in all of these places are going to give you better answers for how to familiarise yourself with their ecosystem than I can -- they _live_ there, and I just vist sometimes. > > If Roger wants to use Python then we might use the ActiveState >version and then build those various resources into it. It reportedly >installs in a Windows environment without problems. And I myself have used >the ActiveState versions of Perl for quite a few years with a considerable >amount of success. If you want to write more tutorials about how to use the various Python resources we already have, then more power to you, we always need more of that. But if you plan on redoing stuff we already have a way to do, then you are likely to be ignored. The usual thing to do is to join some existing Python project, and contribute your ideas and code to it. So, since you are interested in graphics you might join the matplotlib group. Or you might join the bokeh group. It's not impossible to start your own project -- the bokeh people did, after all, but this pretty much only works if you address a real problem that isn't being met by the existing libraries. For instance, the bokeh people wanted to make an interactive visualisation library that targets modern web browsers. It sounds like you are interested in that as well, but the bokeh people are way, way, way ahead of you in that business. There are more of them, and they have been writing code to improve how they do things every day now since 2012 (at least that what their license says). So you aren't going to catch them with your new project. If it turns out they are unable to do something that you need, the thing to do is to join the project and help them by implementing that stuff so it can be added to the library. > This assumes that the ActiveState version of Python can be taught to >do fast calculations and to generate charts. If that does not look possible >or easy then we will probably try one of the available scientific versions >of Python. You are misunderstanding something here. You don't need to teach ActiveState Python to do fast calculations and generate charts. Somebody already has done this, in a variety of ways, some of which have worked for more than a decade, I think more than 15 years now. And that is where numpy comes in -- this is one of the ways to teach Python to do faster calculations. So is Cython. So is Numba. The reason you would go for a scientific version of python, as opposed to ActiveStates is because you will conveniently have most of the tools that you need for generating charts and doing fast calculations already there. You can add them individually one at a time to ActiveState's Python, but that is just more work for you. But the real reason that you need to start playing with and using a scientific version of Python and, for instance bokeh and matplotlib is to get a sense of what it is we already can do, and are doing right now so you don't waste your time writing 'a poor man's version of X' because you didn't know that X existed in the first place. Coming back with 'well, ActiveState's Python didn't do this, so I didn't know it was there' isn't going to cut it. ActiveState is not in the business of producing Python distributiuons for Scientists. Enthought and Continuum Analytics are. Laura From lac at openend.se Tue Aug 11 05:15:43 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 11 Aug 2015 11:15:43 +0200 Subject: Is Django the way to go for a newbie? In-Reply-To: Message from Dwight GoldWinde of "Tue, 11 Aug 2015 09:49:01 +0800." References: <55C7E15C.6070003@verizon.net> Message-ID: <201508110915.t7B9FhRZ025840@fido.openend.se> In a message of Tue, 11 Aug 2015 09:49:01 +0800, Dwight GoldWinde writes: >Thank you, Gary, for this new information. > >I will be looking into virtualenv and vertualenvwrapper. > >I thought that Django was an IDE. But, it seems that an IDE is one more >thing that I need that I didn?t know I needed!? > > >BIG SMILE... > >Always, Dwight An IDE is a convenience, and some people swear by them and couldn't live without them. An enormous number of people do without, though and just use an editor (one that is designed for code, naturally, such as emacs or VIM and not, OpenOffice or Notepad) instead. Laura From lac at openend.se Tue Aug 11 05:58:22 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 11 Aug 2015 11:58:22 +0200 Subject: Pipes In-Reply-To: Message from Laura Creighton of "Tue, 11 Aug 2015 11:07:57 +0200." <201508110907.t7B97v7o024034@fido.openend.se> References: <2ZWdnZJUbYdxkVTInZ2dnUU7-I-dnZ2d@earthlink.com><201508110907.t7B97v7o024034@fido.openend.se> Message-ID: <201508110958.t7B9wMxf002193@fido.openend.se> The O'Reilly book Effective Computation in Physics that Larry Hudson recommended looks really good. It also occurs to me that another way to get familiar with the scientific python world is to attend a Scientific Python conference. EuroSciPy is the end of this month in Cambridge. https://www.euroscipy.org/2015/ The US conference for 2015 was in July, so you missed it, but there will be one next year. I just don't know when. There is one in India in December. http://scipy.in/2015 The next Latin America conference is in Brazil in May 2016. I may have missed some conferences. Good luck, Laura From mail at timgolden.me.uk Tue Aug 11 06:15:12 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 11 Aug 2015 11:15:12 +0100 Subject: Pipes In-Reply-To: <201508110958.t7B9wMxf002193@fido.openend.se> References: <2ZWdnZJUbYdxkVTInZ2dnUU7-I-dnZ2d@earthlink.com><201508110907.t7B97v7o024034@fido.openend.se> <201508110958.t7B9wMxf002193@fido.openend.se> Message-ID: <55C9CB30.2080403@timgolden.me.uk> On 11/08/2015 10:58, Laura Creighton wrote: > The O'Reilly book Effective Computation in Physics that Larry Hudson > recommended looks really good. It also occurs to me that another way > to get familiar with the scientific python world is to attend a > Scientific Python conference. EuroSciPy is the end of this month in > Cambridge. https://www.euroscipy.org/2015/ > > The US conference for 2015 was in July, so you missed it, but there > will be one next year. I just don't know when. > There is one in India in December. http://scipy.in/2015 > The next Latin America conference is in Brazil in May 2016. > > I may have missed some conferences. This September's PyConUK has a science track: http://www.pyconuk.org/science/ TJG From joel.goldstick at gmail.com Tue Aug 11 06:31:51 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 11 Aug 2015 06:31:51 -0400 Subject: Flan definition collision In-Reply-To: <238cfbd9-6ccb-4dcf-a4ea-3de78932db02@googlegroups.com> References: <238cfbd9-6ccb-4dcf-a4ea-3de78932db02@googlegroups.com> Message-ID: On Tue, Aug 11, 2015 at 2:28 AM, smahabole--- via Python-list wrote: > I am importing two modules, each of which is defining flags (command line arguments) with the same name. This makes it impossible to import both the modules at once, because of flag name definition conflict. Is there any way which doesn't involve modifying the flag names in these modules? Please show relevant code. import a import b will not cause a collision as a variable called v would be identified as a.v or b.v depending on where it is defined -- Joel Goldstick http://joelgoldstick.com From otlucaDELETE at DELETEyahoo.it Tue Aug 11 07:29:08 2015 From: otlucaDELETE at DELETEyahoo.it (Luca Menegotto) Date: Tue, 11 Aug 2015 13:29:08 +0200 Subject: Flan definition collision References: <238cfbd9-6ccb-4dcf-a4ea-3de78932db02@googlegroups.com> Message-ID: Il 11/08/2015 08:28, smahabole at google.com ha scritto: > I am importing two modules, each of which is defining flags > (command line arguments) with the same name. This makes > it impossible to import both the modules at once, because of flag > name definition conflict. > If you use 'import', and not 'from xyz import', you avoid any conflict. Ah: 'from ... import' has caused me a lot of terrible headaches. I don't use this statement if not strictly necessary. -- Bye. Luca From frank at chagford.com Tue Aug 11 07:33:31 2015 From: frank at chagford.com (Frank Millman) Date: Tue, 11 Aug 2015 13:33:31 +0200 Subject: Data integrity problem with sqlite3 Message-ID: Hi all I have a 'data integrity' problem with sqlite3 that I have been battling with for a while. I have not got to the bottom of it yet but I do have some useful info, so I thought I would post it here in the hope that someone with some knowledge of the internals of the python sqlite3 module can throw some light on it. I am running python 3.4.3 on Windows 7, and I have upgraded sqlite from the original '3.7.something' to '3.8.6'. I do not change the isolation level from the default setting. I have a transaction with a number of steps. One of the later steps raises an exception, and I execute a rollback. However, some of the earlier steps are committed to the database. Obviously this is a major problem. I have added 'set_trace_callback' to see exactly what is going on, and in the middle of my series of commands I find the following - COMMIT BEGIN IMMEDIATE According to the docs, the sqlite3 module commits transactions implicitly before a non-DML, non-query statement (i. e. anything other than SELECT/INSERT/UPDATE/DELETE/REPLACE). In my traceback I can only see SELECTs and UPDATEs following the implicit commit, so I do not know what is triggering it. I am trying to reproduce the problem in a simpler example, but so far without success. My running program has two connections to the database open, another connection to an in-memory database, and it is all running under asyncio, so it is quite difficult to mimic all of this. I will persevere, but in the meantime, does anyone happen to know under what other circumstances sqlite3 might issue an implicit commit? Thanks Frank Millman From rosuav at gmail.com Tue Aug 11 07:43:59 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Aug 2015 21:43:59 +1000 Subject: Data integrity problem with sqlite3 In-Reply-To: References: Message-ID: On Tue, Aug 11, 2015 at 9:33 PM, Frank Millman wrote: > I have added 'set_trace_callback' to see exactly what is going on, and in > the middle of my series of commands I find the following - > > COMMIT > BEGIN IMMEDIATE > > According to the docs, the sqlite3 module commits transactions implicitly > before a non-DML, non-query statement (i. e. anything other than > SELECT/INSERT/UPDATE/DELETE/REPLACE). > > In my traceback I can only see SELECTs and UPDATEs following the implicit > commit, so I do not know what is triggering it. I am trying to reproduce the > problem in a simpler example, but so far without success. My running program > has two connections to the database open, another connection to an in-memory > database, and it is all running under asyncio, so it is quite difficult to > mimic all of this. > > I will persevere, but in the meantime, does anyone happen to know under what > other circumstances sqlite3 might issue an implicit commit? > Not sure if it'll actually *solve* your problem, but it might help you to find out more about what's going on... Try switching to PostgreSQL. Among the key differences are (a) transactional DDL, which means you won't get those implicit commits, and (b) server-side logging, so you might get a different window into what your code is doing. Personally, I use Postgres as much as possible, but in your situation, it might be better for you to continue using sqlite3 in production. But for the purposes of debugging, it should be worth a try. ChrisA From uri at speedy.net Tue Aug 11 07:55:56 2015 From: uri at speedy.net (Uri Even-Chen) Date: Tue, 11 Aug 2015 14:55:56 +0300 Subject: pyjs - a compiler from Python to JavaScript In-Reply-To: References: Message-ID: Thanks for the feedback. Actually I asked this question also in the django-users mailing list and Russell Keith-Magee told me about Brython, Skulpt and PyPy.js (I hope it's OK that I reply to these 3 mailing lists) but I also asked if I can use JavaScript scripts such as jQuery, jQuery UI and other jQuery plugins from the scripts in Python and Russell said it's possible but not practical for production. And I'm thinking about developing Speedy Mail Software or other projects for production (of course after the alpha & beta are over) so I guess we are stuck with JavaScript for the client side programming. And I don't mind if they use a compiler or an interpreter or any other method to run Python in the client side, as long as it works. But without using jQuery and other plugins it would be very hard to use these projects in production. Uri. *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 Email: uri at speedy.net Website: http://www.speedysoftware.com/uri/en/ > Speedypedia in Hebrew and English On Mon, Aug 10, 2015 at 7:40 PM, Ian Kelly wrote: > On Fri, Aug 7, 2015 at 5:00 AM, Uri Even-Chen wrote: > > > > Are you familiar with pyjs? I saw the website and I see that the latest > stable release is from May 2012. Is it possible to use pyjs to compile > Python to JavaScript? Which versions of Python are supported? Are versions > 2.7 and 3.4 supported? And is it possible to use Django (in the client > side) and JavaScript frameworks such as jQuery, jQuery UI and jQuery > plugins together with pyjs? > > And if you check the commit history on GitHub, there are only two > commits in the past year. The project was hijacked (i.e. forked plus > "we're taking the domain name and the mailing list too") a few years > ago (also in May 2012, I think not coincidentally), and that sadly > seems to have slowly killed the development momentum on the project. > > I'm not really familiar with the space, but I tend to hear good things > about Brython. PyPy.js and Skulpt are other alternatives. However, I > think that all of these are implementations of Python in Javascript, > not Python to Javascript compilers. > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kmisoft at gmail.com Tue Aug 11 08:06:05 2015 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Tue, 11 Aug 2015 08:06:05 -0400 Subject: looking for standard/builtin dict-like data object In-Reply-To: <20150811042807.GA56342@cskk.homeip.net> References: <20150811042807.GA56342@cskk.homeip.net> Message-ID: >>> I also thought the stdlib had some kind of "namespace" class with this >>> kind >>> of API, but I can't find it now:-( >> >> >> It does - types.SimpleNamespace(). It accepts keyword arguments, and >> will let you create more attributes on the fly (unlike a namedtuple). > > > Yes, that's it. Thanks! > Ah, sad, sad, sad. We unfortunately stuck with built-in Python 2.6.x in our system. I see from docs that SimpleNamespace is rather new creation (3.3+). I know 'namedtuple' way, but don't like it as I prefer freedom in attribute creation/mutation. Looks like I have to stuck with handmade solution for now. Anyway - thanks a lot for everybody! Vladimir https://itunes.apple.com/us/app/python-code-samples/id1025613117 From rosuav at gmail.com Tue Aug 11 08:11:14 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Aug 2015 22:11:14 +1000 Subject: looking for standard/builtin dict-like data object In-Reply-To: References: <20150811042807.GA56342@cskk.homeip.net> Message-ID: On Tue, Aug 11, 2015 at 10:06 PM, Vladimir Ignatov wrote: >>>> I also thought the stdlib had some kind of "namespace" class with this >>>> kind >>>> of API, but I can't find it now:-( >>> >>> >>> It does - types.SimpleNamespace(). It accepts keyword arguments, and >>> will let you create more attributes on the fly (unlike a namedtuple). >> >> >> Yes, that's it. Thanks! >> > > Ah, sad, sad, sad. We unfortunately stuck with built-in Python 2.6.x > in our system. I see from docs that SimpleNamespace is rather new > creation (3.3+). I know 'namedtuple' way, but don't like it as I > prefer freedom in attribute creation/mutation. Looks like I have to > stuck with handmade solution for now. > In that case, what I would recommend is: Use your handmade solution, but call it SimpleNamespace, and make it entirely compatible with the Python 3.3 one. Then, when you do get a chance to upgrade, all you need to do is change your import statement, and you're using the standard library one. Plus, it's going to be easy for anyone else to read - they'll already know what SimpleNamespace does and what to expect of it, so they don't have to dig around to see what your class is doing. ChrisA From frank at chagford.com Tue Aug 11 08:37:38 2015 From: frank at chagford.com (Frank Millman) Date: Tue, 11 Aug 2015 14:37:38 +0200 Subject: Data integrity problem with sqlite3 In-Reply-To: References: Message-ID: "Chris Angelico" wrote in message news:CAPTjJmrHmj2bsdSm4CQ=oRGxuTmycTk3W3e3n-QXoLg2TVQMbA at mail.gmail.com... On Tue, Aug 11, 2015 at 9:33 PM, Frank Millman wrote: > > I have added 'set_trace_callback' to see exactly what is going on, and > > in > > the middle of my series of commands I find the following - > > > > COMMIT > > BEGIN IMMEDIATE > > > > According to the docs, the sqlite3 module commits transactions > > implicitly > > before a non-DML, non-query statement (i. e. anything other than > > SELECT/INSERT/UPDATE/DELETE/REPLACE). > > > > In my traceback I can only see SELECTs and UPDATEs following the > > implicit > > commit, so I do not know what is triggering it. I am trying to reproduce > > the > > problem in a simpler example, but so far without success. My running > > program > > has two connections to the database open, another connection to an > > in-memory > > database, and it is all running under asyncio, so it is quite difficult > > to > > mimic all of this. > > > > I will persevere, but in the meantime, does anyone happen to know under > > what > > other circumstances sqlite3 might issue an implicit commit? > > > > Not sure if it'll actually *solve* your problem, but it might help you > to find out more about what's going on... Try switching to PostgreSQL. > Among the key differences are (a) transactional DDL, which means you > won't get those implicit commits, and (b) server-side logging, so you > might get a different window into what your code is doing. > > Personally, I use Postgres as much as possible, but in your situation, > it might be better for you to continue using sqlite3 in production. > But for the purposes of debugging, it should be worth a try. > My PostgreSQL is inaccessible at the moment as I am moving machines around, but I have tested it with MS SQL Server, and it behaves as expected ? the transaction is fully rolled back and nothing is committed to the database. BTW, I am not using sqlite3 ?in production?. Rather, I offer a choice of 3 databases to my users ? PostgreSQL, SQL Server, and sqlite3, so I have to make sure that my program works with all of them. Frank From rosuav at gmail.com Tue Aug 11 08:44:06 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Aug 2015 22:44:06 +1000 Subject: Data integrity problem with sqlite3 In-Reply-To: References: Message-ID: On Tue, Aug 11, 2015 at 10:37 PM, Frank Millman wrote: > My PostgreSQL is inaccessible at the moment as I am moving machines around, > but I have tested it with MS SQL Server, and it behaves as expected ? the > transaction is fully rolled back and nothing is committed to the database. Does MS SQL offer any hints in its logs? Can you enable full statement logging, and then grep it for anything that doesn't begin INSERT or UPDATE or SELECT? > BTW, I am not using sqlite3 ?in production?. Rather, I offer a choice of 3 > databases to my users ? PostgreSQL, SQL Server, and sqlite3, so I have to > make sure that my program works with all of them. Ah. Comes to the same thing, anyway; if you can't get enough info out of one backend, verify it with the others. ChrisA From frank at chagford.com Tue Aug 11 09:17:44 2015 From: frank at chagford.com (Frank Millman) Date: Tue, 11 Aug 2015 15:17:44 +0200 Subject: Data integrity problem with sqlite3 - solved In-Reply-To: References: Message-ID: "Frank Millman" wrote in message news:mqcmie$po9$1 at ger.gmane.org... > Hi all > > I have a 'data integrity' problem with sqlite3 that I have been battling > with for a while. I have not got to the bottom of it yet but I do have > some useful info, so I thought I would post it here in the hope that > someone with some knowledge of the internals of the python sqlite3 module > can throw some light on it. Oops, I have just spotted my mistake. There are times when I want to issue a SELECT statement with a lock, as it will be followed by an UPDATE and I do not want anything to change in between. MS SQL Server allows you to add 'WITH (UPDLOCK)' to a SELECT statement, PostgreSQL allows you to add 'FOR UPDATE'. I could not find an equivalent for sqlite3, but in my wisdom (this was some time ago) I decided that issuing a 'BEGIN IMMEDIATE' would do the trick. I had not anticipated that this would generate an implied COMMIT first, but it makes sense, and this is what has bitten me. Now I must try to figure out a better solution. Apologies for any wasted time. Frank From mal at europython.eu Tue Aug 11 11:10:59 2015 From: mal at europython.eu (M.-A. Lemburg) Date: Tue, 11 Aug 2015 17:10:59 +0200 Subject: EuroPython 2015: Videos are online Message-ID: <55CA1083.7010701@europython.eu> Thanks to our Media Work Group (WG) and especially Anthon and Luis, the conference videos are now cut, edited and uploaded to our YouTube channel as well as our archive.org collection: http://europython.tv http://archive.europython.tv A total of 173 talk videos were processed, so there?s a lot of interesting content to watch. The talk videos are also embedded into the talk pages referenced in our session list for easy navigation: https://ep2015.europython.eu/en/events/sessions/ Two short examples from the popular lightning talks sessions: * Storing acorns https://www.youtube.com/watch?v=WmvTfUYJ2Bw&feature=youtu.be&t=48m25s * The -ish library https://www.youtube.com/watch?v=LQSWi3QJV8s&t=59m28s These are some short links for easy access: * http://europython.tv - for our YouTube channel * http://ep2015.europython.tv - for the EuroPython 2015 playlist * http://archive.europython.tv - for our archive.org collection Enjoy, -- EuroPython 2015 Team http://ep2015.europython.eu/ http://www.europython-society.org/ From chris at simplistix.co.uk Tue Aug 11 13:10:06 2015 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 11 Aug 2015 18:10:06 +0100 Subject: testfixtures 4.2.0 Released! Message-ID: <55CA2C6E.20608@simplistix.co.uk> Hi All, I'm pleased to announce the release of testfixtures 4.2.0. This is a feature release that fixes the following: - A new MockPopen mock for use when testing code that uses subprocess.Popen. - ShouldRaiss now subclasses object, so that subclasses of it may use super(). - Support for Python 3.2 has been officially dropped. Thanks to BATS Global Markets for donating the code for MockPopen. The package is on PyPI and a full list of all the links to docs, issue trackers and the like can be found here: http://www.simplistix.co.uk/software/python/testfixtures Any questions, please do ask on the Testing in Python list or on the Simplistix open source mailing list... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From fabiofz at gmail.com Tue Aug 11 13:54:26 2015 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 11 Aug 2015 14:54:26 -0300 Subject: pyjs - a compiler from Python to JavaScript In-Reply-To: References: Message-ID: On Tue, Aug 11, 2015 at 8:55 AM, Uri Even-Chen wrote: > Thanks for the feedback. Actually I asked this question also in the > django-users mailing list and Russell Keith-Magee told me about > Brython, Skulpt and PyPy.js (I hope it's OK that I reply to these 3 mailing > lists) but I also asked if I can use JavaScript scripts such as jQuery, > jQuery UI and other jQuery plugins from the scripts in Python and Russell > said it's possible but not practical for production. And I'm thinking about > developing Speedy Mail Software or other projects for production (of course > after the alpha & beta are over) so I guess we are stuck with JavaScript > for the client side programming. And I don't mind if they use a compiler or > an interpreter or any other method to run Python in the client side, as > long as it works. But without using jQuery and other plugins it would be > very hard to use these projects in production. > > Uri. > ?I think that you could try RapydScript: http://rapydscript.pyjeon.com/ Cheers, Fabio -------------- next part -------------- An HTML attachment was scrubbed... URL: From uri at speedy.net Tue Aug 11 14:48:14 2015 From: uri at speedy.net (Uri Even-Chen) Date: Tue, 11 Aug 2015 21:48:14 +0300 Subject: pyjs - a compiler from Python to JavaScript In-Reply-To: References: Message-ID: Thanks Fabio, it's very interesting. Are you related to Pyjeon Software? Do we have to pay to use RapydScript? Is it ready for production? *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 Email: uri at speedy.net Website: http://www.speedysoftware.com/uri/en/ > Speedypedia in Hebrew and English On Tue, Aug 11, 2015 at 8:54 PM, Fabio Zadrozny wrote: > > On Tue, Aug 11, 2015 at 8:55 AM, Uri Even-Chen wrote: > >> Thanks for the feedback. Actually I asked this question also in the >> django-users mailing list and Russell Keith-Magee told me about >> Brython, Skulpt and PyPy.js (I hope it's OK that I reply to these 3 mailing >> lists) but I also asked if I can use JavaScript scripts such as jQuery, >> jQuery UI and other jQuery plugins from the scripts in Python and Russell >> said it's possible but not practical for production. And I'm thinking about >> developing Speedy Mail Software or other projects for production (of course >> after the alpha & beta are over) so I guess we are stuck with JavaScript >> for the client side programming. And I don't mind if they use a compiler or >> an interpreter or any other method to run Python in the client side, as >> long as it works. But without using jQuery and other plugins it would be >> very hard to use these projects in production. >> >> Uri. >> > > > ?I think that you could try RapydScript: http://rapydscript.pyjeon.com/ > > Cheers, > > Fabio > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fabiofz at gmail.com Tue Aug 11 15:08:42 2015 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 11 Aug 2015 16:08:42 -0300 Subject: pyjs - a compiler from Python to JavaScript In-Reply-To: References: Message-ID: Hi Uri, No, I'm not related to it. -- I'm the PyDev/Eclipse maintainer... that already takes a lot of my time ;) It's license is BSD (so, no need to pay). As it's just a way to convert from a Python-like syntax to JavaScript syntax you can even switch to plain JavaScript later on if you want -- in fact, when you debug the code you'll be debugging JavaScript and not Python (it's like CoffeScript but with a Python-like syntax). Cheers, Fabio On Tue, Aug 11, 2015 at 3:48 PM, Uri Even-Chen wrote: > Thanks Fabio, it's very interesting. Are you related to Pyjeon Software? > Do we have to pay to use RapydScript? Is it ready for production? > > > *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 > Email: uri at speedy.net > Website: http://www.speedysoftware.com/uri/en/ > > > > > Speedypedia in Hebrew and English > > > On Tue, Aug 11, 2015 at 8:54 PM, Fabio Zadrozny wrote: > >> >> On Tue, Aug 11, 2015 at 8:55 AM, Uri Even-Chen wrote: >> >>> Thanks for the feedback. Actually I asked this question also in the >>> django-users mailing list and Russell Keith-Magee told me about >>> Brython, Skulpt and PyPy.js (I hope it's OK that I reply to these 3 mailing >>> lists) but I also asked if I can use JavaScript scripts such as jQuery, >>> jQuery UI and other jQuery plugins from the scripts in Python and Russell >>> said it's possible but not practical for production. And I'm thinking about >>> developing Speedy Mail Software or other projects for production (of course >>> after the alpha & beta are over) so I guess we are stuck with JavaScript >>> for the client side programming. And I don't mind if they use a compiler or >>> an interpreter or any other method to run Python in the client side, as >>> long as it works. But without using jQuery and other plugins it would be >>> very hard to use these projects in production. >>> >>> Uri. >>> >> >> >> ?I think that you could try RapydScript: http://rapydscript.pyjeon.com/ >> >> Cheers, >> >> Fabio >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From uri at speedy.net Tue Aug 11 15:22:10 2015 From: uri at speedy.net (Uri Even-Chen) Date: Tue, 11 Aug 2015 22:22:10 +0300 Subject: pyjs - a compiler from Python to JavaScript In-Reply-To: References: Message-ID: Thanks Fabio, we'll check RapydScript and we might use it for Speedy Mail Software as well! I will check with the other developers (which are on the speedy-mail-software list). In the past I had Speedy Mail online from 2000 to 2005 and it was based on a Perl script (Perl was popular in 2000). But since it didn't support Unicode/UTF-8 encoding and didn't have a spam filter I decided to close it in 2005 (after Google introduced Gmail). But I think today it's easier to create software than it was in 2005, and I hope next year we can launch Speedy Mail again, based on the Speedy Mail Software we are developing (which will be free software & open source). I'm looking forward to launching Speedy Mail as an alternative to Gmail. *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 Email: uri at speedy.net Website: http://www.speedysoftware.com/uri/en/ > Speedypedia in Hebrew and English On Tue, Aug 11, 2015 at 10:08 PM, Fabio Zadrozny wrote: > Hi Uri, > > No, I'm not related to it. -- I'm the PyDev/Eclipse maintainer... that > already takes a lot of my time ;) > > It's license is BSD (so, no need to pay). As it's just a way to convert > from a Python-like syntax to JavaScript syntax you can even switch to plain > JavaScript later on if you want -- in fact, when you debug the code you'll > be debugging JavaScript and not Python (it's like CoffeScript but with a > Python-like syntax). > > Cheers, > > Fabio > > On Tue, Aug 11, 2015 at 3:48 PM, Uri Even-Chen wrote: > >> Thanks Fabio, it's very interesting. Are you related to Pyjeon Software? >> Do we have to pay to use RapydScript? Is it ready for production? >> >> >> *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 >> Email: uri at speedy.net >> Website: http://www.speedysoftware.com/uri/en/ >> >> >> >> >> > Speedypedia in Hebrew and English >> >> >> On Tue, Aug 11, 2015 at 8:54 PM, Fabio Zadrozny >> wrote: >> >>> >>> On Tue, Aug 11, 2015 at 8:55 AM, Uri Even-Chen wrote: >>> >>>> Thanks for the feedback. Actually I asked this question also in the >>>> django-users mailing list and Russell Keith-Magee told me about >>>> Brython, Skulpt and PyPy.js (I hope it's OK that I reply to these 3 mailing >>>> lists) but I also asked if I can use JavaScript scripts such as jQuery, >>>> jQuery UI and other jQuery plugins from the scripts in Python and Russell >>>> said it's possible but not practical for production. And I'm thinking about >>>> developing Speedy Mail Software or other projects for production (of course >>>> after the alpha & beta are over) so I guess we are stuck with JavaScript >>>> for the client side programming. And I don't mind if they use a compiler or >>>> an interpreter or any other method to run Python in the client side, as >>>> long as it works. But without using jQuery and other plugins it would be >>>> very hard to use these projects in production. >>>> >>>> Uri. >>>> >>> >>> >>> ?I think that you could try RapydScript: http://rapydscript.pyjeon.com/ >>> >>> Cheers, >>> >>> Fabio >>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From srkunze at mail.de Tue Aug 11 17:47:43 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Tue, 11 Aug 2015 23:47:43 +0200 Subject: Hooking Mechanism when Entering and Leaving a Try Block Message-ID: <55CA6D7F.1060705@mail.de> Hi everybody, is there something like a hook that a Python module could register to in order to 'trace' the entering and leaving of arbitrary try blocks? What is this good for? I am the maintainer of https://pypi.python.org/pypi/xfork . A package for converting a classic sequential program to a parallel one. In order to make sure exception handling basically works the same way as in the sequential implementation, it would be great if I could hook into try blocks. Consider this: try: return 25+fork(b) except: return 11 finally: print('finished') 25+fork(b) is a ResultProxy. That kind of object is basically wraps up operators and evaluate them lazily. In order to preserve sequential/classic exception handling, I would like to evaluate all open/not-already-evaluated result proxies as soon as I enter or leave a try: block. Why when leaving try:? Result proxies might raise exceptions once they evaluate. So, result proxies evaluated outside of their origin try: block, might get caught somewhere else by the wrong exception handler. Why when entering try:? Result proxies might raise exceptions once they evaluate. So, result proxies from before the try: might raise exceptions which in turn might be caught inside the try: by the wrong exception handler. Best, Sven PS: I already looked into the source of CPython and discovered these places: https://github.com/python/cpython/blob/d95bb1adefc7/Python/symtable.c#L947symtable_enter_block https://github.com/python/cpython/blob/d95bb1adefc7/Python/symtable.c#L931 symtable_exit_block Unfortunately, I cannot find anything specific to exception handling in the source. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ltc.hotspot at gmail.com Tue Aug 11 20:01:24 2015 From: ltc.hotspot at gmail.com (Ltc Hotspot) Date: Tue, 11 Aug 2015 17:01:24 -0700 (PDT) Subject: AttributeError Message-ID: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> Hi Everyone, What is the list equivalent to line 12: ncount.sort(reverse=True) count = dict() fname = raw_input("Enter file name: ")# handle = open (fname, 'r')# for line in handle: if line.startswith("From "): address = line.split()[5] line = line.rstrip() count[address] = count.get(address, 0) + 1 for key,val in count.items(): ncount = (key,val) ncount.sort(reverse=True) print key,val Error message, reads: AttributeError, line 12, below : 'tuple' object has no attribute 'sort' Raw data code, available at http://tinyurl.com/ob89r9p Embedded data code, available at http://tinyurl.com/qhm4ppq Visualization URL link, available at http://tinyurl.com/ozzmffy Regards, Hal From kirotawa at gmail.com Tue Aug 11 20:16:40 2015 From: kirotawa at gmail.com (leo kirotawa) Date: Tue, 11 Aug 2015 21:16:40 -0300 Subject: AttributeError In-Reply-To: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> Message-ID: assign using () creates tuple not a list. Tuples have not .sort() method. correct would be: ncount = [key,val] On Tue, Aug 11, 2015 at 9:01 PM, Ltc Hotspot wrote: > Hi Everyone, > > > What is the list equivalent to line 12: ncount.sort(reverse=True) > > > count = dict() > fname = raw_input("Enter file name: ")# > handle = open (fname, 'r')# > for line in handle: > if line.startswith("From "): > address = line.split()[5] > line = line.rstrip() > count[address] = count.get(address, 0) + 1 > > for key,val in count.items(): > ncount = (key,val) > ncount.sort(reverse=True) > print key,val > > > Error message, reads: AttributeError, line 12, below : 'tuple' object has no attribute 'sort' > > Raw data code, available at http://tinyurl.com/ob89r9p > Embedded data code, available at http://tinyurl.com/qhm4ppq > Visualization URL link, available at http://tinyurl.com/ozzmffy > > > Regards, > Hal > -- > https://mail.python.org/mailman/listinfo/python-list -- ---------------------------------------------- Le?nidas S. Barbosa (Kirotawa) blog: corecode.wordpress.com From python at mrabarnett.plus.com Tue Aug 11 20:26:34 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Aug 2015 01:26:34 +0100 Subject: AttributeError In-Reply-To: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> Message-ID: <55CA92BA.7070905@mrabarnett.plus.com> On 2015-08-12 01:01, Ltc Hotspot wrote: > Hi Everyone, > > > What is the list equivalent to line 12: ncount.sort(reverse=True) > > > count = dict() > fname = raw_input("Enter file name: ")# > handle = open (fname, 'r')# > for line in handle: > if line.startswith("From "): > address = line.split()[5] > line = line.rstrip() > count[address] = count.get(address, 0) + 1 > > for key,val in count.items(): > ncount = (key,val) > ncount.sort(reverse=True) > print key,val > > > Error message, reads: AttributeError, line 12, below : 'tuple' object has no attribute 'sort' > > Raw data code, available at http://tinyurl.com/ob89r9p > Embedded data code, available at http://tinyurl.com/qhm4ppq > Visualization URL link, available at http://tinyurl.com/ozzmffy > What are you trying to do? Why are you trying to sort a key/value pair in reverse order? From ltc.hotspot at gmail.com Tue Aug 11 20:43:46 2015 From: ltc.hotspot at gmail.com (Ltc Hotspot) Date: Tue, 11 Aug 2015 17:43:46 -0700 Subject: AttributeError In-Reply-To: <55CA92BA.7070905@mrabarnett.plus.com> References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> Message-ID: The Assignment: I'm trying to write Python code to read through a data file and figure out the distribution by hour of the dat for each message in the data file. Python can pull the hour from the 'From ' line by finding the time and then splitting the string a second time using a colon, i.e., From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 Finally, accumulated the counts for each hour, print out the counts, sorted by hour as shown below: name = raw_input("Enter file:") if len(name) < 1 : name = "mbox-short.txt" handle = open(name) Desired Output: 04 3 06 1 07 1 09 2 10 3 11 6 14 1 15 2 16 4 17 2 18 1 19 1 Raw data code, available at http://tinyurl.com/ob89r9p Embedded data code, available at http://tinyurl.com/qhm4ppq Visualization URL link, available at http://tinyurl.com/ozzmffy Regards, Hal On Tue, Aug 11, 2015 at 5:26 PM, MRAB wrote: > On 2015-08-12 01:01, Ltc Hotspot wrote: > >> Hi Everyone, >> >> >> What is the list equivalent to line 12: ncount.sort(reverse=True) >> >> >> count = dict() >> fname = raw_input("Enter file name: ")# >> handle = open (fname, 'r')# >> for line in handle: >> if line.startswith("From "): >> address = line.split()[5] >> line = line.rstrip() >> count[address] = count.get(address, 0) + 1 >> >> for key,val in count.items(): >> ncount = (key,val) >> ncount.sort(reverse=True) >> print key,val >> >> >> Error message, reads: AttributeError, line 12, below : 'tuple' object has >> no attribute 'sort' >> >> Raw data code, available at http://tinyurl.com/ob89r9p >> Embedded data code, available at http://tinyurl.com/qhm4ppq >> Visualization URL link, available at http://tinyurl.com/ozzmffy >> >> What are you trying to do? Why are you trying to sort a key/value pair in > reverse order? > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Aug 11 20:49:05 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Aug 2015 10:49:05 +1000 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> Message-ID: On Wed, Aug 12, 2015 at 10:43 AM, Ltc Hotspot wrote: > Python can pull the hour from the 'From ' line by finding the time and then > splitting the string a second time using a colon, i.e., From > stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 > > Finally, accumulated the counts for each hour, print out the counts, sorted > by hour as shown below: In that case, you want to sort the entire collection, not a single key-value pair. It seems to me you can do this fairly efficiently with collections.Counter. import collections with open(raw_input("Enter file name: ")) as f: counts = collections.Counter(line.split()[5].rstrip() for line in f if line.startswith("From ")) counts = counts.items() counts.sort() for hour, count in counts: print hour, count The most important part is getting items() and then sorting the whole thing. ChrisA From rosuav at gmail.com Tue Aug 11 20:52:34 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Aug 2015 10:52:34 +1000 Subject: pyjs - a compiler from Python to JavaScript In-Reply-To: References: Message-ID: On Wed, Aug 12, 2015 at 5:08 AM, Fabio Zadrozny wrote: > > As it's just a way to convert from a Python-like syntax to JavaScript syntax you can even switch to plain JavaScript later on if you want -- in fact, when you debug the code you'll be debugging JavaScript and not Python (it's like CoffeScript but with a Python-like syntax). > So, it functions with ECMAScript semantics everywhere? This is an important consideration. A Python integer is not the same as an ECMAScript number (which is a float), and a Python string is not the same as an ECMAScript string, and a Python dictionary has attributes and keys which don't collide. I'm more than a little tickled by the PyPyJS project: http://pypyjs.org/ That's PyPy running in your web browser. The semantics are 100% Python, but... uhh, it does require a fairly hefty download of code before it can do anything. That _is_ a bit of a downside, but it's still a pretty cool project! ChrisA From python at mrabarnett.plus.com Tue Aug 11 20:58:20 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Aug 2015 01:58:20 +0100 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> Message-ID: <55CA9A2C.1040305@mrabarnett.plus.com> On 2015-08-12 01:43, Ltc Hotspot wrote: > The Assignment: > > > > I'm trying to write Python code to read through a data file and figure > out the distribution by hour of the dat for each message in the data file. > > Python can pull the hour from the 'From ' line by finding the time and > then splitting the string a second time using a colon, i.e., From > stephen.marquard at uct.ac.za Sat Jan > 5 09:14:16 2008 > > Finally, accumulated the counts for each hour, print out the counts, > sorted by hour as shown below: > > name = raw_input("Enter file:") > if len(name) < 1 : name = "mbox-short.txt" > handle = open(name) > > > Desired Output: > > > 04 3 > 06 1 > 07 1 > 09 2 > 10 3 > 11 6 > 14 1 > 15 2 > 16 4 > 17 2 > 18 1 > 19 1 > Well, line.split()[5] isn't the address, it's the time, e.g. "09:14:16". You need to do just a little more work to extract the hour. I don't know what you think you'll achieve by sorting key/value pairs in reverse order. What you should be doing is sorting the keys (hours), although sorting the pairs of keys and values (i.e., the items) would have the same effect. Have a look at the 'sorted' function. > > > Raw data code, available at http://tinyurl.com/ob89r9p > Embedded data code, available at http://tinyurl.com/qhm4ppq > Visualization URL link, available at http://tinyurl.com/ozzmffy > > Regards, > Hal > > On Tue, Aug 11, 2015 at 5:26 PM, MRAB > wrote: > > On 2015-08-12 01:01, Ltc Hotspot wrote: > > Hi Everyone, > > > What is the list equivalent to line 12: ncount.sort(reverse=True) > > > count = dict() > fname = raw_input("Enter file name: ")# > handle = open (fname, 'r')# > for line in handle: > if line.startswith("From "): > address = line.split()[5] > line = line.rstrip() > count[address] = count.get(address, 0) + 1 > > for key,val in count.items(): > ncount = (key,val) > ncount.sort(reverse=True) > print key,val > > > Error message, reads: AttributeError, line 12, below : 'tuple' > object has no attribute 'sort' > > Raw data code, available at http://tinyurl.com/ob89r9p > Embedded data code, available at http://tinyurl.com/qhm4ppq > Visualization URL link, available at http://tinyurl.com/ozzmffy > > What are you trying to do? Why are you trying to sort a key/value > pair in reverse order? > > -- > https://mail.python.org/mailman/listinfo/python-list > > From breamoreboy at yahoo.co.uk Tue Aug 11 22:46:05 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 12 Aug 2015 03:46:05 +0100 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> Message-ID: On 12/08/2015 01:49, Chris Angelico wrote: > On Wed, Aug 12, 2015 at 10:43 AM, Ltc Hotspot wrote: >> Python can pull the hour from the 'From ' line by finding the time and then >> splitting the string a second time using a colon, i.e., From >> stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 >> >> Finally, accumulated the counts for each hour, print out the counts, sorted >> by hour as shown below: > > In that case, you want to sort the entire collection, not a single > key-value pair. > > It seems to me you can do this fairly efficiently with collections.Counter. > Which is exactly what the OP was told on the tutor mailing list several days ago, and he's also asked on the core mentorship list earlier today as well. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ltc.hotspot at gmail.com Tue Aug 11 23:05:48 2015 From: ltc.hotspot at gmail.com (Ltc Hotspot) Date: Tue, 11 Aug 2015 20:05:48 -0700 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> Message-ID: Chris, Check the code and the visualize execution of the code, available at http://tinyurl.com/p8tgd5h message reads: NameError: name 'collections' is not defined Regards, Hal On Tue, Aug 11, 2015 at 5:49 PM, Chris Angelico wrote: > On Wed, Aug 12, 2015 at 10:43 AM, Ltc Hotspot > wrote: > > Python can pull the hour from the 'From ' line by finding the time and > then > > splitting the string a second time using a colon, i.e., From > > stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 > > > > Finally, accumulated the counts for each hour, print out the counts, > sorted > > by hour as shown below: > > In that case, you want to sort the entire collection, not a single > key-value pair. > > It seems to me you can do this fairly efficiently with collections.Counter. > > import collections > with open(raw_input("Enter file name: ")) as f: > counts = collections.Counter(line.split()[5].rstrip() for line in > f if line.startswith("From ")) > > counts = counts.items() > counts.sort() > for hour, count in counts: > print hour, count > > The most important part is getting items() and then sorting the whole > thing. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Tue Aug 11 23:32:31 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 12 Aug 2015 04:32:31 +0100 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> Message-ID: On 12/08/2015 04:05, Ltc Hotspot wrote: > Chris, > > Check the code and the visualize execution of the code, available at > http://tinyurl.com/p8tgd5h > > message reads: NameError: name 'collections' is not defined > Which is why we kept telling you over on the tutor mailing list to show us your complete code, not to put it in a link, and also not to top post. Why we bother as volunteers to waste our time on someone such as yourself who posts mutiple times but refuses to take any notice of what actually gets said I really don't know. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Tue Aug 11 23:49:50 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Aug 2015 13:49:50 +1000 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> Message-ID: On Wed, Aug 12, 2015 at 1:05 PM, Ltc Hotspot wrote: > > Check the code and the visualize execution of the code, available at > http://tinyurl.com/p8tgd5h > > message reads: NameError: name 'collections' is not defined I've no idea why you made this Frankenstein monster out of your original code and my suggestion, because there's no way that's going to work. Go back to the people who've helped you on the python-tutor list, and *do what they have requested* in terms of showing code, not top-posting, and so on. ChrisA From ltc.hotspot at gmail.com Wed Aug 12 01:03:05 2015 From: ltc.hotspot at gmail.com (Ltc Hotspot) Date: Tue, 11 Aug 2015 22:03:05 -0700 (PDT) Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> Message-ID: <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> Message heard loud and clear: There are no error messages, the output is the issue. Question: What sorted function should I write to produce the desired output, below: Desired output: 04 3 06 1 07 1 09 2 10 3 11 6 14 1 15 2 16 4 17 2 18 1 19 1 Latest revised code: count = dict() fname = raw_input("Enter file name: ")# handle = open (fname, 'r')# for line in handle: if line.startswith("From "): address = line.split()[5] line = line.rstrip() count[address] = count.get(address, 0) + 1 lst = list() for key,val in count.items(): lst.append( (val, key) ) lst.sort(reverse=True) for val, key in lst[:12]: print key,val Output code: In [3]: %run assignment_10_2_v_01 Enter file name: mbox-short.txt 16:23:48 1 16:23:48 1 11:11:52 1 17:07:00 1 16:23:48 1 11:11:52 1 17:07:00 1 16:23:48 1 11:11:52 1 04:07:34 1 17:07:00 1 16:23:48 1 11:11:52 1 07:02:32 1 04:07:34 1 17:07:00 1 16:23:48 1 11:12:37 1 11:11:52 1 07:02:32 1 04:07:34 1 17:07:00 1 16:23:48 1 14:50:18 1 11:12:37 1 11:11:52 1 07:02:32 1 04:07:34 1 17:07:00 1 16:23:48 1 14:50:18 1 11:35:08 1 11:12:37 1 11:11:52 1 07:02:32 1 04:07:34 1 17:07:00 1 16:23:48 1 14:50:18 1 11:37:30 1 11:35:08 1 11:12:37 1 11:11:52 1 07:02:32 1 04:07:34 1 18:10:48 1 17:07:00 1 16:23:48 1 14:50:18 1 11:37:30 1 11:35:08 1 11:12:37 1 11:11:52 1 07:02:32 1 04:07:34 1 18:10:48 1 17:07:00 1 16:23:48 1 14:50:18 1 11:37:30 1 11:35:08 1 11:12:37 1 11:11:52 1 11:10:22 1 07:02:32 1 04:07:34 1 19:51:21 1 18:10:48 1 17:07:00 1 16:23:48 1 14:50:18 1 11:37:30 1 11:35:08 1 11:12:37 1 11:11:52 1 11:10:22 1 07:02:32 1 04:07:34 1 19:51:21 1 18:10:48 1 17:07:00 1 16:23:48 1 15:46:24 1 14:50:18 1 11:37:30 1 11:35:08 1 11:12:37 1 11:11:52 1 11:10:22 1 07:02:32 1 19:51:21 1 18:10:48 1 17:07:00 1 16:23:48 1 16:10:39 1 15:46:24 1 14:50:18 1 11:37:30 1 11:35:08 1 11:12:37 1 11:11:52 1 11:10:22 1 19:51:21 1 18:10:48 1 17:07:00 1 16:23:48 1 16:10:39 1 15:46:24 1 14:50:18 1 11:37:30 1 11:35:08 1 11:12:37 1 11:11:52 1 11:10:22 1 19:51:21 1 18:10:48 1 17:07:00 1 16:34:40 1 16:23:48 1 16:10:39 1 15:46:24 1 14:50:18 1 11:37:30 1 11:35:08 1 11:12:37 1 11:11:52 1 19:51:21 1 18:10:48 1 17:07:00 1 16:34:40 1 16:23:48 1 16:10:39 1 15:46:24 1 14:50:18 1 11:37:30 1 11:35:08 1 11:12:37 1 11:11:52 1 19:51:21 1 18:10:48 1 17:07:00 1 16:34:40 1 16:23:48 1 16:10:39 1 15:46:24 1 14:50:18 1 11:37:30 1 11:35:08 1 11:12:37 1 11:11:52 1 19:51:21 1 18:10:48 1 17:07:00 1 16:34:40 1 16:29:07 1 16:23:48 1 16:10:39 1 15:46:24 1 14:50:18 1 11:37:30 1 11:35:08 1 11:12:37 1 19:51:21 1 18:10:48 1 17:07:00 1 16:34:40 1 16:29:07 1 16:23:48 1 16:10:39 1 15:46:24 1 15:03:18 1 14:50:18 1 11:37:30 1 11:35:08 1 19:51:21 1 18:10:48 1 17:07:00 1 16:34:40 1 16:29:07 1 16:23:48 1 16:10:39 1 15:46:24 1 15:03:18 1 14:50:18 1 11:37:30 1 11:35:08 1 19:51:21 1 18:10:48 1 17:07:00 1 16:34:40 1 16:29:07 1 16:23:48 1 16:10:39 1 15:46:24 1 15:03:18 1 14:50:18 1 11:37:30 1 11:35:08 1 19:51:21 1 18:10:48 1 17:07:00 1 16:34:40 1 16:29:07 1 16:23:48 1 16:10:39 1 15:46:24 1 15:03:18 1 14:50:18 1 11:37:30 1 11:35:08 1 19:51:21 1 18:10:48 1 17:18:23 1 17:07:00 1 16:34:40 1 16:29:07 1 16:23:48 1 16:10:39 1 15:46:24 1 15:03:18 1 14:50:18 1 11:37:30 1 19:51:21 1 18:10:48 1 17:18:23 1 17:07:00 1 16:34:40 1 16:29:07 1 16:23:48 1 16:10:39 1 15:46:24 1 15:03:18 1 14:50:18 1 11:37:30 1 19:51:21 1 18:10:48 1 17:18:23 1 17:07:00 1 16:34:40 1 16:29:07 1 16:23:48 1 16:10:39 1 15:46:24 1 15:03:18 1 14:50:18 1 11:37:30 1 19:51:21 1 18:10:48 1 17:18:23 1 17:07:00 1 16:34:40 1 16:29:07 1 16:23:48 1 16:10:39 1 15:46:24 1 15:03:18 1 14:50:18 1 11:37:30 1 In [4]: Regards, Hal > > > > > > Error message, reads: AttributeError, line 12, below : 'tuple' > > object has no attribute 'sort' > > > > Raw data code, available at http://tinyurl.com/ob89r9p > > Embedded data code, available at http://tinyurl.com/qhm4ppq > > Visualization URL link, available at http://tinyurl.com/ozzmffy > > > > What are you trying to do? Why are you trying to sort a key/value > > pair in reverse order? > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > From montana.burr at gmail.com Wed Aug 12 02:04:27 2015 From: montana.burr at gmail.com (Montana Burr) Date: Tue, 11 Aug 2015 23:04:27 -0700 Subject: Real-time recoding of video from asx to non-Windows formats Message-ID: Hi, I'm interested in using Python to create a server for streaming my state's traffic cameras - which are only available as Windows Media streams - to devices that do not natively support streaming Windows Media content (think Linux computers & iPads). I know Python makes various problems easy to solve, and I'd like to know if this is one of those problems. I would like to use a module that works on any Linux- or UNIX-based computer, as my primary computer is UNIX-based. -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at chagford.com Wed Aug 12 02:20:17 2015 From: frank at chagford.com (Frank Millman) Date: Wed, 12 Aug 2015 08:20:17 +0200 Subject: Data integrity problem with sqlite3 - solved In-Reply-To: References: Message-ID: "Frank Millman" wrote in message news:mqcslv$tee$1 at ger.gmane.org... > "Frank Millman" wrote in message news:mqcmie$po9$1 at ger.gmane.org... > > > Hi all > > > > I have a 'data integrity' problem with sqlite3 that I have been battling > > with for a while. I have not got to the bottom of it yet but I do have > > some useful info, so I thought I would post it here in the hope that > > someone with some knowledge of the internals of the python sqlite3 > > module can throw some light on it. > > Oops, I have just spotted my mistake. > > There are times when I want to issue a SELECT statement with a lock, as it > will be followed by an UPDATE and I do not want anything to change in > between. > > MS SQL Server allows you to add 'WITH (UPDLOCK)' to a SELECT statement, > PostgreSQL allows you to add 'FOR UPDATE'. > > I could not find an equivalent for sqlite3, but in my wisdom (this was > some time ago) I decided that issuing a 'BEGIN IMMEDIATE' would do the > trick. > > I had not anticipated that this would generate an implied COMMIT first, > but it makes sense, and this is what has bitten me. Now I must try to > figure out a better solution. For the record, I have figured out a better solution. I was on the right lines with 'BEGIN IMMEDIATE', but I had overlooked the possibility that there could be a transaction already in progress. Now I have changed it to - if not conn.in_transaction: cur.execute('BEGIN IMMEDIATE') So far it seems to be working as intended. Frank P.S. Many thanks to the maintainers of the sqlite3 module for continuing to enhance it. 'in_transaction' was added in 3.2, and 'set_trace_callback' was added in 3.3. Without these my life would have been much more difficult. From ben+python at benfinney.id.au Wed Aug 12 05:01:05 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 12 Aug 2015 19:01:05 +1000 Subject: Ensure unwanted names removed in class definition Message-ID: <85fv3oj2y6.fsf@benfinney.id.au> How can I ensure incidental names don't end up in the class definition, with code that works on both Python 2 and Python 3? With the following class definition, the incidental names `foo` and `bar`, only needed for the list comprehension, remain in the `Parrot` namespace:: __metaclass__ = object class Parrot: """ A parrot with beautiful plumage. """ plumage = [ (foo, bar) for (foo, bar) in feathers.items() if bar == "beautiful"] assert hasattr(Parrot, 'plumage') # ? okay, has the wanted name assert not hasattr(Parrot, 'foo') # ? FAILS, has an unwanted name assert not hasattr(Parrot, 'bar') # ? FAILS, has an unwanted name So I can remove those names after using them:: __metaclass__ = object class Parrot: """ A parrot with beautiful plumage. """ plumage = [ (foo, bar) for (foo, bar) in feathers.items() if bar == "beautiful"] del foo, bar assert hasattr(Parrot, 'plumage') # ? okay, has the wanted name assert not hasattr(Parrot, 'foo') # ? okay, no unwanted name assert not hasattr(Parrot, 'bar') # ? okay, no unwanted name But that fails on Python 3, since the names *don't* persist from the list comprehension: __metaclass__ = object class Parrot: """ A parrot with beautiful plumage. """ plumage = [ (foo, bar) for (foo, bar) in feathers.items() if bar == "beautiful"] del foo, bar # ? FAILS, ?NameError: name 'foo' is not defined? How can I write the class definition with the list comprehension and *not* keep the incidental names ? in code that will run correctly on both Python 2 and Python 3? -- \ ?Pinky, are you pondering what I'm pondering?? ?Well, I think | `\ so, but *where* do you stick the feather and call it macaroni?? | _o__) ?_Pinky and The Brain_ | Ben Finney From Cecil at decebal.nl Wed Aug 12 05:06:03 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 12 Aug 2015 11:06:03 +0200 Subject: Is this a correct way to generate an exception when getting a wrong parameter Message-ID: <87h9o46flw.fsf@Equus.decebal.nl> I have: ======================================================================== accepted_params = { 'pcpu', 'rss', 'size', 'time', 'vsize', } ======================================================================== Later I use: ======================================================================== if (to_check != 'all') and not(to_check in accepted_params): raise Exception('Used illegal parameter: {0}.\n' 'Accepted ones: {1}' .format(to_check, sorted(accepted_params))) ======================================================================== When using 'all' I want to do the work for all accepted parameters. ;-) Is this a correct way to do this, or is there a better way? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From rosuav at gmail.com Wed Aug 12 05:14:30 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Aug 2015 19:14:30 +1000 Subject: Ensure unwanted names removed in class definition In-Reply-To: <85fv3oj2y6.fsf@benfinney.id.au> References: <85fv3oj2y6.fsf@benfinney.id.au> Message-ID: On Wed, Aug 12, 2015 at 7:01 PM, Ben Finney wrote: > class Parrot: > """ A parrot with beautiful plumage. """ > > plumage = [ > (foo, bar) for (foo, bar) in feathers.items() > if bar == "beautiful"] > del foo, bar # ? FAILS, ?NameError: name 'foo' is not defined? > > How can I write the class definition with the list comprehension and > *not* keep the incidental names ? in code that will run correctly on > both Python 2 and Python 3? You could always do explicitly what a Py3 comprehension does, and wrap it in a function: plumage = (lambda: [ (foo, bar) for (foo, bar) in feathers.items() if bar == "beautiful"])() Hardly clean code, but it will work, and apart from having a redundant layer of protection in Py3, will do exactly the same thing on both. Is the lambda nesting cruft worth it? ChrisA From rosuav at gmail.com Wed Aug 12 05:25:56 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Aug 2015 19:25:56 +1000 Subject: Is this a correct way to generate an exception when getting a wrong parameter In-Reply-To: <87h9o46flw.fsf@Equus.decebal.nl> References: <87h9o46flw.fsf@Equus.decebal.nl> Message-ID: On Wed, Aug 12, 2015 at 7:06 PM, Cecil Westerhof wrote: > I have: > ======================================================================== > accepted_params = { > 'pcpu', > 'rss', > 'size', > 'time', > 'vsize', > } > ======================================================================== > > Later I use: > ======================================================================== > if (to_check != 'all') and not(to_check in accepted_params): > raise Exception('Used illegal parameter: {0}.\n' > 'Accepted ones: {1}' > .format(to_check, sorted(accepted_params))) > ======================================================================== > > When using 'all' I want to do the work for all accepted parameters. > ;-) > > Is this a correct way to do this, or is there a better way? There are a couple of things I'd do slightly differently, one of which is to raise ValueError rather than Exception; but mostly, yes, that seems reasonable. I'd also use "x not in y" rather than "not (x in y)", for obvious reasons of clarity. But it kinda depends on what those params are going to be used for. Maybe you don't need to check at all - maybe something elsewhere will have a table that maps a parameter to something else, and absence from that table is a clear indication that it's an invalid parameter. If at all possible, have a Single Source Of Truth (SSOT), from which everything else derives. ChrisA From __peter__ at web.de Wed Aug 12 05:33:04 2015 From: __peter__ at web.de (Peter Otten) Date: Wed, 12 Aug 2015 11:33:04 +0200 Subject: Is this a correct way to generate an exception when getting a wrong parameter References: <87h9o46flw.fsf@Equus.decebal.nl> Message-ID: Cecil Westerhof wrote: > I have: > ======================================================================== > accepted_params = { > 'pcpu', > 'rss', > 'size', > 'time', > 'vsize', > } > ======================================================================== > > Later I use: > ======================================================================== > if (to_check != 'all') and not(to_check in accepted_params): > raise Exception('Used illegal parameter: {0}.\n' > 'Accepted ones: {1}' > .format(to_check, sorted(accepted_params))) > ======================================================================== > > When using 'all' I want to do the work for all accepted parameters. > ;-) Doesn't that make it an "accepted parameter"? Why not add it to the set? > Is this a correct way to do this, or is there a better way? I suppose you do this early in a function? Then at least choose a more specific exception (e. g. ValueError). If this is about commandline arguments -- argparse can handle such restrictions: $ cat demo.py import argparse parser = argparse.ArgumentParser() parser.add_argument("--check", choices=["pcpu", "rss"], default="all") print(parser.parse_args().check) $ python3 demo.py all $ python3 demo.py --check rss rss $ python3 demo.py --check ssr usage: demo.py [-h] [--check {pcpu,rss}] demo.py: error: argument --check: invalid choice: 'ssr' (choose from 'pcpu', 'rss') From info at egenix.com Wed Aug 12 06:03:36 2015 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 12 Aug 2015 12:03:36 +0200 Subject: ANN: eGenix mxODBC 3.3.4 - Python ODBC Database Interface Message-ID: <55CB19F8.6020404@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC Python ODBC Database Interface Version 3.3.4 mxODBC is our commercially supported Python extension providing ODBC database connectivity to Python applications on Windows, Mac OS X, Unix and BSD platforms with many advanced Python DB-API extensions and full support of stored procedures This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-3.3.4-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, Oracle Database, IBM DB2, Informix and Netezza, SAP Sybase ASE and Sybase Anywhere, Teradata, MySQL, MariaDB, 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.3.4 release of our mxODBC is a patch level release of our popular Python ODBC Interface for Windows, Linux, Mac OS X and FreeBSD. It includes these enhancements and fixes: Driver Compatibility -------------------- MS SQL Server * Added a work-around for MS SQL Server Native Client to be able to support VARCHAR/VARBINARY(MAX) columns when using the Native Client with direct execution mode or Python type binding mode. Thanks to ZeOmega for reporting this. * Added new helper singleton BinaryNull to allow binding a NULL to a VARBINARY column with SQL Server in direct execution mode or Python type binding mode (as used for FreeTDS). Using the usual None doesn't work in those cases, since SQL Server does not accept a VARCHAR data type as input for VARBINARY, except by using an explicit "CAST(? AS VARBINARY)". mxODBC binds None as VARCHAR for best compatibility, when not getting any type hints from the ODBC driver. Misc: * The various __version__ attributes in mxODBC are now automatically updated during release. In the past, we sometimes missed updating a few places when cutting releases. For the full set of changes please check the mxODBC change log: http://www.egenix.com/products/python/mxODBC/changelog.html ________________________________________________________________________ FEATURES mxODBC 3.3 was released on 2014-04-08. Please see the full announcement for highlights of the 3.3 release: http://www.egenix.com/company/news/eGenix-mxODBC-3.3.0-GA.html For the full set of features mxODBC has to offer, please see: http://www.egenix.com/products/python/mxODBC/#Features ________________________________________________________________________ EDITIONS mxODBC is available in these two editions: * The Professional Edition, which gives full access to all mxODBC features. * The Product Development Edition, which allows including mxODBC in applications you develop. For a complete overview of the available 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/ You can also simply use: pip install egenix-mxodbc and then get evaluation licenses from our website to try mxODBC: http://www.egenix.com/products/python/mxODBC/#Evaluation ________________________________________________________________________ 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.3 licenses can continue to use their licenses with this patch level release. For upgrade purchases, we will give out 20% discount coupons going from mxODBC 2.x to 3.3 and 50% coupons for upgrades from mxODBC 3.x to 3.3. 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 purchase, you can request 30-day evaluation licenses by visiting our web-site http://www.egenix.com/products/python/mxODBC/#Evaluation 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. _______________________________________________________________________ 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 database focused software project, consulting and product company delivering 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, Aug 12 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From breamoreboy at yahoo.co.uk Wed Aug 12 06:43:44 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 12 Aug 2015 11:43:44 +0100 Subject: Is this a correct way to generate an exception when getting a wrong parameter In-Reply-To: References: <87h9o46flw.fsf@Equus.decebal.nl> Message-ID: On 12/08/2015 10:33, Peter Otten wrote: > Cecil Westerhof wrote: > >> I have: >> ======================================================================== >> accepted_params = { >> 'pcpu', >> 'rss', >> 'size', >> 'time', >> 'vsize', >> } >> ======================================================================== >> >> Later I use: >> ======================================================================== >> if (to_check != 'all') and not(to_check in accepted_params): >> raise Exception('Used illegal parameter: {0}.\n' >> 'Accepted ones: {1}' >> .format(to_check, sorted(accepted_params))) >> ======================================================================== >> >> When using 'all' I want to do the work for all accepted parameters. >> ;-) > > Doesn't that make it an "accepted parameter"? Why not add it to the set? > >> Is this a correct way to do this, or is there a better way? > > I suppose you do this early in a function? Then at least choose a more > specific exception (e. g. ValueError). > > If this is about commandline arguments -- argparse can handle such > restrictions: > > $ cat demo.py > import argparse > parser = argparse.ArgumentParser() > parser.add_argument("--check", choices=["pcpu", "rss"], default="all") > print(parser.parse_args().check) > $ python3 demo.py > all > $ python3 demo.py --check rss > rss > $ python3 demo.py --check ssr > usage: demo.py [-h] [--check {pcpu,rss}] > demo.py: error: argument --check: invalid choice: 'ssr' (choose from 'pcpu', > 'rss') > > The wonderful http://docopt.org/ makes this type of thing a piece of cake. I believe there's a newer library that's equivalent in functionality to docopt but I can never remember the name of it, anybody? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From joshstok at cardigan.billanook.vic.edu.au Wed Aug 12 07:25:08 2015 From: joshstok at cardigan.billanook.vic.edu.au (Joshua Stokes) Date: Wed, 12 Aug 2015 11:25:08 +0000 Subject: Symbolic Links Message-ID: Hi I need help deleting broken symbolic links made by Python and/or Python modules Thanks >From Joshua P Stokes From joshstok at cardigan.billanook.vic.edu.au Wed Aug 12 07:26:23 2015 From: joshstok at cardigan.billanook.vic.edu.au (Joshua Stokes) Date: Wed, 12 Aug 2015 11:26:23 +0000 Subject: Symbolic Links In-Reply-To: References: Message-ID: Never Mind Thanks >From Joshua P Stokes > On 12 Aug 2015, at 9:25 PM, Joshua Stokes wrote: > > Hi > > I need help deleting broken symbolic links made by Python and/or Python modules > > Thanks > > From Joshua P Stokes From denismfmcmahon at gmail.com Wed Aug 12 07:36:20 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 12 Aug 2015 11:36:20 +0000 (UTC) Subject: AttributeError References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> Message-ID: On Tue, 11 Aug 2015 17:01:24 -0700, Ltc Hotspot wrote: > What is the list equivalent to line 12: ncount.sort(reverse=True) > > count = dict() > fname = raw_input("Enter file name: ")# > handle = open (fname, 'r')# > for line in handle: > if line.startswith("From "): > address = line.split()[5] > line = line.rstrip() > count[address] = count.get(address, 0) + 1 At this point, count seems to be a dictionary of address: count of lines > for key,val in count.items(): > ncount = (key,val) ncount.sort(reverse=True) print key,val ncount is a single key-value pair. Why are you trying to sort ncount? Do you want results ordered by count? First, change your dictionary into a list of tuples: ncount = [(a,c) for a,c in count.items()] Then sort ncount on the second field of the tuple: ncount.sort(key = lambda x: x[1], reverse=True) print ncount -- Denis McMahon, denismfmcmahon at gmail.com From 0xfoo at mihanmail.ir Wed Aug 12 09:07:41 2015 From: 0xfoo at mihanmail.ir (foo foor) Date: Wed, 12 Aug 2015 17:37:41 +0430 Subject: Python Book In Persian Language Message-ID: <62c2d41249f3f1bfbfb6741a563a61c7@localhost> An HTML attachment was scrubbed... URL: From billy.earney at gmail.com Wed Aug 12 09:52:33 2015 From: billy.earney at gmail.com (Billy Earney) Date: Wed, 12 Aug 2015 08:52:33 -0500 Subject: pyjs - a compiler from Python to JavaScript In-Reply-To: References: Message-ID: Uri, Brython on the other hand, tries to stay true to python (python compatible). As stated before it doesn't compile to stand alone Javascript, but the compile time is usually minimal. Access to Javascript libraries is supported. You really should give it a try.. http://brython.info Billy On Tue, Aug 11, 2015 at 7:52 PM, Chris Angelico wrote: > On Wed, Aug 12, 2015 at 5:08 AM, Fabio Zadrozny wrote: > > > > As it's just a way to convert from a Python-like syntax to JavaScript > syntax you can even switch to plain JavaScript later on if you want -- in > fact, when you debug the code you'll be debugging JavaScript and not Python > (it's like CoffeScript but with a Python-like syntax). > > > > So, it functions with ECMAScript semantics everywhere? This is an > important consideration. A Python integer is not the same as an > ECMAScript number (which is a float), and a Python string is not the > same as an ECMAScript string, and a Python dictionary has attributes > and keys which don't collide. > > I'm more than a little tickled by the PyPyJS project: > > http://pypyjs.org/ > > That's PyPy running in your web browser. The semantics are 100% > Python, but... uhh, it does require a fairly hefty download of code > before it can do anything. That _is_ a bit of a downside, but it's > still a pretty cool project! > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Aug 12 11:09:06 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Aug 2015 16:09:06 +0100 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> Message-ID: <55CB6192.8040500@mrabarnett.plus.com> On 2015-08-12 04:05, Ltc Hotspot wrote: > Chris, > > Check the code and the visualize execution of the code, available at > http://tinyurl.com/p8tgd5h > > message reads: NameError: name 'collections' is not defined > You didn't import the module. > > Regards, > Hal > > On Tue, Aug 11, 2015 at 5:49 PM, Chris Angelico > wrote: > > On Wed, Aug 12, 2015 at 10:43 AM, Ltc Hotspot > wrote: > > Python can pull the hour from the 'From ' line by finding the time and then > > splitting the string a second time using a colon, i.e., From > >stephen.marquard at uct.ac.za Sat > Jan 5 09:14:16 2008 > > > > Finally, accumulated the counts for each hour, print out the counts, sorted > > by hour as shown below: > > In that case, you want to sort the entire collection, not a single > key-value pair. > > It seems to me you can do this fairly efficiently with > collections.Counter. > > import collections > with open(raw_input("Enter file name: ")) as f: > counts = collections.Counter(line.split()[5].rstrip() for line in > f if line.startswith("From ")) > > counts = counts.items() > counts.sort() > for hour, count in counts: > print hour, count > > The most important part is getting items() and then sorting the > whole thing. > From python at mrabarnett.plus.com Wed Aug 12 11:12:45 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Aug 2015 16:12:45 +0100 Subject: AttributeError In-Reply-To: <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> Message-ID: <55CB626D.6080400@mrabarnett.plus.com> On 2015-08-12 06:03, Ltc Hotspot wrote: > Message heard loud and clear: > > There are no error messages, the output is the issue. > > Question: What sorted function should I write to produce the desired > output, below: > Instead of iterating over "count.items()", iterate over "sorted(count.items())". > Desired output: > > 04 3 > 06 1 > 07 1 > 09 2 > 10 3 > 11 6 > 14 1 > 15 2 > 16 4 > 17 2 > 18 1 > 19 1 > > Latest revised code: > > count = dict() > fname = raw_input("Enter file name: ")# > handle = open (fname, 'r')# > for line in handle: > if line.startswith("From "): > address = line.split()[5] > line = line.rstrip() > count[address] = count.get(address, 0) + 1 > > lst = list() > for key,val in count.items(): > lst.append( (val, key) ) > lst.sort(reverse=True) > for val, key in lst[:12]: > print key,val > [snip] I don't know why you have a nested 'for' loop; just iterate over the sorted items and print them. Simple. From python at mrabarnett.plus.com Wed Aug 12 11:14:06 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Aug 2015 16:14:06 +0100 Subject: Ensure unwanted names removed in class definition In-Reply-To: <85fv3oj2y6.fsf@benfinney.id.au> References: <85fv3oj2y6.fsf@benfinney.id.au> Message-ID: <55CB62BE.4080403@mrabarnett.plus.com> On 2015-08-12 10:01, Ben Finney wrote: > How can I ensure incidental names don't end up in the class definition, > with code that works on both Python 2 and Python 3? > > With the following class definition, the incidental names `foo` and > `bar`, only needed for the list comprehension, remain in the `Parrot` > namespace:: > > __metaclass__ = object > > class Parrot: > """ A parrot with beautiful plumage. """ > > plumage = [ > (foo, bar) for (foo, bar) in feathers.items() > if bar == "beautiful"] > > assert hasattr(Parrot, 'plumage') # ? okay, has the wanted name > assert not hasattr(Parrot, 'foo') # ? FAILS, has an unwanted name > assert not hasattr(Parrot, 'bar') # ? FAILS, has an unwanted name > > So I can remove those names after using them:: > > __metaclass__ = object > > class Parrot: > """ A parrot with beautiful plumage. """ > > plumage = [ > (foo, bar) for (foo, bar) in feathers.items() > if bar == "beautiful"] > del foo, bar > > assert hasattr(Parrot, 'plumage') # ? okay, has the wanted name > assert not hasattr(Parrot, 'foo') # ? okay, no unwanted name > assert not hasattr(Parrot, 'bar') # ? okay, no unwanted name > > But that fails on Python 3, since the names *don't* persist from the > list comprehension: > > __metaclass__ = object > > class Parrot: > """ A parrot with beautiful plumage. """ > > plumage = [ > (foo, bar) for (foo, bar) in feathers.items() > if bar == "beautiful"] > del foo, bar # ? FAILS, ?NameError: name 'foo' is not defined? > > How can I write the class definition with the list comprehension and > *not* keep the incidental names ? in code that will run correctly on > both Python 2 and Python 3? > Have you thought about catching the NameError? From ian.g.kelly at gmail.com Wed Aug 12 11:32:36 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 12 Aug 2015 09:32:36 -0600 Subject: Hooking Mechanism when Entering and Leaving a Try Block In-Reply-To: <55CA6D7F.1060705@mail.de> References: <55CA6D7F.1060705@mail.de> Message-ID: On Tue, Aug 11, 2015 at 3:47 PM, Sven R. Kunze wrote: > is there something like a hook that a Python module could register to in > order to 'trace' the entering and leaving of arbitrary try blocks? Not that I'm aware of. However, it sounds like context managers might do what you want. You would just need to instrument your try blocks by adding with blocks. From uri at speedy.net Wed Aug 12 11:35:24 2015 From: uri at speedy.net (Uri Even-Chen) Date: Wed, 12 Aug 2015 18:35:24 +0300 Subject: pyjs - a compiler from Python to JavaScript In-Reply-To: References: Message-ID: Thank you Billy, we will consider using Brython. Uri. *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 Email: uri at speedy.net Website: http://www.speedysoftware.com/uri/en/ > Speedypedia in Hebrew and English On Wed, Aug 12, 2015 at 4:52 PM, Billy Earney wrote: > Uri, > > Brython on the other hand, tries to stay true to python (python > compatible). As stated before it doesn't compile to stand alone > Javascript, but the compile time is usually minimal. Access to Javascript > libraries is supported. You really should give it a try.. > http://brython.info > > Billy > > On Tue, Aug 11, 2015 at 7:52 PM, Chris Angelico wrote: > >> On Wed, Aug 12, 2015 at 5:08 AM, Fabio Zadrozny >> wrote: >> > >> > As it's just a way to convert from a Python-like syntax to JavaScript >> syntax you can even switch to plain JavaScript later on if you want -- in >> fact, when you debug the code you'll be debugging JavaScript and not Python >> (it's like CoffeScript but with a Python-like syntax). >> > >> >> So, it functions with ECMAScript semantics everywhere? This is an >> important consideration. A Python integer is not the same as an >> ECMAScript number (which is a float), and a Python string is not the >> same as an ECMAScript string, and a Python dictionary has attributes >> and keys which don't collide. >> >> I'm more than a little tickled by the PyPyJS project: >> >> http://pypyjs.org/ >> >> That's PyPy running in your web browser. The semantics are 100% >> Python, but... uhh, it does require a fairly hefty download of code >> before it can do anything. That _is_ a bit of a downside, but it's >> still a pretty cool project! >> >> ChrisA >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > -- > https://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Aug 12 11:39:41 2015 From: __peter__ at web.de (Peter Otten) Date: Wed, 12 Aug 2015 17:39:41 +0200 Subject: Ensure unwanted names removed in class definition References: <85fv3oj2y6.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > How can I ensure incidental names don't end up in the class definition, > with code that works on both Python 2 and Python 3? > > With the following class definition, the incidental names `foo` and > `bar`, only needed for the list comprehension, remain in the `Parrot` > namespace:: > > __metaclass__ = object > > class Parrot: > """ A parrot with beautiful plumage. """ > > plumage = [ > (foo, bar) for (foo, bar) in feathers.items() > if bar == "beautiful"] > > assert hasattr(Parrot, 'plumage') # ? okay, has the wanted name > assert not hasattr(Parrot, 'foo') # ? FAILS, has an unwanted name > assert not hasattr(Parrot, 'bar') # ? FAILS, has an unwanted name > > So I can remove those names after using them:: > > __metaclass__ = object > > class Parrot: > """ A parrot with beautiful plumage. """ > > plumage = [ > (foo, bar) for (foo, bar) in feathers.items() > if bar == "beautiful"] > del foo, bar > > assert hasattr(Parrot, 'plumage') # ? okay, has the wanted name > assert not hasattr(Parrot, 'foo') # ? okay, no unwanted name > assert not hasattr(Parrot, 'bar') # ? okay, no unwanted name > > But that fails on Python 3, since the names *don't* persist from the > list comprehension: > > __metaclass__ = object > > class Parrot: > """ A parrot with beautiful plumage. """ > > plumage = [ > (foo, bar) for (foo, bar) in feathers.items() > if bar == "beautiful"] > del foo, bar # ? FAILS, ?NameError: name 'foo' is not defined? > > How can I write the class definition with the list comprehension and > *not* keep the incidental names ? in code that will run correctly on > both Python 2 and Python 3? If you absolutely must: make sure that the names exist by setting them explicitly: class Parrot: per = None a = [... for per in ...] del per But I would probably use a generator expression. These don't leak names: Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Parrot: ... a = [per for per in "abc"] ... b = list(trans for trans in "def") ... >>> Parrot.per 'c' >>> Parrot.trans Traceback (most recent call last): File "", line 1, in AttributeError: class Parrot has no attribute 'trans' From denismfmcmahon at gmail.com Wed Aug 12 11:50:53 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 12 Aug 2015 15:50:53 +0000 (UTC) Subject: AttributeError References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> Message-ID: On Tue, 11 Aug 2015 22:03:05 -0700, Ltc Hotspot wrote: > Question: What sorted function should I write to produce the desired > output, below: Me, I'd start by declaring a dictionary to hold the data: counts = { "{:02d}".format(h):0 for h in range(24) } Then I'd parse the strings in the log file(s), incrementing counts[x] where x is the hour field of the timestamp. Then I'd create a list of tuples: ncounts = [(k,v) for k,v in counts.items()] sort it by the hour field: ncounts.sort(key = lambda x: x[0]) and print it: for x in ncounts: print x[0], x1 -- Denis McMahon, denismfmcmahon at gmail.com From rosuav at gmail.com Wed Aug 12 11:59:10 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Aug 2015 01:59:10 +1000 Subject: Ensure unwanted names removed in class definition In-Reply-To: References: <85fv3oj2y6.fsf@benfinney.id.au> Message-ID: On Thu, Aug 13, 2015 at 1:39 AM, Peter Otten <__peter__ at web.de> wrote: > But I would probably use a generator expression. These don't leak names: > > Python 2.7.6 (default, Jun 22 2015, 17:58:13) > [GCC 4.8.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> class Parrot: > ... a = [per for per in "abc"] > ... b = list(trans for trans in "def") > ... Ooh neat trick! Much cleaner than the explicit lambda that I suggested. Withdrawing my recommendation in favour of this (but with an explanatory comment explaining why list(genexp) is used rather than a list comp). ChrisA From srkunze at mail.de Wed Aug 12 12:05:00 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 12 Aug 2015 18:05:00 +0200 Subject: Hooking Mechanism when Entering and Leaving a Try Block In-Reply-To: References: <55CA6D7F.1060705@mail.de> Message-ID: <55CB6EAC.5040004@mail.de> Unfortunately, no. :( It should work out of the box with no "let me replace all my try-except statements in my 10 million line code base". On 12.08.2015 17:32, Ian Kelly wrote: > On Tue, Aug 11, 2015 at 3:47 PM, Sven R. Kunze wrote: >> is there something like a hook that a Python module could register to in >> order to 'trace' the entering and leaving of arbitrary try blocks? > Not that I'm aware of. > > However, it sounds like context managers might do what you want. You > would just need to instrument your try blocks by adding with blocks. From garyr at fidalgo.net Wed Aug 12 12:08:18 2015 From: garyr at fidalgo.net (garyr) Date: Wed, 12 Aug 2015 09:08:18 -0700 Subject: Extension build link error Message-ID: I'm trying to build an extension module and was having problems so I decided to try something simpler. Article 16.5, "Coding the Methods of a Python Class in C" in the first edition of the Python Cookbook looked about right. I generated the code and a setup.py file (shown below). When I run python setup.py build_ext --inplace I get the following errors: LINK : error LNK2001: unresolved external symbol init_Foo build\temp.win32-2.7\Release\_Foo.lib : fatal error LNK1120: 1 unresolved externals If I change the name of the initialization function from Foo_init (as in the book) to init_Foo the build succeeds but import _Foo fails: import _Foo SystemError: dynamic module not initialized properly This is the problem I was having with the extension module I was trying to write. What can I do to correct this? I'm using Python 2.7 on Win XP. ========================================================== # File: setup.py from setuptools import setup, Extension setup(name='Foo', version='0.1', ext_modules=[Extension('_Foo', ['Foo.c'], include_dirs=['C:\Program Files\Common Files\Microsoft\Visual C++ for Python\9.0\VC\include', 'C:\Miniconda\include'], )], ) ================================================= # File: Foo.c #include PyObject* init_Foo(PyObject *self, PyObject *args){ printf("Foo.__init__ called\n"); Py_INCREF(Py_None); return Py_None; } static PyObject* Foo_doSomething(PyObject *self, PyObject *args){ printf("Foo.doSomething called\n"); Py_INCREF(Py_None); return Py_None; } static PyMethodDef FooMethods[] = { {"__init__", init_Foo, METH_VARARGS, "doc_string"}, {"doSomething", Foo_doSomething, METH_VARARGS, "doc string"}, {0, 0}, }; static PyMethodDef ModuleMethods[] = {{0,0}}; void initFoo() { PyMethodDef *def; PyObject *module = Py_InitModule("Foo", ModuleMethods); PyObject *moduleDict = PyModule_GetDict(module); PyObject *classDict = PyDict_New(); PyObject *className = PyString_FromString("Foo"); PyObject *fooClass = PyClass_New(NULL, classDict, className); PyDict_SetItemString(moduleDict, "Foo", fooClass); Py_DECREF(classDict); Py_DECREF(className); Py_DECREF(fooClass); for (def = FooMethods; def->ml_name != NULL; def++) { PyObject *func = PyCFunction_New(def, NULL); PyObject *method = PyMethod_New(func, NULL, fooClass); PyDict_SetItemString(classDict, def->ml_name, method); Py_DECREF(func); Py_DECREF(method); } } From rosuav at gmail.com Wed Aug 12 12:11:26 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Aug 2015 02:11:26 +1000 Subject: Hooking Mechanism when Entering and Leaving a Try Block In-Reply-To: <55CB6EAC.5040004@mail.de> References: <55CA6D7F.1060705@mail.de> <55CB6EAC.5040004@mail.de> Message-ID: On Thu, Aug 13, 2015 at 2:05 AM, Sven R. Kunze wrote: > Unfortunately, no. :( > > It should work out of the box with no "let me replace all my try-except > statements in my 10 million line code base". (Please don't top-post.) Sounds to me like you want some sort of AST transform, possibly in an import hook. Check out something like MacroPy for an idea of how powerful this sort of thing can be. ChrisA From ltc.hotspot at gmail.com Wed Aug 12 12:15:24 2015 From: ltc.hotspot at gmail.com (Ltc Hotspot) Date: Wed, 12 Aug 2015 09:15:24 -0700 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> Message-ID: Denis, Using the attached file of a diagram as a frame, why is there an attribute message? --------------------------------------------------------------------------------------------------------- Here is the attribute message: AttributeError Traceback (most recent call last) C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_06.py in () 11 time = line.split() # Sort time 12 ---> 13 hours = list.split(":")[5] # Sort hours 14 line = line.rstrip() 15 count[hours] = count.get(hours, 0) + 1 AttributeError: type object 'list' has no attribute 'split' In [45]: --------------------------------------------------------------------------------------------------------- Here is the revised code: handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 >From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 """.split("\n") # Snippet file data: mbox-short.txt count = dict() #fname = raw_input("Enter file name: ")# Add Snippet file #handle = open (fname, 'r')# Add Snippet file for line in handle: if line.startswith("From "): time = line.split() # Sort time hours = time.split(":")[5] # Sort hours line = line.rstrip() count[hours] = count.get(hours, 0) + 1 # counter lst = [(val,key) for key,val in count.items()] print key, val URL link, http://tinyurl.com/oyd4ugp --------------------------------------------------------------------------------------------------------- Regards, Hal On Wed, Aug 12, 2015 at 8:50 AM, Denis McMahon wrote: > On Tue, 11 Aug 2015 22:03:05 -0700, Ltc Hotspot wrote: > >> Question: What sorted function should I write to produce the desired >> output, below: > > Me, I'd start by declaring a dictionary to hold the data: > > counts = { "{:02d}".format(h):0 for h in range(24) } > > Then I'd parse the strings in the log file(s), incrementing counts[x] > where x is the hour field of the timestamp. > > Then I'd create a list of tuples: > > ncounts = [(k,v) for k,v in counts.items()] > > sort it by the hour field: > > ncounts.sort(key = lambda x: x[0]) > > and print it: > > for x in ncounts: > print x[0], x1 > > -- > Denis McMahon, denismfmcmahon at gmail.com > -- > https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- A non-text attachment was scrubbed... Name: diagram_1.pdf Type: application/pdf Size: 1215006 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: diagram_2.pdf Type: application/pdf Size: 1102835 bytes Desc: not available URL: From ltc.hotspot at gmail.com Wed Aug 12 12:29:50 2015 From: ltc.hotspot at gmail.com (Ltc Hotspot) Date: Wed, 12 Aug 2015 09:29:50 -0700 (PDT) Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> Message-ID: <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> Denis, Using the attached file of a diagram as a frame, why is there an attribute message? --------------------------------------------------------------------------------------------------------- Here is the attribute message: AttributeError Traceback (most recent call last) C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_06.py in () 11 time = line.split() # Sort time 12 ---> 13 hours = list.split(":")[5] # Sort hours 14 line = line.rstrip() 15 count[hours] = count.get(hours, 0) + 1 AttributeError: type object 'list' has no attribute 'split' In [45]: --------------------------------------------------------------------------------------------------------- Here is the revised code: handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 >From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 """.split("\n") # Snippet file data: mbox-short.txt count = dict() #fname = raw_input("Enter file name: ")# Add Snippet file #handle = open (fname, 'r')# Add Snippet file for line in handle: if line.startswith("From "): time = line.split() # Sort time hours = time.split(":")[5] # Sort hours line = line.rstrip() count[hours] = count.get(hours, 0) + 1 # counter lst = [(val,key) for key,val in count.items()] print key, val URL link, http://tinyurl.com/oyd4ugp Regards, Hal From ei at kun.ei.invalid Wed Aug 12 12:33:00 2015 From: ei at kun.ei.invalid (Jussi Piitulainen) Date: Wed, 12 Aug 2015 19:33:00 +0300 Subject: Ensure unwanted names removed in class definition References: Message-ID: Ben Finney writes: > How can I ensure incidental names don't end up in the class > definition, with code that works on both Python 2 and Python 3? > > With the following class definition, the incidental names `foo` and > `bar`, only needed for the list comprehension, remain in the `Parrot` > namespace:: > > __metaclass__ = object > > class Parrot: > """ A parrot with beautiful plumage. """ > > plumage = [ > (foo, bar) for (foo, bar) in feathers.items() > if bar == "beautiful"] > > assert hasattr(Parrot, 'plumage') # ? okay, has the wanted name > assert not hasattr(Parrot, 'foo') # ? FAILS, has an unwanted name > assert not hasattr(Parrot, 'bar') # ? FAILS, has an unwanted name [- -] > How can I write the class definition with the list comprehension and > *not* keep the incidental names ? in code that will run correctly on > both Python 2 and Python 3? Make them an implementation detail: plumage = [ (__foo__, __bar__) for (__foo__, __bar__) in feathers.items() if __bar__ == "beautiful" ] From Bernd-Waterkamp at web.de Wed Aug 12 12:42:49 2015 From: Bernd-Waterkamp at web.de (Bernd Waterkamp) Date: Wed, 12 Aug 2015 18:42:49 +0200 Subject: Is this a correct way to generate an exception when getting a wrong parameter References: <87h9o46flw.fsf@Equus.decebal.nl> Message-ID: Mark Lawrence schrieb: > The wonderful http://docopt.org/ makes this type of thing a piece of > cake. I believe there's a newer library that's equivalent in > functionality to docopt but I can never remember the name of it, anybody? Never used it, but "Click" is another choice: http://click.pocoo.org/4/ From python at mrabarnett.plus.com Wed Aug 12 12:45:23 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Aug 2015 17:45:23 +0100 Subject: AttributeError In-Reply-To: <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> Message-ID: <55CB7823.8010402@mrabarnett.plus.com> On 2015-08-12 17:29, Ltc Hotspot wrote: > Denis, > > > Using the attached file of a diagram as a frame, why is there an > attribute message? > The code in the error report doesn't match the "revised code". > > > --------------------------------------------------------------------------------------------------------- > Here is the attribute message: > AttributeError > Traceback (most recent call last) > C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_06.py in > () > 11 time = line.split() # Sort time > 12 > ---> 13 hours = list.split(":")[5] # Sort hours > 14 line = line.rstrip() > 15 count[hours] = count.get(hours, 0) + 1 > > AttributeError: type object 'list' has no attribute 'split' > > In [45]: > > --------------------------------------------------------------------------------------------------------- > Here is the revised code: > handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 >>From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 > """.split("\n") > # Snippet file data: mbox-short.txt > > count = dict() > #fname = raw_input("Enter file name: ")# Add Snippet file > #handle = open (fname, 'r')# Add Snippet file > for line in handle: > if line.startswith("From "): > time = line.split() # Sort time > > hours = time.split(":")[5] # Sort hours > line = line.rstrip() > > count[hours] = count.get(hours, 0) + 1 # counter > > lst = [(val,key) for key,val in count.items()] > > print key, val > > > > URL link, http://tinyurl.com/oyd4ugp > From lac at openend.se Wed Aug 12 12:53:29 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 12 Aug 2015 18:53:29 +0200 Subject: Python Book In Persian Language (fwd) Message-ID: <201508121653.t7CGrTjV020331@fido.openend.se> Are only English language blogs eligible for planet python? This showed up on Python list. I don't want to ask him if he wants to get his blog added if we have a language policy that I am unaware of. Laura ------- Forwarded Message Date: Wed, 12 Aug 2015 17:37:41 +0430 To: python-list at python.org From: "foo foor" <0xfoo at mihanmail.ir> Subject: Python Book In Persian Language Hello, I'm Javad Mokhtari Koushyar from Iran, Hamedan. four month ago I started teaching python 3.4.1 in Persian using a blog. first I thought people do not pay attention to it but after a week I received very messages that makes me to continue and now I am happy that I made a book from my blog posts and shared it with different persian sites. I want you to share this event because everyday people use my book and send me messages for thanksgiving. Thank for yourattention. This is my blog:[1]http://www.iranpython.blog.ir/ . goodbye Python Is best for ever. Javad M. Koushyar ______________________________________________________ Persian web-based mail | MihanMail.Com From ltc.hotspot at gmail.com Wed Aug 12 12:57:00 2015 From: ltc.hotspot at gmail.com (Ltc Hotspot) Date: Wed, 12 Aug 2015 09:57:00 -0700 Subject: AttributeError In-Reply-To: <55CB7823.8010402@mrabarnett.plus.com> References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> Message-ID: MRAB, I ran the code, and the output: Raw data code: handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 >From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 """.split("\n") # Snippet file data: mbox-short.txt count = dict() #fname = raw_input("Enter file name: ")# Add Snippet file #handle = open (fname, 'r')# Add Snippet file for line in handle: if line.startswith("From "): time = line.split() # Sort time hours = list.split(":")[5] # Sort hours line = line.rstrip() count[hours] = count.get(hours, 0) + 1 # counter lst = [(val,key) for key,val in count.items()] print key, val ------------------------------------------------------------------------------------- Syntax message: In [45]: %run assignment_10_2_v_06 AttributeError Traceback (most recent call last) C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_06.py in () 11 time = line.split() # Sort time 12 ---> 13 hours = list.split(":")[5] # Sort hours 14 line = line.rstrip() 15 AttributeError: type object 'list' has no attribute 'split' In [46]: Regards, Hal On Wed, Aug 12, 2015 at 9:45 AM, MRAB wrote: > On 2015-08-12 17:29, Ltc Hotspot wrote: >> >> Denis, >> >> >> Using the attached file of a diagram as a frame, why is there an >> attribute message? >> > The code in the error report doesn't match the "revised code". > >> >> >> >> --------------------------------------------------------------------------------------------------------- >> Here is the attribute message: >> AttributeError >> Traceback (most recent call last) >> C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_06.py in >> >> () >> 11 time = line.split() # Sort time >> 12 >> ---> 13 hours = list.split(":")[5] # Sort hours >> 14 line = line.rstrip() >> 15 count[hours] = count.get(hours, 0) + 1 >> >> AttributeError: type object 'list' has no attribute 'split' >> >> In [45]: >> >> >> --------------------------------------------------------------------------------------------------------- >> Here is the revised code: >> handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 >>> >>> From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 >> >> """.split("\n") >> # Snippet file data: mbox-short.txt >> >> count = dict() >> #fname = raw_input("Enter file name: ")# Add Snippet file >> #handle = open (fname, 'r')# Add Snippet file >> for line in handle: >> if line.startswith("From "): >> time = line.split() # Sort time >> >> hours = time.split(":")[5] # Sort hours >> line = line.rstrip() >> >> count[hours] = count.get(hours, 0) + 1 # counter >> >> lst = [(val,key) for key,val in count.items()] >> >> print key, val >> >> >> >> URL link, http://tinyurl.com/oyd4ugp >> > > -- > https://mail.python.org/mailman/listinfo/python-list From lac at openend.se Wed Aug 12 13:00:26 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 12 Aug 2015 19:00:26 +0200 Subject: Python Book In Persian Language (fwd) In-Reply-To: Message from Laura Creighton of "Wed, 12 Aug 2015 18:53:29 +0200." <201508121653.t7CGrTjV020331@fido.openend.se> References: <201508121653.t7CGrTjV020331@fido.openend.se> Message-ID: <201508121700.t7CH0QAf021852@fido.openend.se> In a message of Wed, 12 Aug 2015 18:53:29 +0200, Laura Creighton writes: >Are only English language blogs eligible for planet python? >This showed up on Python list. I don't want to ask him if he wants to >get his blog added if we have a language policy that I am unaware of. > >Laura Oh rats, I didn't mean to cc python-list here. Just count me in as somebody who would like to see non-English language blogs on planet python. Laura From python at mrabarnett.plus.com Wed Aug 12 13:24:43 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Aug 2015 18:24:43 +0100 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> Message-ID: <55CB815B.8070800@mrabarnett.plus.com> On 2015-08-12 17:57, Ltc Hotspot wrote: > MRAB, > > I ran the code, and the output: > > > Raw data code: > handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 > >From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 > """.split("\n") > # Snippet file data: mbox-short.txt > > count = dict() > #fname = raw_input("Enter file name: ")# Add Snippet file > #handle = open (fname, 'r')# Add Snippet file > for line in handle: > if line.startswith("From "): > time = line.split() # Sort time > > hours = list.split(":")[5] # Sort hours > line = line.rstrip() > > count[hours] = count.get(hours, 0) + 1 # counter > > lst = [(val,key) for key,val in count.items()] > > print key, val > > ------------------------------------------------------------------------------------- > Syntax message: > In [45]: %run assignment_10_2_v_06 > > AttributeError > Traceback (most recent call last) > C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_06.py in > () > 11 time = line.split() # Sort time > 12 > ---> 13 hours = list.split(":")[5] # Sort hours > 14 line = line.rstrip() > 15 > > AttributeError: type object 'list' has no attribute 'split' > > In [46]: Read the indicated line _carefully_. What is it _actually_ trying to split? From crk at godblessthe.us Wed Aug 12 13:31:25 2015 From: crk at godblessthe.us (Clayton Kirkwood) Date: Wed, 12 Aug 2015 10:31:25 -0700 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> Message-ID: <07a201d0d524$b79db790$26d926b0$@godblessthe.us> > -----Original Message----- > From: Python-list [mailto:python-list- > bounces+crk=godblessthe.us at python.org] On Behalf Of Ltc Hotspot > Sent: Wednesday, August 12, 2015 9:57 AM > To: MRAB > Cc: python-list at python.org > Subject: Re: AttributeError > > MRAB, > > I ran the code, and the output: > > > Raw data code: > handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 From > louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 > """.split("\n") > # Snippet file data: mbox-short.txt > > count = dict() > #fname = raw_input("Enter file name: ")# Add Snippet file #handle = open > (fname, 'r')# Add Snippet file for line in handle: > if line.startswith("From "): > time = line.split() # Sort time > > hours = list.split(":")[5] # Sort hours > line = line.rstrip() > > count[hours] = count.get(hours, 0) + 1 # counter > > lst = [(val,key) for key,val in count.items()] > > print key, val > > ---------------------------------------------------------------------------- --------- > Syntax message: > In [45]: %run assignment_10_2_v_06 > > AttributeError > Traceback (most recent call last) > C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_06. > py in > () > 11 time = line.split() # Sort time > 12 > ---> 13 hours = list.split(":")[5] # Sort hours > 14 line = line.rstrip() > 15 > > AttributeError: type object 'list' has no attribute 'split' >From my na?ve view what you wanted was not list.split but line.split. Isn't list a keyword or function? Crk > > In [46]: > > Regards, > Hal > > On Wed, Aug 12, 2015 at 9:45 AM, MRAB > wrote: > > On 2015-08-12 17:29, Ltc Hotspot wrote: > >> > >> Denis, > >> > >> > >> Using the attached file of a diagram as a frame, why is there an > >> attribute message? > >> > > The code in the error report doesn't match the "revised code". > > > >> > >> > >> > >> --------------------------------------------------------------------- > >> ------------------------------------ > >> Here is the attribute message: > >> AttributeError > >> Traceback (most recent call last) > >> > C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_06. > py > >> in > >> () > >> 11 time = line.split() # Sort time > >> 12 > >> ---> 13 hours = list.split(":")[5] # Sort hours > >> 14 line = line.rstrip() > >> 15 count[hours] = count.get(hours, 0) + 1 > >> > >> AttributeError: type object 'list' has no attribute 'split' > >> > >> In [45]: > >> > >> > >> --------------------------------------------------------------------- > >> ------------------------------------ > >> Here is the revised code: > >> handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 > >>> > >>> From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 > >> > >> """.split("\n") > >> # Snippet file data: mbox-short.txt > >> > >> count = dict() > >> #fname = raw_input("Enter file name: ")# Add Snippet file #handle = > >> open (fname, 'r')# Add Snippet file for line in handle: > >> if line.startswith("From "): > >> time = line.split() # Sort time > >> > >> hours = time.split(":")[5] # Sort hours > >> line = line.rstrip() > >> > >> count[hours] = count.get(hours, 0) + 1 # counter > >> > >> lst = [(val,key) for key,val in count.items()] > >> > >> print key, val > >> > >> > >> > >> URL link, http://tinyurl.com/oyd4ugp > >> > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > -- > https://mail.python.org/mailman/listinfo/python-list From mal at egenix.com Wed Aug 12 13:34:36 2015 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 12 Aug 2015 19:34:36 +0200 Subject: Python Book In Persian Language (fwd) In-Reply-To: <201508121653.t7CGrTjV020331@fido.openend.se> References: <201508121653.t7CGrTjV020331@fido.openend.se> Message-ID: <55CB83AC.3020207@egenix.com> On 12.08.2015 18:53, Laura Creighton wrote: > Are only English language blogs eligible for planet python? > This showed up on Python list. I don't want to ask him if he wants to > get his blog added if we have a language policy that I am unaware of. Apparently, we do: https://github.com/python/planet FWIW: I think it's better to have different planet installations for different languages. See the left side on http://planetpython.org/ for a list of planets using other languages than English. I guess someone could set up a Persian planet installation and get it added there as well. > Laura > > > ------- Forwarded Message > Date: Wed, 12 Aug 2015 17:37:41 +0430 > To: python-list at python.org > From: "foo foor" <0xfoo at mihanmail.ir> > Subject: Python Book In Persian Language > > > Hello, I'm Javad Mokhtari Koushyar from Iran, Hamedan. four month ago I > started teaching python 3.4.1 in Persian using a blog. first I thought people > do not pay attention to it but after a week I received very messages that > makes me to continue and now I am happy that I made a book from my blog posts > and shared it with different persian sites. I want you to share this event > because everyday people use my book and send me messages for thanksgiving. > Thank for yourattention. This is my blog:[1]http://www.iranpython.blog.ir/ . > > goodbye > Python Is best for ever. > Javad M. Koushyar > > ______________________________________________________ > Persian web-based mail | MihanMail.Com > -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 12 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2015-08-12: Released mxODBC 3.3.4 ... http://egenix.com/go80 2015-07-30: Released eGenix pyOpenSSL 0.13.11 ... http://egenix.com/go81 2015-08-22: FrOSCon 2015 ... 10 days to go 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 emile at fenx.com Wed Aug 12 13:37:26 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 12 Aug 2015 10:37:26 -0700 Subject: AttributeError In-Reply-To: <55CB815B.8070800@mrabarnett.plus.com> References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> Message-ID: On 8/12/2015 10:24 AM, MRAB wrote: > What is it _actually_ trying to split? Aah, reading. Such an underused skill. Emile From ltc.hotspot at gmail.com Wed Aug 12 14:35:03 2015 From: ltc.hotspot at gmail.com (Ltc Hotspot) Date: Wed, 12 Aug 2015 11:35:03 -0700 (PDT) Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> Message-ID: <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> Emile How do I define time in the revised code ? --------------------------------------------------------------------------- Traceback Message reads: In [66]: %run assignment_10_2_v_07 NameError Traceback (most recent call last) C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_07.py in () 9 for line in handle: 10 if line.startswith("From "): ---> 11 for key, val in time.split()[5]: 12 for key, val in hours.split(':')[0]: 13 count[hours] = count.get(hours, 0) + 1 # counter NameError: name 'time' is not defined --------------------------------------------------------------------------- >>> In [67]: print time 0 --------------------------------------------------------------------------- Revised Code reads: handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 >From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 """.split("\n") # Snippet file data: mbox-short.txt count = dict() #fname = raw_input("Enter file name: ")# insert snippet file #handle = open (fname, 'r')# insert snippet file for line in handle: if line.startswith("From "): for key, val in time.split()[5]: for key, val in hours.split(':')[0]: count[hours] = count.get(hours, 0) + 1 # counter lst = [(val,key) for key,val in count.items()] lst.sort(reverse=True) for key, val in lst[:12] : print key, val --------------------------------------------------------------------------- Regards, Hal From srkunze at mail.de Wed Aug 12 14:44:53 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 12 Aug 2015 20:44:53 +0200 Subject: Hooking Mechanism when Entering and Leaving a Try Block In-Reply-To: References: <55CA6D7F.1060705@mail.de> <55CB6EAC.5040004@mail.de> Message-ID: <55CB9425.5050109@mail.de> On 12.08.2015 18:11, Chris Angelico wrote: > On Thu, Aug 13, 2015 at 2:05 AM, Sven R. Kunze wrote: >> Unfortunately, no. :( >> >> It should work out of the box with no "let me replace all my try-except >> statements in my 10 million line code base". > (Please don't top-post.) Is this some guideline? I actually quite dislike pick somebody's mail to pieces. It actually pulls things out of context. But if this is a rule for this, so be it. > Sounds to me like you want some sort of AST transform, possibly in an > import hook. Check out something like MacroPy for an idea of how > powerful this sort of thing can be. Sounds like I MacroPy would enable me to basically insert a function call before and after each try: block at import time. Is that correct so far? That sounds not so bad at all. However, if that only works due to importing it is not a solution. I need to make sure I catch all try: blocks, the current stack is in (and is about to step into). Ah yes, and it should work with Python 3 as well. Regards, Sven From python at mrabarnett.plus.com Wed Aug 12 14:59:09 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Aug 2015 19:59:09 +0100 Subject: AttributeError In-Reply-To: <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> Message-ID: <55CB977D.9080300@mrabarnett.plus.com> On 2015-08-12 19:35, Ltc Hotspot wrote: > Emile > > How do I define time in the revised code ? > > Have a look at assignment_10_2_v_06.py. > > --------------------------------------------------------------------------- > Traceback Message reads: > In [66]: %run assignment_10_2_v_07 > > NameError > Traceback (most recent call last) > C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_07.py in > () > 9 for line in handle: > 10 if line.startswith("From "): > ---> 11 for key, val in time.split()[5]: > 12 for key, val in hours.split(':')[0]: > 13 count[hours] = count.get(hours, 0) + 1 # counter > > NameError: name 'time' is not defined > --------------------------------------------------------------------------- >>>> > In [67]: print time > 0 > --------------------------------------------------------------------------- > > Revised Code reads: > handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 >>From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 > """.split("\n") > # Snippet file data: mbox-short.txt > > count = dict() > #fname = raw_input("Enter file name: ")# insert snippet file > #handle = open (fname, 'r')# insert snippet file > for line in handle: > if line.startswith("From "): > for key, val in time.split()[5]: > for key, val in hours.split(':')[0]: > count[hours] = count.get(hours, 0) + 1 # counter > > lst = [(val,key) for key,val in count.items()] > lst.sort(reverse=True) > > for key, val in lst[:12] : > print key, val > > --------------------------------------------------------------------------- > Regards, > Hal > I'm baffled as to why you now have a nested 'for' loop 3 levels deep! From ltc.hotspot at gmail.com Wed Aug 12 15:05:37 2015 From: ltc.hotspot at gmail.com (Ltc Hotspot) Date: Wed, 12 Aug 2015 12:05:37 -0700 Subject: AttributeError In-Reply-To: <55CB977D.9080300@mrabarnett.plus.com> References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CB977D.9080300@mrabarnett.plus.com> Message-ID: >Have a look at assignment_10_2_v_06.py. What should I look at assignment_10_2_v_06.py.: handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 >From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 """.split("\n") # Snippet file data: mbox-short.txt count = dict() #fname = raw_input("Enter file name: ")# Add Snippet file #handle = open (fname, 'r')# Add Snippet file for line in handle: if line.startswith("From "): time = line.split() # Sort time hours = line.split(":")[5] # Sort hours line = line.rstrip() count[hours] = count.get(hours, 0) + 1 # counter lst = [(val,key) for key,val in count.items()] print key, val On Wed, Aug 12, 2015 at 11:59 AM, MRAB wrote: > On 2015-08-12 19:35, Ltc Hotspot wrote: >> >> Emile >> >> How do I define time in the revised code ? >> >> > Have a look at assignment_10_2_v_06.py. > >> >> >> --------------------------------------------------------------------------- >> Traceback Message reads: >> In [66]: %run assignment_10_2_v_07 >> >> NameError >> Traceback (most recent call last) >> C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_07.py in >> >> () >> 9 for line in handle: >> 10 if line.startswith("From "): >> ---> 11 for key, val in time.split()[5]: >> 12 for key, val in hours.split(':')[0]: >> 13 count[hours] = count.get(hours, 0) + 1 # counter >> >> NameError: name 'time' is not defined >> >> --------------------------------------------------------------------------- >>>>> >>>>> >> In [67]: print time >> 0 >> >> --------------------------------------------------------------------------- >> >> Revised Code reads: >> handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 >>> >>> From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 >> >> """.split("\n") >> # Snippet file data: mbox-short.txt >> >> count = dict() >> #fname = raw_input("Enter file name: ")# insert snippet file >> #handle = open (fname, 'r')# insert snippet file >> for line in handle: >> if line.startswith("From "): >> for key, val in time.split()[5]: >> for key, val in hours.split(':')[0]: >> count[hours] = count.get(hours, 0) + 1 # counter >> >> lst = [(val,key) for key,val in count.items()] >> lst.sort(reverse=True) >> >> for key, val in lst[:12] : >> print key, val >> >> >> --------------------------------------------------------------------------- >> Regards, >> Hal >> > I'm baffled as to why you now have a nested 'for' loop 3 levels deep! > > -- > https://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Wed Aug 12 16:04:48 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Aug 2015 21:04:48 +0100 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CB977D.9080300@mrabarnett.plus.com> Message-ID: <55CBA6E0.5020700@mrabarnett.plus.com> On 2015-08-12 20:05, Ltc Hotspot wrote: > >Have a look at assignment_10_2_v_06.py. > > What should I look at assignment_10_2_v_06.py.: How "time" is defined! > > handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 > >From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 > """.split("\n") > # Snippet file data: mbox-short.txt > > count = dict() > #fname = raw_input("Enter file name: ")# Add Snippet file > #handle = open (fname, 'r')# Add Snippet file > for line in handle: > if line.startswith("From "): > time = line.split() # Sort time > > hours = line.split(":")[5] # Sort hours > line = line.rstrip() > > count[hours] = count.get(hours, 0) + 1 # counter > > lst = [(val,key) for key,val in count.items()] > > print key, val > > On Wed, Aug 12, 2015 at 11:59 AM, MRAB wrote: > > On 2015-08-12 19:35, Ltc Hotspot wrote: > >> > >> Emile > >> > >> How do I define time in the revised code ? > >> > >> > > Have a look at assignment_10_2_v_06.py. > > > >> > >> > >> --------------------------------------------------------------------------- > >> Traceback Message reads: > >> In [66]: %run assignment_10_2_v_07 > >> > >> NameError > >> Traceback (most recent call last) > >> C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_07.py in > >> > >> () > >> 9 for line in handle: > >> 10 if line.startswith("From "): > >> ---> 11 for key, val in time.split()[5]: > >> 12 for key, val in hours.split(':')[0]: > >> 13 count[hours] = count.get(hours, 0) + 1 # counter > >> > >> NameError: name 'time' is not defined > >> > >> --------------------------------------------------------------------------- > >>>>> > >>>>> > >> In [67]: print time > >> 0 > >> > >> --------------------------------------------------------------------------- > >> > >> Revised Code reads: > >> handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 > >>> > >>> From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 > >> > >> """.split("\n") > >> # Snippet file data: mbox-short.txt > >> > >> count = dict() > >> #fname = raw_input("Enter file name: ")# insert snippet file > >> #handle = open (fname, 'r')# insert snippet file > >> for line in handle: > >> if line.startswith("From "): > >> for key, val in time.split()[5]: > >> for key, val in hours.split(':')[0]: > >> count[hours] = count.get(hours, 0) + 1 # counter > >> > >> lst = [(val,key) for key,val in count.items()] > >> lst.sort(reverse=True) > >> > >> for key, val in lst[:12] : > >> print key, val > >> > >> > >> --------------------------------------------------------------------------- > >> Regards, > >> Hal > >> > > I'm baffled as to why you now have a nested 'for' loop 3 levels deep! > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > From denismfmcmahon at gmail.com Wed Aug 12 16:28:01 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 12 Aug 2015 20:28:01 +0000 (UTC) Subject: AttributeError References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> Message-ID: On Wed, 12 Aug 2015 09:29:50 -0700, Ltc Hotspot wrote: > Using the attached file of a diagram as a frame, why is there an > attribute message? Perhaps you should read the message. It's very clear. -- Denis McMahon, denismfmcmahon at gmail.com From denismfmcmahon at gmail.com Wed Aug 12 16:38:34 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 12 Aug 2015 20:38:34 +0000 (UTC) Subject: AttributeError References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CB977D.9080300@mrabarnett.plus.com> Message-ID: On Wed, 12 Aug 2015 12:05:37 -0700, Ltc Hotspot wrote: >>Have a look at assignment_10_2_v_06.py. > What should I look at assignment_10_2_v_06.py.: You shouldn't. You should instead approach your tutor and tell him you are too stupid to learn computer programming[1], and can you please transfer to floor-scrubbing 101. [1] You have repeatedly ignored advice and instructions that you have been given. This is de-facto proof that you are not capable of learning to program computers. -- Denis McMahon, denismfmcmahon at gmail.com From breamoreboy at yahoo.co.uk Wed Aug 12 16:54:00 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 12 Aug 2015 21:54:00 +0100 Subject: Hooking Mechanism when Entering and Leaving a Try Block In-Reply-To: <55CB9425.5050109@mail.de> References: <55CA6D7F.1060705@mail.de> <55CB6EAC.5040004@mail.de> <55CB9425.5050109@mail.de> Message-ID: On 12/08/2015 19:44, Sven R. Kunze wrote: > On 12.08.2015 18:11, Chris Angelico wrote: >> (Please don't top-post.) > > Is this some guideline? I actually quite dislike pick somebody's mail to > pieces. It actually pulls things out of context. But if this is a rule > for this, so be it. > The rules here are very simple. Snip what you don't wish to reply to (yes I know I forget sometimes), intersperse your answers to what you do want to respond to. Apart from that *NEVER* top post. Other than that how you can state "It actually pulls things out of context" baffles me, unless you were taught to write top to bottom, left to write, or something similar. To put it another way M$ Outlook no more rules the world than does the BDFL :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Wed Aug 12 16:58:06 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 12 Aug 2015 21:58:06 +0100 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> Message-ID: On 12/08/2015 21:28, Denis McMahon wrote: > On Wed, 12 Aug 2015 09:29:50 -0700, Ltc Hotspot wrote: > >> Using the attached file of a diagram as a frame, why is there an >> attribute message? > > Perhaps you should read the message. It's very clear. > Not to Ltc Hotspot. I'm unsure as to whether he's simply incompetent or a troll, but whatever I plonked him several days ago on the tutor mailing list. Since then he's asked the same question here and on the core mentorship list. I suggest that everybody stop wasting their time and bandwidth. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ltc.hotspot at gmail.com Wed Aug 12 17:04:31 2015 From: ltc.hotspot at gmail.com (Ltc Hotspot) Date: Wed, 12 Aug 2015 14:04:31 -0700 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CB977D.9080300@mrabarnett.plus.com> Message-ID: So calling people stupid and ignorant on the internet makes you sexual arousal and to masturbate with yourself On Wed, Aug 12, 2015 at 1:38 PM, Denis McMahon wrote: > On Wed, 12 Aug 2015 12:05:37 -0700, Ltc Hotspot wrote: > >>>Have a look at assignment_10_2_v_06.py. > >> What should I look at assignment_10_2_v_06.py.: > > You shouldn't. You should instead approach your tutor and tell him you > are too stupid to learn computer programming[1], and can you please > transfer to floor-scrubbing 101. > > [1] You have repeatedly ignored advice and instructions that you have > been given. This is de-facto proof that you are not capable of learning > to program computers. > > -- > Denis McMahon, denismfmcmahon at gmail.com > -- > https://mail.python.org/mailman/listinfo/python-list From crk at godblessthe.us Wed Aug 12 17:15:32 2015 From: crk at godblessthe.us (Clayton Kirkwood) Date: Wed, 12 Aug 2015 14:15:32 -0700 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CB977D.9080300@mrabarnett.plus.com> Message-ID: <07dc01d0d544$061116a0$123343e0$@godblessthe.us> I'm thinking we are being played by a Turing type machine. crk > -----Original Message----- > From: Python-list [mailto:python-list- > bounces+crk=godblessthe.us at python.org] On Behalf Of Denis McMahon > Sent: Wednesday, August 12, 2015 1:39 PM > To: python-list at python.org > Subject: Re: AttributeError > > On Wed, 12 Aug 2015 12:05:37 -0700, Ltc Hotspot wrote: > > >>Have a look at assignment_10_2_v_06.py. > > > What should I look at assignment_10_2_v_06.py.: > > You shouldn't. You should instead approach your tutor and tell him you are > too stupid to learn computer programming[1], and can you please transfer to > floor-scrubbing 101. > > [1] You have repeatedly ignored advice and instructions that you have been > given. This is de-facto proof that you are not capable of learning to program > computers. > > -- > Denis McMahon, denismfmcmahon at gmail.com > -- > https://mail.python.org/mailman/listinfo/python-list From denismfmcmahon at gmail.com Wed Aug 12 17:16:41 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 12 Aug 2015 21:16:41 +0000 (UTC) Subject: AttributeError References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> Message-ID: On Wed, 12 Aug 2015 11:35:03 -0700, Ltc Hotspot wrote: > How do I define time in the revised code ? I'm guessing that you have a line of input like: word word word timestamp word word word word and that timestamp looks something like: hh:mm:ss Start of by defining a list with 24 elements all integer 0. Open the file. for each line, first you trim it, then you split it on spaces, you take the relevant element of the list of bits as the timestamp, and then you split that on the ':' character, then you take the int value of the hours element of that list and use that as the index into your list to update the count. Processing a file takes very few lines of actual code. There is no need to use a dictionary, you can do it with a single list and no sorting. This is a solution in 8 lines, and assumes that the actual requirement is to count, for each hour, the number of log messages generated in that hour, and then display, listed by hour, the number of messages generated in each hour during the day. It also assumes that there is a timestamp of the form hh:mm:ss that always appears at the same word position X in each line in the file, and that the hours record always at position Y in the timestamp. c = [0 for i in range(24)] f = open(filename,'r') for l in f: h = int(l.strip().split()[X].split(':')[Y]) c[h] = c[h] + 1 f.close() for i in range(24): print '{:02d} {}'.format(i, c[i]) -- Denis McMahon, denismfmcmahon at gmail.com From gheskett at wdtv.com Wed Aug 12 17:25:17 2015 From: gheskett at wdtv.com (Gene Heskett) Date: Wed, 12 Aug 2015 17:25:17 -0400 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CB977D.9080300@mrabarnett.plus.com> Message-ID: <201508121725.17249.gheskett@wdtv.com> On Wednesday 12 August 2015 15:05:37 Ltc Hotspot wrote: > >Have a look at assignment_10_2_v_06.py. > > What should I look at assignment_10_2_v_06.py.: > > > handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 > From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 > """.split("\n") > # Snippet file data: mbox-short.txt > > count = dict() > #fname = raw_input("Enter file name: ")# Add Snippet file > #handle = open (fname, 'r')# Add Snippet file > for line in handle: > if line.startswith("From "): > time = line.split() # Sort time > > hours = line.split(":")[5] # Sort hours > line = line.rstrip() > > count[hours] = count.get(hours, 0) + 1 # counter > > lst = [(val,key) for key,val in count.items()] > > print key, val > > On Wed, Aug 12, 2015 at 11:59 AM, MRAB wrote: > > On 2015-08-12 19:35, Ltc Hotspot wrote: > >> Emile > >> > >> How do I define time in the revised code ? > > > > Have a look at assignment_10_2_v_06.py. > > > >> ------------------------------------------------------------------- > >>-------- Traceback Message reads: > >> In [66]: %run assignment_10_2_v_07 > >> > >> NameError > >> Traceback (most recent call last) > >> C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_07.p > >>y in > >> () > >> 9 for line in handle: > >> 10 if line.startswith("From "): > >> ---> 11 for key, val in time.split()[5]: > >> 12 for key, val in hours.split(':')[0]: > >> 13 count[hours] = count.get(hours, 0) + 1 # > >> counter > >> > >> NameError: name 'time' is not defined > >> > >> ------------------------------------------------------------------- > >>-------- > >> > >> > >> In [67]: print time > >> 0 > >> > >> ------------------------------------------------------------------- > >>-------- > >> > >> Revised Code reads: > >> handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 > >> 2008 > >> > >>> From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 > >> > >> """.split("\n") > >> # Snippet file data: mbox-short.txt > >> > >> count = dict() > >> #fname = raw_input("Enter file name: ")# insert snippet file > >> #handle = open (fname, 'r')# insert snippet file > >> for line in handle: > >> if line.startswith("From "): > >> for key, val in time.split()[5]: > >> for key, val in hours.split(':')[0]: > >> count[hours] = count.get(hours, 0) + 1 # counter > >> > >> lst = [(val,key) for key,val in count.items()] > >> lst.sort(reverse=True) > >> > >> for key, val in lst[:12] : > >> print key, val > >> > >> > >> ------------------------------------------------------------------- > >>-------- Regards, > >> Hal > > > > I'm baffled as to why you now have a nested 'for' loop 3 levels > > deep! > > > > -- > > https://mail.python.org/mailman/listinfo/python-list After following this thread to late afternoon today, I would say that Denis's response was a bit strong and less than helpfull because the perceived insult drowns out the true meaning of his remark. OTOH, _you_ are putting zero effort into understanding the error, something the others have encouraged, apparently several times now on at least 2 other venues. This IS how one learns best, by seeing an error and taking an action that aleviates the error. Handing the answer to you on a clean plate may fix the error, but your chances of understanding why it was fixed are perhaps 10% as good than the understanding in the future would be if you followed normal debugging proceedures and fixed it yourself. If you aren't willing to put any effort into it yourself, then perhaps Denis does have the right idea. Find another line of endeavor that _will_ pay the bills. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From emile at fenx.com Wed Aug 12 17:32:40 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 12 Aug 2015 14:32:40 -0700 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CB977D.9080300@mrabarnett.plus.com> Message-ID: On 8/12/2015 1:38 PM, Denis McMahon wrote: > On Wed, 12 Aug 2015 12:05:37 -0700, Ltc Hotspot wrote: > >>> Have a look at assignment_10_2_v_06.py. > >> What should I look at assignment_10_2_v_06.py.: > > You shouldn't. You should instead approach your tutor and tell him you > are too stupid to learn computer programming[1], and can you please > transfer to floor-scrubbing 101. > > [1] You have repeatedly ignored advice and instructions that you have > been given. This is de-facto proof that you are not capable of learning > to program computers. Ooooh! I've heard stories people were released from *mart (or was that dell?) for comments like that. :) However-a-propos-ly y'rs, Emile @ltc -- read this -- then re-read all the responses you've been given. Repeat ad nauseam. Until you can understand and incorporate advice given you're wasting your time and ours asking. From breamoreboy at yahoo.co.uk Wed Aug 12 17:45:38 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 12 Aug 2015 22:45:38 +0100 Subject: AttributeError In-Reply-To: <07dc01d0d544$061116a0$123343e0$@godblessthe.us> References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CB977D.9080300@mrabarnett.plus.com> <07dc01d0d544$061116a0$123343e0$@godblessthe.us> Message-ID: On 12/08/2015 22:15, Clayton Kirkwood wrote: > I'm thinking we are being played by a Turing type machine. > crk > Will you please stop top posting, how many times do people have to be asked until the message gets through? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Wed Aug 12 17:51:52 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 12 Aug 2015 22:51:52 +0100 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CB977D.9080300@mrabarnett.plus.com> Message-ID: On 12/08/2015 22:32, Emile van Sebille wrote: > > @ltc -- read this -- then re-read all the responses you've been given. > Repeat ad nauseam. Until you can understand and incorporate advice > given you're wasting your time and ours asking. > This question has been asked on *THREE* different Python mailing lists. Do you really expect him to take any notice? I certainly don't, he got plonked by me days ago on the tutor mailing list, I just wish everone else would do the same so we could get rid of him, same as Nick the Greek and the RUE. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ltc.hotspot at gmail.com Wed Aug 12 18:02:25 2015 From: ltc.hotspot at gmail.com (Ltc Hotspot) Date: Wed, 12 Aug 2015 15:02:25 -0700 Subject: AttributeError In-Reply-To: <201508121725.17249.gheskett@wdtv.com> References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CB977D.9080300@mrabarnett.plus.com> <201508121725.17249.gheskett@wdtv.com> Message-ID: The problem here is that these are home work assignment and to code an else word assignment would be in contradiction to the academic curriculum. Specifically, I want to deploy a quick and simply dic solution: Revised code: c = [0 for i in range(24)] filename = raw_input("Enter file name: ") f = open(filename,'r') for l in f: h = int(l.strip().split()[X].split(':')[Y]) c[h] = c[h] + 1 f.close() for i in range(24): print '{:02d} {}'.format(i, c[i]) --------------------------------------------------------------------------- NameError Traceback (most recent call last) C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_10.py in () 5 f = open(filename,'r') 6 for l in f: ----> 7 h = int(l.strip().split()[X].split(':')[Y]) 8 c[h] = c[h] + 1 9 f.close() NameError: name 'X' is not defined In [74]: print X --------------------------------------------------------------------------- Print X: NameError Traceback (most recent call last) in () ----> 1 print X NameError: name 'X' is not defined In [75]: On Wed, Aug 12, 2015 at 2:25 PM, Gene Heskett wrote: > On Wednesday 12 August 2015 15:05:37 Ltc Hotspot wrote: > >> >Have a look at assignment_10_2_v_06.py. >> >> What should I look at assignment_10_2_v_06.py.: >> >> >> handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 >> From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 >> """.split("\n") >> # Snippet file data: mbox-short.txt >> >> count = dict() >> #fname = raw_input("Enter file name: ")# Add Snippet file >> #handle = open (fname, 'r')# Add Snippet file >> for line in handle: >> if line.startswith("From "): >> time = line.split() # Sort time >> >> hours = line.split(":")[5] # Sort hours >> line = line.rstrip() >> >> count[hours] = count.get(hours, 0) + 1 # counter >> >> lst = [(val,key) for key,val in count.items()] >> >> print key, val >> >> On Wed, Aug 12, 2015 at 11:59 AM, MRAB > wrote: >> > On 2015-08-12 19:35, Ltc Hotspot wrote: >> >> Emile >> >> >> >> How do I define time in the revised code ? >> > >> > Have a look at assignment_10_2_v_06.py. >> > >> >> ------------------------------------------------------------------- >> >>-------- Traceback Message reads: >> >> In [66]: %run assignment_10_2_v_07 >> >> >> >> NameError >> >> Traceback (most recent call last) >> >> C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_07.p >> >>y in >> >> () >> >> 9 for line in handle: >> >> 10 if line.startswith("From "): >> >> ---> 11 for key, val in time.split()[5]: >> >> 12 for key, val in hours.split(':')[0]: >> >> 13 count[hours] = count.get(hours, 0) + 1 # >> >> counter >> >> >> >> NameError: name 'time' is not defined >> >> >> >> ------------------------------------------------------------------- >> >>-------- >> >> >> >> >> >> In [67]: print time >> >> 0 >> >> >> >> ------------------------------------------------------------------- >> >>-------- >> >> >> >> Revised Code reads: >> >> handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 >> >> 2008 >> >> >> >>> From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 >> >> >> >> """.split("\n") >> >> # Snippet file data: mbox-short.txt >> >> >> >> count = dict() >> >> #fname = raw_input("Enter file name: ")# insert snippet file >> >> #handle = open (fname, 'r')# insert snippet file >> >> for line in handle: >> >> if line.startswith("From "): >> >> for key, val in time.split()[5]: >> >> for key, val in hours.split(':')[0]: >> >> count[hours] = count.get(hours, 0) + 1 # counter >> >> >> >> lst = [(val,key) for key,val in count.items()] >> >> lst.sort(reverse=True) >> >> >> >> for key, val in lst[:12] : >> >> print key, val >> >> >> >> >> >> ------------------------------------------------------------------- >> >>-------- Regards, >> >> Hal >> > >> > I'm baffled as to why you now have a nested 'for' loop 3 levels >> > deep! >> > >> > -- >> > https://mail.python.org/mailman/listinfo/python-list > > After following this thread to late afternoon today, I would say that > Denis's response was a bit strong and less than helpfull because the > perceived insult drowns out the true meaning of his remark. > > OTOH, _you_ are putting zero effort into understanding the error, > something the others have encouraged, apparently several times now on at > least 2 other venues. > > This IS how one learns best, by seeing an error and taking an action that > aleviates the error. Handing the answer to you on a clean plate may fix > the error, but your chances of understanding why it was fixed are > perhaps 10% as good than the understanding in the future would be if you > followed normal debugging proceedures and fixed it yourself. > > If you aren't willing to put any effort into it yourself, then perhaps > Denis does have the right idea. Find another line of endeavor that > _will_ pay the bills. > > Cheers, Gene Heskett > -- > "There are four boxes to be used in defense of liberty: > soap, ballot, jury, and ammo. Please use in that order." > -Ed Howdershelt (Author) > Genes Web page > -- > https://mail.python.org/mailman/listinfo/python-list From breamoreboy at yahoo.co.uk Wed Aug 12 18:16:42 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 12 Aug 2015 23:16:42 +0100 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CB977D.9080300@mrabarnett.plus.com> <201508121725.17249.gheskett@wdtv.com> Message-ID: On 12/08/2015 23:02, Ltc Hotspot wrote: FOR GOD'S SAKE WILL YOU PLEASE STOP TOP POSTING AND TRIM DOWN YOUR REPLIES. WHAT GRADE DO YOU EXPECT, A Z-? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From python at mrabarnett.plus.com Wed Aug 12 18:35:57 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Aug 2015 23:35:57 +0100 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> Message-ID: <55CBCA4D.1010706@mrabarnett.plus.com> On 2015-08-12 22:16, Denis McMahon wrote: [snip] > c = [0 for i in range(24)] > f = open(filename,'r') > for l in f: > h = int(l.strip().split()[X].split(':')[Y]) > c[h] = c[h] + 1 > f.close() > for i in range(24): > print '{:02d} {}'.format(i, c[i]) > There's no need to strip whitespace just before splitting on it. This: l.strip().split() can be shortened to this: l.split() From ben+python at benfinney.id.au Wed Aug 12 18:50:52 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 13 Aug 2015 08:50:52 +1000 Subject: Ensure unwanted names removed in class definition References: <85fv3oj2y6.fsf@benfinney.id.au> Message-ID: <85a8twi0j7.fsf@benfinney.id.au> Peter Otten <__peter__ at web.de> writes: > I would probably use a generator expression. These don't leak names: That's an unexpected inconsistency between list comprehensions versus generator expressions, then. Is that documented explicitly in the Python 2 documentation? > Python 2.7.6 (default, Jun 22 2015, 17:58:13) > [GCC 4.8.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> class Parrot: > ... a = [per for per in "abc"] > ... b = list(trans for trans in "def") > ... > >>> Parrot.per > 'c' > >>> Parrot.trans > Traceback (most recent call last): > File "", line 1, in > AttributeError: class Parrot has no attribute 'trans' We have a winner! That's elegant, expressive, and has the right behaviour on both Python 2 and Python 3. -- \ ?I turned to speak to God/About the world's despair; But to | `\ make bad matters worse/I found God wasn't there.? ?Robert Frost | _o__) | Ben Finney From ben+python at benfinney.id.au Wed Aug 12 18:55:50 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 13 Aug 2015 08:55:50 +1000 Subject: Ensure unwanted names removed in class definition References: <85fv3oj2y6.fsf@benfinney.id.au> <55CB62BE.4080403@mrabarnett.plus.com> Message-ID: <8537zoi0ax.fsf@benfinney.id.au> MRAB writes: > Have you thought about catching the NameError? I had not, but that is obvious now you say it. Thanks. Where there isn't a more elegant solution, I'll use that. It might not be elegant, but it's at least clear and expressive of the intent. Jussi Piitulainen writes: > Make them an implementation detail: > > plumage = [ > (__foo__, __bar__) for (__foo__, __bar__) in feathers.items() > if __bar__ == "beautiful" ] That still makes the name persist, so doesn't meet the requirements. It also commits the further mistake of using a ?__dunder__? name style for something that *isn't* a Python magic attribute. Thanks for the attempt :-) -- \ ?Teeth extracted by the latest Methodists.? dentist | `\ advertisement, Hong Kong | _o__) | Ben Finney From ltc.hotspot at gmail.com Wed Aug 12 19:05:55 2015 From: ltc.hotspot at gmail.com (Ltc Hotspot) Date: Wed, 12 Aug 2015 16:05:55 -0700 Subject: AttributeError In-Reply-To: <55CBCA4D.1010706@mrabarnett.plus.com> References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CBCA4D.1010706@mrabarnett.plus.com> Message-ID: On Wed, Aug 12, 2015 at 3:35 PM, MRAB wrote: > On 2015-08-12 22:16, Denis McMahon wrote: > [snip] > >> c = [0 for i in range(24)] >> f = open(filename,'r') >> for l in f: >> h = int(l.strip().split()[X].split(':')[Y]) >> c[h] = c[h] + 1 >> f.close() >> for i in range(24): >> print '{:02d} {}'.format(i, c[i]) >> > There's no need to strip whitespace just before splitting on it. > > This: > > l.strip().split() > > can be shortened to this: > > l.split() > > -- > https://mail.python.org/mailman/listinfo/python-list MRAB, The Revised code produces a traceback: () 9 10 c = [0 for i in range(24)] ---> 11 f = open(filename,'r') 12 for l in f: 13 h = int(l.split()[X].split(':')[Y]) NameError: name 'filename' is not defined The revised code reads: handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 >From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 """.split("\n") # Snippet file data: mbox-short.txt count = dict() #fname = raw_input("Enter file name: ")# Add Snippet file #handle = open (fname, 'r')# Add Snippet file c = [0 for i in range(24)] f = open(filename,'r') for l in f: h = int(l.split()[X].split(':')[Y]) c[h] = c[h] + 1 f.close() for i in range(24): print '{:02d} {}'.format(i, c[i]) How do I define the file name in order to remove the traceback? Regards, Hal From emile at fenx.com Wed Aug 12 19:15:14 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 12 Aug 2015 16:15:14 -0700 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CBCA4D.1010706@mrabarnett.plus.com> Message-ID: On 8/12/2015 4:05 PM, Ltc Hotspot wrote: > On Wed, Aug 12, 2015 at 3:35 PM, MRAB wrote: >> On 2015-08-12 22:16, Denis McMahon wrote: >> [snip] >> >>> c = [0 for i in range(24)] >>> f = open(filename,'r') >>> for l in f: >>> h = int(l.strip().split()[X].split(':')[Y]) >>> c[h] = c[h] + 1 >>> f.close() >>> for i in range(24): >>> print '{:02d} {}'.format(i, c[i]) >>> >> There's no need to strip whitespace just before splitting on it. >> >> This: >> >> l.strip().split() >> >> can be shortened to this: >> >> l.split() >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > > > MRAB, > > The Revised code produces a traceback: > () > 9 > 10 c = [0 for i in range(24)] > ---> 11 f = open(filename,'r') > 12 for l in f: > 13 h = int(l.split()[X].split(':')[Y]) > > NameError: name 'filename' is not defined So, read your posted code below and tell us where the label 'filename' is defined. We can't find it. Neither can python. That's what the error message means. Was that not clear? You do understand the difference between text and labels, right? You have by now reviewed the tutorial? Emile > > > > The revised code reads: > > handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 > From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 > """.split("\n") > # Snippet file data: mbox-short.txt > > count = dict() > #fname = raw_input("Enter file name: ")# Add Snippet file > #handle = open (fname, 'r')# Add Snippet file > > c = [0 for i in range(24)] > f = open(filename,'r') > for l in f: > h = int(l.split()[X].split(':')[Y]) > c[h] = c[h] + 1 > f.close() > for i in range(24): > print '{:02d} {}'.format(i, c[i]) > > > How do I define the file name in order to remove the traceback? > > Regards, > Hal > From python at mrabarnett.plus.com Wed Aug 12 19:16:46 2015 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 13 Aug 2015 00:16:46 +0100 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CBCA4D.1010706@mrabarnett.plus.com> Message-ID: <55CBD3DE.2080407@mrabarnett.plus.com> On 2015-08-13 00:05, Ltc Hotspot wrote: > On Wed, Aug 12, 2015 at 3:35 PM, MRAB wrote: > > On 2015-08-12 22:16, Denis McMahon wrote: > > [snip] > > > >> c = [0 for i in range(24)] > >> f = open(filename,'r') > >> for l in f: > >> h = int(l.strip().split()[X].split(':')[Y]) > >> c[h] = c[h] + 1 > >> f.close() > >> for i in range(24): > >> print '{:02d} {}'.format(i, c[i]) > >> > > There's no need to strip whitespace just before splitting on it. > > > > This: > > > > l.strip().split() > > > > can be shortened to this: > > > > l.split() > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > MRAB, > > The Revised code produces a traceback: > () > 9 > 10 c = [0 for i in range(24)] > ---> 11 f = open(filename,'r') > 12 for l in f: > 13 h = int(l.split()[X].split(':')[Y]) > > NameError: name 'filename' is not defined > > > > The revised code reads: > > handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 > >From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 > """.split("\n") > # Snippet file data: mbox-short.txt > > count = dict() > #fname = raw_input("Enter file name: ")# Add Snippet file > #handle = open (fname, 'r')# Add Snippet file > > c = [0 for i in range(24)] > f = open(filename,'r') > for l in f: > h = int(l.split()[X].split(':')[Y]) > c[h] = c[h] + 1 > f.close() > for i in range(24): > print '{:02d} {}'.format(i, c[i]) > > > How do I define the file name in order to remove the traceback? > At this point I think I'll just let you figure that out for yourself... From ltc.hotspot at gmail.com Wed Aug 12 19:46:32 2015 From: ltc.hotspot at gmail.com (Ltc Hotspot) Date: Wed, 12 Aug 2015 16:46:32 -0700 Subject: AttributeError In-Reply-To: <55CBD3DE.2080407@mrabarnett.plus.com> References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CBCA4D.1010706@mrabarnett.plus.com> <55CBD3DE.2080407@mrabarnett.plus.com> Message-ID: >> How do I define the file name in order to remove the traceback? >> > At this point I think I'll just let you figure that out for yourself... > > -- > https://mail.python.org/mailman/listinfo/python-list MRAB, How do I define X? ------------------------------------------------------------------------------------- Traceback reads: 10 f = open(filename,'r') 11 for l in f: ---> 12 h = int(l.split()[X].split(':')[Y]) 13 c[h] = c[h] + 1 14 f.close() NameError: name 'X' is not defined ------------------------------------------------------------------------------------- Revised code reads: handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 >From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 """.split("\n") # Snippet file data: mbox-short.txt filename = raw_input("Enter file:") if len(filename) < 1 : filename = "mbox-short.txt" c = [0 for i in range(24)] f = open(filename,'r') for l in f: h = int(l.split()[X].split(':')[Y]) c[h] = c[h] + 1 f.close() for i in range(24): print '{:02d} {}'.format(i, c[i]) Regards, Hal From python at mrabarnett.plus.com Wed Aug 12 19:56:42 2015 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 13 Aug 2015 00:56:42 +0100 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CBCA4D.1010706@mrabarnett.plus.com> <55CBD3DE.2080407@mrabarnett.plus.com> Message-ID: <55CBDD3A.6030204@mrabarnett.plus.com> On 2015-08-13 00:46, Ltc Hotspot wrote: > >> How do I define the file name in order to remove the traceback? > >> > > At this point I think I'll just let you figure that out for yourself... > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > MRAB, > > How do I define X? > ------------------------------------------------------------------------------------- > Traceback reads: > > 10 f = open(filename,'r') > 11 for l in f: > ---> 12 h = int(l.split()[X].split(':')[Y]) > 13 c[h] = c[h] + 1 > 14 f.close() > > NameError: name 'X' is not defined > ------------------------------------------------------------------------------------- > Revised code reads: > handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 > >From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 > """.split("\n") # Snippet file data: mbox-short.txt > > filename = raw_input("Enter file:") > if len(filename) < 1 : filename = "mbox-short.txt" > > > c = [0 for i in range(24)] > f = open(filename,'r') > for l in f: > h = int(l.split()[X].split(':')[Y]) > c[h] = c[h] + 1 > f.close() > for i in range(24): > print '{:02d} {}'.format(i, c[i]) > Print out the result of "l.split()" and figure out the value of X that will give you the part you want. Then, print out the result of the ".split(':')" part and figure out the value of Y that will give you the part you want. From rosuav at gmail.com Wed Aug 12 20:45:24 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Aug 2015 10:45:24 +1000 Subject: Hooking Mechanism when Entering and Leaving a Try Block In-Reply-To: References: <55CA6D7F.1060705@mail.de> <55CB6EAC.5040004@mail.de> <55CB9425.5050109@mail.de> Message-ID: On Thu, Aug 13, 2015 at 6:54 AM, Mark Lawrence wrote: > On 12/08/2015 19:44, Sven R. Kunze wrote: >> >> On 12.08.2015 18:11, Chris Angelico wrote: >>> >>> (Please don't top-post.) >> >> >> Is this some guideline? I actually quite dislike pick somebody's mail to >> pieces. It actually pulls things out of context. But if this is a rule >> for this, so be it. >> > > The rules here are very simple. Snip what you don't wish to reply to (yes I > know I forget sometimes), intersperse your answers to what you do want to > respond to. As Mark says, the key is to intersperse your answers with the context. In some email clients, you can highlight a block of text and hit Reply, and it'll quote only that text. (I was so happy when Gmail introduced that feature. It was the one thing I'd been most missing from it.) ChrisA From tjreedy at udel.edu Wed Aug 12 21:49:24 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 12 Aug 2015 21:49:24 -0400 Subject: Linux users: please run gui tests In-Reply-To: <201508080640.t786e4QU000440@fido.openend.se> References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> <201508071346.t77DkL2t031696@fido.openend.se> <201508071701.t77H1Csn004579@fido.openend.se> <201508080640.t786e4QU000440@fido.openend.se> Message-ID: On 8/8/2015 2:40 AM, Laura Creighton wrote: > In a message of Fri, 07 Aug 2015 21:25:21 -0400, Terry Reedy writes: >> https://bugs.python.org/issue15601 >> was about this very test failure. The failure only occurred with tk >> 8.4. What tk version do you have? (Easily found, for instance, in Idle >> -> Help -> About Idle. (python3 -m idlelib should start idle). > Tk version 8.6.4 Could you add a note to the issue then? -- Terry Jan Reedy From lac at openend.se Thu Aug 13 01:11:33 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 13 Aug 2015 07:11:33 +0200 Subject: Linux users: please run gui tests In-Reply-To: Message from Terry Reedy of "Wed, 12 Aug 2015 21:49:24 -0400." References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> <201508071346.t77DkL2t031696@fido.openend.se> <201508071701.t77H1Csn004579@fido.openend.se> <201508080640.t786e4QU000440@fido.openend.se> Message-ID: <201508130511.t7D5BXTn020058@fido.openend.se> In a message of Wed, 12 Aug 2015 21:49:24 -0400, Terry Reedy writes: >On 8/8/2015 2:40 AM, Laura Creighton wrote: >> In a message of Fri, 07 Aug 2015 21:25:21 -0400, Terry Reedy writes: > > >> https://bugs.python.org/issue15601 >>> was about this very test failure. The failure only occurred with tk >>> 8.4. What tk version do you have? (Easily found, for instance, in Idle >>> -> Help -> About Idle. (python3 -m idlelib should start idle). > >> Tk version 8.6.4 > >Could you add a note to the issue then? > > >-- >Terry Jan Reedy Done, though I wonder if it isn't a separate issue. I didn't re-open the issue, which is marked closed. From __peter__ at web.de Thu Aug 13 01:44:39 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 13 Aug 2015 07:44:39 +0200 Subject: Ensure unwanted names removed in class definition References: <85fv3oj2y6.fsf@benfinney.id.au> <85a8twi0j7.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Peter Otten <__peter__ at web.de> writes: > >> I would probably use a generator expression. These don't leak names: > > That's an unexpected inconsistency between list comprehensions versus > generator expressions, then. Is that documented explicitly in the Python > 2 documentation? https://docs.python.org/2/reference/expressions.html has one sentence """ Note that the comprehension is executed in a separate scope, so names assigned to in the target list don?t ?leak? in the enclosing scope. """ -- which is wrong unless I'm misunderstanding something, but https://docs.python.org/2.4/whatsnew/node4.html clearly states """ Generator expressions differ from list comprehensions in various small ways. Most notably, the loop variable (obj in the above example) is not accessible outside of the generator expression. List comprehensions leave the variable assigned to its last value; future versions of Python will change this, making list comprehensions match generator expressions in this respect. """ From ben+python at benfinney.id.au Thu Aug 13 02:04:06 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 13 Aug 2015 16:04:06 +1000 Subject: Ensure unwanted names removed in class definition References: <85fv3oj2y6.fsf@benfinney.id.au> <85a8twi0j7.fsf@benfinney.id.au> Message-ID: <85y4hfhgh5.fsf@benfinney.id.au> Peter Otten <__peter__ at web.de> writes: > Ben Finney wrote: > > > Peter Otten <__peter__ at web.de> writes: > > > > That's an unexpected inconsistency between list comprehensions > > versus generator expressions, then. Is that documented explicitly in > > the Python 2 documentation? > > https://docs.python.org/2.4/whatsnew/node4.html Or . Also in the PEP that introduces generator expressions, PEP 289: List comprehensions also "leak" their loop variable into the surrounding scope. This will also change in Python 3.0, so that the semantic definition of a list comprehension in Python 3.0 will be equivalent to list(). Thanks for seeking the answer. Can you describe an improvement to that makes clear this unexpected, deprecated behaviour which is only in Python 2? -- \ ?What is needed is not the will to believe but the will to find | `\ out, which is the exact opposite.? ?Bertrand Russell, _Free | _o__) Thought and Official Propaganda_, 1928 | Ben Finney From srkunze at mail.de Thu Aug 13 02:26:35 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Thu, 13 Aug 2015 08:26:35 +0200 Subject: Hooking Mechanism when Entering and Leaving a Try Block In-Reply-To: References: <55CA6D7F.1060705@mail.de> <55CB6EAC.5040004@mail.de> <55CB9425.5050109@mail.de> Message-ID: <55CC389B.7030604@mail.de> On 13.08.2015 02:45, Chris Angelico wrote: > On Thu, Aug 13, 2015 at 6:54 AM, Mark Lawrence wrote: >> On 12/08/2015 19:44, Sven R. Kunze wrote: >>> On 12.08.2015 18:11, Chris Angelico wrote: >>>> (Please don't top-post.) >>> >>> Is this some guideline? I actually quite dislike pick somebody's mail to >>> pieces. It actually pulls things out of context. But if this is a rule >>> for this, so be it. >>> >> The rules here are very simple. Snip what you don't wish to reply to (yes I >> know I forget sometimes), intersperse your answers to what you do want to >> respond to. > As Mark says, the key is to intersperse your answers with the context. > In some email clients, you can highlight a block of text and hit > Reply, and it'll quote only that text. (I was so happy when Gmail > introduced that feature. It was the one thing I'd been most missing > from it.) > > ChrisA So, I take this as a "my personal preference guideline" because I cannot find an official document for this (maybe, I am looking at the wrong places). In order to keep you happy, I perform this ancient type communication where the most relevant information (i.e. the new one) is either to find at the bottom (scrolling is such fun) OR hidden between the lines (wasting time is even more fun these days). Btw. to me, the *context is the entire post*, not just two lines. I hate if people answer me on every single word I've written and try to explain what've got wrong instead of trying to understand the message and my perspective as a whole. I find it very difficult to respond to such a post and I am inclined to completely start from an empty post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From srkunze at mail.de Thu Aug 13 02:28:01 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Thu, 13 Aug 2015 08:28:01 +0200 Subject: Hooking Mechanism when Entering and Leaving a Try Block In-Reply-To: <55CB9425.5050109@mail.de> References: <55CA6D7F.1060705@mail.de> <55CB6EAC.5040004@mail.de> <55CB9425.5050109@mail.de> Message-ID: <55CC38F1.8070307@mail.de> On 12.08.2015 20:44, Sven R. Kunze wrote: > On 12.08.2015 18:11, Chris Angelico wrote: >> Sounds to me like you want some sort of AST transform, possibly in an >> import hook. Check out something like MacroPy for an idea of how >> powerful this sort of thing can be. > > Sounds like I MacroPy would enable me to basically insert a function > call before and after each try: block at import time. Is that correct > so far? That sounds not so bad at all. > > > However, if that only works due to importing it is not a solution. I > need to make sure I catch all try: blocks, the current stack is in > (and is about to step into). > > Ah yes, and it should work with Python 3 as well. Back to topic, please. :) From jonas at wielicki.name Thu Aug 13 03:59:05 2015 From: jonas at wielicki.name (Jonas Wielicki) Date: Thu, 13 Aug 2015 09:59:05 +0200 Subject: Hooking Mechanism when Entering and Leaving a Try Block In-Reply-To: <55CC389B.7030604@mail.de> References: <55CA6D7F.1060705@mail.de> <55CB6EAC.5040004@mail.de> <55CB9425.5050109@mail.de> <55CC389B.7030604@mail.de> Message-ID: <55CC4E49.3050903@wielicki.name> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 On 13.08.2015 08:26, Sven R. Kunze wrote: > > So, I take this as a "my personal preference guideline" because I > cannot find an official document for this (maybe, I am looking at > the wrong places). - From RFC 1855 (Netiquette Guidelines ): - If you are sending a reply to a message or a posting be sure you summarize the original at the top of the message, or include just enough text of the original to give a context. This will make sure readers understand when they start to read your response. Since NetNews, especially, is proliferated by distributing the postings from one host to another, it is possible to see a response to a message before seeing the original. Giving context helps everyone. But do not include the entire original! (there is other stuff related to this in there too) > In order to keep you happy, I perform this ancient type > communication where the most relevant information (i.e. the new > one) is either to find at the bottom (scrolling is such fun) OR > hidden between the lines (wasting time is even more fun these > days). I have seen that notion with people who have not much mail traffic or are not trying to keep track of several threads at once. I personally have much less trouble (i.e. I am actually saving time!) following multiple threads when the posters are using proper quoting and are not top-posting. regards, jwi -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIbBAEBCgAGBQJVzE5BAAoJEMBiAyWXYliKe48P+L9fZm55y/0ORi7FtdzDmUaL 1gD5zhSflGrI0dRusfETu8kkAJOi3uDFs0rKRXJuWh3vY9f+Dj0573wWFuJ5CRPz SRIb3M8s7txo3Oxj+IJEgKk+FRqVwBrw5MIbkuNrhZ0UmZnvO0JhtqPYEmZpb+Ht Yvnj+PeLChytKzuMYGVz3bwU7FM9C5VMIkXeszL2oEMbqdfwfINP89bS779RQwz0 ZcT3z1OG/rqNgAJrn2/fMVZTMQe9lhfLcgWvIR2+/pxPpU7iuaTqRXC130kc7hIu ifzZf25Wi2Wxz5B4Psx0dJFKfSxasPa5qEBO1rlrH4vxJI6sPu8CI0P15fS7bO1O Mh3IPrPPZM8mByxuJxcdKHyCvOOXcs4G0Iz2+QjXuvujP8p9vrA+TVq2trB07FL9 lleXkH0ETjZzwxdzpdmgCePP302nqm5MZimpGLCjmygvSZo/HFj4PH9WWcmEhVgA kzN1uyk1f0RVk/8KqtnKNWs5pWKORxuCBCeMhm8PeIov1uJwhsWenqHsbmERUciY RKs3raJQ+M4fedGHAmlrWcI9N0slG2MIcYBCXbA0v0HM/7+JF63Orc6TCqf5iQ1p O1VyJqUASRKJ9XekWcliGkyuIS9WPR0vUsjjqdpRWfGhd62FAq6xfzPuf8V4PdfI K+TfUFKDSS6yjLNGxY0= =8iLz -----END PGP SIGNATURE----- From breamoreboy at yahoo.co.uk Thu Aug 13 04:34:10 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 13 Aug 2015 09:34:10 +0100 Subject: Hooking Mechanism when Entering and Leaving a Try Block In-Reply-To: <55CC389B.7030604@mail.de> References: <55CA6D7F.1060705@mail.de> <55CB6EAC.5040004@mail.de> <55CB9425.5050109@mail.de> <55CC389B.7030604@mail.de> Message-ID: On 13/08/2015 07:26, Sven R. Kunze wrote: > On 13.08.2015 02:45, Chris Angelico wrote: >> On Thu, Aug 13, 2015 at 6:54 AM, Mark Lawrence wrote: >>> On 12/08/2015 19:44, Sven R. Kunze wrote: >>>> On 12.08.2015 18:11, Chris Angelico wrote: >>>>> (Please don't top-post.) >>>> >>>> Is this some guideline? I actually quite dislike pick somebody's mail to >>>> pieces. It actually pulls things out of context. But if this is a rule >>>> for this, so be it. >>>> >>> The rules here are very simple. Snip what you don't wish to reply to (yes I >>> know I forget sometimes), intersperse your answers to what you do want to >>> respond to. >> As Mark says, the key is to intersperse your answers with the context. >> In some email clients, you can highlight a block of text and hit >> Reply, and it'll quote only that text. (I was so happy when Gmail >> introduced that feature. It was the one thing I'd been most missing >> from it.) >> >> ChrisA > > So, I take this as a "my personal preference guideline" because I cannot > find an official document for this (maybe, I am looking at the wrong > places). > This is a community list. The rule has been no top posting here for the 15 years I've been using Python. I find trying to follow the really long threads on python-dev or python-ideas almost impossible as there is no rule, so you're up and down responses like a yo-yo. > In order to keep you happy, I perform this ancient type communication > where the most relevant information (i.e. the new one) is either to find > at the bottom (scrolling is such fun) OR hidden between the lines > (wasting time is even more fun these days). What rubbish. Just because some people have been brainwashed into writing English incorrectly by their using M$ Outlook doesn't mean that the rest of the world has to follow suit. If you don't want to work so hard to use this list then simply don't bother coming here, I doubt that the list will miss you. > Btw. to me, the *context is the entire post*, not just two lines. I hate > if people answer me on every single word I've written and try to explain > what've got wrong instead of trying to understand the message and my > perspective as a whole. I find it very difficult to respond to such a > post and I am inclined to completely start from an empty post. Which is why we prefer interspersed posting such as this. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marko at pacujo.net Thu Aug 13 05:09:20 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 13 Aug 2015 12:09:20 +0300 Subject: [OT] How to post properly (was: Re: Hooking Mechanism when Entering and Leaving a Try Block) References: <55CA6D7F.1060705@mail.de> <55CB6EAC.5040004@mail.de> <55CB9425.5050109@mail.de> <55CC389B.7030604@mail.de> Message-ID: <878u9fa727.fsf_-_@elektro.pacujo.net> Mark Lawrence : > The rule has been no top posting here for the 15 years I've been using > Python. Top posting is simply annoying. However, I'd like people to also stick to another rule: only quote a few lines. I should start seeing your contribution to the discussion without scrolling because those few lines help me decide if I should skip the posting altogether. (Well, if I can't see any original content at once, I'll skip the posting.) A third rule, which I'm violating here myself, is stick to Python-related topics on this newsgroup. Marko From denismfmcmahon at gmail.com Thu Aug 13 05:15:20 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 13 Aug 2015 09:15:20 +0000 (UTC) Subject: AttributeError References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CBCA4D.1010706@mrabarnett.plus.com> <55CBD3DE.2080407@mrabarnett.plus.com> Message-ID: On Wed, 12 Aug 2015 16:46:32 -0700, Ltc Hotspot wrote: > How do I define X? > ------------------------------------------------------------------------------------- > Traceback reads: > > 10 f = open(filename,'r') > 11 for l in f: > ---> 12 h = int(l.split()[X].split(':')[Y]) > 13 c[h] = c[h] + 1 14 f.close() > > NameError: name 'X' is not defined If you read the text that I posted with the solution, it tells you what X and Y are. They are numbers that describe the positions of elements in your input data. This absolute refusal by you to read any explanations that are posted are exactly why you will never be a good programmer. To become a good programmer you need to read and understand the explanations. In the post with that code example, I wrote: It also assumes that there is a timestamp of the form hh:mm:ss that always appears at the same word position X in each line in the file, and that the hours record always at position Y in the timestamp. You have to replace X and Y in that line with numbers that represent the positions in the lists returned by the relevant split commands of the actual text elements that you want to extract. -- Denis McMahon, denismfmcmahon at gmail.com From breamoreboy at yahoo.co.uk Thu Aug 13 05:37:48 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 13 Aug 2015 10:37:48 +0100 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CB977D.9080300@mrabarnett.plus.com> Message-ID: On 12/08/2015 22:04, Ltc Hotspot wrote: > So calling people stupid and ignorant on the internet makes you sexual > arousal and to masturbate with yourself *plonk* - please follow suit everybody, it's quite clear that he has no interest in bothering with any of the data we've all provided. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ltc.hotspot at gmail.com Thu Aug 13 05:41:55 2015 From: ltc.hotspot at gmail.com (Ltc Hotspot) Date: Thu, 13 Aug 2015 02:41:55 -0700 Subject: AttributeError In-Reply-To: References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CBCA4D.1010706@mrabarnett.plus.com> <55CBD3DE.2080407@mrabarnett.plus.com> Message-ID: On Thu, Aug 13, 2015 at 2:15 AM, Denis McMahon wrote: > On Wed, 12 Aug 2015 16:46:32 -0700, Ltc Hotspot wrote: > >> How do I define X? >> > ------------------------------------------------------------------------------------- >> Traceback reads: >> >> 10 f = open(filename,'r') >> 11 for l in f: >> ---> 12 h = int(l.split()[X].split(':')[Y]) >> 13 c[h] = c[h] + 1 14 f.close() >> >> NameError: name 'X' is not defined > > If you read the text that I posted with the solution, it tells you what X > and Y are. They are numbers that describe the positions of elements in > your input data. > > This absolute refusal by you to read any explanations that are posted are > exactly why you will never be a good programmer. To become a good > programmer you need to read and understand the explanations. > > In the post with that code example, I wrote: > > It also assumes that there is a timestamp of the form hh:mm:ss that > always appears at the same word position X in each line in the file, and > that the hours record always at position Y in the timestamp. > > You have to replace X and Y in that line with numbers that represent the > positions in the lists returned by the relevant split commands of the > actual text elements that you want to extract. > > -- Denis, What are the values of X & Y from the code as follows: Code reads: handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008 >From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008 """.split("\n") # snippet file data: mbox-short.txt count = dict() #fname = raw_input("Enter file name: ")# insert # to add snippet file data #handle = open (fname, 'r')# insert # to add snippet file data for line in handle: if line.startswith("From "): time = line.split() # splitting the lines -> # print time: ['From', 'stephen.marquard at uct.ac.za', 'Sat', 'Jan', '5', '09:14:16', '2008'] for hours in time: #getting the index pos of time -> hours = line.split(":")[2] # splitting on ":" -> line = line.rstrip() count[hours] = count.get(hours, 0) + 1 # getting the index pos of hours. lst = [(val,key) for key,val in count.items()] # find the most common words lst.sort(reverse=True) for key, val in lst[:12] : print key, val Regards, Hal From werotizy at freent.dd Thu Aug 13 06:32:38 2015 From: werotizy at freent.dd (Tom P) Date: Thu, 13 Aug 2015 12:32:38 +0200 Subject: problem with netCDF4 OpenDAP Message-ID: I'm having a problem trying to access OpenDAP files using netCDF4. The netCDF4 is installed from the Anaconda package. According to their changelog, openDAP is supposed to be supported. netCDF4.__version__ Out[7]: '1.1.8' Here's some code: url = 'http://www1.ncdc.noaa.gov/pub/data/cmb/ersst/v3b/netcdf/ersst.201507.nc' nc = netCDF4.Dataset(url) I get the error - netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Dataset.__init__ (netCDF4/_netCDF4.c:9551)() RuntimeError: NetCDF: file not found However if I download the same file, it works - url = '/home/tom/Downloads/ersst.201507.nc' nc = netCDF4.Dataset(url) print nc . . . . Is it something I'm doing wrong? From Dwight at GoldWinde.com Thu Aug 13 07:06:08 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Thu, 13 Aug 2015 19:06:08 +0800 Subject: Global command doesn't seem to work... Message-ID: Inside of Functions.py I define the function: def subwords (): global subwordsDL subwordsDL = {'enjoy':['like', 'appreciate', 'love', 'savor'], 'hurt':['damage', 'suffering']} print (subwordsDL) Return In my test code module, the code is: global subwordsDL from Functions import subwords subwords () print (subwordsDL) print (subwordsDL['enjoy'][2]) I get an error on the 4th line of this module (BTW, I tried this module with and without the first line, reaffirming subwordsDL as global, and the results are the same): {'hurt': ['damage', 'suffering'], 'enjoy': ['like', 'appreciate', 'love', 'savor']} Traceback (most recent call last): File "test short.py", line 4, in print (subwordsDL) NameError: name 'subwordsDL' is not defined LOL?worked on this for over an hour? Please help. BIG SMILE... Always, Dwight -------------- next part -------------- An HTML attachment was scrubbed... URL: From denismfmcmahon at gmail.com Thu Aug 13 07:06:20 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 13 Aug 2015 11:06:20 +0000 (UTC) Subject: AttributeError References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CBCA4D.1010706@mrabarnett.plus.com> <55CBD3DE.2080407@mrabarnett.plus.com> Message-ID: On Thu, 13 Aug 2015 02:41:55 -0700, Ltc Hotspot wrote: >>> How do I define X? > What are the values of X & Y from the code as follows: > # print time: ['From', 'stephen.marquard at uct.ac.za', 'Sat', 'Jan', '5', '09:14:16', '2008'] This is the data you need to look at. X is the position in the printed list of the time information. If you can not determine the correct X value by inspection of the list having been told which element it should be, then you need to go back to the python documentation and read about the list data object and how elements within the list are referenced. Once you understand from the documentation how to reference the list elements, you will be able to determine by inspection of the above list the correct value for X. Y is the position of the hours element within the time information when that information is further split using the ':' separator. You may need to refer to the documentation for the split() method of the string data object. Once you understand from the documentation how the string.split() function creates a list, and how to reference the list elements (as above), you will be able to determine by inspection the correct value for Y. This is fundamental python knowledge, and you must discover it in the documentation and understand it. You will then be able to determine the correct values for X and Y. Note that the code I posted may need the addition of a line something like: if line.startswith("From "): in a relevant position, as well as additional indenting to take account of that addition. -- Denis McMahon, denismfmcmahon at gmail.com From ben+python at benfinney.id.au Thu Aug 13 07:08:09 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 13 Aug 2015 21:08:09 +1000 Subject: AttributeError References: <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <55CB815B.8070800@mrabarnett.plus.com> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <55CB977D.9080300@mrabarnett.plus.com> Message-ID: <85tws3h2ee.fsf@benfinney.id.au> Ltc Hotspot writes: > So calling people stupid and ignorant on the internet makes you sexual > arousal and to masturbate with yourself With that, you have worn out your welcome here. Please don't post here again until you can refrain from puerile demeaning insults. -- \ ?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 tjreedy at udel.edu Thu Aug 13 07:55:47 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 13 Aug 2015 07:55:47 -0400 Subject: Linux users: please run gui tests In-Reply-To: <201508130511.t7D5BXTn020058@fido.openend.se> References: <87wpx7fsb9.fsf@Equus.decebal.nl> <87si7vfqwn.fsf@Equus.decebal.nl> <201508071238.t77CcY7n018432@fido.openend.se> <201508071346.t77DkL2t031696@fido.openend.se> <201508071701.t77H1Csn004579@fido.openend.se> <201508080640.t786e4QU000440@fido.openend.se> <201508130511.t7D5BXTn020058@fido.openend.se> Message-ID: On 8/13/2015 1:11 AM, Laura Creighton wrote: > In a message of Wed, 12 Aug 2015 21:49:24 -0400, Terry Reedy writes: >>>> https://bugs.python.org/issue15601 >> Could you add a note to the issue then? > Done, though I wonder if it isn't a separate issue. I was not sure. The people currently nosy will get email. > I didn't re-open the issue, which is marked closed. I decided to do so, so issue is included in new issues list. -- Terry Jan Reedy From python at rgbaz.eu Thu Aug 13 08:53:01 2015 From: python at rgbaz.eu (Python UL) Date: Thu, 13 Aug 2015 14:53:01 +0200 Subject: Real-time recoding of video from asx to non-Windows formats In-Reply-To: References: Message-ID: <55CC932D.8020701@rgbaz.eu> On 12-08-15 08:04, Montana Burr wrote: > Hi, > > I'm interested in using Python to create a server for streaming my > state's traffic cameras - which are only available as Windows Media > streams - to devices that do not natively support streaming Windows > Media content (think Linux computers & iPads). I know Python makes > various problems easy to solve, and I'd like to know if this is one of > those problems. I would like to use a module that works on any Linux- > or UNIX-based computer, as my primary computer is UNIX-based. > > Hi Montana, You should take a look at FFmpeg (www.ffmpeg.org). There's a python wrapper but I doubt you need it. https://github.com/mhaller/pyffmpeg gr Arno -------------- next part -------------- An HTML attachment was scrubbed... URL: From torriem at gmail.com Thu Aug 13 10:19:40 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 13 Aug 2015 08:19:40 -0600 Subject: Real-time recoding of video from asx to non-Windows formats In-Reply-To: References: Message-ID: <55CCA77C.6020503@gmail.com> On 08/12/2015 12:04 AM, Montana Burr wrote: > I'm interested in using Python to create a server for streaming my > state's traffic cameras - which are only available as Windows Media streams > - to devices that do not natively support streaming Windows Media content > (think Linux computers & iPads). I know Python makes various problems easy > to solve, and I'd like to know if this is one of those problems. I would > like to use a module that works on any Linux- or UNIX-based computer, as my > primary computer is UNIX-based. This is a case of use the best tool for the job. Python could glue the parts together, but maybe a bash script would be best. As for the tools themselves, they aren't going to be Python. Things like mplayer, vlc, ffmpeg all might assist. VLC is very good at this kind of thing, and can be driven from the command line, say from a bash script. VLC can connect to a network stream, transcode it, and offer it up as a different network stream. However VLC network transcoding is only a one connection at a time sort of thing, so it may not be enough for your needs. If your main target is Linux, windows media streams work fairly well with mplayer or vlc. From henrique.calandra at walljobs.com.br Thu Aug 13 10:59:58 2015 From: henrique.calandra at walljobs.com.br (henrique.calandra at walljobs.com.br) Date: Thu, 13 Aug 2015 07:59:58 -0700 (PDT) Subject: Vaga Java (Belgica, com tudo pago) Message-ID: https://walljobs.typeform.com/to/uWpUqj We seek a software developer with experience in web application development. Should you have the passion to work in the start-up environment and the willingness to evolve in a fast-paced environment, then we'd like to get in touch. We are located in Brussels, Belgium, in the center of Europe. You should be able to work in an international team, show passion and commitment to towards the project, and be able to adapt to challenging European working standards. Responsibilities Understand design documents, giving feedback when necessary, and implement the required changes in the code base. Interact with an existing large software implementation and independently perform the required actions Review code from peers Develop automated tests and other quality assurance techniques Interact with the marketing, psychology and business teams giving advice and feedback Adapt and adjust to a fast pacing environment https://walljobs.typeform.com/to/uWpUqj From jason.swails at gmail.com Thu Aug 13 11:55:49 2015 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 13 Aug 2015 11:55:49 -0400 Subject: problem with netCDF4 OpenDAP In-Reply-To: References: Message-ID: On Thu, Aug 13, 2015 at 6:32 AM, Tom P wrote: > I'm having a problem trying to access OpenDAP files using netCDF4. > The netCDF4 is installed from the Anaconda package. According to their > changelog, openDAP is supposed to be supported. > > netCDF4.__version__ > Out[7]: > '1.1.8' > > Here's some code: > > url = ' > http://www1.ncdc.noaa.gov/pub/data/cmb/ersst/v3b/netcdf/ersst.201507.nc' > nc = netCDF4.Dataset(url) > > I get the error - > netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Dataset.__init__ > (netCDF4/_netCDF4.c:9551)() > > RuntimeError: NetCDF: file not found > > > However if I download the same file, it works - > url = '/home/tom/Downloads/ersst.201507.nc' > nc = netCDF4.Dataset(url) > print nc > . . . . > > Is it something I'm doing wrong? ?Yes. URLs are not files and cannot be opened like normal files. netCDF4 *requires* a local file as far as I can tell. All the best, Jason -- Jason M. Swails BioMaPS, Rutgers University Postdoctoral Researcher -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas.lehmann.private at googlemail.com Thu Aug 13 11:58:38 2015 From: thomas.lehmann.private at googlemail.com (Thomas Lehmann) Date: Thu, 13 Aug 2015 08:58:38 -0700 (PDT) Subject: Mock object but also assert method calls? Message-ID: <509adc48-996d-44b0-abf1-e15ee387023b@googlegroups.com> Hi, How about asserting that test2 of class Bar is called? Of course I can do a patch for a concrete method but I was looking for something like: mocked_object.assert_method_called_with(name="test2", "hello") If find following totally different to the normal API which is provided by the mock library: assert call().test2("hello") in mocked_objects.mock_calls Is there a better way? APPENDIX: Foo delegates calls to Bar. [code] from mock import patch with patch("__main__.Bar") as mocked_object: foo = Foo() foo.test1() foo.test2("hello") print(mocked_object.mock_calls) # print all calls (c'tor as well as normal methods) for name, args, kwargs in mocked_object.mock_calls: print(name, args, kwargs) [/code] Generates: test1: Foo has been called test2: Foo has been called with value hello [call(), call().test1(), call().test2('hello')] ('', (), {}) ('().test1', (), {}) ('().test2', ('hello',), {}) From kirotawa at gmail.com Thu Aug 13 12:01:15 2015 From: kirotawa at gmail.com (leo kirotawa) Date: Thu, 13 Aug 2015 13:01:15 -0300 Subject: Vaga Java (Belgica, com tudo pago) In-Reply-To: References: Message-ID: Wondering why a position for Java/JS was sent to this list...just wondering... On Thu, Aug 13, 2015 at 11:59 AM, wrote: > https://walljobs.typeform.com/to/uWpUqj > > We seek a software developer with experience in web application development. > > Should you have the passion to work in the start-up environment and the willingness to evolve in a fast-paced environment, then we'd like to get in touch. > > We are located in Brussels, Belgium, in the center of Europe. You should be able to work in an international team, show passion and commitment to towards the project, and be able to adapt to challenging European working standards. > > Responsibilities > > Understand design documents, giving feedback when necessary, and implement the required changes in the code base. > > Interact with an existing large software implementation and independently perform the required actions > > Review code from peers > > Develop automated tests and other quality assurance techniques > > Interact with the marketing, psychology and business teams giving advice and feedback > > Adapt and adjust to a fast pacing environment > > https://walljobs.typeform.com/to/uWpUqj > -- > https://mail.python.org/mailman/listinfo/python-list -- ---------------------------------------------- Le?nidas S. Barbosa (Kirotawa) blog: corecode.wordpress.com From amrishb12 at gmail.com Thu Aug 13 12:42:41 2015 From: amrishb12 at gmail.com (Amrish B) Date: Thu, 13 Aug 2015 09:42:41 -0700 (PDT) Subject: OBIEE Developer and Administrator @ Seattle WA Message-ID: Hello Folks, Please go through below job description and send me updated resume to amrish at uniteditinc.com Job Title: OBIEE Developer and Administrator Location: Seattle WA Duration: 12+months Experience: 10+ years only Job Description: * maintain the Oracle Business Intelligence Enterprise Edition application and develop reports/dashboards for functional areas * Act as an analyst interacting with departments to understand, define, and document report and dashboard requirements * Assist in configuring complex Oracle systems (Oracle client tools, administration of Web Logic, and setup and configuration of web server with front end reporting tools) * Responsible for security administration within OBIEE as well as integrations with active directory * Research, tune, and implement configurations to ensure applications are performing to expected standards * Researches, evaluates and recommends enabling software design practices, trends, and related technologies * Support and comply with security model and company audit standards * Conduct comprehensive analysis of enterprise systems concepts, design, and test requirements * Analyzes, defines, and documents requirements for data, workflow, logical processes, interfaces with other systems, internal and external checks and controls, and outputs Qualifications/Knowledge, Skills, & Abilities Requirements * Bachelor's Degree in Computer Science, Engineering, or related discipline, or equivalent, experience * 8 plus years of experience in data warehouse or reporting design and development * Experience with DBMS (i.e. Oracle) and working with data * Experience in system administration * Ability to troubleshoot and solve complex issues in an Enterprise environment * Ability to establish and maintain a high level of customer trust and confidence * Strong analytical and conceptual skills; ability to create original concepts and ideas Thanks & Regards, Amrish Babu | IT Recruiter From stephane at wirtel.be Thu Aug 13 12:48:24 2015 From: stephane at wirtel.be (=?utf-8?q?St=C3=A9phane?= Wirtel) Date: Thu, 13 Aug 2015 18:48:24 +0200 Subject: OBIEE Developer and Administrator @ Seattle WA In-Reply-To: References: Message-ID: Hi Amrish, I think you can post to jobs at python.org See: https://www.python.org/community/jobs/howto/ Thank you Stephane On 13 Aug 2015, at 18:42, Amrish B wrote: > Hello Folks, > > Please go through below job description and send me updated resume to > amrish at uniteditinc.com > > Job Title: OBIEE Developer and Administrator > Location: Seattle WA > Duration: 12+months > Experience: 10+ years only > > Job Description: > * maintain the Oracle Business Intelligence Enterprise Edition > application and develop reports/dashboards for functional areas > * Act as an analyst interacting with departments to > understand, define, and document report and dashboard requirements > * Assist in configuring complex Oracle systems (Oracle client > tools, administration of Web Logic, and setup and configuration of web > server with front end reporting tools) > * Responsible for security administration within OBIEE as well > as integrations with active directory > * Research, tune, and implement configurations to ensure > applications are performing to expected standards > * Researches, evaluates and recommends enabling software > design practices, trends, and related technologies > * Support and comply with security model and company audit > standards > * Conduct comprehensive analysis of enterprise systems > concepts, design, and test requirements > * Analyzes, defines, and documents requirements for data, > workflow, logical processes, interfaces with other systems, internal > and external checks and controls, and outputs > > Qualifications/Knowledge, Skills, & Abilities Requirements > * Bachelor's Degree in Computer Science, Engineering, or > related discipline, or equivalent, experience > * 8 plus years of experience in data warehouse or reporting > design and development > * Experience with DBMS (i.e. Oracle) and working with data > * Experience in system administration > * Ability to troubleshoot and solve complex issues in an > Enterprise environment > * Ability to establish and maintain a high level of customer > trust and confidence > * Strong analytical and conceptual skills; ability to create > original concepts and ideas > > > Thanks & Regards, > > Amrish Babu | IT Recruiter > -- > https://mail.python.org/mailman/listinfo/python-list -- St?phane Wirtel - http://wirtel.be - @matrixise From jcasale at activenetwerx.com Thu Aug 13 12:56:24 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 13 Aug 2015 16:56:24 +0000 Subject: Module load times Message-ID: I have an auto generated module that provides functions exported from a c dll. Its rather large and we are considering some dynamic code generation and caching, however before I embark on that I want to test import times. As the module is all auto generated through XSL, things like __all__ are not used, a consumer only imports one class which has methods for their use. It is the internal supporting classes which are large such as the ctype function prototypes and structures. My concern is simply reloading this in Python 3.3+ in a timeit loop is not accurate. What is the best way to do this? Thanks, jlc From alexglaros at gmail.com Thu Aug 13 15:10:12 2015 From: alexglaros at gmail.com (Alex Glaros) Date: Thu, 13 Aug 2015 12:10:12 -0700 (PDT) Subject: How to model government organization hierarchies so that the list can expand and compress Message-ID: It's like the desktop folder/directory model where you can create unlimited folders and put folders within other folders. Instead of folders, I want to use government organizations. Example: Let user create agency names: Air Force, Marines, Navy, Army. Then let them create an umbrella collection called "Pentagon", and let users drag Air Force, Marines, Navy, etc. into the umbrella collection. User may wish to add smaller sub-sets of Army, such as "Army Jeep Repair Services" User may also want to add a new collection "Office of the President" and put OMB and Pentagon under that as equals. What would the data model look like for this? If I have a field: next_higher_level_parent that lets children records keep track of parent record, it's hard for me to imagine anything but an inefficient bubble sort to produce a hierarchical organizational list. Am using Postgres, not graph database. I'm hoping someone else has worked on this problem, probably not with government agency names, but perhaps the same principle with other objects. Thanks! Alex Glaros From stefan_ml at behnel.de Thu Aug 13 15:12:08 2015 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 13 Aug 2015 21:12:08 +0200 Subject: Module load times In-Reply-To: References: Message-ID: Joseph L. Casale schrieb am 13.08.2015 um 18:56: > I have an auto generated module that provides functions exported from a > c dll. Its rather large and we are considering some dynamic code generation > and caching, however before I embark on that I want to test import times. > > As the module is all auto generated through XSL, things like __all__ are not > used, a consumer only imports one class which has methods for their use. > > It is the internal supporting classes which are large such as the ctype function > prototypes and structures. How is the DLL binding implemented? Using "ctypes"? Or something else? Obviously, instantiating a large ctypes wrapper will take some time. A binary module would certainly be quicker here, both in terms of import time and execution time. Since you're generating the code anyway, generating Cython code instead shouldn't be difficult but would certainly yield faster code. > My concern is simply reloading this in Python 3.3+ in a timeit loop is not > accurate. What is the best way to do this? What makes you think the import might be a problem? That's a one-time thing. Or is your application a command-line tool or so that needs to start and terminate quickly? Stefan From stephane at wirtel.be Thu Aug 13 15:17:44 2015 From: stephane at wirtel.be (=?utf-8?q?St=C3=A9phane?= Wirtel) Date: Thu, 13 Aug 2015 21:17:44 +0200 Subject: How to model government organization hierarchies so that the list can expand and compress In-Reply-To: References: Message-ID: Create a model with a parent_id on the current model and you can use the mptt concept or some others for the reading. On 13 Aug 2015, at 21:10, Alex Glaros wrote: > It's like the desktop folder/directory model where you can create > unlimited folders and put folders within other folders. Instead of > folders, I want to use government organizations. > > Example: Let user create agency names: Air Force, Marines, Navy, Army. > Then let them create an umbrella collection called "Pentagon", and let > users drag Air Force, Marines, Navy, etc. into the umbrella > collection. > > User may wish to add smaller sub-sets of Army, such as "Army Jeep > Repair Services" > > User may also want to add a new collection "Office of the President" > and put OMB and Pentagon under that as equals. > > What would the data model look like for this? If I have a field: > next_higher_level_parent that lets children records keep track of > parent record, it's hard for me to imagine anything but an inefficient > bubble sort to produce a hierarchical organizational list. Am using > Postgres, not graph database. > > I'm hoping someone else has worked on this problem, probably not with > government agency names, but perhaps the same principle with other > objects. > > Thanks! > > Alex Glaros > -- > https://mail.python.org/mailman/listinfo/python-list -- St?phane Wirtel - http://wirtel.be - @matrixise From ian.g.kelly at gmail.com Thu Aug 13 15:26:19 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 13 Aug 2015 13:26:19 -0600 Subject: How to model government organization hierarchies so that the list can expand and compress In-Reply-To: References: Message-ID: On Thu, Aug 13, 2015 at 1:10 PM, Alex Glaros wrote: > It's like the desktop folder/directory model where you can create unlimited folders and put folders within other folders. Instead of folders, I want to use government organizations. > > Example: Let user create agency names: Air Force, Marines, Navy, Army. Then let them create an umbrella collection called "Pentagon", and let users drag Air Force, Marines, Navy, etc. into the umbrella collection. > > User may wish to add smaller sub-sets of Army, such as "Army Jeep Repair Services" > > User may also want to add a new collection "Office of the President" and put OMB and Pentagon under that as equals. > > What would the data model look like for this? If I have a field: next_higher_level_parent that lets children records keep track of parent record, it's hard for me to imagine anything but an inefficient bubble sort to produce a hierarchical organizational list. Am using Postgres, not graph database. > > I'm hoping someone else has worked on this problem, probably not with government agency names, but perhaps the same principle with other objects. https://en.wikipedia.org/wiki/Tree_(data_structure) From lac at openend.se Thu Aug 13 15:43:58 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 13 Aug 2015 21:43:58 +0200 Subject: How to model government organization hierarchies so that the list can expand and compress In-Reply-To: Message from "=?utf-8?q?St=C3=A9phane?= Wirtel" of "Thu, 13 Aug 2015 21:17:44 +0200." References: Message-ID: <201508131943.t7DJhwgU028613@fido.openend.se> Figure out, right now, what you want to do when you find a government agency that has 2 masters and not one, so the strict heirarchy won't work. Laura From jcasale at activenetwerx.com Thu Aug 13 17:12:58 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 13 Aug 2015 21:12:58 +0000 Subject: Module load times In-Reply-To: References: , Message-ID: <1439500378035.80552@activenetwerx.com> Hi Stefan, > How is the DLL binding implemented? Using "ctypes"? Or something else? It is through ctypes. > Obviously, instantiating a large ctypes wrapper will take some time. A > binary module would certainly be quicker here, both in terms of import time > and execution time. Since you're generating the code anyway, generating > Cython code instead shouldn't be difficult but would certainly yield faster > code. True, I was using XSLT to auto generate the module. I will however explore this. > What makes you think the import might be a problem? That's a one-time > thing. Or is your application a command-line tool or so that needs to start > and terminate quickly? The code is used within plugin points and soon to be asynchronous code (once the original broken implementation is fixed) where in some cases it will be instantiated 100's of 1000's of times etc... Thanks, jlc From ben+python at benfinney.id.au Thu Aug 13 17:21:54 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 14 Aug 2015 07:21:54 +1000 Subject: Mock object but also assert method calls? References: <509adc48-996d-44b0-abf1-e15ee387023b@googlegroups.com> Message-ID: <85pp2qhojx.fsf@benfinney.id.au> Thomas Lehmann via Python-list writes: > How about asserting that test2 of class Bar is called? It is unusual to call class methods; do you mean a method on an instance? You will make a mock instance of the class, or a mock of the class; and you'll need to know which it is. > Of course I can do a patch for a concrete method but I was looking for > something like: > > mocked_object.assert_method_called_with(name="test2", "hello") The ?mock? library defaults to providing ?MagicMock?, which is ?magic? in the sense that it automatically provides any attribute you request, and those attributes are themselves also MagicMocks:: import unittest.mock def test_spam_calls_foo_bar(): """ Should call the `spam` method on the specified `Foo` instance. """ mock_foo = unittest.mock.MagicMock(system_under_test.Foo) system_under_test.spam(mock_foo) mock_foo.spam.assert_called_with("hello") > If find following totally different to the normal API which > is provided by the mock library: > > assert call().test2("hello") in mocked_objects.mock_calls The ?assert? statement is a crude tool, which knows little about the intent of your assertion. You should be instead using the specialised methods from ?unittest.TestCase? and the methods on the mock objects themselves. -- \ ?It is the mark of an educated mind to be able to entertain a | `\ thought without accepting it.? ?Aristotle | _o__) | Ben Finney From steve at pearwood.info Thu Aug 13 19:15:47 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 14 Aug 2015 09:15:47 +1000 Subject: [Meta] How to post properly (was: Re: Hooking Mechanism when Entering and Leaving a Try Block) References: <55CA6D7F.1060705@mail.de> <55CB6EAC.5040004@mail.de> <55CB9425.5050109@mail.de> <55CC389B.7030604@mail.de> <878u9fa727.fsf_-_@elektro.pacujo.net> Message-ID: <55cd2523$0$1663$c3e8da3$5496439d@news.astraweb.com> On Thu, 13 Aug 2015 07:09 pm, Marko Rauhamaa wrote: > A third rule, which I'm violating here myself, is stick to > Python-related topics on this newsgroup. On the sorts of places that take these sorts of fine distinctions seriously, your post would be considered Meta rather than Off-topic. That is: - posts about the main topic (here, that would be Python) are on-topic; - posts about posting are meta; - everything else is off-topic. We have a reasonable tolerance to off-topic discussions, particularly if they evolve naturally from an on-topic one. -- Steven From torriem at gmail.com Thu Aug 13 20:53:57 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 13 Aug 2015 18:53:57 -0600 Subject: [OT] unwritten list etiquette ate, was Re: Hooking Mechanism when Entering and Leaving a Try Block In-Reply-To: <55CC389B.7030604@mail.de> References: <55CA6D7F.1060705@mail.de> <55CB6EAC.5040004@mail.de> <55CB9425.5050109@mail.de> <55CC389B.7030604@mail.de> Message-ID: <55CD3C25.2010206@gmail.com> On 08/13/2015 12:26 AM, Sven R. Kunze wrote: > > Btw. to me, the *context is the entire post*, not just two lines. You're a very rare person indeed. Most people seem to not read any of the post except the first and last lines. At least posting inline shows me they've read and understood the portion of my email they are quoting. Many times I've emailed someone with a few details and queries (not too many; attention spans are short), only to get a one sentence, top-posted reply that completely fails to come remotely close to answering my actual question. I went back and forth with one guy three times once, each time pleading with him to read what I wrote. Note that I removed content that isn't relevant to my reply, thus making it easier for others to follow this. > I hate if people answer me on every single word I've written and try > to explain what've got wrong instead of trying to understand the > message and my perspective as a whole. I find it very difficult to > respond to such a post and I am inclined to completely start from an > empty post. In my experience, when a person does this (delete everything and start from an empty post, or just say screw it and top post), he or she is likely the one who got the wrong message and failed to understand the message or my perspective. Not saying you do, but in general it's this rationale that has led to the reaction people on usenet have to top posting. From torriem at gmail.com Thu Aug 13 20:57:58 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 13 Aug 2015 18:57:58 -0600 Subject: [Back off topic] - Re: Hooking Mechanism when Entering and Leaving a Try Block In-Reply-To: <55CC38F1.8070307@mail.de> References: <55CA6D7F.1060705@mail.de> <55CB6EAC.5040004@mail.de> <55CB9425.5050109@mail.de> <55CC38F1.8070307@mail.de> Message-ID: <55CD3D16.8030806@gmail.com> On 08/13/2015 12:28 AM, Sven R. Kunze wrote: > On 12.08.2015 20:44, Sven R. Kunze wrote: >> On 12.08.2015 18:11, Chris Angelico wrote: >>> Sounds to me like you want some sort of AST transform, possibly in an >>> import hook. Check out something like MacroPy for an idea of how >>> powerful this sort of thing can be. >> >> Sounds like I MacroPy would enable me to basically insert a function >> call before and after each try: block at import time. Is that correct >> so far? That sounds not so bad at all. >> >> >> However, if that only works due to importing it is not a solution. I >> need to make sure I catch all try: blocks, the current stack is in >> (and is about to step into). >> >> Ah yes, and it should work with Python 3 as well. > > Back to topic, please. :) But we love being off topic! Also if you change the subject line to demarcate a branch in the discussion (and mark it as off topic), that is completely acceptable as well. This in fact was done eventually by Marko. That leaves the original part of the thread to carry on its merry way. Of course I am assuming you read your email using a threaded email client that shows you the nested tree structure of the replies, instead of the really strange 1-dimensional gmail-style conversations that lose that structure entirely. But I digress. We get sidetracked rather easily around here. From torriem at gmail.com Thu Aug 13 21:05:10 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 13 Aug 2015 19:05:10 -0600 Subject: Is Django the way to go for a newbie? In-Reply-To: <6f2dc159-146b-44b8-b72e-fa34c4dc43cf@googlegroups.com> References: <55C7E15C.6070003@verizon.net> <6f2dc159-146b-44b8-b72e-fa34c4dc43cf@googlegroups.com> Message-ID: <55CD3EC6.7030300@gmail.com> On 08/10/2015 10:08 PM, Rustom Mody wrote: > On Tuesday, August 11, 2015 at 8:59:47 AM UTC+5:30, Michael Torrie wrote: >> On 08/10/2015 07:49 PM, Dwight GoldWinde wrote: >>> Thank you, Gary, for this new information. >>> >>> I will be looking into virtualenv and vertualenvwrapper. >>> >>> I thought that Django was an IDE. But, it seems that an IDE is one more >>> thing that I need that I didn?t know I needed!? >> >> Django is a programming _library_ (also called a framework) > > Please dont conflate library and framework. > Library, framework, DSL are different approaches for solving similar problems. > I personally tend to prefer DSL's, dislike frameworks and am neutral to libraries. > Which is why I would tend to start with flask + template-language + ORM > rather than start with a framework. > Others may have for very good reasons different preferences and that is fine?. > > But if you say equate all these, discussion becomes a mess. Ahh. Well at least you didn't rail on me for being too lazy to capitalize acronyms like html. Given that until recently he thought Django was an IDE, I think calling Django a library is fair, as it describes to him how it relates to Python. You download it and install it and it goes in site-packages along with all the other libraries you might install. Of course it comes with utilities as well (which I mentioned). Making the distinctions you are making, in this context, is probably ultimately going to be confusing to him at this stage of the game. As he gets familiar with django I don't think he'll find this original simplification confusing, nor has it seemed to make this discussion a mess. As to the DSL, I'm not quite sure which part of django you're getting at. Are you referring to the (optional) templating system? From rustompmody at gmail.com Thu Aug 13 21:30:17 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 13 Aug 2015 18:30:17 -0700 (PDT) Subject: Is Django the way to go for a newbie? In-Reply-To: References: <55C7E15C.6070003@verizon.net> <6f2dc159-146b-44b8-b72e-fa34c4dc43cf@googlegroups.com> Message-ID: On Friday, August 14, 2015 at 6:35:27 AM UTC+5:30, Michael Torrie wrote: > On 08/10/2015 10:08 PM, Rustom Mody wrote: > > On Tuesday, August 11, 2015 at 8:59:47 AM UTC+5:30, Michael Torrie wrote: > >> On 08/10/2015 07:49 PM, Dwight GoldWinde wrote: > >>> Thank you, Gary, for this new information. > >>> > >>> I will be looking into virtualenv and vertualenvwrapper. > >>> > >>> I thought that Django was an IDE. But, it seems that an IDE is one more > >>> thing that I need that I didn?t know I needed!? > >> > >> Django is a programming _library_ (also called a framework) > > > > Please dont conflate library and framework. > > Library, framework, DSL are different approaches for solving similar problems. > > I personally tend to prefer DSL's, dislike frameworks and am neutral to libraries. > > Which is why I would tend to start with flask + template-language + ORM > > rather than start with a framework. > > Others may have for very good reasons different preferences and that is fine?. > > > > But if you say equate all these, discussion becomes a mess. > > Ahh. Well at least you didn't rail on me for being too lazy to > capitalize acronyms like html. No I am not trolling :-) > > Given that until recently he thought Django was an IDE, I think calling > Django a library is fair, as it describes to him how it relates to > Python. You download it and install it and it goes in site-packages > along with all the other libraries you might install. Of course it > comes with utilities as well (which I mentioned). Making the > distinctions you are making, in this context, is probably ultimately > going to be confusing to him at this stage of the game. As he gets > familiar with django I don't think he'll find this original > simplification confusing, nor has it seemed to make this discussion a mess. > True. Purposive, directed lying is usually better pedagogy than legalistic correctness. > As to the DSL, I'm not quite sure which part of django you're getting > at. Are you referring to the (optional) templating system? Nothing specifically Django I am getting at. Just that learning - a templating engine -- eg Cheetah, Mako - an ORM eg SQLAlchemy - etc is more fun than learning to chant the right mantras that a framework demands without any clue of what/why/how I dont know Django. Used RoR some years ago and it was frightening. And Ruby is not bad. So I assume Rails is. I just assumed -- maybe ignorantly -- that Django and RoR are generically similar systems From rosuav at gmail.com Thu Aug 13 21:44:42 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Aug 2015 11:44:42 +1000 Subject: Is Django the way to go for a newbie? In-Reply-To: <55CD3EC6.7030300@gmail.com> References: <55C7E15C.6070003@verizon.net> <6f2dc159-146b-44b8-b72e-fa34c4dc43cf@googlegroups.com> <55CD3EC6.7030300@gmail.com> Message-ID: On Fri, Aug 14, 2015 at 11:05 AM, Michael Torrie wrote: > Given that until recently he thought Django was an IDE, I think calling > Django a library is fair, as it describes to him how it relates to > Python. You download it and install it and it goes in site-packages > along with all the other libraries you might install. Of course it > comes with utilities as well (which I mentioned). Making the > distinctions you are making, in this context, is probably ultimately > going to be confusing to him at this stage of the game. As he gets > familiar with django I don't think he'll find this original > simplification confusing, nor has it seemed to make this discussion a mess. > > As to the DSL, I'm not quite sure which part of django you're getting > at. Are you referring to the (optional) templating system? My view, for what it's worth: Django is a library, but it's also a framework. The difference isn't really that great, and most frameworks are implemented using libraries. The "library vs framework" distinction, from an application's standpoint, broadly one of how you structure your code - do you write a bunch of top-level code that calls on library functions, or do you write a bunch of functions that the framework calls on? The distinction can blur some, too. And as Michael says, the slight simplification isn't causing problems, so it's really only a technical correctness issue. (Pedantry, in the best sense of the word.) I've often explained things using technically-incorrect language, because going into immense detail won't help; we don't explain quantum mechanics and the nuances of electrical engineering when we explain how an HTTP request arrives at your app, because it doesn't matter. Saying "The system hands you a request to process" is slightly sloppy even from a network admin's perspective (what you actually get is a socket connection, and then you read from that until you reckon you have the whole request, yada yada), but it's what you most likely care about. On Fri, Aug 14, 2015 at 11:30 AM, Rustom Mody wrote: > Purposive, directed lying is usually better pedagogy than legalistic correctness. Right :) Only I wouldn't call it "lying", as that term indicates an intent to deceive. Purposeful inaccuracy, let's say. ChrisA From steve at pearwood.info Thu Aug 13 22:10:20 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 14 Aug 2015 12:10:20 +1000 Subject: Module load times References: Message-ID: <55cd4e0c$0$1642$c3e8da3$5496439d@news.astraweb.com> On Fri, 14 Aug 2015 07:12 am, Joseph L. Casale wrote: >> What makes you think the import might be a problem? That's a one-time >> thing. Or is your application a command-line tool or so that needs to >> start and terminate quickly? > > The code is used within plugin points and soon to be asynchronous code > (once the original broken implementation is fixed) where in some cases it > will be instantiated 100's of 1000's of times etc... Importing is not the same as instantiation. When you import a module, the code is only read from disk and instantiated the first time. Then it is cached. Subsequent imports in the same Python session use the cached version. So the answer will depend on your application. If your application runs for a long time (relatively speaking), and imports the plugins 100s or 1000s of times, it should not matter. Only the first import is likely to be slow. But if the application starts up, imports the plugin, then shuts down, then repeats 100s or 1000s of times, that may be slow. Or if it launches separate processes, each of which imports the plugin. Without understanding your application, and the plugin model, it is difficult to predict the impact of importing. -- Steven From jcasale at activenetwerx.com Thu Aug 13 22:25:29 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Fri, 14 Aug 2015 02:25:29 +0000 Subject: Module load times In-Reply-To: <55cd4e0c$0$1642$c3e8da3$5496439d@news.astraweb.com> References: <55cd4e0c$0$1642$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Importing is not the same as instantiation. > > When you import a module, the code is only read from disk and instantiated > the first time. Then it is cached. Subsequent imports in the same Python > session use the cached version. I do mean imported, in the original design there were many ctype function prototypes, the c developer had ran some tests and showed quite a bit of time taken up just the import over 100 clean imports. I don't have his test harness and hence why I am trying to validate the results. > So the answer will depend on your application. If your application runs for > a long time (relatively speaking), and imports the plugins 100s or 1000s of > times, it should not matter. Only the first import is likely to be slow. > > But if the application starts up, imports the plugin, then shuts down, then > repeats 100s or 1000s of times, that may be slow. Or if it launches > separate processes, each of which imports the plugin. Yeah that wasn't clear. The plugins are invoked in fresh interpreter processes and hence modules with import side effects or simply large modules can manifest over time. Thanks Steven jlc From rosuav at gmail.com Thu Aug 13 22:38:35 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Aug 2015 12:38:35 +1000 Subject: Module load times In-Reply-To: References: <55cd4e0c$0$1642$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 14, 2015 at 12:25 PM, Joseph L. Casale wrote: > Yeah that wasn't clear. The plugins are invoked in fresh interpreter processes > and hence modules with import side effects or simply large modules can > manifest over time. If they're invoked in fresh processes, then you're looking at process startup time, and I would recommend using OS-level tools to play around with that. Unix-like systems will usually have a 'time' command which will tell you exactly how much wall and CPU time a process took needed; just create a system that starts up and promptly shuts down, and then you can test iterations that way. Of course, there are a million and one variables (disk caches, other activity on the system, etc), but it's better than nothing. ChrisA From steve at pearwood.info Thu Aug 13 22:53:44 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 14 Aug 2015 12:53:44 +1000 Subject: Mock object but also assert method calls? References: <509adc48-996d-44b0-abf1-e15ee387023b@googlegroups.com> Message-ID: <55cd5839$0$1636$c3e8da3$5496439d@news.astraweb.com> On Fri, 14 Aug 2015 07:21 am, Ben Finney wrote: >> If find following totally different to the normal API which >> is provided by the mock library: >> >> assert call().test2("hello") in mocked_objects.mock_calls > > The ?assert? statement is a crude tool, which knows little about the > intent of your assertion. I agree with Ben here. Despite the popularity of "nose" (I think it is nose?) which uses `assert` for testing, I think that is a gross misuse of the statement. It is okay to use assertions this way for quick and dirty ad hoc testing, say at the command line, but IMO totally inappropriate for anything more formal, like unit testing. If for no other reason than the use of `assert` for testing makes it impossible to test your code when running with the Python -O (optimize) switch. For more detail on the uses, and abuses, of `assert` see this: http://import-that.dreamwidth.org/676.html -- Steven From torriem at gmail.com Thu Aug 13 23:10:42 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 13 Aug 2015 21:10:42 -0600 Subject: Is Django the way to go for a newbie? In-Reply-To: References: <55C7E15C.6070003@verizon.net> <6f2dc159-146b-44b8-b72e-fa34c4dc43cf@googlegroups.com> Message-ID: <55CD5C32.70809@gmail.com> On 08/13/2015 07:30 PM, Rustom Mody wrote: > Nothing specifically Django I am getting at. > Just that learning > - a templating engine -- eg Cheetah, Mako > - an ORM eg SQLAlchemy > - etc > > is more fun than learning to chant the right mantras that a framework > demands without any clue of what/why/how Indeed. It's this very thing that you speak of that makes web development very discouraging to me because it does demand knowledge of quite a few separate but interconnected domains and their specific languages. In my original post I had forgotten to mention ORM, though I did mention SQL. Adding abstraction in theory makes things easier. In practice it's often kind of like the old saying about solving a problem using regular expressions. From lac at openend.se Fri Aug 14 00:23:35 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 14 Aug 2015 06:23:35 +0200 Subject: Is Django the way to go for a newbie? In-Reply-To: Message from Rustom Mody of "Thu, 13 Aug 2015 18:30:17 -0700." References: <55C7E15C.6070003@verizon.net> <6f2dc159-146b-44b8-b72e-fa34c4dc43cf@googlegroups.com> Message-ID: <201508140423.t7E4NZlv031456@fido.openend.se> In a message of Thu, 13 Aug 2015 18:30:17 -0700, Rustom Mody writes: > >I dont know Django. Used RoR some years ago and it was frightening. >And Ruby is not bad. So I assume Rails is. >I just assumed -- maybe ignorantly -- that Django and RoR are generically >similar systems > It's web2py that is the Python web framework that was inspired and influenced by RoR. And they are about as different as can be and still both be Full Stack Frameworks, to the extent that most people (at least all the ones I know) who really like one framework also really dislike the other. Laura From frank at chagford.com Fri Aug 14 02:36:08 2015 From: frank at chagford.com (Frank Millman) Date: Fri, 14 Aug 2015 08:36:08 +0200 Subject: How to model government organization hierarchies so that the list can expand and compress In-Reply-To: References: Message-ID: "Alex Glaros" wrote in message news:b3c1e2da-9f72-420a-8b68-288dddf9fc67 at googlegroups.com... > It's like the desktop folder/directory model where you can create > unlimited folders and put folders within other folders. Instead of > folders, I want to use government organizations. > Example: Let user create agency names: Air Force, Marines, Navy, Army. > Then let them create an umbrella collection called "Pentagon", and let > users drag Air Force, Marines, Navy, etc. into the umbrella collection. > User may wish to add smaller sub-sets of Army, such as "Army Jeep Repair > Services" > User may also want to add a new collection "Office of the President" and > put OMB and Pentagon under that as equals. > What would the data model look like for this? If I have a field: > next_higher_level_parent that lets children records keep track of parent > record, it's hard for me to imagine anything but an inefficient bubble > sort to produce a hierarchical organizational list. Am using Postgres, not > graph database. Before you read my response, make sure that you read Laura's. Are you 100% sure that a hierarchical model is the correct solution for your requirement? It is not clear whether you want the data model to be expressed in Python or in the database. The following thoughts assume the latter. There are two classic approaches to using a relational database for this - 'adjacency lists' and 'nested sets'. Google for both and you will find many interesting articles. Nested sets were invented to overcome a problem with building complex queries on adjacency lists, but this problem has been overcome in recent years by the introduction of recursive queries, which most modern databases support. For PostgreSQL, read this page of the docs - http://www.postgresql.org/docs/9.1/static/queries-with.html . Because adjacency lists are easier to manipulate, and your comments above imply that this is a major requirement, I think that this is the way to go. As an aside, I mentioned in a recent post that I had upgraded the version of sqlite3 shipped with python3.4 to the most recent version. The reason was that the older version did not support recursive queries properly, but the latest version does. Regarding allowing your users to manipulate the structure, I think this is a function of the gui that you choose. Most gui toolkits will have a 'tree' widget, and hopefully make it easy to implement 'drag-and-drop' between the nodes. Then your task becomes one of getting the data out of the database and into the gui, and back again. Once you get used to the concepts, it is not that difficult. HTH Frank Millman From __peter__ at web.de Fri Aug 14 02:37:30 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 14 Aug 2015 08:37:30 +0200 Subject: Ensure unwanted names removed in class definition References: <85fv3oj2y6.fsf@benfinney.id.au> <85a8twi0j7.fsf@benfinney.id.au> <85y4hfhgh5.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Peter Otten <__peter__ at web.de> writes: > >> Ben Finney wrote: >> >> > Peter Otten <__peter__ at web.de> writes: >> > >> > That's an unexpected inconsistency between list comprehensions >> > versus generator expressions, then. Is that documented explicitly in >> > the Python 2 documentation? >> >> https://docs.python.org/2.4/whatsnew/node4.html > > Or > . > > Also in the PEP that introduces generator expressions, PEP 289: > > List comprehensions also "leak" their loop variable into the > surrounding scope. This will also change in Python 3.0, so that the > semantic definition of a list comprehension in Python 3.0 will be > equivalent to list(). > > > > Thanks for seeking the answer. Can you describe an improvement to > > that makes clear this unexpected, deprecated behaviour which is only in > Python 2? > A sentence like that in the PEP would help, but I think the main problem is that list comprehensions and lists are subsumed under list displays. >From a user perspective [f(x) for x in y] has more in common with {x: f(x) for x in y} than with [x, y, z]. I think it would be great if list comprehensions could be moved in a separate paragraph or into 5.2.5 Displays for [lists,] sets and dictionaries with a note For backwards compatibility list comprehensions leak their loop variables into the surrounding scope. Set and dictionary displays do not leak. I don't know if such a modification is feasible; I'm definitely no "language lawyer". From werotizy at freent.dd Fri Aug 14 03:18:54 2015 From: werotizy at freent.dd (Tom P) Date: Fri, 14 Aug 2015 09:18:54 +0200 Subject: problem with netCDF4 OpenDAP In-Reply-To: References: Message-ID: On 08/13/2015 05:55 PM, Jason Swails wrote: > > > On Thu, Aug 13, 2015 at 6:32 AM, Tom P > wrote: > > I'm having a problem trying to access OpenDAP files using netCDF4. > The netCDF4 is installed from the Anaconda package. According to > their changelog, openDAP is supposed to be supported. > > netCDF4.__version__ > Out[7]: > '1.1.8' > > Here's some code: > > url = > 'http://www1.ncdc.noaa.gov/pub/data/cmb/ersst/v3b/netcdf/ersst.201507.nc' > nc = netCDF4.Dataset(url) > > I get the error - > netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Dataset.__init__ > (netCDF4/_netCDF4.c:9551)() > > RuntimeError: NetCDF: file not found > > > However if I download the same file, it works - > url = '/home/tom/Downloads/ersst.201507.nc ' > nc = netCDF4.Dataset(url) > print nc > . . . . > > Is it something I'm doing wrong? > > > ?Yes. URLs are not files and cannot be opened like normal files. > netCDF4 *requires* a local file as far as I can tell. > > All the best, > Jason > > -- > Jason M. Swails > BioMaPS, > Rutgers University > Postdoctoral Researcher Thanks for the reply but that is not what the documentation says. http://unidata.github.io/netcdf4-python/#section8 "Remote OPeNDAP-hosted datasets can be accessed for reading over http if a URL is provided to the netCDF4.Dataset constructor instead of a filename. However, this requires that the netCDF library be built with OPenDAP support, via the --enable-dap configure option (added in version 4.0.1)." and for the Anaconda package - http://docs.continuum.io/anaconda/changelog "2013-05-08: 1.5.0: Highlights: updates to all important packages: python, numpy, scipy, ipython, matplotlib, pandas, cython added netCDF4 (with OpenDAP support) on Linux and MacOSX" From sam.heyman at gmail.com Fri Aug 14 07:13:14 2015 From: sam.heyman at gmail.com (sam.heyman at gmail.com) Date: Fri, 14 Aug 2015 04:13:14 -0700 (PDT) Subject: python command not working In-Reply-To: References: <7e209349-aedb-4068-a032-8a8b47ebbb48@37g2000yqp.googlegroups.com> Message-ID: <566d3f3d-e9f9-4e15-9fbf-19ebb4855269@googlegroups.com> On Wednesday, April 22, 2009 at 8:36:21 AM UTC+1, David Cournapeau wrote: > On Wed, Apr 22, 2009 at 4:20 PM, 83nini <83nini at gmail.com> wrote: > > Hi guys, > > > > I'm new to python, i downloaded version 2.5, opened windows (vista) > > command line and wrote "python", this should take me to the python > > command line, but it did not! i'm getting : python is not an internal > > command, external command, program, or command file. > > The installer does not add the path of python into your %PATH% > variable, You have to do it manually or call the full command path > (C:\Python25\python.exe or something) > > David You can do it easily by adding the Python path (in my case C:\Python27) to your system PATH. Simply go to Control Panel > System > Advanced system settings, select 'Advanced' tab, click 'Environment Variables'. There you need to add the path to Python (C:\Python27) to the Path BOTH: - User variables and - System variables For each one click 'Edit' and paste the path (C:\Python27) at the end of the line with a ';' to separate it Restart your shell window and it should work! From srkunze at mail.de Fri Aug 14 07:21:44 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Fri, 14 Aug 2015 13:21:44 +0200 Subject: [Back off topic] - Hooking Mechanism when Entering and Leaving a Try Block Message-ID: <20150814112145.8CA8E848D5@smtp04.mail.de> Am 14-Aug-2015 03:00:05 +0200 schrieb torriem at gmail.com: > But I digress. We get sidetracked rather easily around here. You don't say. ;) ------------------------------------------------------------------------------------------------- FreeMail powered by mail.de - MEHR SICHERHEIT, SERIOSIT?T UND KOMFORT -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason.swails at gmail.com Fri Aug 14 09:15:17 2015 From: jason.swails at gmail.com (Jason Swails) Date: Fri, 14 Aug 2015 09:15:17 -0400 Subject: problem with netCDF4 OpenDAP In-Reply-To: References: Message-ID: <84E53F80-AE25-487B-B673-3B03796E9AAE@gmail.com> > On Aug 14, 2015, at 3:18 AM, Tom P wrote: > > Thanks for the reply but that is not what the documentation says. > > http://unidata.github.io/netcdf4-python/#section8 > "Remote OPeNDAP-hosted datasets can be accessed for reading over http if a URL is provided to the netCDF4.Dataset constructor instead of a filename. However, this requires that the netCDF library be built with OPenDAP support, via the --enable-dap configure option (added in version 4.0.1).? ?Huh, so it does. Your error message says "file not found", though, which suggested to me that it's trying to interpret the NetCDF file as a local file instead of a URL. Indeed, when I run that example, the traceback is more complete (the traceback you printed had omitted some information): >>> netCDF4.Dataset('http://www1.ncdc.noaa.gov/pub/data/cmb/ersst/v3b/netcdf/ersst.201507.nc') syntax error, unexpected WORD_WORD, expecting SCAN_ATTR or SCAN_DATASET or SCAN_ERROR context: 404 Not Found

Not Found

The requested URL /pub/data/cmb/ersst/v3b/netcdf/ersst.201507.nc.dds was not found on this server.

Traceback (most recent call last): File "", line 1, in File "netCDF4/_netCDF4.pyx", line 1547, in netCDF4._netCDF4.Dataset.__init__ (netCDF4/_netCDF4.c:9551) RuntimeError: NetCDF: file not found So it?s clear that netCDF4 is at least *trying* to go online to look for the file, but it simply can?t find it. Since the docs say it?s linking to libcurl, I tried using curl to download the file (curl -# http://www1.ncdc.noaa.gov/pub/data/cmb/ersst/v3b/netcdf/ersst.201507.nc > test.nc) and it worked fine. What?s more, it *seems* like the file (/pub/.../ersst.201507.nc.dds) was decorated with the ?.dds? suffix for some reason (not sure if the server redirected the request there or not). But this looks like a netCDF4 issue. Perhaps you can go to their project page on Github and file an issue there -- they will be more likely to have your answer than people here. HTH, Jason > > and for the Anaconda package - > http://docs.continuum.io/anaconda/changelog > "2013-05-08: 1.5.0: > Highlights: > updates to all important packages: python, numpy, scipy, ipython, matplotlib, pandas, cython > added netCDF4 (with OpenDAP support) on Linux and MacOSX" > > -- > https://mail.python.org/mailman/listinfo/python-list -- Jason M. Swails BioMaPS, Rutgers University Postdoctoral Researcher From meily.adam at gmail.com Fri Aug 14 09:21:57 2015 From: meily.adam at gmail.com (Adam Meily) Date: Fri, 14 Aug 2015 13:21:57 +0000 Subject: Python 2.7: _PyLong_NumBits() Segfault Message-ID: I am working on a CPython library that serializes Python objects to disk in a custom format. I'm using _PyLong_NumBits() to determine whether PyLong_AsLong(), PyLong_AsUnsignedLong(), PyLong_AsLongLong(), or PyLong_AsUnsignedLongLong() should be used. In Python 3.x, I'm able to determine how many bits are required to write an int to disk without issue. However, in Python 2.7, _PyLong_NumBits() segfaults when the type is a PyInt that has the value of 0xffffffff (maximum unsigned 32-bit value). Additionally, _PyLong_NumBits() is not accurate when the number is negative. My guess is that I can't use _PyLong_NumBits() on a PyInt object. So, what is the correct way to determine the number of bits required to represent a PyInt object in Python 2.7? I'm using Python 2.7.6, x86-64 on Ubuntu. -------------- next part -------------- An HTML attachment was scrubbed... URL: From werotizy at freent.dd Fri Aug 14 11:26:27 2015 From: werotizy at freent.dd (Tom P) Date: Fri, 14 Aug 2015 17:26:27 +0200 Subject: problem with netCDF4 OpenDAP In-Reply-To: References: Message-ID: On 08/14/2015 03:15 PM, Jason Swails wrote: > >> On Aug 14, 2015, at 3:18 AM, Tom P wrote: >> >> Thanks for the reply but that is not what the documentation says. >> >> http://unidata.github.io/netcdf4-python/#section8 >> "Remote OPeNDAP-hosted datasets can be accessed for reading over http if a URL is provided to the netCDF4.Dataset constructor instead of a filename. However, this requires that the netCDF library be built with OPenDAP support, via the --enable-dap configure option (added in version 4.0.1).? > > ?Huh, so it does. Your error message says "file not found", though, which suggested to me that it's trying to interpret the NetCDF file as a local file instead of a URL. Indeed, when I run that example, the traceback is more complete (the traceback you printed had omitted some information): > >>>> netCDF4.Dataset('http://www1.ncdc.noaa.gov/pub/data/cmb/ersst/v3b/netcdf/ersst.201507.nc') > syntax error, unexpected WORD_WORD, expecting SCAN_ATTR or SCAN_DATASET or SCAN_ERROR > context: 404 Not Found

Not Found

The requested URL /pub/data/cmb/ersst/v3b/netcdf/ersst.201507.nc.dds was not found on this server.

> Traceback (most recent call last): > File "", line 1, in > File "netCDF4/_netCDF4.pyx", line 1547, in netCDF4._netCDF4.Dataset.__init__ (netCDF4/_netCDF4.c:9551) > RuntimeError: NetCDF: file not found > > So it?s clear that netCDF4 is at least *trying* to go online to look for the file, but it simply can?t find it. Since the docs say it?s linking to libcurl, I tried using curl to download the file (curl -# http://www1.ncdc.noaa.gov/pub/data/cmb/ersst/v3b/netcdf/ersst.201507.nc > test.nc) and it worked fine. What?s more, it *seems* like the file (/pub/.../ersst.201507.nc.dds) was decorated with the ?.dds? suffix for some reason (not sure if the server redirected the request there or not). But this looks like a netCDF4 issue. Perhaps you can go to their project page on Github and file an issue there -- they will be more likely to have your answer than people here. > > HTH, > Jason Hi, yes the file does appear to be there, I can download it and I can open and read the URL using urllib. Since there are a whole bunch of files in the directory, I really need MFDataset, but according to the documentation that doesn't work with URLs. Maybe the solution really is to D/L them all into a temporary folder and use MFDataset. > >> >> and for the Anaconda package - >> http://docs.continuum.io/anaconda/changelog >> "2013-05-08: 1.5.0: >> Highlights: >> updates to all important packages: python, numpy, scipy, ipython, matplotlib, pandas, cython >> added netCDF4 (with OpenDAP support) on Linux and MacOSX" >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > > -- > Jason M. Swails > BioMaPS, > Rutgers University > Postdoctoral Researcher > From george.trojan at noaa.gov Fri Aug 14 12:11:10 2015 From: george.trojan at noaa.gov (George Trojan) Date: Fri, 14 Aug 2015 16:11:10 +0000 Subject: problem with netCDF4 OpenDAP In-Reply-To: References: Message-ID: <55CE131E.9090905@noaa.gov> > Subject: > problem with netCDF4 OpenDAP > From: > Tom P > Date: > 08/13/2015 10:32 AM > > To: > python-list at python.org > > > I'm having a problem trying to access OpenDAP files using netCDF4. > The netCDF4 is installed from the Anaconda package. According to their > changelog, openDAP is supposed to be supported. > > netCDF4.__version__ > Out[7]: > '1.1.8' > > Here's some code: > > url = > 'http://www1.ncdc.noaa.gov/pub/data/cmb/ersst/v3b/netcdf/ersst.201507.nc' > nc = netCDF4.Dataset(url) > > I get the error - > netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Dataset.__init__ > (netCDF4/_netCDF4.c:9551)() > > RuntimeError: NetCDF: file not found > > > However if I download the same file, it works - > url = '/home/tom/Downloads/ersst.201507.nc' > nc = netCDF4.Dataset(url) > print nc > . . . . > > Is it something I'm doing wrong? Same thing here: (devenv-3.4.1) dilbert at gtrojan> python Python 3.4.1 (default, Jul 7 2014, 15:47:25) [GCC 4.8.3 20140624 (Red Hat 4.8.3-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import netCDF4 >>> url = 'http://www1.ncdc.noaa.gov/pub/data/cmb/ersst/v3b/netcdf/ersst.201507.nc' >>> nc = netCDF4.Dataset(url) syntax error, unexpected WORD_WORD, expecting SCAN_ATTR or SCAN_DATASET or SCAN_ERROR context: 404 Not Found

Not Found

The requested URL /pub/data/cmb/ersst/v3b/netcdf/ersst.201507.nc.dds was not found on this server.

Traceback (most recent call last): File "", line 1, in File "netCDF4.pyx", line 1466, in netCDF4.Dataset.__init__ (netCDF4.c:19738) RuntimeError: NetCDF: file not found >>> It looks like NCDC does not support OpeNDAP (note the .dds extension in the error message). It is not a Python/netCDF4 issue. (devenv-3.4.1) dilbert at gtrojan> ncdump -h http://www1.ncdc.noaa.gov/pub/data/cmb/ersst/v3b/netcdf/ersst.201507.nc syntax error, unexpected WORD_WORD, expecting SCAN_ATTR or SCAN_DATASET or SCAN_ERROR context: 404 Not Found

Not Found

The requested URL /pub/data/cmb/ersst/v3b/netcdf/ersst.201507.nc.dds was not found on this server.

ncdump: http://www1.ncdc.noaa.gov/pub/data/cmb/ersst/v3b/netcdf/ersst.201507.nc: NetCDF: file not found George -------------- next part -------------- An HTML attachment was scrubbed... URL: From chuks155 at gmail.com Fri Aug 14 13:43:09 2015 From: chuks155 at gmail.com (chuks155 at gmail.com) Date: Fri, 14 Aug 2015 10:43:09 -0700 (PDT) Subject: New Intermediate Python Book Message-ID: <90af8c90-5265-43ea-bbc9-6b4b7a2a8f9f@googlegroups.com> Hi folks, I have just finished my first ebook titled Intermediate Python. It is targeted at users from other languages or that have just finished a python programming beginners tutorial. It is available at https://leanpub.com/intermediatepython. Content includes writings on python data model, object oriented programming, function and functional programming, sequence and generators, meta-programming, and modules and packages. If you would like to provide a review then I am willing to provide a copy for such. Just get in touch. From tjreedy at udel.edu Fri Aug 14 16:00:36 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 14 Aug 2015 16:00:36 -0400 Subject: Fixing tkinter on 3.5.0rc1 for some Windows machines. Message-ID: Symptom: Using 3.5.0rc1 on Windows machines without VS2015 installed, import tkinter or use something that does so (Idle, Turtle, turtledemo, ...) and get message "Your Python may not be configured for Tk." Fix: In install directory, find /DLLs. In that find /MicrosoftVC140.CRT with one file vcruntime140.dll. Move this file up into /DLLs -- Terry Jan Reedy From jacob.macritchie at gmail.com Fri Aug 14 16:47:51 2015 From: jacob.macritchie at gmail.com (Jacob MacRitchie) Date: Fri, 14 Aug 2015 13:47:51 -0700 (PDT) Subject: Help with Flask (database stage of the Flask Mega Tutorial by Miguel Grinberg) Message-ID: <6e5dfb26-7e27-4b2d-bd41-2be610bf064e@googlegroups.com> http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database I've just finished making db_create.py (you can ctrl+f to it) and am getting... from migrate.versioning import api ImportError: No module named 'migrate' ...I diffed everything at this stage of the tutorial so I know I have no typos, I double checked my venv to make sure I have sqlalchemy-migrate installed. I did notice in the comments (page 2 of the comments I think) that the newer version of SQLAlchemy isn't compatible with sqlalchemy-migrate, so is that what's causing this problem? I didn't find anyone else having quite the same problem. I tried downgrading sqlalchemy to 0.7.9 (necessary for other parts of the tutorial, but didn't solve this problem), tried running from the command line (venv activated) instead of running it with the venv selected as project interpreter in pycharm, but get... from config import SQLALCHEMY_DATABASE_URI ImportError: no module named 'config' ...instead. I've tried moving db_create.py from the app folder for the heck of it, but just get a long traceback. I'm not sure what else to try, any help is appreciated! From DLipman~NoSpam~ at Verizon.Net Fri Aug 14 17:07:13 2015 From: DLipman~NoSpam~ at Verizon.Net (David H. Lipman) Date: Fri, 14 Aug 2015 17:07:13 -0400 Subject: Vaga Java (Belgica, com tudo pago) In-Reply-To: References: Message-ID: <7Omdnf29yLEdxVPInZ2dnUU7-aGdnZ2d@giganews.com> From: "leo kirotawa" > Wondering why a position for Java/JS was sent to this list...just > wondering... > Because spammers make no sense. -- Dave Multi-AV Scanning Tool - http://multi-av.thespykiller.co.uk http://www.pctipp.ch/downloads/dl/35905.asp From anthra.norell at bluewin.ch Fri Aug 14 17:25:20 2015 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Fri, 14 Aug 2015 23:25:20 +0200 Subject: How to model government organization hierarchies so that the list can expand and compress In-Reply-To: References: Message-ID: <55CE5CC0.9080108@bluewin.ch> On 08/13/2015 09:10 PM, Alex Glaros wrote: > It's like the desktop folder/directory model where you can create unlimited folders and put folders within other folders. Instead of folders, I want to use government organizations. > > Example: Let user create agency names: Air Force, Marines, Navy, Army. Then let them create an umbrella collection called "Pentagon", and let users drag Air Force, Marines, Navy, etc. into the umbrella collection. > > User may wish to add smaller sub-sets of Army, such as "Army Jeep Repair Services" > > User may also want to add a new collection "Office of the President" and put OMB and Pentagon under that as equals. > > What would the data model look like for this? If I have a field: next_higher_level_parent that lets children records keep track of parent record, it's hard for me to imagine anything but an inefficient bubble sort to produce a hierarchical organizational list. Am using Postgres, not graph database. > > I'm hoping someone else has worked on this problem, probably not with government agency names, but perhaps the same principle with other objects. > > Thanks! > > Alex Glaros After struggling for years with a tree-like estate management system (onwer at the top, next level: real estate, banks, art collection, etc., third level: real estate units, bank accounts, etc. fourth level: investment positions, currency accounts, etc)--it recently occurred to me that I had such a system all along: the file system. The last folder at the bottom end of each branch names its contents (AAPL or USD or Lamborghini, etc) the contents is a csv file recording an in and out, revenue, expense history (date, quantity, paid or received, memo, . . .). Any documentation on the respective value item may also be stored in the same folder, easy to find without requiring cross referencing. Managing the data is not a awkward as one might fear. A bash wizard could probably do it quite efficiently with bash scripts. Bash dummies, like me, are more comfortable with python. Moving, say, a portfolio from one bank to another is a matter of "mv i/banks/abc/account-123 i/banks/xyz" (system call). With the tabular data base system (MySQL) I have, simple operations like this one are quite awkward. Well, you might laugh. Or others might. If your task is a commercial order, then this approach will hardly do. Anyway, I thought I'd toss it up. If it won't help it won't hurt. Frederic From yanzhipingliu at gmail.com Fri Aug 14 19:41:13 2015 From: yanzhipingliu at gmail.com (Ping Liu) Date: Fri, 14 Aug 2015 16:41:13 -0700 Subject: memory control in Python Message-ID: Dear All, I am working on an optimization problem, where we are trying to minimize some indicators like energy usage, energy cost, CO2 emission. In this problem, we have a bunch of energy conversion technologies for electricity and thermal purpose, such as heat pump, boiler, chiller, etc.. We are trying to model it with a one year time period. the current time step is one hour. We have preselected the candidate technologies to exclude those we don't want to study so that the problem size could be reduced with a limited candidate technologies. In the current case study, we only analyze the electric chiller and heat pump to supply the cooling load, while power grid will supply the electricity for all electric loads. There are binary variables regarding installation decisions of technologies and continuous variables related to installation capacity and hourly operational decisions. For small cases, Python works well. But if we consider longer time period. then it would fail due to the memory usage issues. We have tested several case studies to check the memory use for different time period, including 1) 2 hours in one day, 2) 24 hours in one day, 3) 20 days with 24 hours each day, as well as 4) 30 days with 24 hours each day. The first 3 cases are feasible while the last case gives out the memory error. When we are testing the forth case, the memory error comes out while creating the inequality constraints. The problem size is 1) Aeq: 12 * 26, Aineq: 30 * 26; 2) Aeq: 144*268, Aineq:316*268; 3) Aeq: 2880*5284, Aineq: 6244*5284; 4) Aeq: 4320 * 7924, Aineq is unknown due to the memory error. The solver is CPLEX (academic). It turns out that the solver is taking a lot of memory as you can see in the memory test report. for the first three cases, different memory usage is observed, and it grows up dramatically with the increase of the time period. 1) solver memory usage: 25.6 MB, 2) 19.5 MB; 3) solver memory usage: 830.0742 MB. Based on my observations, I have some of the following questions regarding 1) In order to create the optimization problem (Aeq, Aineq), how can we reduce the memory usage in python programming? 2) how can I reduce the memory usage of different solvers in Python? Why would the memory decrease for the CPLEX solver within the 24-hours-in-one-day case compared with the case 1? Thanks in advance, Ping -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: solver memory comparison.xlsx Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet Size: 8549 bytes Desc: not available URL: From alexglaros at gmail.com Fri Aug 14 19:42:00 2015 From: alexglaros at gmail.com (Alex Glaros) Date: Fri, 14 Aug 2015 16:42:00 -0700 (PDT) Subject: How to model government organization hierarchies so that the list can expand and compress In-Reply-To: References: Message-ID: Frank, thanks for describing the terminology of what I'm trying to do. 1. Do the recursive join Postgres examples you linked to, use a data structure where the child has the adjoining parent-ID? Examples look great. 2. Not 100% sure that hierarchical is the perfect solution but will go with that now. Of course some agencies will be at equal levels; will ignore for now. 3. Could not find Laura's response. Was it deleted? 4. Solution will expressed in the DB, not Python. Much appreciated! Alex From michael at stroeder.com Fri Aug 14 20:02:42 2015 From: michael at stroeder.com (=?UTF-8?Q?Michael_Str=c3=b6der?=) Date: Sat, 15 Aug 2015 02:02:42 +0200 Subject: problem with netCDF4 OpenDAP In-Reply-To: References: Message-ID: Tom P wrote: > yes the file does appear to be there, I can download it and I can open and > read the URL using urllib. Since there are a whole bunch of files in the > directory, I really need MFDataset, but according to the documentation that > doesn't work with URLs. Maybe the solution really is to D/L them all into a > temporary folder and use MFDataset. Not sure about the size and other aspects of your deployment. But the safest way to backup an OpenLDAP database is to export it to a single LDIF file because this can be done while slapd is running and it's guaranteed that the LDIF contains only data of finished transactions. Ciao, Michael. From rustompmody at gmail.com Fri Aug 14 21:21:43 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 14 Aug 2015 18:21:43 -0700 (PDT) Subject: How to model government organization hierarchies so that the list can expand and compress In-Reply-To: References: Message-ID: On Saturday, August 15, 2015 at 5:12:13 AM UTC+5:30, Alex Glaros wrote: > 3. Could not find Laura's response. Was it deleted? I dont see it either. I expect its in some other thread Laura's mail client is doing funny things to threading... Something Ive been noticing for a few days From lac at openend.se Sat Aug 15 00:54:56 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 15 Aug 2015 06:54:56 +0200 Subject: How to model government organization hierarchies so that the list can expand and compress In-Reply-To: Message from Alex Glaros of "Fri, 14 Aug 2015 16:42:00 -0700." References: Message-ID: <201508150454.t7F4suTn024970@fido.openend.se> In a message of Fri, 14 Aug 2015 16:42:00 -0700, Alex Glaros writes: >Frank, thanks for describing the terminology of what I'm trying to do. > >1. Do the recursive join Postgres examples you linked to, use a data structure where the child has the adjoining parent-ID? Examples look great. > >2. Not 100% sure that hierarchical is the perfect solution but will go with that now. Of course some agencies will be at equal levels; will ignore for now. > >3. Could not find Laura's response. Was it deleted? > >4. Solution will expressed in the DB, not Python. > >Much appreciated! > >Alex What I said was, that real agencies are almost never perfectly heirarchical. That's an oversimplification. In the real world Organisation A (say Army) and Organisation B (say Navy) decide they have common interests and make a Joint Department. If you run that department you report to superiors in _both_ organisation A and organisation B, get orders from both places and so on and so forth. You must decide now what you want to do when you run into such departments, because that will greatly influence your design. Laura From frank at chagford.com Sat Aug 15 01:59:06 2015 From: frank at chagford.com (Frank Millman) Date: Sat, 15 Aug 2015 07:59:06 +0200 Subject: How to model government organization hierarchies so that the list can expand and compress In-Reply-To: References: Message-ID: "Alex Glaros" wrote in message news:ae4e203d-c664-4388-af0b-41c41d5ec724 at googlegroups.com... > Frank, thanks for describing the terminology of what I'm trying to do. > > 1. Do the recursive join Postgres examples you linked to, use a data > structure where the child has the adjoining parent-ID? Examples look > great. I think that their example is very simple - it seems that each level contains one link to the level below, and the level below has no link to the level above (or at least they did not make use of it). The following (untested) example assumes that each row can have multiple children, and each row has a link to its parent called parent_id. WITH RECURSIVE included_parts(part, quantity) AS ( SELECT part, quantity FROM parts WHERE part = 'our_product' UNION ALL SELECT p.part, p.quantity FROM included_parts pr, parts p WHERE p.parent_id = pr.part ) SELECT part, SUM(quantity) as total_quantity FROM included_parts GROUP BY part You will find many variations in various on-line tutorials. For example, you can traverse *up* the tree by changing the WHERE clause to WHERE p.part = pr.parent_id > > 2. Not 100% sure that hierarchical is the perfect solution but will go > with that now. Of course some agencies will be at equal levels; will > ignore for now. > > 3. Could not find Laura's response. Was it deleted? > Laura responded to this in another post, but in case you cannot see that one either, I reproduce it here - """ What I said was, that real agencies are almost never perfectly heirarchical. That's an oversimplification. In the real world Organisation A (say Army) and Organisation B (say Navy) decide they have common interests and make a Joint Department. If you run that department you report to superiors in _both_ organisation A and organisation B, get orders from both places and so on and so forth. You must decide now what you want to do when you run into such departments, because that will greatly influence your design. """ > 4. Solution will expressed in the DB, not Python. > Much appreciated! Glad I could help. Frank From rosuav at gmail.com Sat Aug 15 02:56:11 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 15 Aug 2015 16:56:11 +1000 Subject: Global command doesn't seem to work... In-Reply-To: References: Message-ID: On Thu, Aug 13, 2015 at 9:06 PM, Dwight GoldWinde wrote: > global subwordsDL > from Functions import subwords > subwords () > print (subwordsDL) > print (subwordsDL['enjoy'][2]) In Python, "global" means module-level. The easiest way to do this would be to import the Functions module directly (rather than using a from-import), and then you can use Function.subwords and Functions.subwordsDL. ChrisA From dieter at handshake.de Sat Aug 15 03:21:52 2015 From: dieter at handshake.de (dieter) Date: Sat, 15 Aug 2015 09:21:52 +0200 Subject: memory control in Python References: Message-ID: <87io8hc8z3.fsf@handshake.de> Ping Liu writes: > ... > For small cases, Python works well. But if we consider longer time period. > then it would fail due to the memory usage issues. We have tested several > case studies to check the memory use for different time period, including > 1) 2 hours in one day, 2) 24 hours in one day, 3) 20 days with 24 hours > each day, as well as 4) 30 days with 24 hours each day. The first 3 cases > are feasible while the last case gives out the memory error. > > When we are testing the forth case, the memory error comes out while > creating the inequality constraints. The problem size is 1) Aeq: 12 * 26, > Aineq: 30 * 26; 2) Aeq: 144*268, Aineq:316*268; 3) Aeq: 2880*5284, Aineq: > 6244*5284; 4) Aeq: 4320 * 7924, Aineq is unknown due to the memory error. > > The solver is CPLEX (academic). It turns out that the solver is taking a > lot of memory as you can see in the memory test report. for the first three > cases, different memory usage is observed, and it grows up dramatically > with the increase of the time period. 1) solver memory usage: 25.6 MB, 2) > 19.5 MB; 3) solver memory usage: 830.0742 MB. The C implementation of Python (called "CPython") does not use memory compaction and places most of its objects on the heap. Those implementations tend to suffer from memory fragmentation in long running processes with large memory use. You may consider "Jython" (a Python implementation in "Java") or "IronPython" (a ".Net" based Python implementation) to get a Python implementation with memory compaction. From uri at speedy.net Sat Aug 15 05:47:17 2015 From: uri at speedy.net (Uri Even-Chen) Date: Sat, 15 Aug 2015 12:47:17 +0300 Subject: Encrypted web mail Message-ID: To Python, Django and Speedy Mail Software developers, Is it possible to make Speedy Mail encrypted? I want mail to be encrypted on the server, and only the user will be able to read his/her mail. The user's password will be encrypted on the server and nobody will be able to read the user's mail except the user himself. Is it possible? When I had Speedy Mail from 2000 to 2005 I received a court order by a court in Tel Aviv once from two policemen to give a specific user's password to the Israeli police, and the password and mail were not encrypted then. And I was not allowed to tell anyone about this court order, except my lawyer. But I refused to give the user's password to the police. So if I receive a court order again, I don't want to be able to give the user's password or mail to anyone, and I don't want it to be on the servers unless it's encrypted. That's why I want it to be encrypted. If I receive a court order again I want to be able to tell the police that the mail and password are encrypted, and only the user knows the password and is able to read his mail. Is it possible? I believe a user's mail is something personal, like his thoughts. I don't want the police to read my mail and it's similar to reading my thoughts. Thanks, Uri. *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 Email: uri at speedy.net Website: http://www.speedysoftware.com/uri/en/ > Speedypedia in Hebrew and English -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas.lehmann.private at googlemail.com Sat Aug 15 07:07:21 2015 From: thomas.lehmann.private at googlemail.com (Thomas Lehmann) Date: Sat, 15 Aug 2015 04:07:21 -0700 (PDT) Subject: Mock object but also assert method calls? In-Reply-To: <55cd5839$0$1636$c3e8da3$5496439d@news.astraweb.com> References: <509adc48-996d-44b0-abf1-e15ee387023b@googlegroups.com> <55cd5839$0$1636$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am Freitag, 14. August 2015 04:53:56 UTC+2 schrieb Steven D'Aprano: > On Fri, 14 Aug 2015 07:21 am, Ben Finney wrote: > > >> If find following totally different to the normal API which > >> is provided by the mock library: > >> > >> assert call().test2("hello") in mocked_objects.mock_calls > > > > The 'assert' statement is a crude tool, which knows little about the > > intent of your assertion. > > I agree with Ben here. Despite the popularity of "nose" (I think it is > nose?) which uses `assert` for testing, I think that is a gross misuse of > the statement. It is okay to use assertions this way for quick and dirty ad > hoc testing, say at the command line, but IMO totally inappropriate for > anything more formal, like unit testing. > > If for no other reason than the use of `assert` for testing makes it > impossible to test your code when running with the Python -O (optimize) > switch. > > For more detail on the uses, and abuses, of `assert` see this: > Of course you do NOT use assert in unit tests but I provided just test code to show my problem. Of course I take nose and hamcrest and code coverage ... Here a complete example of my problem (with comments): from mock import MagicMock, call, patch class Bla: def test1(self, value): pass mocked_object = MagicMock(Bla) bla = Bla() bla.test1("hello") # empty, why? print(mocked_object.mock_calls) # does not work: mocked_object.test1.assert_called_with("hello") with patch("__main__.Bla") as mocked_object: bla = Bla() bla.test1("hello") # not empty! print(mocked_object.mock_calls) # does also not work: mocked_object.test1.assert_called_with("hello") # but this does work: assert call().test1("hello") in mocked_object.mock_calls I don't wanna patch each individual method. Is there no other way? From ned at nedbatchelder.com Sat Aug 15 07:19:35 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 15 Aug 2015 04:19:35 -0700 (PDT) Subject: Python 2.7: _PyLong_NumBits() Segfault In-Reply-To: References: Message-ID: <495fbec4-2942-41e0-b334-84287d031aeb@googlegroups.com> On Saturday, August 15, 2015 at 2:36:44 AM UTC-4, Adam Meily wrote: > I am working on a CPython library that serializes Python objects to disk in a custom format.?I'm using _PyLong_NumBits() to determine whether PyLong_AsLong(), PyLong_AsUnsignedLong(), PyLong_AsLongLong(), or PyLong_AsUnsignedLongLong() should be used. > > > In Python 3.x, I'm able to determine how many bits are?required to write an int to disk without issue. However, in Python 2.7, _PyLong_NumBits() segfaults when the type is a PyInt that has the value of 0xffffffff (maximum unsigned 32-bit value). Additionally, _PyLong_NumBits() is not accurate when the number is negative. My guess is that I can't use _PyLong_NumBits() on a PyInt object. So, what is the correct way to determine the number of bits required to represent a PyInt object in Python 2.7? > > > I'm using Python 2.7.6, x86-64 on Ubuntu. You are right that _PyLong_NumBits is only usable with long objects. PyInt has PyInt_GetMax, which will tell you the maximum size for an int. All ints will fit in that number of bits, so you can use that size for any int. Keep in mind that _PyLong_NumBits is not a documented and supported API, so you'll have to be very careful using it. Also, you might consider doing work in Python that doesn't absolutely have to be done in C. It's much easier working in Python than in C. --Ned. From harish.shastry at gmail.com Sat Aug 15 07:40:01 2015 From: harish.shastry at gmail.com (Harish Vishwanath) Date: Sat, 15 Aug 2015 17:10:01 +0530 Subject: Detecting if a library has native dependency Message-ID: Hello Is there a reliable way to detect if a python library has native dependency or native code? For ex. can I programmatically determine that "lxml" package has native code and depends on the presence of libxml on the system? Regards, Harish -------------- next part -------------- An HTML attachment was scrubbed... URL: From uri at speedy.net Sat Aug 15 08:48:51 2015 From: uri at speedy.net (Uri Even-Chen) Date: Sat, 15 Aug 2015 15:48:51 +0300 Subject: Encrypted web mail In-Reply-To: References: Message-ID: Thanks Pedro, actually I understand cryptography and I agree with you. Sonebody replied to me off-list and wrote me about ProtonMail , actually they are doing exactly what I wanted (I think), so maybe I will try to cooperate with them and/or use their open source source code. Anyway thanks for the feedback! Uri. *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 Email: uri at speedy.net Website: http://www.speedysoftware.com/uri/en/ > Speedypedia in Hebrew and English On Sat, Aug 15, 2015 at 3:32 PM, Pedro wrote: > Hello Uri, > > what you want is completely possible, but demands you to understand some > concepts of cryptography. To make your server completely safe against court > orders or anyone that have access to it, including yourself, you need to > encrypt and decrypt the emails at client side. For this you may use some > public-key cryptosystem and store all user's public keys at your server > (they are not secret). Probably the best option for you is to use PGP. If > the clients run in Javascript you can use OpenPGP.js for this. It is very > easy to use and you won't need to know anything about how to implement a > secure cipher. > > > > ---------- > Pedro Alves > > *Mestrando em Ci?ncia da Computa??o* > *Universidade Estadual de Campinas* > > 2015-08-15 6:47 GMT-03:00 Uri Even-Chen : > >> To Python, Django and Speedy Mail Software developers, >> >> Is it possible to make Speedy Mail encrypted? I want mail to be encrypted >> on the server, and only the user will be able to read his/her mail. The >> user's password will be encrypted on the server and nobody will be able to >> read the user's mail except the user himself. Is it possible? When I had >> Speedy Mail from 2000 to 2005 I received a court order by a court in Tel >> Aviv once from two policemen to give a specific user's password to the >> Israeli police, and the password and mail were not encrypted then. And I >> was not allowed to tell anyone about this court order, except my lawyer. >> But I refused to give the user's password to the police. So if I receive a >> court order again, I don't want to be able to give the user's password or >> mail to anyone, and I don't want it to be on the servers unless it's >> encrypted. That's why I want it to be encrypted. If I receive a court order >> again I want to be able to tell the police that the mail and password are >> encrypted, and only the user knows the password and is able to read his >> mail. Is it possible? >> >> I believe a user's mail is something personal, like his thoughts. I don't >> want the police to read my mail and it's similar to reading my thoughts. >> >> Thanks, >> Uri. >> >> *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 >> Email: uri at speedy.net >> Website: http://www.speedysoftware.com/uri/en/ >> >> >> >> >> > Speedypedia in Hebrew and English >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-users+unsubscribe at googlegroups.com. >> To post to this group, send email to django-users at googlegroups.com. >> Visit this group at http://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAMQ2MsHDNLRuth59FRAtXwMXY14LyMUibxHCFxZswdD7Jw4oyg%40mail.gmail.com >> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscribe at googlegroups.com. > To post to this group, send email to django-users at googlegroups.com. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CACW_pa3PGDg0b6zNQertR0NXHZPDd75oh1ZcVU12SXy9aN%3DmiQ%40mail.gmail.com > > . > For more options, visit https://groups.google.com/d/optout. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lac at openend.se Sat Aug 15 09:32:20 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 15 Aug 2015 15:32:20 +0200 Subject: Detecting if a library has native dependency In-Reply-To: Message from Harish Vishwanath of "Sat, 15 Aug 2015 17:10:01 +0530." References: Message-ID: <201508151332.t7FDWKnv028978@fido.openend.se> In a message of Sat, 15 Aug 2015 17:10:01 +0530, Harish Vishwanath writes: >Hello > >Is there a reliable way to detect if a python library has native dependency >or native code? For ex. can I programmatically determine that "lxml" >package has native code and depends on the presence of libxml on the system? > >Regards, >Harish I'm using snakefood http://furius.ca/snakefood/ to make dependency graphs. You can get it from PyPI. It uses its own tool called sfood to make a list of dependencies, but I am not sure how tweakable that is to get the list of what you want. Worth a look, at any rate. Laura From torriem at gmail.com Sat Aug 15 11:04:42 2015 From: torriem at gmail.com (Michael Torrie) Date: Sat, 15 Aug 2015 09:04:42 -0600 Subject: Encrypted web mail In-Reply-To: References: Message-ID: <55CF550A.2070005@gmail.com> On 08/15/2015 03:47 AM, Uri Even-Chen wrote: > To Python, Django and Speedy Mail Software developers, > > Is it possible to make Speedy Mail encrypted? I want mail to be encrypted > on the server, and only the user will be able to read his/her mail. The > user's password will be encrypted on the server and nobody will be able to > read the user's mail except the user himself. Is it possible? When I had > Speedy Mail from 2000 to 2005 I received a court order by a court in Tel > Aviv once from two policemen to give a specific user's password to the > Israeli police, and the password and mail were not encrypted then. And I > was not allowed to tell anyone about this court order, except my lawyer. > But I refused to give the user's password to the police. So if I receive a > court order again, I don't want to be able to give the user's password or > mail to anyone, and I don't want it to be on the servers unless it's > encrypted. That's why I want it to be encrypted. If I receive a court order > again I want to be able to tell the police that the mail and password are > encrypted, and only the user knows the password and is able to read his > mail. Is it possible? Could you encrypt your email body with gpg (say with a subprocess) and then email that? As to the username and password, I've never worked on a system where passwords could even be extracted by a sysadmin. I could tell you the salted hash but never the password. From hhenrysmith at gmail.com Sat Aug 15 11:42:13 2015 From: hhenrysmith at gmail.com (Henry Quansah) Date: Sat, 15 Aug 2015 16:42:13 +0100 Subject: Error in IDLE Message-ID: I just installed python. But I'm unable to access IDLE after several clicks and double clicks. I even tried repairing by trying to reinstall but I have the same issue. -------------- next part -------------- An HTML attachment was scrubbed... URL: From uri at speedy.net Sat Aug 15 12:47:27 2015 From: uri at speedy.net (Uri Even-Chen) Date: Sat, 15 Aug 2015 19:47:27 +0300 Subject: Encrypted web mail In-Reply-To: <55CF550A.2070005@gmail.com> References: <55CF550A.2070005@gmail.com> Message-ID: Hi Michael, Thanks for the feedback. Actually the passwords on my webmail in 2000 to 2005 were not encrypted, but I agree with you that passwords should be always encrypted. Uri. *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 Email: uri at speedy.net Website: http://www.speedysoftware.com/uri/en/ > Speedypedia in Hebrew and English On Sat, Aug 15, 2015 at 6:04 PM, Michael Torrie wrote: > On 08/15/2015 03:47 AM, Uri Even-Chen wrote: > > To Python, Django and Speedy Mail Software developers, > > > > Is it possible to make Speedy Mail encrypted? I want mail to be encrypted > > on the server, and only the user will be able to read his/her mail. The > > user's password will be encrypted on the server and nobody will be able > to > > read the user's mail except the user himself. Is it possible? When I had > > Speedy Mail from 2000 to 2005 I received a court order by a court in Tel > > Aviv once from two policemen to give a specific user's password to the > > Israeli police, and the password and mail were not encrypted then. And I > > was not allowed to tell anyone about this court order, except my lawyer. > > But I refused to give the user's password to the police. So if I receive > a > > court order again, I don't want to be able to give the user's password or > > mail to anyone, and I don't want it to be on the servers unless it's > > encrypted. That's why I want it to be encrypted. If I receive a court > order > > again I want to be able to tell the police that the mail and password are > > encrypted, and only the user knows the password and is able to read his > > mail. Is it possible? > > Could you encrypt your email body with gpg (say with a subprocess) and > then email that? > > As to the username and password, I've never worked on a system where > passwords could even be extracted by a sysadmin. I could tell you the > salted hash but never the password. > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Aug 15 13:28:19 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 15 Aug 2015 13:28:19 -0400 Subject: memory control in Python In-Reply-To: <87io8hc8z3.fsf@handshake.de> References: <87io8hc8z3.fsf@handshake.de> Message-ID: On 8/15/2015 3:21 AM, dieter wrote: > Ping Liu writes: >> ... >> For small cases, Python works well. But if we consider longer time period. >> then it would fail due to the memory usage issues. We have tested several >> case studies to check the memory use for different time period, including >> 1) 2 hours in one day, 2) 24 hours in one day, 3) 20 days with 24 hours >> each day, as well as 4) 30 days with 24 hours each day. The first 3 cases >> are feasible while the last case gives out the memory error. >> >> When we are testing the forth case, the memory error comes out while >> creating the inequality constraints. The problem size is 1) Aeq: 12 * 26, >> Aineq: 30 * 26; 2) Aeq: 144*268, Aineq:316*268; 3) Aeq: 2880*5284, Aineq: >> 6244*5284; 4) Aeq: 4320 * 7924, Aineq is unknown due to the memory error. >> >> The solver is CPLEX (academic). It turns out that the solver is taking a >> lot of memory as you can see in the memory test report. for the first three >> cases, different memory usage is observed, and it grows up dramatically >> with the increase of the time period. 1) solver memory usage: 25.6 MB, 2) >> 19.5 MB; 3) solver memory usage: 830.0742 MB. Make sure that the solver is using numpy arrays. > The C implementation of Python (called "CPython") does not use > memory compaction and places most of its objects on the heap. > Those implementations tend to suffer from memory fragmentation in > long running processes with large memory use. This can be helped somewhat by reusing arrays instead of deleting and creating a new one. > You may consider "Jython" (a Python implementation in "Java") or > "IronPython" (a ".Net" based Python implementation) to get a > Python implementation with memory compaction. > -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Sat Aug 15 14:21:04 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 15 Aug 2015 19:21:04 +0100 Subject: memory control in Python In-Reply-To: References: <87io8hc8z3.fsf@handshake.de> Message-ID: On 15/08/2015 18:28, Terry Reedy wrote: > On 8/15/2015 3:21 AM, dieter wrote: >> Ping Liu writes: >>> ... >>> For small cases, Python works well. But if we consider longer time >>> period. >>> then it would fail due to the memory usage issues. We have tested >>> several >>> case studies to check the memory use for different time period, >>> including >>> 1) 2 hours in one day, 2) 24 hours in one day, 3) 20 days with 24 hours >>> each day, as well as 4) 30 days with 24 hours each day. The first 3 >>> cases >>> are feasible while the last case gives out the memory error. >>> >>> When we are testing the forth case, the memory error comes out while >>> creating the inequality constraints. The problem size is 1) Aeq: 12 * >>> 26, >>> Aineq: 30 * 26; 2) Aeq: 144*268, Aineq:316*268; 3) Aeq: 2880*5284, >>> Aineq: >>> 6244*5284; 4) Aeq: 4320 * 7924, Aineq is unknown due to the memory >>> error. >>> >>> The solver is CPLEX (academic). It turns out that the solver is taking a >>> lot of memory as you can see in the memory test report. for the first >>> three >>> cases, different memory usage is observed, and it grows up dramatically >>> with the increase of the time period. 1) solver memory usage: 25.6 >>> MB, 2) >>> 19.5 MB; 3) solver memory usage: 830.0742 MB. > > Make sure that the solver is using numpy arrays. > I doubt that as CPLEX was first released in 1988. A very quick bit of searching found this http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linprog.html which I believe is the equivalent of the Aeq and Aineq mentioned above. Possibly a better option as must surely be using numpy, but as usual there's only one way to find out? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From lac at openend.se Sat Aug 15 14:55:39 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 15 Aug 2015 20:55:39 +0200 Subject: memory control in Python In-Reply-To: Message from Terry Reedy of "Sat, 15 Aug 2015 13:28:19 -0400." References: <87io8hc8z3.fsf@handshake.de> Message-ID: <201508151855.t7FItdLq027074@fido.openend.se> If the problem is that Python is using too much memory, then PyPy may be able to help you. PyPy is an alternative implementation of Python, and by defaiult uses a minimark garbage collector. https://pypy.readthedocs.org/en/release-2.4.x/garbage_collection.html You will have to write your own bindings for the CPLEX C library, though, using cffi. http://cffi.readthedocs.org/en/latest/overview.html (since the bindings you have assume the CPython ref counting gc). But if your C program is itself using too much memory, then this probably won't help. Discuss this more on pypy-dev at python.org or the #pypy channel on freenode. People on pypy-dev would appreciate not getting libreoffice spreadsheet attachments but just the figures as plain text. Laura From denismfmcmahon at gmail.com Sat Aug 15 18:51:17 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sat, 15 Aug 2015 22:51:17 +0000 (UTC) Subject: How to model government organization hierarchies so that the list can expand and compress References: Message-ID: On Thu, 13 Aug 2015 12:10:12 -0700, Alex Glaros wrote: > What would the data model look like for this? Define an organizational unit. Give it a unique name. Give it a list of superiors and a list of subordinates. government = { 'president' : { 'superiors' : [], 'subordinates' : ['jcs', 'cia', 'fbi', 'nsa', 'treasury', 'nasa' ..... ] }, 'jcs' : { 'superiors': ['president', 'congress', 'senate', 'treasury'], 'subordinates' : ['army', 'navy', 'air force', 'jsoc'] }, 'navy' : { 'superiors' : ['jcs', 'nsa', 'cia'], 'subordinates' : ['seals', 'marines', 'pacific fleet' ....] }, ........ } The multiple parenting means that you need to use something as references. You can't represent the hierarchy as a simple tree, because in a simple tree a node only has one parent. -- Denis McMahon, denismfmcmahon at gmail.com From uri at speedy.net Sun Aug 16 02:09:12 2015 From: uri at speedy.net (Uri Even-Chen) Date: Sun, 16 Aug 2015 09:09:12 +0300 Subject: Encrypted web mail In-Reply-To: References: Message-ID: Hi Dennis, On Sat, Aug 15, 2015 at 7:35 PM, Dennis Lee Bieber wrote: > On Sat, 15 Aug 2015 12:47:17 +0300, Uri Even-Chen > declaimed the following: > > >To Python, Django and Speedy Mail Software developers, > > > >Is it possible to make Speedy Mail encrypted? I want mail to be encrypted > >on the server, and only the user will be able to read his/her mail. The > >user's password will be encrypted on the server and nobody will be able to > > Most systems I know of don't store the password on the server in > the > first place. They store a one-way hash generated from the password > (possibly using a randomly generated salt that is also saved with the hash > -- that is, rather than just hash "password" into "hashstring", they hash > "saltpassword" into "otherhash" and prepend the "salt" -> "saltotherhash". > When user comes to connect later, they match the user name in the password > database, extract the "salt" from "saltotherhash", attach it to the > password given by the user, generate the hash, and see if it matches the > rest of the saved hash). The hash value is only used for matching purposes, > not for any subsequent processing -- it is not a cryptography key, nor is > any cryptography key used to produce it. > > Thanks for the feedback. Actually the passwords on my webmail in 2000 to 2005 were not encrypted, but I agree with you that passwords should be always encrypted. > >read the user's mail except the user himself. Is it possible? When I had > > How do you intend to handle new inbound email? After all, the > sender of > the email sure won't know about any user encryption key -- that means you > have to have the encryption key stored on your server associated with the > recipient username, so that you can encrypt inbound email before putting it > into the user's mailbox... Do you also intend to encrypt the header > information or just the body of the message? > > A public key system MIGHT support that, in that the public key -- > used > to "send to" the recipient is only used to encrypt the data, and can be > stored on your server (in the same username/password account file). The > private (decryption) key would have to be stored on the user's computer and > never provided to your server machine -- and you'd need some way to send > individual encrypted messages to the user where they are decrypted on their > computer, NOT ON the server. You'd also need to be able to identify which > messages are new, read, deleted -- if the mailbox is encrypted, this likely > means each message is a file within the mailbox, since you can't do things > like mark and compress an MBOX (all mail is in one file with a special > header marking the start of a message) file without corrupting the > encryption stream. > > If, at anytime, the decryption key is on the server, you have lost > the > security you claim to be striving for -- as any court ordered system could > just patch in a packet sniffer and wait for your user to connect, capture > the password, and capture the decryption key if it is sent to the server to > retrieve mail (though they don't even need it at that point -- they could > just capture the decrypted contents being sent to the user... TLS/SSL > sessions may alleviate that problem, but it does mean having certificates > to initiate the TLS session keys). If the packets are TLS encrypted, they > can require one to patch into the server at the point where the contents > are converted back to plain text and capture the traffic. > > Of course, this now means the user has to carry around a "keyring" > that > can be accessed by any computer used to read the email (since the > decryption key can not be on the server, if they read email from an android > tablet they need to have the key installed on the tablet; they also need it > on their desktop if they use it to access the server; on their phone if it > has a browser, etc.). > > A Javascript client is probably going to be rather slow at > decrypting > the emails -- but you may not be able to install a compiled Java encryption > package on all the clients out there (you'd have to have something for iOS, > something for Android, for Linux, Macintosh, and Windows -- though the > latter three might be able to use the same core Java code). > > We've taken care of inbound email. What were your plans for > outgoing > email? You can't encrypt that as it is going to other systems and other > users who are not part of your server and don't expect to see encrypted > stuff. You could perhaps store the already sent messages using the same > public key, but you can't do that with in-work drafts stored on the server > prior to being sent (at least, not without requiring them to pass from the > server to the client for decryption and then back to the server in > plain-text for delivery -- deleting the draft copy and saving an encrypted > sent copy) > > I think ProtonMail is doing something similar to what I want, so maybe I'll check what they are doing. I also want the user's mail to be searchable, like Gmail. > >I believe a user's mail is something personal, like his thoughts. I don't > >want the police to read my mail and it's similar to reading my thoughts. > > > And the solution, in my mind, is to not use a central mail > repository > (no webmail client, nor even an IMAP client) and always do a > delete-from-server when the POP3 client fetches the mail (and the server > should do some sort of secure scrub of the deleted file area on disk). That > way the only mail that will ever be found on the server is the mail the > user hasn't logged in to retrieve yet, or outgoing messages that the SMTP > daemon hasn't gotten around to forwarding to the destination (and deleting > once the receiving server ACKs the message). (This also reduces the storage > needed by the server, and likely speeds access to mail if using MBOX format > as it doesn't have to scan humongous files). > Yes, but then the mail is on your computer, and the police can enter your house and take it (but you can encrypt it on your computer). There is no way to have 100% security against the police. Uri. -------------- next part -------------- An HTML attachment was scrubbed... URL: From agostinhoteixeira17 at gmail.com Sun Aug 16 12:40:06 2015 From: agostinhoteixeira17 at gmail.com (AGOSTINHO TEIXEIRA) Date: Sun, 16 Aug 2015 09:40:06 -0700 (PDT) Subject: Old DbaseV DOS Programmer wants to step over to new/actual modern program software Message-ID: <12bc0fae-7331-48f2-80fb-831b210cd90d@googlegroups.com> I'm a 25year DBASE-5 DOS programmer and want/have to step over to new program/platform software, because there is no future anymore for DOS after W-XP, I've been looking around for alternatives and cannot figure out where to start, I already have been learning the SQL with SSMS database system/script this is very important because I work mostly with large databases invoicing/stock/statements etc. I always manage my users with design-programs,windows-input,files-views, using custom made windows/input. I did all this in *.prg files with hard-coding. I have some ideas in mind like Java with (ECLIPS) because it is very popular, it is the most widely used and can get tutorials and videos all over the internet. I've read a lot of good things about Python, that it is much easier but too complicate to define what to choose, at the first place witch version 2.x or 3.x, a lot of IDE's to choose from, beside of that witch IDE with what pluggin. I'll need something suitable to manage/manipulate M-SQL. I have a lot of programs to rewrite and not much time, that's why it is very important to me to start with something appropriate with the best software combination that I can learn completely from the internet, cannot go back to the classroom, too old for that. I appreciate very much that any of you can help me to figure out to choose the right software combination for my new project. Thanks....! From sven.boden at gmail.com Sun Aug 16 12:53:32 2015 From: sven.boden at gmail.com (Sven Boden) Date: Sun, 16 Aug 2015 09:53:32 -0700 (PDT) Subject: -2146826246 in win32com.client for empty #N/A cell in Excel Message-ID: <29fb0de6-2d4a-4392-9c85-8f1633ad5454@googlegroups.com> Anyone know how to handle "#N/A" in Excel from win32com.client. I'm extracting data from an Excel file using win32com.client. Everything works fine except for when the value "#N/A" is entered in excel. An empty cell. I assumed I do something as if ws.Cells(r, c).Value is None: ... But that doesn't seem to work. When I debug the piece of code while handling #N/A in a cell the type of the cell according to win32com.client is int and the value in the cell is -2146826246. Chances are small just this number will appear in Excel, but it looks dirty to depend on that value to decide if a cell is empty. Looked around the net for a solution, but nothing came up so far. Anyone knows how to handle a "#N/A" cell in Excel in the proper way? Regards, Sven From ikorot01 at gmail.com Sun Aug 16 12:54:19 2015 From: ikorot01 at gmail.com (Igor Korot) Date: Sun, 16 Aug 2015 12:54:19 -0400 Subject: Old DbaseV DOS Programmer wants to step over to new/actual modern program software In-Reply-To: <12bc0fae-7331-48f2-80fb-831b210cd90d@googlegroups.com> References: <12bc0fae-7331-48f2-80fb-831b210cd90d@googlegroups.com> Message-ID: Hi, On Sun, Aug 16, 2015 at 12:40 PM, AGOSTINHO TEIXEIRA wrote: > I'm a 25year DBASE-5 DOS programmer and want/have to step over to new program/platform software, because there is no future anymore for DOS after W-XP, I've been looking around for alternatives and cannot figure out where to start, I already have been learning the SQL with SSMS database system/script this is very important because I work mostly with large databases invoicing/stock/statements etc. I always manage my users with design-programs,windows-input,files-views, using custom made windows/input. I did all this in *.prg files with hard-coding. I have some ideas in mind like Java with (ECLIPS) because it is very popular, it is the most widely used and can get tutorials and videos all over the internet. I've read a lot of good things about Python, that it is much easier but too complicate to define what to choose, at the first place witch version 2.x or 3.x, a lot of IDE's to choose from, beside of that witch IDE with what pluggin. I'll need something suitable to manage/manipulate > M-SQL. I have a lot of programs to rewrite and not much time, that's why it is very important to me to start with something appropriate with the best software combination that I can learn completely from the internet, cannot go back to the classroom, too old for that. I appreciate very much that any of you can help me to figure out to choose the right software combination for my new project. Thanks....! It really doesn't matter which language you choose for you implementation. You will still need to learn it somehow and understand how to operate with it and how to write a nice maintainable code with it. I'd suggest to go to some local college and get some knowledge about your language of the choice. Perl/python might be better. because with them you will be able to test you changes right away on the spot. Also make sure that you DBMS does have a ODBC driver so you can connect to the DB... Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list From torriem at gmail.com Sun Aug 16 13:07:12 2015 From: torriem at gmail.com (Michael Torrie) Date: Sun, 16 Aug 2015 11:07:12 -0600 Subject: Old DbaseV DOS Programmer wants to step over to new/actual modern program software In-Reply-To: <12bc0fae-7331-48f2-80fb-831b210cd90d@googlegroups.com> References: <12bc0fae-7331-48f2-80fb-831b210cd90d@googlegroups.com> Message-ID: <55D0C340.5020304@gmail.com> On 08/16/2015 10:40 AM, AGOSTINHO TEIXEIRA wrote: > I'm a 25year DBASE-5 DOS programmer and want/have to step over to new > program/platform software, because there is no future anymore for DOS > after W-XP, I've been looking around for alternatives and cannot > figure out where to start, I already have been learning the SQL with > SSMS database system/script this is very important because I work > mostly with large databases invoicing/stock/statements etc. I always > manage my users with design-programs,windows-input,files-views, using > custom made windows/input. I did all this in *.prg files with > hard-coding. I have some ideas in mind like Java with (ECLIPS) > because it is very popular, it is the most widely used and can get > tutorials and videos all over the internet. I've read a lot of good > things about Python, that it is much easier but too complicate to > define what to choose, at the first place witch version 2.x or 3.x, a > lot of IDE's to choose from, beside of that witch IDE with what > pluggin. I'll need something suitable to manage/manipulate M-SQL. I > have a lot of programs to rewrite and not much time, that's why it is > very important to me to start with something appropriate with the > best software combination that I can learn completely from the > internet, cannot go back to the classroom, too old for that. I > appreciate very much that any of you can help me to figure out to > choose the right software combination for my new project. > Thanks....! > Here're a couple of interesting projects that I found on a google search that might relate to what you're trying to do: http://www.python-camelot.com/ http://kivy.org/ But like the other poster said, take some time to learn a new language, such as Python. Things can get complicated in a hurry, but if you have a solid understanding of the language, it's doable. Also it is helpful if you have a good working knowledge of SQL. SQL is useful when interacting with a variety of database engines such as MS SQL, or a freely available one like PostgreSQL. Then there are dozens of different database access libraries and abstractions you can choose from such as SQLAlchemy. And for creating a GUI there are several different toolkits. As for the future of DOS, existing DOS programs including your DBASE-5 apps should continue running indefinitely with the wonderful DOSBox program: http://www.dosbox.com/. While it's aimed at running games, it runs business apps quite well. From rustompmody at gmail.com Sun Aug 16 13:11:04 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 16 Aug 2015 10:11:04 -0700 (PDT) Subject: Old DbaseV DOS Programmer wants to step over to new/actual modern program software In-Reply-To: <12bc0fae-7331-48f2-80fb-831b210cd90d@googlegroups.com> References: <12bc0fae-7331-48f2-80fb-831b210cd90d@googlegroups.com> Message-ID: <65e075e4-211b-4800-af04-0ffc9eebd86c@googlegroups.com> On Sunday, August 16, 2015 at 10:10:18 PM UTC+5:30, AGOSTINHO TEIXEIRA wrote: > I'm a 25year DBASE-5 DOS programmer and want/have to step over to new program/platform software, because there is no future anymore for DOS after W-XP, I've been looking around for alternatives and cannot figure out where to start, I already have been learning the SQL with SSMS database system/script this is very important because I work mostly with large databases invoicing/stock/statements etc. I always manage my users with design-programs,windows-input,files-views, using custom made windows/input. I did all this in *.prg files with hard-coding. I have some ideas in mind like Java with (ECLIPS) because it is very popular, it is the most widely used and can get tutorials and videos all over the internet. I've read a lot of good things about Python, that it is much easier but too complicate to define what to choose, at the first place witch version 2.x or 3.x, a lot of IDE's to choose from, beside of that witch IDE with what pluggin. I'll need something suitable to manage/manipulate M-SQL. I have a lot of programs to rewrite and not much time, that's why it is very important to me to start with something appropriate with the best software combination that I can learn completely from the internet, cannot go back to the classroom, too old for that. I appreciate very much that any of you can help me to figure out to choose the right software combination for my new project. Thanks....! Questions 1. Are you talking MSQL, MS-SQL? Quite different and also different from MySQL 2. How bound are you to your DBMS? If you are going to anyway port DBase-V to a modern DBMS, you can as well choose a more python-friendly one -- one of postgres, MySql, Sqlite. Anyways... Assuming you are committed to MsSql, I'd suggest in sequence: 1. Forget about DBMS and study the python tutorial for a few days 2. Forget get about *your* DBMS and play around with Sqlite that runs out of the box. This will familiarize you with python's DBMS model without the headaches of installing many pieces of softwares 3. Pick a python MsSql library and port your stuff to that From sjeik_appie at hotmail.com Sun Aug 16 13:27:27 2015 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Sun, 16 Aug 2015 17:27:27 +0000 Subject: -2146826246 in win32com.client for empty #N/A cell in Excel In-Reply-To: <29fb0de6-2d4a-4392-9c85-8f1633ad5454@googlegroups.com> References: <29fb0de6-2d4a-4392-9c85-8f1633ad5454@googlegroups.com> Message-ID: > Date: Sun, 16 Aug 2015 09:53:32 -0700 > Subject: -2146826246 in win32com.client for empty #N/A cell in Excel > From: sven.boden at gmail.com > To: python-list at python.org > > > Anyone know how to handle "#N/A" in Excel from win32com.client. > > I'm extracting data from an Excel file using win32com.client. Everything works fine except for when the value "#N/A" is entered in excel. An empty cell. I assumed I do something as > > if ws.Cells(r, c).Value is None: > ... > > But that doesn't seem to work. When I debug the piece of code while handling #N/A in a cell the type of the cell according to win32com.client is int and the value in the cell is -2146826246. Chances are small just this number will appear in Excel, but it looks dirty to depend on that value to decide if a cell is empty. Looked around the net for a solution, but nothing came up so far. > > Anyone knows how to handle a "#N/A" cell in Excel in the proper way? > > Regards, > Sven > -- > https://mail.python.org/mailman/listinfo/python-list Hello, Does that number happen to be -1 * sys.maxint? Regards,Albert-Jan -------------- next part -------------- An HTML attachment was scrubbed... URL: From sven.boden at gmail.com Sun Aug 16 13:38:57 2015 From: sven.boden at gmail.com (Sven Boden) Date: Sun, 16 Aug 2015 19:38:57 +0200 Subject: -2146826246 in win32com.client for empty #N/A cell in Excel In-Reply-To: References: <29fb0de6-2d4a-4392-9c85-8f1633ad5454@googlegroups.com> Message-ID: On Sun, Aug 16, 2015 at 7:27 PM, Albert-Jan Roskam wrote: > > > > > Date: Sun, 16 Aug 2015 09:53:32 -0700 > > Subject: -2146826246 in win32com.client for empty #N/A cell in Excel > > From: sven.boden at gmail.com > > To: python-list at python.org > > > > > > Anyone know how to handle "#N/A" in Excel from win32com.client. > > > > I'm extracting data from an Excel file using win32com.client. Everything > works fine except for when the value "#N/A" is entered in excel. An empty > cell. I assumed I do something as > > > > if ws.Cells(r, c).Value is None: > > ... > > > > But that doesn't seem to work. When I debug the piece of code while > handling #N/A in a cell the type of the cell according to win32com.client > is int and the value in the cell is -2146826246. Chances are small just > this number will appear in Excel, but it looks dirty to depend on that > value to decide if a cell is empty. Looked around the net for a solution, > but nothing came up so far. > > > > Anyone knows how to handle a "#N/A" cell in Excel in the proper way? > > > > Regards, > > Sven > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > Hello, > > Does that number happen to be -1 * sys.maxint? > > Regards, > Albert-Jan > > > On python 3.x sys.maxint is gone... sys.maxsize is a lot larger on Windows 64bit (same laptop I run the code on). Regards, Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From kmisoft at gmail.com Sun Aug 16 14:40:53 2015 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Sun, 16 Aug 2015 14:40:53 -0400 Subject: Old DbaseV DOS Programmer wants to step over to new/actual modern program software In-Reply-To: <65e075e4-211b-4800-af04-0ffc9eebd86c@googlegroups.com> References: <12bc0fae-7331-48f2-80fb-831b210cd90d@googlegroups.com> <65e075e4-211b-4800-af04-0ffc9eebd86c@googlegroups.com> Message-ID: On Sun, Aug 16, 2015 at 1:11 PM, Rustom Mody wrote: >> I have some ideas in mind like Java with (ECLIPS) because it is very popular, it is the most widely used and can get tutorials and videos all over the internet. >> I've read a lot of good things about Python, that it is much easier but too complicate to define what to choose, >> at the first place witch version 2.x or 3.x, a lot of IDE's to choose from, beside of that witch IDE with what pluggin. Hi, I am using python for years but still curious about best IDE to suggest newbies. IMHO - too many choices with no clear winner and each with its own flaws. For me two crucial features are: good autocompletion and ability to step over code in debugger. I'd try Eclipse+PyDev first and then additionally check PyCharm ($$$) for comparison (to see how "best free" compares to "good commercial") Vladimir https://itunes.apple.com/us/app/python-code-samples/id1025613117 From rosuav at gmail.com Sun Aug 16 14:41:06 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 17 Aug 2015 04:41:06 +1000 Subject: -2146826246 in win32com.client for empty #N/A cell in Excel In-Reply-To: References: <29fb0de6-2d4a-4392-9c85-8f1633ad5454@googlegroups.com> Message-ID: On Mon, Aug 17, 2015 at 3:27 AM, Albert-Jan Roskam wrote: > Does that number happen to be -1 * sys.maxint? No, it's -1 * 0x7ff5f806. As a signed 32-bit integer, it's 0x800a07fa. Does either of those numbers mean anything? Sven, you might do better to ask on a dedicated Python + Win32 mailing list; I haven't used Python on Windows much for a while. ChrisA From katewinslet626 at gmail.com Sun Aug 16 15:16:53 2015 From: katewinslet626 at gmail.com (shiva upreti) Date: Sun, 16 Aug 2015 12:16:53 -0700 (PDT) Subject: "no module named kivy" import error in ubuntu 14.04 Message-ID: Hi I am new to linux. I tried various things in attempt to install kivy. I installed python 2.7.10 (I think python3 was already installed in ubuntu 14.04). Then i downloaded kivy from https://pypi.python.org/packages/source/K/Kivy/Kivy-1.9.0.tar.gz, extracted it and tried to execute "python setup.py" inside the kivy folder. But it showed the error "no module named cython". Then I tried installing cython, it installed successfully but the command "python setup.py" still gave the error "no module named cython". Finally I installed kivy using instructions on this video: https://www.youtube.com/watch?v=mypVFCIIZtw. Now when i try to run the following commands: "$ cd (I used the actual path, i.e., "/usr/share/kivy-examples") $ cd demo/touchtracer $ python main.py" I am still getting the error:"ImportError: No module named kivy". Any help will be highly appreciated. Thanks. From garyr at fidalgo.net Sun Aug 16 15:25:53 2015 From: garyr at fidalgo.net (garyr) Date: Sun, 16 Aug 2015 12:25:53 -0700 Subject: distutils error ? Message-ID: I tried building the spammodule.c example described in the documentation section "Extending Python with C or C++." As shown the code compiles OK but generates a link error: LINK : error LNK2001: unresolved external symbol init_spam build\temp.win32-2.7\Release\_spam.lib : fatal error LNK1120: 1 unresolved externals I tried changing the name of the initialization function spam_system to init_spam and removed the static declaration. This compiled and linked without errors but generated a system error when _spam was imported. The same error occurs with Python 2.6 and the current compiler. The code and the setup.py file are shown below. setup.py: ----------------------------------------------------------------------------- from setuptools import setup, Extension setup(name='spam', version='0.1', description='test module', ext_modules=[Extension('_spam', ['spammodule.c'], include_dirs=[C:\Documents and Settings\Owner\Miniconda\include], )], ) sammodule.c -------------------------------------------------- #include static PyObject *SpamError; static PyObject * spam_system(PyObject *self, PyObject *args) { const char *command; int sts; if (!PyArg_ParseTuple(args, "s", &command)) return NULL; sts = system(command); if (sts < 0) { PyErr_SetString(SpamError, "System command failed"); return NULL; } return PyLong_FromLong(sts); } static PyMethodDef SpamMethods[] = { {"system", spam_system, METH_VARARGS, "Execute a shell command."}, {NULL, NULL, 0, NULL} /* Sentinel */ }; PyMODINIT_FUNC initspam(void) { PyObject *m; m = Py_InitModule("spam", SpamMethods); if (m == NULL) return; SpamError = PyErr_NewException("spam.error", NULL, NULL); Py_INCREF(SpamError); PyModule_AddObject(m, "error", SpamError); } From python at mrabarnett.plus.com Sun Aug 16 15:27:12 2015 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 16 Aug 2015 20:27:12 +0100 Subject: "no module named kivy" import error in ubuntu 14.04 In-Reply-To: References: Message-ID: <55D0E410.1070709@mrabarnett.plus.com> On 2015-08-16 20:16, shiva upreti wrote: > Hi > I am new to linux. I tried various things in attempt to install kivy. I installed python 2.7.10 (I think python3 was already installed in ubuntu 14.04). Then i downloaded kivy from https://pypi.python.org/packages/source/K/Kivy/Kivy-1.9.0.tar.gz, extracted it and tried to execute "python setup.py" inside the kivy folder. But it showed the error "no module named cython". Then I tried installing cython, it installed successfully but the command "python setup.py" still gave the error "no module named cython". > Finally I installed kivy using instructions on this video: https://www.youtube.com/watch?v=mypVFCIIZtw. Now when i try to run the following commands: > > "$ cd (I used the actual path, i.e., "/usr/share/kivy-examples") > $ cd demo/touchtracer > $ python main.py" > I am still getting the error:"ImportError: No module named kivy". > > Any help will be highly appreciated. > Thanks. > Do you know which Python they were installed into? Was it the system Python (you should probably leave that one alone) or the one that you installed? And which one is it trying to run? From davros at bellaliant.net Sun Aug 16 15:40:01 2015 From: davros at bellaliant.net (John McKenzie) Date: Sun, 16 Aug 2015 19:40:01 GMT Subject: RPI.GPIO Help Message-ID: Hello, all. I am hoping some people here are familiar with the RPi.GPIO python module for the Raspberry Pi. Very new to Python and electronics. Not to computing in general though. I posted for help about accepting key presses and then discovered that wiring up buttons directly to the Pi was 1/50th as difficult as I thought it would be so I am going a different route than keyboard emulation and needing GUI toolkits, etc. However, I am getting error messages with RPi.GPIO. I have three buttons, Red, Yellow and Blue in colour, attached to the Pi. The eventual goal is to have pressing one button result in changing the colour of an LED lightstrip to that colour and the Pi record how long the strip spent as each colour. For development purposes I have the controls near me and my desktop computer, and the Pi networked to this computer. For now I have each button press result in a print statement. When I get this working I will replace the print statements with the code to change colours on the LED strip using the Blinkstick module. This is the basic test code. import atexit import time from blinkstick import blinkstick import RPi.GPIO as GPIO led = blinkstick.find_first() colour = 0 timered = 0 timeyellow = 0 timeblue = 0 timestamp = time.strftime("%H:%M:%S") GPIO.setmode(GPIO.BCM) GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) def red_button(channel): colour = 1 print "Red Button Pressed" while colour == 1: timered += 1 def yellow_button(channel): colour = 2 print "Yellow Button Pressed" while colour == 2: timeyellow += 1 def blue_button(channel): colour = 3 print "Blue Button Pressed" while colour == 3: timeblue += 1 while True: GPIO.add_event_detect(22, GPIO.RISING, callback=red_button, bouncetime=200) GPIO.add_event_detect(23, GPIO.RISING, callback=yellow_button, bouncetime=200) GPIO.add_event_detect(24, GPIO.RISING, callback=blue_button, bouncetime=200) def exit_handler(): print '\033[0;41;37mRed Team:\033[0m ', timered print '\033[0;43;30mYellow Time:\033[0m ', timeyellow print '\033[0;44;37mBlue Time:\033[0m ', timeblue flog = open('flag1log.text', 'a') flog.write(timestamp + '\n' + 'Red Team: ' + str(timered) + '\n' + 'Yellow Team: ' + str(timeyellow) + '\n' + 'Blue Team: ' + str(timeblue) + '\n') flog.close() atexit.register(exit_handler) GPIO.cleanup() This results in the error message "RuntimeError: Conflicting edge detection already enabled for this GPIO channel". Running GPIO.cleanup() in the interpreter results in a message stating the GPIO pins are not assigned and there is nothing to cleanup. Removing line 40, the while True: line, removes the error, but the program does not sit and wait waiting for a button press, it just runs and ends a second later. There are other things this script will need, but this is the core function that I need to get working -pressing a button does what I want and the script keeps running so I can press another button if I want. If are familiar with the RPi.GPIO or see a more general Python mistake that could be affecting everything know I would appreciate your help. Thanks. From davros at bellaliant.net Sun Aug 16 15:45:03 2015 From: davros at bellaliant.net (John McKenzie) Date: Sun, 16 Aug 2015 19:45:03 GMT Subject: Keypress Input References: <9aypx.126956$r46.110087@fx28.iad> Message-ID: <3L5Ax.73239$E26.11652@fx20.iad> Thanks again to everyone who tried to help. Michael, I especially appreciate your encouragement and chiming in to point out that telling newbies to learn everything there is before posting question was not helpful in getting more people using Python. Have the Pi wired up directly to the buttons, read up on the GPIO library and I just posted for help regarding the error messages I am getting from my Python buttons script. Thanks. From lac at openend.se Sun Aug 16 15:49:20 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 16 Aug 2015 21:49:20 +0200 Subject: -2146826246 in win32com.client for empty #N/A cell in Excel In-Reply-To: Message from Chris Angelico of "Mon, 17 Aug 2015 04:41:06 +1000." References: <29fb0de6-2d4a-4392-9c85-8f1633ad5454@googlegroups.com> Message-ID: <201508161949.t7GJnKUT025504@fido.openend.se> For what it's worth, I use xlrd for this. http://www.python-excel.org/ Laura From lac at openend.se Sun Aug 16 15:58:42 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 16 Aug 2015 21:58:42 +0200 Subject: "no module named kivy" import error in ubuntu 14.04 In-Reply-To: Message from shiva upreti of "Sun, 16 Aug 2015 12:16:53 -0700." References: Message-ID: <201508161958.t7GJwgf9027307@fido.openend.se> In a message of Sun, 16 Aug 2015 12:16:53 -0700, shiva upreti writes: >I am still getting the error:"ImportError: No module named kivy". > >Any help will be highly appreciated. >Thanks. The preferred way to install kivy with ubuntu is to follow the instructions here: http://kivy.org/docs/installation/installation-linux.html i.e. $ sudo apt-get install python3-kivy $ sudo apt-get install kivy-examples This assumes you want to use Python 3. See if this works, write back if it doesn't. Laura From python at mrabarnett.plus.com Sun Aug 16 16:15:30 2015 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 16 Aug 2015 21:15:30 +0100 Subject: RPI.GPIO Help In-Reply-To: References: Message-ID: <55D0EF62.9010808@mrabarnett.plus.com> On 2015-08-16 20:40, John McKenzie wrote: > > Hello, all. I am hoping some people here are familiar with the RPi.GPIO > python module for the Raspberry Pi. > > Very new to Python and electronics. Not to computing in general though. > I posted for help about accepting key presses and then discovered that > wiring up buttons directly to the Pi was 1/50th as difficult as I thought > it would be so I am going a different route than keyboard emulation and > needing GUI toolkits, etc. > > However, I am getting error messages with RPi.GPIO. > > I have three buttons, Red, Yellow and Blue in colour, attached to the > Pi. The eventual goal is to have pressing one button result in changing > the colour of an LED lightstrip to that colour and the Pi record how long > the strip spent as each colour. > > For development purposes I have the controls near me and my desktop > computer, and the Pi networked to this computer. For now I have each > button press result in a print statement. When I get this working I will > replace the print statements with the code to change colours on the LED > strip using the Blinkstick module. > > This is the basic test code. > > > import atexit > import time > from blinkstick import blinkstick > import RPi.GPIO as GPIO > > led = blinkstick.find_first() > colour = 0 > timered = 0 > timeyellow = 0 > timeblue = 0 > timestamp = time.strftime("%H:%M:%S") > > > GPIO.setmode(GPIO.BCM) > GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) > GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) > GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) > > > > > def red_button(channel): > colour = 1 > print "Red Button Pressed" > while colour == 1: > timered += 1 > > def yellow_button(channel): > colour = 2 > print "Yellow Button Pressed" > while colour == 2: > timeyellow += 1 > > def blue_button(channel): > colour = 3 > print "Blue Button Pressed" > while colour == 3: > timeblue += 1 > > while True: > GPIO.add_event_detect(22, GPIO.RISING, callback=red_button, > bouncetime=200) > GPIO.add_event_detect(23, GPIO.RISING, callback=yellow_button, > bouncetime=200) > GPIO.add_event_detect(24, GPIO.RISING, callback=blue_button, > bouncetime=200) > > > def exit_handler(): > print '\033[0;41;37mRed Team:\033[0m ', timered > print '\033[0;43;30mYellow Time:\033[0m ', timeyellow > print '\033[0;44;37mBlue Time:\033[0m ', timeblue > flog = open('flag1log.text', 'a') > flog.write(timestamp + '\n' + 'Red Team: ' + str(timered) + '\n' + > 'Yellow Team: ' + str(timeyellow) + '\n' + 'Blue Team: ' + str(timeblue) > + '\n') > flog.close() > atexit.register(exit_handler) > GPIO.cleanup() > > > > This results in the error message "RuntimeError: Conflicting edge > detection already enabled for this GPIO channel". Running GPIO.cleanup() > in the interpreter results in a message stating the GPIO pins are not > assigned and there is nothing to cleanup. > > Removing line 40, the while True: line, removes the error, but the > program does not sit and wait waiting for a button press, it just runs > and ends a second later. > > There are other things this script will need, but this is the core > function that I need to get working -pressing a button does what I want > and the script keeps running so I can press another button if I want. If > are familiar with the RPi.GPIO or see a more general Python mistake that > could be affecting everything know I would appreciate your help. Thanks. > I'm looking at this: http://sourceforge.net/p/raspberry-gpio-python/wiki/Inputs/ As far as I can tell, the 'add_event_detect' method adds a callback. However, you have it in a loop, so you're trying to add more than one callback (actually, the same one more than once!), which it doesn't like. You should add the callbacks only once and then have some kind of sleep or do-nothing loop, perhaps waiting for the signal to quit (I don't have a Raspberry Pi, so I don't know what the usual practice is). From nobody at nowhere.invalid Sun Aug 16 17:37:52 2015 From: nobody at nowhere.invalid (Nobody) Date: Sun, 16 Aug 2015 22:37:52 +0100 Subject: -2146826246 in win32com.client for empty #N/A cell in Excel References: <29fb0de6-2d4a-4392-9c85-8f1633ad5454@googlegroups.com> Message-ID: On Sun, 16 Aug 2015 09:53:32 -0700, Sven Boden wrote: > Anyone knows how to handle a "#N/A" cell in Excel in the proper way? 0x800A07FA is how xlErrNA (error 2042) is marshalled. This isn't specific to Python; you'll get the same value using e.g C# or VB.NET. There's a fairly thorough article on this topic at: https://xldennis.wordpress.com/2006/11/22/ https://xldennis.wordpress.com/2006/11/29/ From random832 at fastmail.us Sun Aug 16 17:39:30 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Sun, 16 Aug 2015 17:39:30 -0400 Subject: -2146826246 in win32com.client for empty #N/A cell in Excel In-Reply-To: References: <29fb0de6-2d4a-4392-9c85-8f1633ad5454@googlegroups.com> Message-ID: <1439761170.2076135.357681129.652F0ECB@webmail.messagingengine.com> On Sun, Aug 16, 2015, at 14:41, Chris Angelico wrote: > On Mon, Aug 17, 2015 at 3:27 AM, Albert-Jan Roskam > wrote: > > Does that number happen to be -1 * sys.maxint? > > No, it's -1 * 0x7ff5f806. As a signed 32-bit integer, it's 0x800a07fa. > Does either of those numbers mean anything? That's a COM error code, for Excel error 2042, which (unsurprisingly) means N/A. http://stackoverflow.com/questions/7526640/any-ideas-why-excel-interop-reads-many-decimals-as-2146826246 Here's some information from someone having the same problem in .NET, which may or may not be helpful https://xldennis.wordpress.com/2006/11/22/dealing-with-cverr-values-in-net-%E2%80%93-part-i-the-problem/ It looks like the values are actually returned as a VT_ERROR variant, which .NET (and apparently python) reads as an integer. From jcasale at activenetwerx.com Sun Aug 16 19:31:30 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Sun, 16 Aug 2015 23:31:30 +0000 Subject: return types from library api wrappers Message-ID: What's the accepted practice for return types from a c based API Python wrapper? I have many methods which return generators which yield potentially many fields per iteration. In lower level languages we would yield a struct with readonly fields. The existing implementation returns a dict which I am not fond of. I'd rather return an object with properties, however all the guys who use this api use IDE's and want the type hinting. So, options I can think of are to create a load of classes and returning instances of them, return named tuples or even terser would be to return something like: def api_method(foo, bar): """produces two return values, x and y.""" ... return type('MyResult', (), {'__slots__': [], 'some_field': x, 'another_field': y})() The last option humorously returns readonly fields. However, the latter two don't help much for type hinting unless someone knows something I don't about doc strings? As a Python user, what is preferred? Thanks, jlc From rosuav at gmail.com Sun Aug 16 21:47:36 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 17 Aug 2015 11:47:36 +1000 Subject: "no module named kivy" import error in ubuntu 14.04 In-Reply-To: References: Message-ID: On Mon, Aug 17, 2015 at 5:16 AM, shiva upreti wrote: > I am new to linux. I tried various things in attempt to install kivy. I installed python 2.7.10 (I think python3 was already installed in ubuntu 14.04). Then i downloaded kivy from https://pypi.python.org/packages/source/K/Kivy/Kivy-1.9.0.tar.gz, extracted it and tried to execute "python setup.py" inside the kivy folder. As Laura said, the preferred way to install under Ubuntu would be to use apt-get. But if you want to install directly from PyPI, the best way is to use pip. Those are two package managers, which remove from you the hassle of hunting down all the different dependencies, like Cython. Try apt-get first, and if that doesn't do what you're looking for, use pip (maybe inside a virtualenv). It'll chug for a while and then give you what you need. ChrisA From tjreedy at udel.edu Sun Aug 16 22:23:39 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 16 Aug 2015 22:23:39 -0400 Subject: return types from library api wrappers In-Reply-To: References: Message-ID: On 8/16/2015 7:31 PM, Joseph L. Casale wrote: > What's the accepted practice for return types from a c based API > Python wrapper? I have many methods which return generators > which yield potentially many fields per iteration. In lower level > languages we would yield a struct with readonly fields. Current practice is a NamedTuple for python code or the C equivalent. I forget the C name, but I believe it is used by os.stat >>> os.stat('C:/programs') os.stat_result(st_mode=16895, st_ino=1970324837036820, st_dev=1816146727, st_nlink=1, st_uid=0, st_gid=0, st_size=4096, st_atime=1437490766, st_mtime=1437490766, st_ctime=1313612988) >>> s = os.stat('C:/programs') >>> s.st_atime 1437490766.6669185 >>> s.st_atime = 3 Traceback (most recent call last): File "", line 1, in s.st_atime = 3 AttributeError: readonly attribute > The existing implementation returns a dict which I am not fond of. > I'd rather return an object with properties, however all the guys > who use this api use IDE's and want the type hinting. I believe the above gives you both: custom class for type hinting and properties. -- Terry Jan Reedy From rustompmody at gmail.com Sun Aug 16 22:51:50 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 16 Aug 2015 19:51:50 -0700 (PDT) Subject: "no module named kivy" import error in ubuntu 14.04 In-Reply-To: References: Message-ID: On Monday, August 17, 2015 at 7:30:14 AM UTC+5:30, Chris Angelico wrote: > On Mon, Aug 17, 2015 at 5:16 AM, shiva upreti wrote: > > I am new to linux. I tried various things in attempt to install kivy. I installed python 2.7.10 (I think python3 was already installed in ubuntu 14.04). Then i downloaded kivy from https://pypi.python.org/packages/source/K/Kivy/Kivy-1.9.0.tar.gz, extracted it and tried to execute "python setup.py" inside the kivy folder. > > As Laura said, the preferred way to install under Ubuntu would be to > use apt-get. But if you want to install directly from PyPI, the best > way is to use pip. Those are two package managers, which remove from > you the hassle of hunting down all the different dependencies, like > Cython. Try apt-get first, and if that doesn't do what you're looking > for, use pip (maybe inside a virtualenv). It'll chug for a while and > then give you what you need. Its not vanilla apt-get but ppa-apt-get (as Laura's link indicates) From rosuav at gmail.com Sun Aug 16 22:59:45 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 17 Aug 2015 12:59:45 +1000 Subject: "no module named kivy" import error in ubuntu 14.04 In-Reply-To: References: Message-ID: On Mon, Aug 17, 2015 at 12:51 PM, Rustom Mody wrote: > On Monday, August 17, 2015 at 7:30:14 AM UTC+5:30, Chris Angelico wrote: >> On Mon, Aug 17, 2015 at 5:16 AM, shiva upreti wrote: >> > I am new to linux. I tried various things in attempt to install kivy. I installed python 2.7.10 (I think python3 was already installed in ubuntu 14.04). Then i downloaded kivy from https://pypi.python.org/packages/source/K/Kivy/Kivy-1.9.0.tar.gz, extracted it and tried to execute "python setup.py" inside the kivy folder. >> >> As Laura said, the preferred way to install under Ubuntu would be to >> use apt-get. But if you want to install directly from PyPI, the best >> way is to use pip. Those are two package managers, which remove from >> you the hassle of hunting down all the different dependencies, like >> Cython. Try apt-get first, and if that doesn't do what you're looking >> for, use pip (maybe inside a virtualenv). It'll chug for a while and >> then give you what you need. > > Its not vanilla apt-get but ppa-apt-get (as Laura's link indicates) I didn't actually click the link. But it's still apt-get, just with an additional repository. In any case, it's way better to use a package manager (either system-provided or Python-provided) than to do everything manually. ChrisA From rurpy at yahoo.com Sun Aug 16 23:19:49 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 16 Aug 2015 20:19:49 -0700 (PDT) Subject: "no module named kivy" import error in ubuntu 14.04 In-Reply-To: References: Message-ID: <22e8c1bc-72ba-46e1-9402-fbd1bd893a35@googlegroups.com> On Sunday, August 16, 2015 at 8:00:14 PM UTC-6, Chris Angelico wrote: > On Mon, Aug 17, 2015 at 5:16 AM, shiva upreti wrote: > > I am new to linux. I tried various things in attempt to install kivy. I installed python 2.7.10 (I think python3 was already installed in ubuntu 14.04). Then i downloaded kivy from https://pypi.python.org/packages/source/K/Kivy/Kivy-1.9.0.tar.gz, extracted it and tried to execute "python setup.py" inside the kivy folder. > >[...] > use pip (maybe inside a virtualenv). It'll chug for a while and > then give you what you need. Umm, actually no... | ~# pip3 install kivy | Downloading/unpacking kivy | Downloading Kivy-1.9.0.tar.gz (16.2MB): 16.2MB downloaded | Running setup.py (path:/tmp/pip-build-m40337r5/kivy/setup.py) egg_info for package kivy | Traceback (most recent call last): | File "", line 17, in | File "/tmp/pip-build-m40337r5/kivy/setup.py", line 173, in | from Cython.Distutils import build_ext | ImportError: No module named 'Cython' | Cython is missing, its required for compiling kivy ! (on Fedora-21 where no kivy repo package is available) From lac at openend.se Mon Aug 17 00:14:03 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 17 Aug 2015 06:14:03 +0200 Subject: "no module named kivy" import error in ubuntu 14.04 In-Reply-To: Message from rurpy--- via Python-list of "Sun, 16 Aug 2015 20:19:49 -0700." <22e8c1bc-72ba-46e1-9402-fbd1bd893a35@googlegroups.com> References: <22e8c1bc-72ba-46e1-9402-fbd1bd893a35@googlegroups.com> Message-ID: <201508170414.t7H4E3ca026290@fido.openend.se> In a message of Sun, 16 Aug 2015 20:19:49 -0700, rurpy--- via Python-list write s: >On Sunday, August 16, 2015 at 8:00:14 PM UTC-6, Chris Angelico wrote: >> On Mon, Aug 17, 2015 at 5:16 AM, shiva upreti wrote: >> > I am new to linux. I tried various things in attempt to install kivy. I installed python 2.7.10 (I think python3 was already installed in ubuntu 14.04). Then i downloaded kivy from https://pypi.python.org/packages/source/K/Kivy/Kivy-1.9.0.tar.gz, extracted it and tried to execute "python setup.py" inside the kivy folder. >> >>[...] >> use pip (maybe inside a virtualenv). It'll chug for a while and >> then give you what you need. > >Umm, actually no... > >| ~# pip3 install kivy >| Downloading/unpacking kivy >| Downloading Kivy-1.9.0.tar.gz (16.2MB): 16.2MB downloaded >| Running setup.py (path:/tmp/pip-build-m40337r5/kivy/setup.py) egg_info for package kivy >| Traceback (most recent call last): >| File "", line 17, in >| File "/tmp/pip-build-m40337r5/kivy/setup.py", line 173, in >| from Cython.Distutils import build_ext >| ImportError: No module named 'Cython' >| Cython is missing, its required for compiling kivy ! > >(on Fedora-21 where no kivy repo package is available) >-- >https://mail.python.org/mailman/listinfo/python-list If you scroll down http://kivy.org/docs/installation/installation-linux.html there are instructions for Fedora as well. Laura From rurpy at yahoo.com Mon Aug 17 01:05:29 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 16 Aug 2015 22:05:29 -0700 (PDT) Subject: "no module named kivy" import error in ubuntu 14.04 In-Reply-To: References: <22e8c1bc-72ba-46e1-9402-fbd1bd893a35@googlegroups.com> Message-ID: <7054434a-03fd-46d9-b0a9-850748167376@googlegroups.com> On Sunday, August 16, 2015 at 10:14:29 PM UTC-6, Laura Creighton wrote: > In a message of Sun, 16 Aug 2015 20:19:49 -0700, rurpy--- via Python-list writes: > >On Sunday, August 16, 2015 at 8:00:14 PM UTC-6, Chris Angelico wrote: > >>[...] > >> use pip (maybe inside a virtualenv). It'll chug for a while and > >> then give you what you need. > > > >Umm, actually no... > > > >| ~# pip3 install kivy > >| Downloading/unpacking kivy > >| Downloading Kivy-1.9.0.tar.gz (16.2MB): 16.2MB downloaded > >| Running setup.py (path:/tmp/pip-build-m40337r5/kivy/setup.py) egg_info for package kivy > >| Traceback (most recent call last): > >| File "", line 17, in > >| File "/tmp/pip-build-m40337r5/kivy/setup.py", line 173, in > >| from Cython.Distutils import build_ext > >| ImportError: No module named 'Cython' > >| Cython is missing, its required for compiling kivy ! > > > >(on Fedora-21 where no kivy repo package is available) > >-- > >https://mail.python.org/mailman/listinfo/python-list > > If you scroll down > http://kivy.org/docs/installation/installation-linux.html > > there are instructions for Fedora as well. Thanks. But I note that those are all for very old, EoL'd versions of Fedora. I manually installed cython with pip, but then the kivy install failed with some C errors. At the top of it's multi-thousand line log output was a warning that it requires cython-0.21.2. Pip had installed cython-0.23. I installed cython-0.21.2 (since I do not use cython for anything else and noting that pip did not bother to inform me it was overwriting an existing install) and then pip installed kivy without error. However there were a number of warning message about missing somethings (libs or python packages, was not clear to me). So I eventually found the kivy docs on their website where they list prerequisite packages for installing kivy on ubuntu. I'll translate those to hopefully the equivalent fedora package names, install them, reinstall kivy, and get a working kivy install. The point here that all the above is a LONG way from what was was posted here: "just type 'pip install kivy' and pip will take care of everything". I hope someday Python gets a decent packaging/distribution story. From df at see.replyto.invalid Mon Aug 17 01:11:38 2015 From: df at see.replyto.invalid (Dave Farrance) Date: Mon, 17 Aug 2015 06:11:38 +0100 Subject: "no module named kivy" import error in ubuntu 14.04 References: Message-ID: <7mo2ta17psvpc1c7iqhb4hsqvi2gme9hhs@4ax.com> shiva upreti wrote: >Hi >I am new to linux. I tried various things in attempt to install kivy. I installed python 2.7.10 Just to make clear what others have said -- replacing Ubuntu 14.04's system Python 2.7.6 is a bad idea and will break stuff, so if you really must have the latest version of Python2, then you install it separately, leaving the system Python in place. That in turn means that you can no longer use Ubuntu's normal method of installing libraries via its own software management. > Then i downloaded kivy from > https://pypi.python.org/packages/source/K/Kivy/Kivy-1.9.0.tar.gz I suggest that you DON'T install from tarfiles unless your understanding of Python is of near python-developer level. You really need to know what you're doing regarding dependencies and the search path for modules. If you do want to install a separate instance of the latest version of Python, then the PIP package management is best, and use it to install the libraries separately, NOT in the /usr/ directory -- see the other posts. From dieter at handshake.de Mon Aug 17 02:04:20 2015 From: dieter at handshake.de (dieter) Date: Mon, 17 Aug 2015 08:04:20 +0200 Subject: Detecting if a library has native dependency References: Message-ID: <877foue9i3.fsf@handshake.de> Harish Vishwanath writes: > Is there a reliable way to detect if a python library has native dependency > or native code? For ex. can I programmatically determine that "lxml" > package has native code and depends on the presence of libxml on the system? I do not expect a tool that in all cases can reliably determine such dependencies. In simple cases (and "lxml" might be such a case), an import of the package might reveal a potential problem -- usually, via an "ImportError", resulting from the fact that the Python module binding to the external C library cannot be imported (either because it was not built or because it cannot be initialized). Under "*nix", you can often use "ldd" to determine on which external C libraries a "shared object" depends on. Thus, in the second case (Python binding available, but not initializable), you can often find out what is missing. However, the import of the Python binding might be delayed. Then, importing the package will not directly reveal the missing dependencies. In addition, some packages (e.g. "dm.xmlsec.binding") not only have an external dependency but depend on specific versions of a native library. Thus, even if a dependency seems to be satisfied, there might be a version problem. Thus, I recommend not to rely on program logic but read the installation instructions. From lac at openend.se Mon Aug 17 03:52:13 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 17 Aug 2015 09:52:13 +0200 Subject: "no module named kivy" import error in ubuntu 14.04 In-Reply-To: Message from rurpy--- via Python-list of "Sun, 16 Aug 2015 22:05:29 -0700." <7054434a-03fd-46d9-b0a9-850748167376@googlegroups.com> References: <22e8c1bc-72ba-46e1-9402-fbd1bd893a35@googlegroups.com> <7054434a-03fd-46d9-b0a9-850748167376@googlegroups.com> Message-ID: <201508170752.t7H7qDLU004683@fido.openend.se> In a message of Sun, 16 Aug 2015 22:05:29 -0700, rurpy--- via Python-list write s: >So I eventually found the kivy docs on their website where they >list prerequisite packages for installing kivy on ubuntu. I'll >translate those to hopefully the equivalent fedora package names, >install them, reinstall kivy, and get a working kivy install. > >The point here that all the above is a LONG way from what was >was posted here: "just type 'pip install kivy' and pip will take >care of everything". > >I hope someday Python gets a decent packaging/distribution story. Can you post what one should do with modern Fedora distributions, so we can tell the kivy-devs and they can update that webpage? Laura From renting at astron.nl Mon Aug 17 06:29:25 2015 From: renting at astron.nl (Adriaan Renting) Date: Mon, 17 Aug 2015 12:29:25 +0200 Subject: Old DbaseV DOS Programmer wants to step over to new/actual modern program software In-Reply-To: References: <12bc0fae-7331-48f2-80fb-831b210cd90d@googlegroups.com> <65e075e4-211b-4800-af04-0ffc9eebd86c@googlegroups.com> Message-ID: <55D1D3A50200001B00038153@gwsmtp1.astron.nl> For building new programs using free software, I currently like a mix of Qt, Python, C++ and various open source SQL databases (MySQL, PostGreSQL). I have found QtCreator an easy IDE to use in such cases, I don't really like Eclipse. But it requires a heavy knowledge of C++, which is not an easy language, if you want to use Qt directly. PyQt works for smaller projects, I've used it with http://eric-ide.python-projects.org/ in the past. A few things you need to ask yourself: - How much time do I have? - Who are my users, what OS/systems do they use? I like Qt because it allows me to create programs for all kinds of operating systems. - How do I want to distribute my software? Is it a problem if a user is able to read the souce code? - How well do I really know Dbase V? What do I want to do the same and what differently? My dad worked with Dbase III/IV/V for years, but learned how to program it by changing the autogenerated code, which is a horrible way to learn programming and leads to very bad habbits. - What kind of programs are you trying to make? There also exist a lot of more specialized solutions, like http://www.4d.com/, which might suit your needs, if you're looking for a dBase replacement. Cheers Adriaan Renting | Email: renting at astron.nl Software Engineer Radio Observatory ASTRON | Phone: +31 521 595 100 (797 direct) P.O. Box 2 | GSM: +31 6 24 25 17 28 NL-7990 AA Dwingeloo | FAX: +31 521 595 101 The Netherlands | Web: http://www.astron.nl/~renting/ >>> On 16-8-2015 at 20:40, Vladimir Ignatov wrote: > On Sun, Aug 16, 2015 at 1:11 PM, Rustom Mody wrote: > >>> I have some ideas in mind like Java with (ECLIPS) because it is very > popular, it is the most widely used and can get tutorials and videos all over > the internet. >>> I've read a lot of good things about Python, that it is much easier but too > complicate to define what to choose, >>> at the first place witch version 2.x or 3.x, a lot of IDE's to choose from, > beside of that witch IDE with what pluggin. > > Hi, > > I am using python for years but still curious about best IDE to suggest > newbies. > IMHO - too many choices with no clear winner and each with its own flaws. > For me two crucial features are: good autocompletion and ability to > step over code in debugger. > I'd try Eclipse+PyDev first and then additionally check PyCharm ($$$) > for comparison (to see how "best free" compares to "good commercial") > > > Vladimir > > https://itunes.apple.com/us/app/python-code-samples/id1025613117 From lac at openend.se Mon Aug 17 07:36:54 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 17 Aug 2015 13:36:54 +0200 Subject: Error in IDLE In-Reply-To: Message from Henry Quansah of "Sat, 15 Aug 2015 16:42:13 +0100." References: Message-ID: <201508171136.t7HBas4q016037@fido.openend.se> In a message of Sat, 15 Aug 2015 16:42:13 +0100, Henry Quansah writes: >I just installed python. But I'm unable to access IDLE after several clicks >and double clicks. I even tried repairing by trying to reinstall but I have >the same issue. > What version of Python have you installed? How did you install it? What Operating system are you using? What error messages (if any) do you get when you try to run Idle? Paste the whole traceback into your mail, if you get one. Laura From vladislav86 at inbox.ru Mon Aug 17 07:42:11 2015 From: vladislav86 at inbox.ru (=?koi8-r?B?98zBxMnTzMHX?=) Date: Mon, 17 Aug 2015 14:42:11 +0300 Subject: Python 3 sort() problem Message-ID: <006601d0d8e1$c17c1480$44743d80$@inbox.ru> # first: works fine x = [1, 2, 4, 2, 1, 3] x = list(set(x)) x.sort() print(x) # output: 1, 2, 3, 4 # second: why x became None ?? x = [1, 2, 4, 2, 1, 3] x = list(set(x)).sort() print(x) # output: None I know that sort() returns None, but I guess that it would be returned x that was sorted. Why so? -------------- next part -------------- An HTML attachment was scrubbed... URL: From fabien.maussion at gmail.com Mon Aug 17 10:12:39 2015 From: fabien.maussion at gmail.com (Fabien) Date: Mon, 17 Aug 2015 16:12:39 +0200 Subject: Python 3 sort() problem References: Message-ID: On 08/17/2015 01:42 PM, ????????? wrote: > x = [1, 2, 4, 2, 1, 3] > x = list(set(x)).sort() > print(x) /# output: None/ > > I know that sort() returns None, but I guess that it would be returned x > that was sorted. Why so? If sort() returns None, than the following: x = list(set(x)).sort() is equivalent to writing: x = None So I don't really understand your question, I'm sorry... Cheers, Fabien From liik.joonas at gmail.com Mon Aug 17 10:14:50 2015 From: liik.joonas at gmail.com (Joonas Liik) Date: Mon, 17 Aug 2015 17:14:50 +0300 Subject: Python 3 sort() problem In-Reply-To: <006601d0d8e1$c17c1480$44743d80$@inbox.ru> References: <006601d0d8e1$c17c1480$44743d80$@inbox.ru> Message-ID: > > I know that sort() returns None, but I guess that it would be returned x > that was sorted. Why so? if it returned a sorted list it might lead some people to believe it did not modify the oridinal list which would lead to a ton of confusion for new users. From breamoreboy at yahoo.co.uk Mon Aug 17 10:18:45 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 17 Aug 2015 15:18:45 +0100 Subject: Python 3 sort() problem In-Reply-To: <006601d0d8e1$c17c1480$44743d80$@inbox.ru> References: <006601d0d8e1$c17c1480$44743d80$@inbox.ru> Message-ID: On 17/08/2015 12:42, ????????? wrote: > # first: works fine > > x = [1, 2, 4, 2, 1, 3] > x = list(set(x)) > x.sort() > print(x) /# output: 1, 2, 3, 4 > > /# second: why x became None ?? > > x = [1, 2, 4, 2, 1, 3] > x = list(set(x)).sort() > print(x) /# output: None/ > > I know that sort() returns None, but I guess that it would be returned x > that was sorted. Why so?/ A set is created from x. This is converted to a list. You call sort() and assign the return value from that, None, to x. You will see exactly the same thing above if you do:- x = x.sort() -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rustompmody at gmail.com Mon Aug 17 10:28:15 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 17 Aug 2015 07:28:15 -0700 (PDT) Subject: Python 3 sort() problem In-Reply-To: References: Message-ID: On Monday, August 17, 2015 at 7:32:08 PM UTC+5:30, ????????? wrote: > # first: works fine > x = [1, 2, 4, 2, 1, 3] > x = list(set(x)) > x.sort() > print(x)? # output: 1, 2, 3, 4 > > # second: why x became None ?? > x = [1, 2, 4, 2, 1, 3] > x = list(set(x)).sort() > print(x)? # output: None > I know that sort() returns None, but I guess that it would be returned x that was sorted. Why so? > > > ? Maybe you want sorted? >>> x = [4,2,1,3] >>> sorted(x) [1, 2, 3, 4] [The list(set(..)) is probably for removing duplicates. Right? Which you seem to have worked out it seems? So best when asking questions to focus on one issue at a time] From ptmcg at austin.rr.com Mon Aug 17 12:02:16 2015 From: ptmcg at austin.rr.com (Paul McGuire) Date: Mon, 17 Aug 2015 09:02:16 -0700 (PDT) Subject: Who is using littletable? Message-ID: <14856fda-14f0-47b1-92f7-63143a677f8f@googlegroups.com> littletable is a little module I knocked together a few years ago, found it sort of useful, so uploaded to SF and PyPI. The download traffic at SF is very light, as I expected, but PyPI shows > 3000 downloads in the past month! Who *are* all these people? In my own continuing self-education, it is interesting to see overlap in the basic goals in littletable, and the much more widely known pandas module (with littletable being more lightweight/freestanding, not requiring numpy, but correspondingly not as snappy). I know Adam Sah uses (or at least used to use) littletable as an in-memory product catalog for his website Buyer's Best friend (http://www.bbfdirect.com/). Who else is out there, and what enticed you to use this little module? -- Paul From lac at openend.se Mon Aug 17 12:24:26 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 17 Aug 2015 18:24:26 +0200 Subject: Who is using littletable? In-Reply-To: Message from Paul McGuire of "Mon, 17 Aug 2015 09:02:16 -0700." <14856fda-14f0-47b1-92f7-63143a677f8f@googlegroups.com> References: <14856fda-14f0-47b1-92f7-63143a677f8f@googlegroups.com> Message-ID: <201508171624.t7HGOQvn011655@fido.openend.se> Some of the PyPI traffic is for mirrors. In addition to our official mirrors, some people/companies set up their own mirrors and suck down everything. Laura From nigamreetesh84 at gmail.com Mon Aug 17 12:35:12 2015 From: nigamreetesh84 at gmail.com (reetesh nigam) Date: Mon, 17 Aug 2015 09:35:12 -0700 (PDT) Subject: Python Mobile development using kivy Message-ID: Hi All, I am using Python2.7 version, while developing basic app using kivy, I am getting following error : dev at synechron-desktop-156:~/myDev/mobile_app$ cat main.py from kivy import app from kivy.app import App from kivy.uix.label import Label class MyApp(App): def build(self): return Label(text='Hello world') if __name__ == '__main__': MyApp().run() dev at synechron-desktop-156:~/myDev/mobile_app$ python main.py [INFO ] [Logger ] Record log in /home/dev/.kivy/logs/kivy_15-08-17_0.txt [INFO ] [Kivy ] v1.9.0 [INFO ] [Python ] v2.7.5 (default, Aug 9 2015, 22:40:01) [GCC 4.4.3] [INFO ] [Factory ] 173 symbols loaded [INFO ] [Image ] Providers: img_tex, img_dds, img_gif, img_pygame (img_pil, img_ffpyplayer ignored) Traceback (most recent call last): File "main.py", line 1, in from kivy import app File "/usr/local/lib/python2.7/site-packages/kivy/app.py", line 324, in from kivy.uix.widget import Widget File "/usr/local/lib/python2.7/site-packages/kivy/uix/widget.py", line 167, in from kivy.graphics.transformation import Matrix File "/usr/local/lib/python2.7/site-packages/kivy/graphics/__init__.py", line 89, in from kivy.graphics.instructions import Callback, Canvas, CanvasBase, \ File "kivy/graphics/vbo.pxd", line 7, in init kivy.graphics.instructions (kivy/graphics/instructions.c:14003) File "kivy/graphics/compiler.pxd", line 1, in init kivy.graphics.vbo (kivy/graphics/vbo.c:5112) File "kivy/graphics/shader.pxd", line 5, in init kivy.graphics.compiler (kivy/graphics/compiler.c:2863) File "kivy/graphics/texture.pxd", line 3, in init kivy.graphics.shader (kivy/graphics/shader.c:10293) File "kivy/graphics/fbo.pxd", line 5, in init kivy.graphics.texture (kivy/graphics/texture.c:29967) File "kivy/graphics/fbo.pyx", line 84, in init kivy.graphics.fbo (kivy/graphics/fbo.c:7065) ImportError: /usr/local/lib/python2.7/site-packages/kivy/graphics/opengl.so: undefined symbol: glBlendEquationSeparate dev at synechron-desktop-156:~/myDev/mobile_app$ More information : I have installed kivy,pygame and cython as well: dev at synechron-desktop-156:~/myDev/mobile_app$ python Python 2.7.5 (default, Aug 9 2015, 22:40:01) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import kivy [INFO ] [Logger ] Record log in /home/dev/.kivy/logs/kivy_15-08-17_1.txt [INFO ] [Kivy ] v1.9.0 [INFO ] [Python ] v2.7.5 (default, Aug 9 2015, 22:40:01) [GCC 4.4.3] >>> import pygame >>> import cython >>> From jcasale at activenetwerx.com Mon Aug 17 12:53:11 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Mon, 17 Aug 2015 16:53:11 +0000 Subject: return types from library api wrappers In-Reply-To: References: Message-ID: <1439830391617.42079@activenetwerx.com> > Current practice is a NamedTuple for python code or the C equivalent. I > forget the C name, but I believe it is used by os.stat Hi Terry, Ok, that is what I will go with. Thanks for the confirmation, jlc From ptmcg at austin.rr.com Mon Aug 17 13:02:48 2015 From: ptmcg at austin.rr.com (Paul McGuire) Date: Mon, 17 Aug 2015 10:02:48 -0700 (PDT) Subject: python command not working In-Reply-To: <566d3f3d-e9f9-4e15-9fbf-19ebb4855269@googlegroups.com> References: <7e209349-aedb-4068-a032-8a8b47ebbb48@37g2000yqp.googlegroups.com> <566d3f3d-e9f9-4e15-9fbf-19ebb4855269@googlegroups.com> Message-ID: <53310243-368b-4819-9e7d-295fa8156eb7@googlegroups.com> On Friday, August 14, 2015 at 6:13:37 AM UTC-5, sam.h... at gmail.com wrote: > On Wednesday, April 22, 2009 at 8:36:21 AM UTC+1, David Cournapeau wrote: > > On Wed, Apr 22, 2009 at 4:20 PM, 83nini <83nini at gmail.com> wrote: > > > Hi guys, > > > > > > I'm new to python, i downloaded version 2.5, opened windows (vista) > > > command line and wrote "python", this should take me to the python > > You can do it easily by adding the Python path (in my case C:\Python27) to your system PATH. > This thread is > 6 years old, OP has probably gone on to other things... From rustompmody at gmail.com Mon Aug 17 13:13:05 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 17 Aug 2015 10:13:05 -0700 (PDT) Subject: "no module named kivy" import error in ubuntu 14.04 In-Reply-To: <7054434a-03fd-46d9-b0a9-850748167376@googlegroups.com> References: <22e8c1bc-72ba-46e1-9402-fbd1bd893a35@googlegroups.com> <7054434a-03fd-46d9-b0a9-850748167376@googlegroups.com> Message-ID: <740eebef-a359-4a8f-9c5c-4d43cb2e75b3@googlegroups.com> On Monday, August 17, 2015 at 10:35:48 AM UTC+5:30, rurpy wrote: > I hope someday Python gets a decent packaging/distribution story. You are in august company | The final question was about what he (Guido) hates in Python. "Anything to do | with package distribution", he answered immediately. There are problems | with version skew and dependencies that just make for an "endless | mess". He dreads it when a colleague comes to him with a "simple Python | question". Half the time it is some kind of import path problem and | there is no easy solution to offer. >From https://mail.python.org/pipermail/python-list/2015-July/694818.html Quoting https://lwn.net/Articles/651967/ From lac at openend.se Mon Aug 17 13:14:26 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 17 Aug 2015 19:14:26 +0200 Subject: Python Mobile development using kivy In-Reply-To: Message from reetesh nigam of "Mon, 17 Aug 2015 09:35:12 -0700." References: Message-ID: <201508171714.t7HHEQh4021336@fido.openend.se> In a message of Mon, 17 Aug 2015 09:35:12 -0700, reetesh nigam writes: >Hi All, > >I am using Python2.7 version, while developing basic app using kivy, I am getting following error : > >dev at synechron-desktop-156:~/myDev/mobile_app$ cat main.py >from kivy import app >from kivy.app import App >from kivy.uix.label import Label >class MyApp(App): > def build(self): > return Label(text='Hello world') >if __name__ == '__main__': > MyApp().run() > >dev at synechron-desktop-156:~/myDev/mobile_app$ python main.py >[INFO ] [Logger ] Record log in /home/dev/.kivy/logs/kivy_15-08-17_0.txt >[INFO ] [Kivy ] v1.9.0 >[INFO ] [Python ] v2.7.5 (default, Aug 9 2015, 22:40:01) >[GCC 4.4.3] >[INFO ] [Factory ] 173 symbols loaded >[INFO ] [Image ] Providers: img_tex, img_dds, img_gif, img_pygame (img_pil, img_ffpyplayer ignored) > Traceback (most recent call last): > File "main.py", line 1, in > from kivy import app > File "/usr/local/lib/python2.7/site-packages/kivy/app.py", line 324, in > from kivy.uix.widget import Widget > File "/usr/local/lib/python2.7/site-packages/kivy/uix/widget.py", line 167, in > from kivy.graphics.transformation import Matrix > File "/usr/local/lib/python2.7/site-packages/kivy/graphics/__init__.py", line 89, in > from kivy.graphics.instructions import Callback, Canvas, CanvasBase, \ > File "kivy/graphics/vbo.pxd", line 7, in init kivy.graphics.instructions (kivy/graphics/instructions.c:14003) > File "kivy/graphics/compiler.pxd", line 1, in init kivy.graphics.vbo (kivy/graphics/vbo.c:5112) > File "kivy/graphics/shader.pxd", line 5, in init kivy.graphics.compiler (kivy/graphics/compiler.c:2863) > File "kivy/graphics/texture.pxd", line 3, in init kivy.graphics.shader (kivy/graphics/shader.c:10293) > File "kivy/graphics/fbo.pxd", line 5, in init kivy.graphics.texture (kivy/graphics/texture.c:29967) > File "kivy/graphics/fbo.pyx", line 84, in init kivy.graphics.fbo (kivy/graphics/fbo.c:7065) > ImportError: /usr/local/lib/python2.7/site-packages/kivy/graphics/opengl.so: undefined symbol: glBlendEquationSeparate >dev at synechron-desktop-156:~/myDev/mobile_app$ If you get undefined opengl errors, it is usually caused by an old version of opengl, and the error you got is common. This is a puzzling error that most often happens when compiling under i386 for the old libGL. Given that the symbol is present in libGL and that compilation works under amd64, this shouldn't be happening. But for some reason it does. If a newer version of opengl.so doesn't fix your problem, post a bug report here: https://github.com/kivy/kivy/issues or discuss it on #kivy on freenode Laura From tjreedy at udel.edu Mon Aug 17 14:39:04 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 17 Aug 2015 14:39:04 -0400 Subject: Error in IDLE In-Reply-To: References: Message-ID: On 8/15/2015 11:42 AM, Henry Quansah wrote: > I just installed python. But I'm unable to access IDLE after several > clicks and double clicks. I even tried repairing by trying to reinstall > but I have the same issue. If you just installed 3.5.0rc1 on Windows, look for my fix message on or about the 14th. -- Terry Jan Reedy From yanzhipingliu at gmail.com Mon Aug 17 14:40:32 2015 From: yanzhipingliu at gmail.com (Ping Liu) Date: Mon, 17 Aug 2015 11:40:32 -0700 (PDT) Subject: memory control in Python In-Reply-To: References: <87io8hc8z3.fsf@handshake.de> Message-ID: On Saturday, August 15, 2015 at 11:56:22 AM UTC-7, Laura Creighton wrote: > If the problem is that Python is using too much memory, then PyPy may > be able to help you. PyPy is an alternative implementation of Python, > and by defaiult uses a minimark garbage collector. > https://pypy.readthedocs.org/en/release-2.4.x/garbage_collection.html > > You will have to write your own bindings for the CPLEX C library, though, > using cffi. http://cffi.readthedocs.org/en/latest/overview.html (since > the bindings you have assume the CPython ref counting gc). > > But if your C program is itself using too much memory, then this probably > won't help. > > Discuss this more on pypy-dev at python.org or the #pypy channel on freenode. > People on pypy-dev would appreciate not getting libreoffice spreadsheet > attachments but just the figures as plain text. > > Laura Hi, Laura, Thank you for the advice. I see that some people also mention that PyPy may save some speed and memory than CPython. But since I am working on an optimization problem, I wonder whether PyPy would support NumPy and Scipy. In which progress have this integration been done? From lac at openend.se Mon Aug 17 14:52:52 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 17 Aug 2015 20:52:52 +0200 Subject: memory control in Python In-Reply-To: Message from Ping Liu of "Mon, 17 Aug 2015 11:40:32 -0700." References: <87io8hc8z3.fsf@handshake.de> Message-ID: <201508171852.t7HIqqi5008620@fido.openend.se> In a message of Mon, 17 Aug 2015 11:40:32 -0700, Ping Liu writes: >> Discuss this more on pypy-dev at python.org or the #pypy channel on freenode. >> People on pypy-dev would appreciate not getting libreoffice spreadsheet >> attachments but just the figures as plain text. >> >> Laura > >Hi, Laura, >Thank you for the advice. I see that some people also mention that PyPy may save some speed and memory than CPython. But since I am working on an optimization problem, I wonder whether PyPy would support NumPy and Scipy. In which progress have this integration been done? >-- >https://mail.python.org/mailman/listinfo/python-list Significant progress has been made to support NumPy. SciPy, no. Ask on pypy-dev and/or freenode to find out if the NumPy features you need are done yet. Laura From alexglaros at gmail.com Mon Aug 17 16:37:33 2015 From: alexglaros at gmail.com (Alex Glaros) Date: Mon, 17 Aug 2015 13:37:33 -0700 (PDT) Subject: How to model government organization hierarchies so that the list can expand and compress In-Reply-To: References: Message-ID: <3bb9ce18-ebaf-4c19-870c-579c691f6ab9@googlegroups.com> Perhaps most jointly parented governmental organizations are functionally, collaborative "projects" (not organizations) which my model handles. But thanks to Laura, will not assume there are none, or will never be any in the future, so will use adjacent list (see fast response times documented in explainedextended.com article below), but created new 1:M table to handle multiple parents. ORGANIZATION ----------------------------- 1. organization_Id (PK) 2. organization_name ORGANIZATION_HIERARCHY (1:M) ------------------------------ 1. organization_Id (FK to above table) - can have multiple parents 2. adjacent_parent_id (FK to above table) Thanks to all for the assistance. Led me to some great articles including http://explainextended.com/2009/09/24/adjacency-list-vs-nested-sets-postgresql/ Alex From martin.schoon at gmail.com Mon Aug 17 17:14:20 2015 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 17 Aug 2015 21:14:20 GMT Subject: How to rearrange array using Python? References: <1468455.P0rGZF1LBf@PointedEars.de> Message-ID: Den 2015-07-31 skrev Martin Sch??n : > Den 2015-07-31 skrev Thomas 'PointedEars' Lahn : >> Mark Lawrence wrote: >>> >>> I'm not absolutely certain but I think you're into what's known as a >>> constraint satisfaction problem, in which case this >>> https://pypi.python.org/pypi/python-constraint/1.2 is as good a starting >>> point as any. If I'm wrong we'll soon get told :) >> >> It is a CSP indeed, and as I was reading the OP I was thinking of SWI- >> > Thanks guys, I will follow up on the CSP lead. It is not something I > have prior experience of so it will be interesting. > Brief progress report (just to tell you that your advice has been 'absorbed'). I have been reading a bit, here is one example. http://kti.ms.mff.cuni.cz/~bartak/constraints/index.html Interesting stuff but sometimes head-spinning -- I don't always follow the lingo. I have also downloaded and installed Python-Constraint. It works as advertised as long as I replicate the examples found at: http://labix.org/python-constraint I can even scale some of the examples. Creating my own examples has proven harder -- in part because the documentation is minimalistic but also because I have not tried very hard. We have, finally, got some nice summer weather here... I have tried my hand at a *very* basic room placement problem. It works apart from the fact that I have not figured out how to tell the solver there are limits to how many occupants each room can house. Yesterday I started on a basic Kenken example. I need to experiment a little to find a way to add the needed division and subtraction constraints. I haven't given this much thought yet. Today I found Numberjack: http://numberjack.ucc.ie/ It seems better documented than Python-Constraint but that is all I know. Anyone with experience of Numberjack? In summary: I am having fun using ipython and org-mode for emacs. I am not making much headway but then I don't have a dead-line :-) /Martin From yanzhipingliu at gmail.com Mon Aug 17 18:09:47 2015 From: yanzhipingliu at gmail.com (Ping Liu) Date: Mon, 17 Aug 2015 15:09:47 -0700 (PDT) Subject: memory control in Python In-Reply-To: References: Message-ID: <685b4197-973b-432b-83fd-099f3bfc5239@googlegroups.com> Hi, Dieter, If I move from Python to Jython or IronPython, do I need to retool whatever I have done? If so, that may take quite a long time. This may make the reimplementation impossible. From alex.flint at gmail.com Mon Aug 17 18:23:53 2015 From: alex.flint at gmail.com (alex.flint at gmail.com) Date: Mon, 17 Aug 2015 15:23:53 -0700 (PDT) Subject: why does id(multiprocessing.Process.start) == id(multiprocessing.Process.start)? Message-ID: using Python 2.7.9, I get the following: >>> id(multiprocessing.Process.start) == id(multiprocessing.Process.start) True But on the other hand: >>> multiprocessing.Process.start is multiprocessing.Process.start False I thought that these two expressions were equivalent. Can somebody help me to understand what's going on here? From alex.flint at gmail.com Mon Aug 17 18:25:39 2015 From: alex.flint at gmail.com (alex.flint at gmail.com) Date: Mon, 17 Aug 2015 15:25:39 -0700 (PDT) Subject: why does id(multiprocessing.Process.start) == id(multiprocessing.Process.start)? In-Reply-To: References: Message-ID: On Monday, August 17, 2015 at 3:24:22 PM UTC-7, alex.... at gmail.com wrote: > using Python 2.7.9, I get the following: > > >>> id(multiprocessing.Process.start) == id(multiprocessing.Process.start) > True > > But on the other hand: > > >>> multiprocessing.Process.start is multiprocessing.Process.start > False > > I thought that these two expressions were equivalent. Can somebody help me to understand what's going on here? Sorry I completely mistype that. It was supposed to read: >>> id(multiprocessing.Process.is_alive) == id(multiprocessing.Process.start) True >>> multiprocessing.Process.is_alive is multiprocessing.Process.start False From srkunze at mail.de Mon Aug 17 18:26:33 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Tue, 18 Aug 2015 00:26:33 +0200 Subject: Python Import Hooks and __main__ Message-ID: <55D25F99.4050002@mail.de> Hi, following up on this thread on StackOverflow http://stackoverflow.com/questions/16515347/python-import-hooks-and-main does somebody has a great idea how to manage this? The issue at hand is, that I would like to apply a specific import hook right from the beginning of the interpreter run (here, a simple test case), i.e. also affecting the import/exec of the module __main__. Hook: https://github.com/srkunze/fork/blob/2e7ecd4b0a/fork.py#L429 Dirty Magic to get things running: https://github.com/srkunze/fork/blob/2e7ecd4b0a/fork.py#L425 Best, Sven From ckaynor at zindagigames.com Mon Aug 17 18:57:22 2015 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 17 Aug 2015 15:57:22 -0700 Subject: why does id(multiprocessing.Process.start) == id(multiprocessing.Process.start)? In-Reply-To: References: Message-ID: On Mon, Aug 17, 2015 at 3:25 PM, wrote: > > Sorry I completely mistype that. It was supposed to read: > > >>> id(multiprocessing.Process.is_alive) == > id(multiprocessing.Process.start) > True > What is going on here is that it get multiprocessing.Process.is_alive, computes the id of it, then throws away the value of multiprocessing.Process.is_alive. It then does the same thing for multiprocessing.Process.start, where by it happens to reuse the id of the first value. > >>> multiprocessing.Process.is_alive is multiprocessing.Process.start > False > In this case, the "is" operator keeps both references around during its call, and therefore they will get different ids. The rules for the id is that they are only guaranteed unique during the lifespan of both objects. Also, generally, you do not want to use id or is for much of anything unless you really know what you are doing - generally, you just want == instead. > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Aug 17 19:11:43 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 17 Aug 2015 17:11:43 -0600 Subject: why does id(multiprocessing.Process.start) == id(multiprocessing.Process.start)? In-Reply-To: References: Message-ID: On Mon, Aug 17, 2015 at 4:57 PM, Chris Kaynor wrote: > The rules for the id is that they are only guaranteed unique during the > lifespan of both objects. Also, generally, you do not want to use id or is > for much of anything unless you really know what you are doing - generally, > you just want == instead. In the case of "is", I don't agree. "is" is a useful operator and is not prone to user error like "id". The only caveat is that one should understand the distinction between "is" and "==". From rurpy at yahoo.com Mon Aug 17 19:35:44 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Mon, 17 Aug 2015 16:35:44 -0700 (PDT) Subject: "no module named kivy" import error in ubuntu 14.04 In-Reply-To: References: <22e8c1bc-72ba-46e1-9402-fbd1bd893a35@googlegroups.com> <7054434a-03fd-46d9-b0a9-850748167376@googlegroups.com> Message-ID: On 08/17/2015 01:52 AM, Laura Creighton wrote: > In a message of Sun, 16 Aug 2015 22:05:29 -0700, rurpy--- via Python-list writes: >> So I eventually found the kivy docs on their website where they >> list prerequisite packages for installing kivy on ubuntu. I'll >> translate those to hopefully the equivalent fedora package names, >> install them, reinstall kivy, and get a working kivy install. Actually, right after I posted, I saw a Fedora-specific list of packages on the kivy website. However, after I installed them and reinstalled kivy I still got the same set of missing package warning that I got before. And hoping that the packages just enabled optional features I tried running the simple "hello-world" program from their website. It died horribly: | [CRITICAL] [Window ] Unable to find any valuable Window provider at all! | egl_rpi - ImportError: cannot import name 'bcm' | File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in core_select_lib and | x11 - ImportError: No module named 'kivy.core.window.window_x11' | File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in core_select_lib | fromlist=[modulename], level=0) | [CRITICAL] [App ] Unable to get a Window, abort. >> The point here that all the above is a LONG way from what was >> was posted here: "just type 'pip install kivy' and pip will take >> care of everything". >> >> I hope someday Python gets a decent packaging/distribution story. > > Can you post what one should do with modern Fedora distributions, so > we can tell the kivy-devs and they can update that webpage? Unfortunately I have no idea what one should do. The standard response in this group is that pip knows, hence I don't need to. I just wanted to point out the fallacy of that. From rosuav at gmail.com Mon Aug 17 20:13:57 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Aug 2015 10:13:57 +1000 Subject: memory control in Python In-Reply-To: <685b4197-973b-432b-83fd-099f3bfc5239@googlegroups.com> References: <685b4197-973b-432b-83fd-099f3bfc5239@googlegroups.com> Message-ID: On Tue, Aug 18, 2015 at 8:09 AM, Ping Liu wrote: > If I move from Python to Jython or IronPython, do I need to retool whatever I have done? If so, that may take quite a long time. This may make the reimplementation impossible. You're not moving from Python to something else; you're moving from CPython to something else. It's like moving from Borland's C compiler to Watcom's C compiler - all your code should still run unchanged. There will be differences, but the bulk of your code shouldn't need changing. With Python interpreters, the usual difference is extension libraries - CPython can call on a bunch of things implemented in native code, Jython can call on a bunch of things implemented in Java, etc. ChrisA From harirammanohar159 at gmail.com Mon Aug 17 22:57:03 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Mon, 17 Aug 2015 19:57:03 -0700 (PDT) Subject: execute commands as su on remote server Message-ID: execute commands as su on remote server Postby hariram ? Mon Aug 17, 2015 4:02 am Needed: I need to execute commands after doing su to other user on remote server(not sudo which doesn't require password) how i can achieve this using python? I googled and came to know that its not possible, so just for confirmation asking again, is it possible ? Already Tried: Tried paramiko that's too not working. From rosuav at gmail.com Mon Aug 17 23:06:45 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Aug 2015 13:06:45 +1000 Subject: execute commands as su on remote server In-Reply-To: References: Message-ID: On Tue, Aug 18, 2015 at 12:57 PM, wrote: > I need to execute commands after doing su to other user on remote server(not sudo which doesn't require password) how i can achieve this using python? > I googled and came to know that its not possible, so just for confirmation asking again, is it possible ? Ultimately, this isn't a Python question, it's a systems administration one. You want a way to execute commands as a specific user, triggering them remotely. There are basically two ways you can do this: either you provide some form of credentials (this is what sudo does), or you elevate the entire management process. The latter option is far FAR easier (running it as root if you might need to go to any different user, or as that specific user if you'll only ever use one), but then you have to ensure, in some way, that your Python program can't be compromised. Python has nothing to do with any of this. If you want to manage elevation using sudo, Python can invoke sudo in a subprocess. If you want to elevate the Python process and then simply invoke something directly, Python won't even be aware of it. ChrisA From random832 at fastmail.us Tue Aug 18 00:11:59 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Tue, 18 Aug 2015 00:11:59 -0400 Subject: why does id(multiprocessing.Process.start) == id(multiprocessing.Process.start)? In-Reply-To: References: Message-ID: <1439871119.3380794.358894137.6E14CA79@webmail.messagingengine.com> On Mon, Aug 17, 2015, at 18:25, alex.flint at gmail.com wrote: > Sorry I completely mistype that. It was supposed to read: > > >>> id(multiprocessing.Process.is_alive) == id(multiprocessing.Process.start) > True > > >>> multiprocessing.Process.is_alive is multiprocessing.Process.start > False Try this: is_alive = multiprocessing.Process.is_alive start = multiprocessing.Process.start id(is_alive) == id(start) If (as I believe it will) this ends up being false, this shows that it's an issue of object lifespan with the values of the expression being temporary method wrappers. From some testing, on my machine on CPython 2.7 this appears to work for any method of any class written in python. While you fixed the typo, it is instructive to note that, as in your original example, multiprocessing.Process.start is multiprocessing.Process.start is *also* False, which would not be the case if the method wrapper were a permanent object. From dieter at handshake.de Tue Aug 18 02:02:02 2015 From: dieter at handshake.de (dieter) Date: Tue, 18 Aug 2015 08:02:02 +0200 Subject: memory control in Python References: <685b4197-973b-432b-83fd-099f3bfc5239@googlegroups.com> Message-ID: <878u99qgmd.fsf@handshake.de> Ping Liu writes: > If I move from Python to Jython or IronPython, do I need to retool whatever I have done? If so, that may take quite a long time. This may make the reimplementation impossible. As Chris already pointed out, you are still using Python -- i.e. the base language does not change. However, extension packages, such as "NumPy", might not be supported. If you are using extension packages, carefully check whether they are supported for a different Python implementation before you decide a switch. From lac at openend.se Tue Aug 18 02:16:21 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 18 Aug 2015 08:16:21 +0200 Subject: memory control in Python In-Reply-To: Message from Chris Angelico of "Tue, 18 Aug 2015 10:13:57 +1000." References: <685b4197-973b-432b-83fd-099f3bfc5239@googlegroups.com> Message-ID: <201508180616.t7I6GLuL013212@fido.openend.se> In a message of Tue, 18 Aug 2015 10:13:57 +1000, Chris Angelico writes: >On Tue, Aug 18, 2015 at 8:09 AM, Ping Liu wrote: >> If I move from Python to Jython or IronPython, do I need to retool whatever I have done? If so, that may take quite a long time. This may make the reimplementation impossible. > >You're not moving from Python to something else; you're moving from >CPython to something else. It's like moving from Borland's C compiler >to Watcom's C compiler - all your code should still run unchanged. >There will be differences, but the bulk of your code shouldn't need >changing. With Python interpreters, the usual difference is extension >libraries - CPython can call on a bunch of things implemented in >native code, Jython can call on a bunch of things implemented in Java, >etc. > >ChrisA Unless, as I expect, what he has done uses Numpy and or SciPy a lot. Enthought is no longer supporting NumPy for IronPython (and it never worked all that well, anyway, I am told ... but I never used it myself). Even the maintainer of Jnumeric (which is trying to do Numeric not NumPy) thinks the Jnumeric project should die. http://stackoverflow.com/questions/18832169/numpy-analog-for-jython We already know that Ping has a really big C extension he needs to work with -- CPLEX, and well, here he may be in luck as there are java versions of CPLEX and there is something called the CPLEX/Concert .NET API which may -- I never tried this -- let him work with Iron Python. But that is one lirary. If he has many more C extensions he needs to use, then this could mean retooling them. Laura From rustompmody at gmail.com Tue Aug 18 04:56:16 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 18 Aug 2015 01:56:16 -0700 (PDT) Subject: memory control in Python In-Reply-To: <685b4197-973b-432b-83fd-099f3bfc5239@googlegroups.com> References: <685b4197-973b-432b-83fd-099f3bfc5239@googlegroups.com> Message-ID: On Tuesday, August 18, 2015 at 3:40:11 AM UTC+5:30, Ping Liu wrote: > Hi, Dieter, > > If I move from Python to Jython or IronPython, do I need to retool whatever I have done? If so, that may take quite a long time. This may make the reimplementation impossible. Hi Ping There is a message from Laura Creighton that may be useful to you that googlegroups shows in the thread: "python implementation of a new integer encoding algorithm." Thought I'd mention in case you are not seeing other threads. [How she (her mail client) manages to befuddle googlegroups thusly is quite a mystery... ] From lac at openend.se Tue Aug 18 05:13:12 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 18 Aug 2015 11:13:12 +0200 Subject: memory control in Python In-Reply-To: Message from Rustom Mody of "Tue, 18 Aug 2015 01:56:16 -0700." References: <685b4197-973b-432b-83fd-099f3bfc5239@googlegroups.com> Message-ID: <201508180913.t7I9DCUg015413@fido.openend.se> In a message of Tue, 18 Aug 2015 01:56:16 -0700, Rustom Mody writes: >[How she (her mail client) manages to befuddle googlegroups thusly is >quite a mystery... >] For me as well, as all I am doing is just replying to the mail ... And I haven't changed my mail client at all in years and years ... Laura From oscar.j.benjamin at gmail.com Tue Aug 18 07:21:52 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 18 Aug 2015 12:21:52 +0100 Subject: memory control in Python In-Reply-To: References: Message-ID: On 15 August 2015 at 00:41, Ping Liu wrote: > Dear All, Hi Ping Liu, > I am working on an optimization problem, where we are trying to minimize > some indicators like energy usage, energy cost, CO2 emission. In this > problem, we have a bunch of energy conversion technologies for electricity > and thermal purpose, such as heat pump, boiler, chiller, etc.. We are trying > to model it with a one year time period. the current time step is one hour. I guess this means that you are running a simulation over a period of 1 year. If the timestep is one hour then the number of timesteps is 24*365 = 8760. > We have preselected the candidate technologies to exclude those we don't > want to study so that the problem size could be reduced with a limited > candidate technologies. In the current case study, we only analyze the > electric chiller and heat pump to supply the cooling load, while power grid > will supply the electricity for all electric loads. There are binary > variables regarding installation decisions of technologies and continuous > variables related to installation capacity and hourly operational decisions. How many binary variables do you have? I ask because it may be preferable to consider each case of the binary variables separately. Suppose that there are 5 binary variables. Then that makes 2**5 = 32 possible cases. It might be simpler to solve the continuous optimisation problem for each of the 32 cases separately. On the other hand if you have 20 binary variables then you'll have 1e6 cases to consider in which case it is less likely to be feasible to consider each one. > For small cases, Python works well. But if we consider longer time period. > then it would fail due to the memory usage issues. We have tested several > case studies to check the memory use for different time period, including 1) > 2 hours in one day, 2) 24 hours in one day, 3) 20 days with 24 hours each > day, as well as 4) 30 days with 24 hours each day. The first 3 cases are > feasible while the last case gives out the memory error. If I understand correctly what you mean is that you are attempting different length simulations. In the first case you have 2 timesteps meaning a simulation of 2 hours, then 24, then 480, and then 720. Your target is to get to 8760 timesteps. Is that correct? > When we are testing the forth case, the memory error comes out while > creating the inequality constraints. The problem size is 1) Aeq: 12 * 26, > Aineq: 30 * 26; 2) Aeq: 144*268, Aineq:316*268; 3) Aeq: 2880*5284, Aineq: > 6244*5284; 4) Aeq: 4320 * 7924, Aineq is unknown due to the memory error. I assume that this refers to the constraints that you pass to the solver which varies depending on the number of timesteps in your simulation: Aeq refers to the number of equality constraints and Aineq to the number of inequality constraints? The number of constraints is (timesteps, equality, inequality): 2 12*26 30*26 24 144*268 316*268 480 2880*5284 6244*5284 720 4320*7924 unknown So the pattern for N timesteps seems to be: N (6*N)*(11*N+4) (13*N+4)*(11*N+4) So I guess the number of inequality constraints in the case of memory error is 9364*7924. Essentially what this shows is that your problem is complexity is N**2 where N is the number of timesteps. Even if you can get the memory to go up to 720 timesteps you still need 10 times more steps to get to your target of 8760. Since the problem is growing quadratically you'll need to have 100 times more computer memory again to reach your target. Your problem scales very badly and is probably badly posed. Is it really necessary to impose so many constraints or can the problem be formulated in a way that uses fewer? > The solver is CPLEX (academic). It turns out that the solver is taking a lot > of memory as you can see in the memory test report. for the first three > cases, different memory usage is observed, and it grows up dramatically with > the increase of the time period. 1) solver memory usage: 25.6 MB, 2) 19.5 > MB; 3) solver memory usage: 830.0742 MB. This is unsurprising since the size of your problem grows quadratically. In the 720 timestep case you are trying to optimise with 100 million constraints. For your target of 1 year the number of constraints would be 16 billion. The amount of memory required to store these constraints is proportional to the number of constraints but the time taken to optimise with the constraints will probably grow even faster so even if you had the memory you're unlikely to have the CPU power to solve this. > Based on my observations, I have some of the following questions regarding > 1) In order to create the optimization problem (Aeq, Aineq), how can we > reduce the memory usage in python programming? 2) how can I reduce the > memory usage of different solvers in Python? Why would the memory decrease > for the CPLEX solver within the 24-hours-in-one-day case compared with the > case 1? Others have already pointed out that your problem is not really about Python at all. There's no point in trying to use PyPy, IronPython etc. It also doesn't matter if you ditch Python and use C or Matlab or some other language. As long as you're using the same basic algorithm and approach I don't think you will be able to reach your target of 1 year. I think that you need to approach this whole problem in a different way. Either reformulate it so that there are fewer constraints or choose a different algorithm. Does the CPLEX library only have one solver routine (you may be able to simply select a different algorithm)? Perhaps it's just not necessary to use CPLEX and you can use a different optimisation software or even a completely different way to pose the problem so that it's not even an optimisation problem at all. -- Oscar From steve at pearwood.info Tue Aug 18 08:25:52 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 18 Aug 2015 22:25:52 +1000 Subject: Dave Angel RIP Message-ID: <55d3244f$0$1651$c3e8da3$5496439d@news.astraweb.com> Folks, Many of us will remember the long-time list regular Dave Angel. Dave was active on this list for many years, a keen participant in many discussions, and very helpful to Python users of all levels of expertise. Unfortunately, I am saddened to say that Dave passed away on May 25th, and the far too young an age of 66. He will be missed. http://www.monaghanfunerals.com/obits/obituary.php?id=552157 Thanks to Alan Gould on the tutor mailing list for passing this information on. -- Steven From thinmanj at gmail.com Tue Aug 18 08:41:10 2015 From: thinmanj at gmail.com (=?UTF-8?Q?Julio_O=C3=B1a?=) Date: Tue, 18 Aug 2015 12:41:10 +0000 Subject: execute commands as su on remote server In-Reply-To: References: Message-ID: Hi, try to use http://www.fabfile.org/ look at: http://docs.fabfile.org/en/latest/api/core/operations.html sudo() call has the posibility to change to another user besides root, with: with settings(sudo_user='mysql'): sudo("whoami") # prints 'mysql' El lun., 17 de ago. de 2015 a la(s) 11:07 p. m., Chris Angelico < rosuav at gmail.com> escribi?: > On Tue, Aug 18, 2015 at 12:57 PM, wrote: > > I need to execute commands after doing su to other user on remote > server(not sudo which doesn't require password) how i can achieve this > using python? > > I googled and came to know that its not possible, so just for > confirmation asking again, is it possible ? > > Ultimately, this isn't a Python question, it's a systems > administration one. You want a way to execute commands as a specific > user, triggering them remotely. There are basically two ways you can > do this: either you provide some form of credentials (this is what > sudo does), or you elevate the entire management process. The latter > option is far FAR easier (running it as root if you might need to go > to any different user, or as that specific user if you'll only ever > use one), but then you have to ensure, in some way, that your Python > program can't be compromised. > > Python has nothing to do with any of this. If you want to manage > elevation using sudo, Python can invoke sudo in a subprocess. If you > want to elevate the Python process and then simply invoke something > directly, Python won't even be aware of it. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Aug 18 08:58:57 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Aug 2015 22:58:57 +1000 Subject: Dave Angel RIP In-Reply-To: <55d3244f$0$1651$c3e8da3$5496439d@news.astraweb.com> References: <55d3244f$0$1651$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 18, 2015 at 10:25 PM, Steven D'Aprano wrote: > Many of us will remember the long-time list regular Dave Angel. Dave was > active on this list for many years, a keen participant in many discussions, > and very helpful to Python users of all levels of expertise. Aww :( He was notable to me personally for having a similar surname and similar signature style to mine, which we'd both been using for years before ever coming across each other. Vale DaveA. ChrisA From alpfalzgraf at hotmail.com Tue Aug 18 09:07:51 2015 From: alpfalzgraf at hotmail.com (Al Pfalzgraf) Date: Tue, 18 Aug 2015 08:07:51 -0500 Subject: Logging to a file from a C-extension Message-ID: If a logging file is opened at the level of a Python application, how would the log file name be communicated to a C-extension so that logging from the extension would be sent to the same log file? -------------- next part -------------- An HTML attachment was scrubbed... URL: From nonami.ayo at gmail.com Tue Aug 18 09:13:49 2015 From: nonami.ayo at gmail.com (Nonami Animashaun) Date: Tue, 18 Aug 2015 13:13:49 +0000 Subject: Dave Angel RIP In-Reply-To: <55d3244f$0$1651$c3e8da3$5496439d@news.astraweb.com> References: <55d3244f$0$1651$c3e8da3$5496439d@news.astraweb.com> Message-ID: Folks, Many of us will remember the long-time list regular Dave Angel. Dave was active on this list for many years, a keen participant in many discussions, and very helpful to Python users of all levels of expertise. Unfortunately, I am saddened to say that Dave passed away on May 25th, and the far too young an age of 66. He will be missed. He will be dearly missed. His contributions have been very helpful and will be even more valued now that they are all we have left to remind us of him here on the list. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Tue Aug 18 10:25:54 2015 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 18 Aug 2015 10:25:54 -0400 Subject: regex recursive matching (regex 2015.07.19) Message-ID: Trying regex 2015.07.19 I'd like to match recursive parenthesized expressions, with groups such that '(a(b)c)' would give group(0) -> '(a(b)c)' group(1) -> '(b)' but that's not what I get import regex #r = r'\((?>[^()]|(?R))*\)' r = r'\(([^()]|(?R))*\)' #r = r'\((?:[^()]|(?R))*\)' m = regex.match (r, '(a(b)c)') m.groups() Out[28]: ('c',) From tjreedy at udel.edu Tue Aug 18 11:27:43 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 18 Aug 2015 11:27:43 -0400 Subject: regex recursive matching (regex 2015.07.19) In-Reply-To: References: Message-ID: On 8/18/2015 10:25 AM, Neal Becker wrote: > Trying regex 2015.07.19 > > I'd like to match recursive parenthesized expressions, with groups such that > '(a(b)c)' Extended regular expressions can only match strings in extended regular languages. General nested expressions are too general for that. You need a context-free parser. You can find them on pypi or write your own, which in this case is quite simple. --- from xploro.test import ftest # my personal function test function io_pairs = (('abc', []), ('(a)', [(0, '(a)')]), ('a(b)c', [(1, '(b)')]), ('(a(b)c)', [(0, '(a(b)c)'), (2, '(b)')]), ('a(b(cd(e))(f))g', [(1, '(b(cd(e))(f))'), (3, '(cd(e))'), (6, '(e)'), (10, '(f)')]),) def parens(text): '''Return sorted list of paren tuples for text. Paren tuple is start index (for sorting) and substring. ''' opens = [] parens = set() for i, char in enumerate(text): if char == '(': opens.append(i) elif char == ')': start = opens.pop() parens.add((start, text[start:(i+1)])) return sorted(parens) ftest(parens, io_pairs) --- all pass > would give > group(0) -> '(a(b)c)' > group(1) -> '(b)' > > but that's not what I get > > import regex > > #r = r'\((?>[^()]|(?R))*\)' > r = r'\(([^()]|(?R))*\)' > #r = r'\((?:[^()]|(?R))*\)' > m = regex.match (r, '(a(b)c)') > > m.groups() > Out[28]: ('c',) > -- Terry Jan Reedy From python at mrabarnett.plus.com Tue Aug 18 12:36:18 2015 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 18 Aug 2015 17:36:18 +0100 Subject: regex recursive matching (regex 2015.07.19) In-Reply-To: References: Message-ID: <55D35F02.1070203@mrabarnett.plus.com> On 2015-08-18 15:25, Neal Becker wrote: > Trying regex 2015.07.19 > > I'd like to match recursive parenthesized expressions, with groups such that > '(a(b)c)' > > would give > group(0) -> '(a(b)c)' > group(1) -> '(b)' > > but that's not what I get > > import regex > > #r = r'\((?>[^()]|(?R))*\)' > r = r'\(([^()]|(?R))*\)' > #r = r'\((?:[^()]|(?R))*\)' > m = regex.match (r, '(a(b)c)') > > m.groups() > Out[28]: ('c',) > You can't capture them into different groups in the general case; it won't create capture groups dynamically. Capture into 1 group and then use the .captures method: import regex r = r'(\([^()]*(?:(?R)[^()]*)*\))' m = regex.match(r, '(a(b)c)') print(m.captures(1)) From python at hope.cz Tue Aug 18 15:34:52 2015 From: python at hope.cz (Johny) Date: Tue, 18 Aug 2015 12:34:52 -0700 (PDT) Subject: I2C protocol Message-ID: <621d83c6-61ed-4bae-9d96-efece244fbec@googlegroups.com> Is there any library for I2C protocol so that I can control a device connected to Windows? From breamoreboy at yahoo.co.uk Tue Aug 18 16:19:36 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 18 Aug 2015 21:19:36 +0100 Subject: I2C protocol In-Reply-To: <621d83c6-61ed-4bae-9d96-efece244fbec@googlegroups.com> References: <621d83c6-61ed-4bae-9d96-efece244fbec@googlegroups.com> Message-ID: On 18/08/2015 20:34, Johny wrote: > Is there any library for I2C protocol so that I can control a device connected to Windows? Go to https://pypi.python.org/pypi, put i2c in the search box and take your pick. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From laurent.pointal at free.fr Tue Aug 18 17:42:33 2015 From: laurent.pointal at free.fr (Laurent Pointal) Date: Tue, 18 Aug 2015 23:42:33 +0200 Subject: Regular expression and substitution, unexpected duplication Message-ID: <55d3a6c9$0$3335$426a74cc@news.free.fr> Hello, I want to make a replacement in a string, to ensure that ellipsis are surrounded by spaces (this is not a typographycal problem, but a preparation for late text chunking). I tried with regular expressions and the SRE_Pattern.sub() method, but I have an unexpected duplication of the replacement pattern: The code: ellipfind_re = re.compile(r"((?=\.\.\.)|?)", re.IGNORECASE|re.VERBOSE) ellipfind_re.sub(' ... ', "C'est un essai... avec diff?rents caract?res? pour voir.") And I retrieve: "C'est un essai ... ... avec diff?rents caract?res ... pour voir." ^^^ I tested with/without group capture, same result. My Python version: Python 3.4.3 (default, Mar 26 2015, 22:03:40) [GCC 4.9.2] on linux Any idea ? Thanks. Laurent. From yanzhipingliu at gmail.com Tue Aug 18 17:52:29 2015 From: yanzhipingliu at gmail.com (Ping Liu) Date: Tue, 18 Aug 2015 14:52:29 -0700 (PDT) Subject: memory control in Python In-Reply-To: References: Message-ID: <3dd3769c-7a49-4956-a0b7-f940d3d6d800@googlegroups.com> Hi, Oscar, Your feedback is very valuable to me since you dig into the problem itself. Basically, we are trying to develop an open source software with multiple interface to several free solvers so that we can switch among them in case one of them is not working or so efficient. The optimization problem is developed on the basis of OPENOPT. the number of binary variables grows with the change of time period. The problem size (Aeq: equality constraints, Aineq: inequality constraints)and binary variables are as listed below. As you can imagine, it is hard to test each case of binary variables separately. Aeq Aineq Binary 1 hr 6*15 17*15 6 2 hr 12*26 30*26 10 24 hr 144*268 316*268 98 480 hr 2880*5284 6244*5284 1922 720 hr 4320*7924 9364*7924 unknown Our final goal is to test 8760 time steps in our problem. We can reduce it according to the purpose of optimization. For example, for planning, the time period would be one year with longer time step than 1 hr; for operational purpose, the time period would be 7 days, with 15 min time step. In the second case, the total time step comes down to 402. Actually, we have tried several solvers, including cplex, LPSOLVE, GLPK. We don't need to stick to CPLEX for the MIP problem. The performance of each solver is compared regarding memory usage(MB). 2hr 24hr 240hr 480hr GLPK 26 27.6 222.6 806 LPSOLVE 11.6 15.5 421.6 1557.3 CPLEX 25.6 19.5 192.06 719.1 I think one way to reduce the problem size probably would be to categorize it into planning and operation problem. Another way would be to look into Cython for which I am not quite sure whether it would help. But I would like to try to reformulate the problem itself as you advised. From ben.usenet at bsb.me.uk Tue Aug 18 17:55:48 2015 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Tue, 18 Aug 2015 22:55:48 +0100 Subject: regex recursive matching (regex 2015.07.19) References: Message-ID: <87bne4b6sb.fsf@bsb.me.uk> Neal Becker writes: > Trying regex 2015.07.19 > > I'd like to match recursive parenthesized expressions, with groups such that > '(a(b)c)' > > would give > group(0) -> '(a(b)c)' > group(1) -> '(b)' > > but that's not what I get > > import regex > > #r = r'\((?>[^()]|(?R))*\)' > r = r'\(([^()]|(?R))*\)' > #r = r'\((?:[^()]|(?R))*\)' > m = regex.match (r, '(a(b)c)') The (?R) syntax is Perl -- it's no implemented in Python. Python and Perl regexs are very similar in syntax (for very good reasons) but neither (?R) nor the numbered or named versions of it are in Python. -- Ben. From python at mrabarnett.plus.com Tue Aug 18 18:08:46 2015 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 18 Aug 2015 23:08:46 +0100 Subject: Regular expression and substitution, unexpected duplication In-Reply-To: <55d3a6c9$0$3335$426a74cc@news.free.fr> References: <55d3a6c9$0$3335$426a74cc@news.free.fr> Message-ID: <55D3ACEE.5080408@mrabarnett.plus.com> On 2015-08-18 22:42, Laurent Pointal wrote: > Hello, > > I want to make a replacement in a string, to ensure that ellipsis are > surrounded by spaces (this is not a typographycal problem, but a preparation > for late text chunking). > > I tried with regular expressions and the SRE_Pattern.sub() method, but I > have an unexpected duplication of the replacement pattern: > > > The code: > > ellipfind_re = re.compile(r"((?=\.\.\.)|?)", re.IGNORECASE|re.VERBOSE) > ellipfind_re.sub(' ... ', > "C'est un essai... avec diff?rents caract?res? pour voir.") > > And I retrieve: > > "C'est un essai ... ... avec diff?rents caract?res ... pour voir." > ^^^ > > I tested with/without group capture, same result. > > My Python version: > Python 3.4.3 (default, Mar 26 2015, 22:03:40) > [GCC 4.9.2] on linux > > Any idea ? > (?=...) is a lookahead; a non-capture group is (?:...). The regex should be r"((?:\.\.\.)|?)", which can be simplified to just r"\.\.\.|?" for your use-case. (You don't need the re.IGNORECASE|re.VERBOSE either!) From tim at akwebsoft.com Tue Aug 18 18:34:44 2015 From: tim at akwebsoft.com (Tim Johnson) Date: Tue, 18 Aug 2015 14:34:44 -0800 Subject: testing, please disregard Message-ID: <20150818223444.GE53693@mail.akwebsoft.com> I have had some problems with another python.org ML. I am sending this to see if it is received. Please disregard. thanks -- Tim http://www.akwebsoft.com, http://www.tj49.com From python at mrabarnett.plus.com Tue Aug 18 18:48:46 2015 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 18 Aug 2015 23:48:46 +0100 Subject: regex recursive matching (regex 2015.07.19) In-Reply-To: <87bne4b6sb.fsf@bsb.me.uk> References: <87bne4b6sb.fsf@bsb.me.uk> Message-ID: <55D3B64E.4040001@mrabarnett.plus.com> On 2015-08-18 22:55, Ben Bacarisse wrote: > Neal Becker writes: > >> Trying regex 2015.07.19 >> >> I'd like to match recursive parenthesized expressions, with groups such that >> '(a(b)c)' >> >> would give >> group(0) -> '(a(b)c)' >> group(1) -> '(b)' >> >> but that's not what I get >> >> import regex >> >> #r = r'\((?>[^()]|(?R))*\)' >> r = r'\(([^()]|(?R))*\)' >> #r = r'\((?:[^()]|(?R))*\)' >> m = regex.match (r, '(a(b)c)') > > The (?R) syntax is Perl -- it's no implemented in Python. Python and > Perl regexs are very similar in syntax (for very good reasons) but > neither (?R) nor the numbered or named versions of it are in Python. > He's using the regex module from PyPI: https://pypi.python.org/pypi/regex From gh at ghaering.de Tue Aug 18 20:17:45 2015 From: gh at ghaering.de (=?UTF-8?Q?Gerhard_H=C3=A4ring?=) Date: Wed, 19 Aug 2015 02:17:45 +0200 Subject: pysqlite 2.8.0 released Message-ID: NEW FEATURES - No new features, but tons of bugfixes. These mean that things now work that didn't before: - Transactional DDL now works - You can use SAVEPOINTs now BUILD PROCESS - Python 2.7.x is now required. If trying to use it with Python 3, print a useful error message. Integrated all fixes from the sqlite3 module in Python 2.7.10. MAJOR IMPROVEMENTS - Completety got rid of statement parsing. We now use SQLite functions to determine if a statement modifies the database or not. If a statement modifies the database, then we implicitly start a transaction. For backwards compatibility reasons, we do NOT implicitly start a transaction if we encounter a DDL statement. You can, however, now have transactional DDL if you want to: cur = con.cursor() cur.execute("begin") cur.execute("create table foo(bar)") con.rollback() This also means that people can now finally use SAVEPOINTS. - Use sqlite3_get_autocommit() to determine if we are within a transaction instead of trying to be smart. - Switch to v2 statement API. This simplified the code and will increase stability. MINOR IMPROVEMENTS - You can use unicode strings as index for Row objects. BUGFIXES - Fixed a regression: statements should not be reset after a commit. GENERAL CLEANUP AND DEPRECATIONS - Since december 2005, row_factory is a feature of the Connection class instead of the Cursor class. It was kept in the Cursor class for backwards compatibility. Now it was time to finally remove it from the Cursor class. - DEPRECATE converters and adapters. - DEPRECATE text_factory. - Remove compatibility workarounds for old Python versions. - Remove workarounds for old SQLite versions. - Remove apsw related code. -------------- next part -------------- An HTML attachment was scrubbed... URL: From harirammanohar159 at gmail.com Wed Aug 19 02:53:44 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Tue, 18 Aug 2015 23:53:44 -0700 (PDT) Subject: How to parse XML file and save results as .txt or .csv? In-Reply-To: <5760243f-7f27-4438-8f1a-dc2e93f00277@googlegroups.com> References: <5760243f-7f27-4438-8f1a-dc2e93f00277@googlegroups.com> Message-ID: <665b0cfe-6d8b-418b-8eac-036d0f27b3ac@googlegroups.com> On Tuesday, 18 August 2015 22:20:32 UTC+5:30, ryguy7272 wrote: > I am trying to parse this XML file. > http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml > > I tried a bunch of things in R, and almost got it working, but it seems like there was some issue with the rows and columns being out of sync, or some such thing. Can someone here share some Python code that will parse the XML file mentioned above, possibly clean up any garbage, and save the results as .txt or .csv? > > Thanks!! Hey, you can use argparse or xml tree in python and you can save it any where in any format. its really work...... see the examples and try to figure out the code.... From Dwight at GoldWinde.com Wed Aug 19 02:57:00 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Wed, 19 Aug 2015 14:57:00 +0800 Subject: Permission denied error in download nltk_data... Message-ID: Please help? Using this code: import nltk nltk.download('maxent_treebank_pos_tagger?) I get this error: [nltk_data] Downloading package maxent_treebank_pos_tagger to [nltk_data] /Users/dwightgoldwindex/nltk_data... Traceback (most recent call last): File "test short.py", line 18, in nltk.download('maxent_treebank_pos_tagger') File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packag es/nltk/downloader.py", line 664, in download for msg in self.incr_download(info_or_id, download_dir, force): File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packag es/nltk/downloader.py", line 549, in incr_download for msg in self._download_package(info, download_dir, force): File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packag es/nltk/downloader.py", line 604, in _download_package os.mkdir(download_dir) PermissionError: [Errno 13] Permission denied: '/Users/dwightgoldwindex/nltk_data' BIG SMILE... Always, Dwight www.3forliving.key.to (video playlist on YouTube) www.couragebooks.key.to (all my books on Amazon) -------------- next part -------------- An HTML attachment was scrubbed... URL: From harirammanohar159 at gmail.com Wed Aug 19 02:58:48 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Tue, 18 Aug 2015 23:58:48 -0700 (PDT) Subject: execute commands as su on remote server In-Reply-To: References: Message-ID: <0eedd27d-e806-468f-9e1e-6e9cf49eb3c5@googlegroups.com> On Tuesday, 18 August 2015 08:27:33 UTC+5:30, hariramm... at gmail.com wrote: > execute commands as su on remote server > > Postby hariram ? Mon Aug 17, 2015 4:02 am > Needed: > I need to execute commands after doing su to other user on remote server(not sudo which doesn't require password) how i can achieve this using python? > I googled and came to know that its not possible, so just for confirmation asking again, is it possible ? > > Already Tried: > Tried paramiko that's too not working. Hey Chris, Thanks for that, requirement is not to use sudo, we have to use only su. anyway i have tried with subprocess too with su which is not working as it needs tty...even paramiko also SSHClient... From harirammanohar159 at gmail.com Wed Aug 19 03:02:06 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Wed, 19 Aug 2015 00:02:06 -0700 (PDT) Subject: execute commands as su on remote server In-Reply-To: References: Message-ID: On Tuesday, 18 August 2015 08:27:33 UTC+5:30, hariramm... at gmail.com wrote: > execute commands as su on remote server > > Postby hariram ? Mon Aug 17, 2015 4:02 am > Needed: > I need to execute commands after doing su to other user on remote server(not sudo which doesn't require password) how i can achieve this using python? > I googled and came to know that its not possible, so just for confirmation asking again, is it possible ? > > Already Tried: > Tried paramiko that's too not working. Hey Julio, i have seen that in forums speaking about fabfile... but i believe that it also supports only sudo not su...sudo rights we dont have in our env... even fabfile implementation is up to python 2.7 only and we are using python 3.4 Tried creating channel and invoking shell and spawning it delay, that too didnt worked, just checking that any possible way is there to control the tty.. From lac at openend.se Wed Aug 19 04:13:35 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 19 Aug 2015 10:13:35 +0200 Subject: Logging to a file from a C-extension In-Reply-To: References: Message-ID: <201508190813.t7J8DZi3028032@fido.openend.se> In a message of Tue, 18 Aug 2015 08:07:51 -0500, Al Pfalzgraf writes: > If a logging file is opened at the level of a Python application, how would the log file name be communicated to a C-extension so that logging from the extension would be sent to the same log file? To convert a file to an integer file descriptor, use PyFile_FromFd() PyObject *fobj; /* File object (already obtained somehow) */ int fd = PyObject_AsFileDescriptor(fobj); if (fd < 0) { return NULL; } This works for files, sockets, anything that produces a file descriptor. Remember to flush your file on the Python side before you hand it to your C extension, or your data will arrive scrambled, or you can lose some. If you need to go the other way: int fd; /* Existing file descriptor (already open) */ PyObject *fobj = PyFile_FromFd(fd, "filename","r",-1,NULL,NULL,NULL,1); From lac at openend.se Wed Aug 19 04:44:53 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 19 Aug 2015 10:44:53 +0200 Subject: execute commands as su on remote server In-Reply-To: References: Message-ID: <201508190844.t7J8irDJ001699@fido.openend.se> I haven't tried this but fabric looks encouraging: From http://docs.fabfile.org/en/latest/api/core/operations.html#fabric.operations.run fabric.operations.run(*args, **kwargs) Run a shell command on a remote host. ... Any text entered in your local terminal will be forwarded to the remote program as it runs, thus allowing you to interact with password or other prompts naturally ... You may pass pty=False to forego creation of a pseudo-terminal on the remote end in case the presence of one causes problems for the command in question. Laura From lac at openend.se Wed Aug 19 04:51:56 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 19 Aug 2015 10:51:56 +0200 Subject: execute commands as su on remote server In-Reply-To: <201508190844.t7J8irDJ001699@fido.openend.se> References: <201508190844.t7J8irDJ001699@fido.openend.se> Message-ID: <201508190851.t7J8puk7003334@fido.openend.se> In a message of Wed, 19 Aug 2015 10:44:53 +0200, Laura Creighton writes: >I haven't tried this but fabric looks encouraging: > >>From http://docs.fabfile.org/en/latest/api/core/operations.html#fabric.operations.run > > fabric.operations.run(*args, **kwargs) > > Run a shell command on a remote host. > > ... > > Any text entered in your local terminal will be forwarded to the > remote program as it runs, thus allowing you to interact with > password or other prompts naturally > > ... > > You may pass pty=False to forego creation of a pseudo-terminal on > the remote end in case the presence of one causes problems for the > command in question. > >Laura >-- >https://mail.python.org/mailman/listinfo/python-list And now that I started looking, I found this: http://stackoverflow.com/questions/12641514/switch-to-different-user-using-fabric so, somebody got it to work ... Laura From info at egenix.com Wed Aug 19 06:06:27 2015 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 19 Aug 2015 12:06:27 +0200 Subject: ANN: eGenix mxODBC 3.3.5 - Python ODBC Database Interface Message-ID: <55D45523.7060802@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC Python ODBC Database Interface Version 3.3.5 mxODBC is our commercially supported Python extension providing ODBC database connectivity to Python applications on Windows, Mac OS X, Unix and BSD platforms with many advanced Python DB-API extensions and full support of stored procedures This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-3.3.5-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, Oracle Database, IBM DB2, Informix and Netezza, SAP Sybase ASE and Sybase Anywhere, Teradata, MySQL, MariaDB, 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.3.5 release of our mxODBC is a patch level release of our popular Python ODBC Interface for Windows, Linux, Mac OS X and FreeBSD. It includes these enhancements and fixes: Features -------- * Documented the use of transaction isolation levels with mxODBC in a new section of the mxODBC manual. This features has been part of mxODBC for long time, but was never documented as such. Driver Compatibility -------------------- MS SQL Server * Fixed the definition of the BinaryNull singleton added in mxODBC 3.3.4 to make it pickleable and protect it against recreation. * Documented and recommended use of SET NOCOUNT ON for running multiple statements or stored procedures. This can not only resolve issues with error reporting, it also results in better performance. Bug Fixes --------- * Fixed a potential segfault during interpreter shutdown introduced in mxODBC 3.3.4. Found by ZeOmega while testing mxODBC with SQLAlchemy (SA) using the "mssql+mxodbc" SA engine Installation Enhancements ------------------------- * Added support for bdist_wheels to mxSetup, which is used for creating distribution packages of mxODBC, to allow building wheels from the prebuilt packages, e.g. during installation via pip. For the full set of changes please check the mxODBC change log: http://www.egenix.com/products/python/mxODBC/changelog.html ________________________________________________________________________ FEATURES mxODBC 3.3 was released on 2014-04-08. Please see the full announcement for highlights of the 3.3 release: http://www.egenix.com/company/news/eGenix-mxODBC-3.3.0-GA.html For the full set of features mxODBC has to offer, please see: http://www.egenix.com/products/python/mxODBC/#Features ________________________________________________________________________ EDITIONS mxODBC is available in these two editions: * The Professional Edition, which gives full access to all mxODBC features. * The Product Development Edition, which allows including mxODBC in applications you develop. For a complete overview of the available 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/ You can also simply use: pip install egenix-mxodbc and then get evaluation licenses from our website to try mxODBC: http://www.egenix.com/products/python/mxODBC/#Evaluation ________________________________________________________________________ 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.3 licenses can continue to use their licenses with this patch level release. For upgrade purchases, we will give out 20% discount coupons going from mxODBC 2.x to 3.3 and 50% coupons for upgrades from mxODBC 3.x to 3.3. 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 purchase, you can request 30-day evaluation licenses by visiting our web-site http://www.egenix.com/products/python/mxODBC/#Evaluation 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. _______________________________________________________________________ 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 eGenix (http://www.egenix.com/): eGenix is a database focused software project, consulting and product company delivering expert services and professional quality products for companies, Python users and developers. 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. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 19 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From antoon.pardon at rece.vub.ac.be Wed Aug 19 07:05:52 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 19 Aug 2015 13:05:52 +0200 Subject: Why the different parameter signatures to indicate blocking/timeouts. Message-ID: <55D46310.4010106@rece.vub.ac.be> I have been looking through the threading module and I am a bit annoyed at the different signatures for indicating whether some calls should block or not and the timeout. On the one hand we have the acquire on locks with the following signature: def accquire(blocking=True, timeout=-1) On the other hand we have wait and join methods with this signature: def join(timeout=None). As far as I understand timeout=None is equivallent to: blocking=True, timeout=-1 timeout=NR is equivallent to: blocking=True, timeout=NR. timeout=0 is equivallent to: blocking=False, timeout=-1 which may be equivallent to : blocking=True, timeout=0 Can someone explain why these different signatures, or should I consider this a relict from the past? -- Antoon Pardon //// From ryanshuell at gmail.com Wed Aug 19 07:57:44 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Wed, 19 Aug 2015 04:57:44 -0700 (PDT) Subject: Can I download XML data from the web and save, in as CSV or TXT delimitation? Message-ID: I'm trying to get R to download the data from here: http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml # install and load the necessary package install.packages("XML") library(XML) # Save the URL of the xml file in a variable xml.url <- "http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml" # Use the xmlTreePares-function to parse xml file directly from the web xmlfile <- xmlTreeParse(xml.url) # the xml file is now saved as an object you can easily work with in R: class(xmlfile) # Use the xmlRoot-function to access the top node xmltop = xmlRoot(xmlfile) # have a look at the XML-code of the first subnodes: print(xmltop)[1:3] Everything seems fine up to that point. The next line seems to NOT parse the data as I thought it would. # To extract the XML-values from the document, use xmlSApply: datacat <- xmlSApply(xmltop, function(x) xmlSApply(x, xmlValue)) I did some research on this, and it seemed to work in other examples of xml data. I guess this data set is different...or I just don't understand this well enough to know what's really going on... Basically, I want to get this: xmltop Into a data table. How can I do that? Thanks. From steve at pearwood.info Wed Aug 19 08:00:38 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 19 Aug 2015 22:00:38 +1000 Subject: Permission denied error in download nltk_data... References: Message-ID: <55d46fe5$0$1642$c3e8da3$5496439d@news.astraweb.com> On Wed, 19 Aug 2015 04:57 pm, Dwight GoldWinde wrote: > Please help? > > Using this code: > > import nltk > nltk.download('maxent_treebank_pos_tagger?) > > > I get this error: [...] > os.mkdir(download_dir) > > PermissionError: [Errno 13] Permission denied: > '/Users/dwightgoldwindex/nltk_data' That's a permissions problem. Firstly, when you run this code, are you logged in as the "dwightgoldwindex" user? Note the "x" at the end of the directory name. Is that what you expect? Secondly, can you open a terminal and get a command line prompt? **NOT** a Python prompt: if you see the prompt ">>>" type "quit()" and enter. You should have a prompt $ or % or similar. At the prompt, type: whoami ls -ld /Users/dwightgoldwindex/ ls -ld /Users/dwightgoldwindex/nltk_data and hit Enter after each line. What results do you get? -- Steven From lac at openend.se Wed Aug 19 08:21:07 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 19 Aug 2015 14:21:07 +0200 Subject: Can I download XML data from the web and save, in as CSV or TXT delimitation? In-Reply-To: References: Message-ID: <201508191221.t7JCL7gF012970@fido.openend.se> In a message of Wed, 19 Aug 2015 04:57:44 -0700, ryguy7272 writes: >I'm trying to get R to download the data from here: > >http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml > > ># install and load the necessary package >install.packages("XML") >library(XML) ># Save the URL of the xml file in a variable > >xml.url <- "http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml" ># Use the xmlTreePares-function to parse xml file directly from the web > >xmlfile <- xmlTreeParse(xml.url) ># the xml file is now saved as an object you can easily work with in R: >class(xmlfile) > > ># Use the xmlRoot-function to access the top node >xmltop = xmlRoot(xmlfile) ># have a look at the XML-code of the first subnodes: >print(xmltop)[1:3] > > > >Everything seems fine up to that point. The next line seems to NOT parse the data as I thought it would. ># To extract the XML-values from the document, use xmlSApply: >datacat <- xmlSApply(xmltop, function(x) xmlSApply(x, xmlValue)) > > > >I did some research on this, and it seemed to work in other examples of xml data. I guess this data set is different...or I just don't understand this well enough to know what's really going on... > >Basically, I want to get this: > >xmltop > > >Into a data table. How can I do that? > >Thanks. This is a mailing list about the Python programming language, not R xmlSApply is something R uses. The R mailing lists are here: https://www.r-project.org/mail.html When you talk to them, tell them exactly what you were expecting as a result, what you got instead, and what error messages were generated. Also let them know what verison of R you are using and what operating system you are running on. This will make it a lot easier for them to help you. Good luck, Laura Creighton From ryanshuell at gmail.com Wed Aug 19 09:32:46 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Wed, 19 Aug 2015 06:32:46 -0700 (PDT) Subject: Can I download XML data from the web and save, in as CSV or TXT delimitation? In-Reply-To: References: Message-ID: On Wednesday, August 19, 2015 at 8:21:50 AM UTC-4, Laura Creighton wrote: > In a message of Wed, 19 Aug 2015 04:57:44 -0700, ryguy7272 writes: > >I'm trying to get R to download the data from here: > > > >http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml > > > > > ># install and load the necessary package > >install.packages("XML") > >library(XML) > ># Save the URL of the xml file in a variable > > > >xml.url <- "http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml" > ># Use the xmlTreePares-function to parse xml file directly from the web > > > >xmlfile <- xmlTreeParse(xml.url) > ># the xml file is now saved as an object you can easily work with in R: > >class(xmlfile) > > > > > ># Use the xmlRoot-function to access the top node > >xmltop = xmlRoot(xmlfile) > ># have a look at the XML-code of the first subnodes: > >print(xmltop)[1:3] > > > > > > > >Everything seems fine up to that point. The next line seems to NOT parse the data as I thought it would. > ># To extract the XML-values from the document, use xmlSApply: > >datacat <- xmlSApply(xmltop, function(x) xmlSApply(x, xmlValue)) > > > > > > > >I did some research on this, and it seemed to work in other examples of xml data. I guess this data set is different...or I just don't understand this well enough to know what's really going on... > > > >Basically, I want to get this: > > > >xmltop > > > > > >Into a data table. How can I do that? > > > >Thanks. > > This is a mailing list about the Python programming language, not R > xmlSApply is something R uses. The R mailing lists are here: > https://www.r-project.org/mail.html > > When you talk to them, tell them exactly what you were expecting as > a result, what you got instead, and what error messages were generated. > Also let them know what verison of R you are using and what operating > system you are running on. This will make it a lot easier for them > to help you. > > Good luck, > > Laura Creighton Well, yes, I was originally trying to do it it R, but I couldn't get it working, so I thought I'd try to do it in Python. That was a sample R script. Can I do essentially the same thing in Python? Can I read the XML from the web? http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml Parse it, or clean it, or whatever, and save it as a CSV or TXT? Is that possible? Thanks. From joel.goldstick at gmail.com Wed Aug 19 09:49:11 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 19 Aug 2015 09:49:11 -0400 Subject: Can I download XML data from the web and save, in as CSV or TXT delimitation? In-Reply-To: References: Message-ID: > > > Well, yes, I was originally trying to do it it R, but I couldn't get it working, so I thought I'd try to do it in Python. That was a sample R script. Can I do essentially the same thing in Python? Can I read the XML from the web? > http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml > > Parse it, or clean it, or whatever, and save it as a CSV or TXT? Is that possible? > > Thanks. Of course you can 1. read a file from a website using python urllib modules or requests module (3rd party but simpler) 2. There are several xml parsers. I haven't experienced them, so google is your friend 3. python has csv reader and writer modules -- Joel Goldstick http://joelgoldstick.com From lac at openend.se Wed Aug 19 09:51:16 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 19 Aug 2015 15:51:16 +0200 Subject: Can I download XML data from the web and save, in as CSV or TXT delimitation? In-Reply-To: References: Message-ID: <201508191351.t7JDpGpw031214@fido.openend.se> In a message of Wed, 19 Aug 2015 06:32:46 -0700, ryguy7272 writes: >Well, yes, I was originally trying to do it it R, but I couldn't get >it working, so I thought I'd try to do it in Python. That was a >sample R script. Can I do essentially the same thing in Python? Can >I read the XML from the web? >http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml >Parse it, or clean it, or whatever, and save it as a CSV or TXT? Is >that possible? Thanks. -- >https://mail.python.org/mailman/listinfo/python-list The question is, is this a reasonable thing to do. If your xml file is flat, and simple, then moving to csv is easy, and a fine idea. Python has tons of utilities for dealing with xml files. For instance https://pypi.python.org/pypi/xmlutils download that and conversion is a simple as running the command line command xml2csv --input "samples/fruits.xml" --output "samples/fruits.csv" --tag "item" But XML is designed for the representation of complex data -- if your xmlfile has a lot of structure then a CSV file doesn't have enough structure in itself to do a good job of holding the data. xml2json -- you will get one of those too -- might give you a file that you would find more suitable to use. But there is a very good chance that you will have to analyse the structure of your data, and parse it, and decide what to keep and what you don't care about. Python is very, very good at doing this but you will have to learn how to program in Python -- at least a little -- to do this. Have you programmed in Python before? In another language? Laura Creighton From ben.usenet at bsb.me.uk Wed Aug 19 10:41:06 2015 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Wed, 19 Aug 2015 15:41:06 +0100 Subject: regex recursive matching (regex 2015.07.19) References: <87bne4b6sb.fsf@bsb.me.uk> Message-ID: <87614bbat9.fsf@bsb.me.uk> MRAB writes: > On 2015-08-18 22:55, Ben Bacarisse wrote: >> Neal Becker writes: >> >>> Trying regex 2015.07.19 >>> >>> I'd like to match recursive parenthesized expressions, with groups such that >>> '(a(b)c)' >>> >>> would give >>> group(0) -> '(a(b)c)' >>> group(1) -> '(b)' >>> >>> but that's not what I get >>> >>> import regex >>> >>> #r = r'\((?>[^()]|(?R))*\)' >>> r = r'\(([^()]|(?R))*\)' >>> #r = r'\((?:[^()]|(?R))*\)' >>> m = regex.match (r, '(a(b)c)') >> >> The (?R) syntax is Perl -- it's no implemented in Python. Python and >> Perl regexs are very similar in syntax (for very good reasons) but >> neither (?R) nor the numbered or named versions of it are in Python. >> > He's using the regex module from PyPI: Ah, right. Then he might find r = r'(\((?:[^()]|(?R))*\))' more suitable when combined with captures() rather than groups(): regex.match(r, '(a(b)c)').captures(1) ['(b)', '(a(b)c)'] -- Ben. From laurent.pointal at free.fr Wed Aug 19 12:32:57 2015 From: laurent.pointal at free.fr (Laurent Pointal) Date: Wed, 19 Aug 2015 18:32:57 +0200 Subject: Regular expression and substitution, unexpected duplication References: <55d3a6c9$0$3335$426a74cc@news.free.fr> Message-ID: <55d4afb9$0$4567$426a74cc@news.free.fr> MRAB wrote: > On 2015-08-18 22:42, Laurent Pointal wrote: >> Hello, >> ellipfind_re = re.compile(r"((?=\.\.\.)|?)", re.IGNORECASE|re.VERBOSE) >> ellipfind_re.sub(' ... ', >> "C'est un essai... avec diff?rents caract?res? pour voir.") > (?=...) is a lookahead; a non-capture group is (?:...). > > The regex should be r"((?:\.\.\.)|?)", which can be simplified to just > r"\.\.\.|?" for your use-case. (You don't need the > re.IGNORECASE|re.VERBOSE either!) Thanks, I made same mistake in another place, but dont see it here. A+ Laurent. From denismfmcmahon at gmail.com Wed Aug 19 13:01:10 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 19 Aug 2015 17:01:10 +0000 (UTC) Subject: Can I download XML data from the web and save, in as CSV or TXT delimitation? References: Message-ID: On Wed, 19 Aug 2015 04:57:44 -0700, ryguy7272 wrote: [stuff] Downloading xml from the web is easy writing csv or txt is easy The tricky bit is converting the xml you have into the csv or text data you want. And to do that, you need to understand the structure of the xml data that you are receiving and how the xml nodes and their attributes and values should be mapped into the csv file you want to create. Unfortunately I don't think that there is a single standard mechanism for doing that bit, although there are some tools and libraries that can help. -- Denis McMahon, denismfmcmahon at gmail.com From petite.abeille at gmail.com Wed Aug 19 13:14:29 2015 From: petite.abeille at gmail.com (Petite Abeille) Date: Wed, 19 Aug 2015 19:14:29 +0200 Subject: Can I download XML data from the web and save, in as CSV or TXT delimitation? In-Reply-To: References: Message-ID: > On Aug 19, 2015, at 7:01 PM, Denis McMahon wrote: > > Downloading xml from the web is easy > > writing csv or txt is easy > > The tricky bit is converting the xml you have into the csv or text data > you want. > curl | xml2 | 2csv http://www.ofb.net/~egnor/xml2/ref From info at wingware.com Wed Aug 19 14:22:19 2015 From: info at wingware.com (Wingware) Date: Wed, 19 Aug 2015 14:22:19 -0400 Subject: ANN: Wing IDE 5.1.6 released Message-ID: <55D4C95B.7070702@wingware.com> Hi, Wingware has released version 5.1.6 of Wing IDE, our cross-platform integrated development environment for the Python programming language. Wing IDE features a professional code editor with vi, emacs, visual studio, and other key bindings, auto-completion, call tips, context-sensitive auto-editing, goto-definition, find uses, refactoring, a powerful debugger, version control, unit testing, search, project management, and many other features. This release includes the following improvements: Support for debugging code running on Raspberry Pi Support for debugging Python 3.5c1+ Option to run more than one test file concurrently from the Testing tool Fix several problems with Django project creation Show correct stdout/stderr output from pytest unit tests in the Testing tool Partially updated French localization (thanks to Jean Sanchez) Fix autocompletion after from . and from ..name statements Correctly reuse locked splits for already-open files Fix editing input lines in Debug I/O About 40 other improvements For details see http://wingware.com/news/2015-08-18 and http://wingware.com/pub/wingide/5.1.6/CHANGELOG.txt What's New in Wing 5.1: Wing IDE 5.1 adds multi-process and child process debugging, syntax highlighting in the shells, support for pytest, Find Symbol in Project, persistent time-stamped unit test results, auto-conversion of indents on paste, an XCode keyboard personality, support for Flask, Django 1.7 and 1.8, Python 3.5 and recent Google App Engine versions, improved auto-completion for PyQt, recursive snippet invocation, and many other minor features and improvements. Free trial: http://wingware.com/wingide/trial Downloads: http://wingware.com/downloads Feature list: http://wingware.com/wingide/features Sales: http://wingware.com/store/purchase Upgrades: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at support at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE The Intelligent Development Environment for Python Programmers wingware.com From ryanshuell at gmail.com Wed Aug 19 14:43:40 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Wed, 19 Aug 2015 11:43:40 -0700 (PDT) Subject: Can I download XML data from the web and save, in as CSV or TXT delimitation? In-Reply-To: References: Message-ID: <765e7e63-9e6e-4b6f-8aaf-6dc3fae7ef05@googlegroups.com> On Wednesday, August 19, 2015 at 1:14:44 PM UTC-4, Petite Abeille wrote: > > On Aug 19, 2015, at 7:01 PM, Denis McMahon wrote: > > > > Downloading xml from the web is easy > > > > writing csv or txt is easy > > > > The tricky bit is converting the xml you have into the csv or text data > > you want. > > > > curl | xml2 | 2csv > > http://www.ofb.net/~egnor/xml2/ref WOW!!! This is so powerful!!! https://pypi.python.org/pypi/xmlutils You're right, Denis, it is a bit tricky. I definitely need to play with this a bit to get it to do what I really want it to do, but anyway, I think I can take it from here. Thanks everyone!! From stefan_ml at behnel.de Wed Aug 19 15:51:24 2015 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 19 Aug 2015 21:51:24 +0200 Subject: Logging to a file from a C-extension In-Reply-To: References: Message-ID: Al Pfalzgraf schrieb am 18.08.2015 um 15:07: > If a logging file is opened at the level of a Python application, how > would the log file name be communicated to a C-extension so that logging > from the extension would be sent to the same log file? Writing to the file directly (as was suggested) may not be a good idea as it would bypass the log filtering and formatting. Instead, I'd suggest sending output to a normal Python Logger object instead. This is obviously trivial in Cython (where you can just implement it in Python code), but you can do the same in C with just the usual C-API overhead. Stefan From ptmcg at austin.rr.com Wed Aug 19 15:53:36 2015 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 19 Aug 2015 12:53:36 -0700 (PDT) Subject: Python re to extract useful information from each line In-Reply-To: References: Message-ID: Here is a first shot at a pyparsing parser for these lines: from pyparsing import * SET,POLICY,ID,FROM,TO,NAT,SRC,DST,IP,PORT,SCHEDULE,LOG,PERMIT,ALLOW,DENY = map(CaselessKeyword, "SET,POLICY,ID,FROM,TO,NAT,SRC,DST,IP,PORT,SCHEDULE,LOG,PERMIT,ALLOW,DENY".split(',')) integer = Word(nums) ipAddr = Combine(integer + ('.'+integer)*3) quotedString.setParseAction(removeQuotes) logParser = (SET + POLICY + ID + integer("id") + FROM + quotedString("from_") + TO + quotedString("to_") + quotedString("service")) I run this with: for line in """ 1- set policy id 1000 from "Untrust" to "Trust" "Any" "1.1.1.1" "HTTP" nat dst ip 10.10.10.10 port 8000 permit log 2- set policy id 5000 from "Trust" to "Untrust" "Any" "microsoft.com" "HTTP" nat src permit schedule "14August2014" log 3- set policy id 7000 from "Trust" to "Untrust" "Users" "Any" "ANY" nat src dip-id 4 permit log 4- set policy id 7000 from "Trust" to "Untrust" "servers" "Any" "ANY" deny """.splitlines(): line = line.strip() if not line: continue print (integer + '-' + logParser).parseString(line).dump() print Getting: ['1', '-', 'SET', 'POLICY', 'ID', '1000', 'FROM', 'Untrust', 'TO', 'Trust', 'Any'] - from_: Untrust - id: 1000 - service: Any - to_: Trust ['2', '-', 'SET', 'POLICY', 'ID', '5000', 'FROM', 'Trust', 'TO', 'Untrust', 'Any'] - from_: Trust - id: 5000 - service: Any - to_: Untrust ['3', '-', 'SET', 'POLICY', 'ID', '7000', 'FROM', 'Trust', 'TO', 'Untrust', 'Users'] - from_: Trust - id: 7000 - service: Users - to_: Untrust ['4', '-', 'SET', 'POLICY', 'ID', '7000', 'FROM', 'Trust', 'TO', 'Untrust', 'servers'] - from_: Trust - id: 7000 - service: servers - to_: Untrust Pyparsing adds Optional classes so that you can include expressions for pieces that might be missing like "... + Optional(NAT + (SRC | DST)) + ..." -- Paul From zzzeek at gmail.com Wed Aug 19 16:10:29 2015 From: zzzeek at gmail.com (zzzeek at gmail.com) Date: Wed, 19 Aug 2015 13:10:29 -0700 (PDT) Subject: pysqlite 2.8.0 released In-Reply-To: References: Message-ID: Hi Gerhard - is the download missing? On Pypi I see 2.8.0 is registered but no download file: https://pypi.python.org/pypi/pysqlite/2.8.0 pip fails: $ ./bin/pip install pysqlite==2.8.0 --upgrade --force Collecting pysqlite==2.8.0 Could not find a version that satisfies the requirement pysqlite==2.8.0 (from versions: 2.5.6, 2.6.0, 2.6.3, 2.7.0) Some externally hosted files were ignored as access to them may be unreliable (use --allow-external to allow). No distributions matching the version for pysqlite==2.8.0 On Tuesday, August 18, 2015 at 8:17:46 PM UTC-4, Gerhard H?ring wrote: > > NEW FEATURES > > - No new features, but tons of bugfixes. These mean that things now work > that > didn't before: > - Transactional DDL now works > - You can use SAVEPOINTs now > > > BUILD PROCESS > > - Python 2.7.x is now required. If trying to use it with Python 3, print a > useful error message. Integrated all fixes from the sqlite3 module in > Python > 2.7.10. > > > MAJOR IMPROVEMENTS > > - Completety got rid of statement parsing. We now use SQLite functions to > determine if a statement modifies the database or not. If a statement > modifies the database, then we implicitly start a transaction. For > backwards > compatibility reasons, we do NOT implicitly start a transaction if we > encounter a DDL statement. > > You can, however, now have transactional DDL if you want to: > > cur = con.cursor() > cur.execute("begin") > cur.execute("create table foo(bar)") > con.rollback() > > This also means that people can now finally use SAVEPOINTS. > > - Use sqlite3_get_autocommit() to determine if we are within a transaction > instead of trying to be smart. > > - Switch to v2 statement API. This simplified the code and will increase > stability. > > MINOR IMPROVEMENTS > > - You can use unicode strings as index for Row objects. > > > BUGFIXES > > - Fixed a regression: statements should not be reset after a commit. > > > GENERAL CLEANUP AND DEPRECATIONS > > - Since december 2005, row_factory is a feature of the Connection class > instead > of the Cursor class. It was kept in the Cursor class for backwards > compatibility. Now it was time to finally remove it from the Cursor > class. > - DEPRECATE converters and adapters. > - DEPRECATE text_factory. > - Remove compatibility workarounds for old Python versions. > - Remove workarounds for old SQLite versions. > - Remove apsw related code. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gh at ghaering.de Wed Aug 19 17:03:00 2015 From: gh at ghaering.de (=?UTF-8?Q?Gerhard_H=C3=A4ring?=) Date: Wed, 19 Aug 2015 23:03:00 +0200 Subject: [python-sqlite] Re: pysqlite 2.8.0 released In-Reply-To: References: Message-ID: Yes, I forgot to "setup.py sdist upload". It's fixed now. Sorry for the trouble. I'm of course looking forward to hear if SQLAlchemy still works ok with this release. On Wed, Aug 19, 2015 at 10:10 PM, wrote: > Hi Gerhard - > > is the download missing? On Pypi I see 2.8.0 is registered but no > download file: > > https://pypi.python.org/pypi/pysqlite/2.8.0 > > pip fails: > > $ ./bin/pip install pysqlite==2.8.0 --upgrade --force > Collecting pysqlite==2.8.0 > Could not find a version that satisfies the requirement pysqlite==2.8.0 > (from versions: 2.5.6, 2.6.0, 2.6.3, 2.7.0) > Some externally hosted files were ignored as access to them may be > unreliable (use --allow-external to allow). > No distributions matching the version for pysqlite==2.8.0 > > > > On Tuesday, August 18, 2015 at 8:17:46 PM UTC-4, Gerhard H?ring wrote: >> >> NEW FEATURES >> >> - No new features, but tons of bugfixes. These mean that things now work >> that >> didn't before: >> - Transactional DDL now works >> - You can use SAVEPOINTs now >> >> >> BUILD PROCESS >> >> - Python 2.7.x is now required. If trying to use it with Python 3, print a >> useful error message. Integrated all fixes from the sqlite3 module in >> Python >> 2.7.10. >> >> >> MAJOR IMPROVEMENTS >> >> - Completety got rid of statement parsing. We now use SQLite functions to >> determine if a statement modifies the database or not. If a statement >> modifies the database, then we implicitly start a transaction. For >> backwards >> compatibility reasons, we do NOT implicitly start a transaction if we >> encounter a DDL statement. >> >> You can, however, now have transactional DDL if you want to: >> >> cur = con.cursor() >> cur.execute("begin") >> cur.execute("create table foo(bar)") >> con.rollback() >> >> This also means that people can now finally use SAVEPOINTS. >> >> - Use sqlite3_get_autocommit() to determine if we are within a transaction >> instead of trying to be smart. >> >> - Switch to v2 statement API. This simplified the code and will increase >> stability. >> >> MINOR IMPROVEMENTS >> >> - You can use unicode strings as index for Row objects. >> >> >> BUGFIXES >> >> - Fixed a regression: statements should not be reset after a commit. >> >> >> GENERAL CLEANUP AND DEPRECATIONS >> >> - Since december 2005, row_factory is a feature of the Connection class >> instead >> of the Cursor class. It was kept in the Cursor class for backwards >> compatibility. Now it was time to finally remove it from the Cursor >> class. >> - DEPRECATE converters and adapters. >> - DEPRECATE text_factory. >> - Remove compatibility workarounds for old Python versions. >> - Remove workarounds for old SQLite versions. >> - Remove apsw related code. >> >> -- > > --- > You received this message because you are subscribed to the Google Groups > "python-sqlite" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to python-sqlite+unsubscribe at googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anschatten at gmail.com Wed Aug 19 18:57:47 2015 From: anschatten at gmail.com (Anton) Date: Wed, 19 Aug 2015 15:57:47 -0700 (PDT) Subject: Check if dictionary empty with == {} Message-ID: Probably a silly question. Let's say I have a dictionary mydict and I need to test if a dictionary is empty. I would use if not mydict: """do something""" But I just came across a line of code like: if mydict == {}: """do something""" which seems odd to me, but maybe there is a valid use case, thus I decided to ask the community. Thanks. From skip.montanaro at gmail.com Wed Aug 19 19:15:09 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 19 Aug 2015 18:15:09 -0500 Subject: Check if dictionary empty with == {} In-Reply-To: References: Message-ID: Comparison against {} will be less efficient. You need to create a dictionary every time instead of just checking the length of your dictionary, which is likely stored in the header. So, it will work, but certainly isn't idiomatic Python. Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Wed Aug 19 19:21:13 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 19 Aug 2015 18:21:13 -0500 Subject: Check if dictionary empty with == {} In-Reply-To: References: Message-ID: <20150819182113.111d115c@bigbox.christie.dr> On 2015-08-19 15:57, Anton wrote: > Probably a silly question. > Let's say I have a dictionary mydict and I need to test if a > dictionary is empty. > > I would use > > if not mydict: > """do something""" > > But I just came across a line of code like: > > if mydict == {}: > """do something""" > > which seems odd to me, but maybe there is a valid use case, thus I > decided to ask the community. The only valid reason is "the person who wrote that line doesn't speak idiomatic Python", and that it should be changed to "if not mydict" at your next code checking :-D -tkc From python at mrabarnett.plus.com Wed Aug 19 19:33:49 2015 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 20 Aug 2015 00:33:49 +0100 Subject: Check if dictionary empty with == {} In-Reply-To: References: Message-ID: <55D5125D.6060105@mrabarnett.plus.com> On 2015-08-20 00:15, Skip Montanaro wrote: > Comparison against {} will be less efficient. You need to create a > dictionary every time instead of just checking the length of your > dictionary, which is likely stored in the header. So, it will work, but > certainly isn't idiomatic Python. > Well, that depends on the intention. Is it checking whether the dictionary is empty, or whether it's an empty dictionary (and not, say, an empty list)? From skip.montanaro at gmail.com Wed Aug 19 19:41:40 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 19 Aug 2015 18:41:40 -0500 Subject: Check if dictionary empty with == {} In-Reply-To: <55D5125D.6060105@mrabarnett.plus.com> References: <55D5125D.6060105@mrabarnett.plus.com> Message-ID: On Wed, Aug 19, 2015 at 6:33 PM, MRAB wrote: > Well, that depends on the intention. > > Is it checking whether the dictionary is empty, or whether it's an > empty dictionary (and not, say, an empty list)? > Sure, that's a possibility. I would argue that "mydict == {}" is also not the idiomatic way to see if mydict isn't an empty list. For that, you'd use something like if mydict or not isinstance(mydict, list): blah blah blah Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From ryanshuell at gmail.com Wed Aug 19 21:51:47 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Wed, 19 Aug 2015 18:51:47 -0700 (PDT) Subject: JSON Object to CSV Question In-Reply-To: References: Message-ID: <030ee3e3-df76-4768-af3c-0a0c2e7ec42f@googlegroups.com> On Thursday, June 18, 2015 at 2:59:11 AM UTC-4, kbtyo wrote: > Good Evening Everyone: > > > I would like to have this JSON object written out to a CSV file so that the keys are header fields (for each of the columns) and the values are values that are associated with each header field. Is there a best practice for working with this? Ideally I would like to recursively iterate through the key value pairs. Thank you in advance. I am using Python 3.4 on Windows. My editor is Sublime 2. > > > > Here is the JSON object: > > > { > "Fee": { > "A": "5", > "FEC": "1/1/0001 12:00:00 AM", > "TE": null, > "Locator": null, > "Message": "Transfer Fee", > "AT": null, > "FT": null, > "FR": "True", > "FY": null, > "FR": null, > "FG": "0", > "Comment": null, > "FUD": null, > "cID": null, > "GEO": null, > "ISO": null, > "TRID": null, > "XTY": "931083", > "ANM": null, > "NM": null > }, > "CF": "Fee", > "ID": "2" > } > > The value, "Fee" associated with the key, "CF" should not be included as a column header (only as a value of the key "CF"). ? > > > > Other than the former, the keys should be headers and the corresponding tuples - the field values.? > > In essence, my goal is to the following: > > You get a dictionary object (the "outer" dictionary)You get the data from the "CF" key (fixed name?) which is a string ("Fee"?in your example)You use that value as a key to obtain another value from the same "outer" dictionary, which should be a another dictionary (the "inner" dictionary)You make a CSV file with: > a header that contains "CF" plus all keys in the "inner" dictionary that have an associated valuethe value from key "CF" in the "outer" dictionary plus all non-null values in the "inner" dictionary. > I have done the following: > > > import csv? > import json? > import sys? > > def hook(obj):? > ? ? return obj? > > def flatten(obj):? > ? ? for k, v in obj:? > ? ? ? ? if isinstance(v, list):? > ? ? ? ? ? ? yield from flatten(v)? > ? ? ? ? else:? > ? ? ? ? ? ? yield k, v? > > if __name__ == "__main__":? > ? ? with open("data.json") as f:? > ? ? ? ? data = json.load(f, object_pairs_hook=hook)? > > ? ? pairs = list(flatten(data))? > > ? ? writer = csv.writer(sys.stdout)? > ? ? writer.writerow([k for k, v in pairs])? > ? ? writer.writerow([v for k, v in pairs])? > > > > The output is as follows: > > $ python3 json2csv.py? > A,FEC,TE,Locator,Message,AT,FT,FR,FY,FR,FG,Comment,FUD,cID,GEO,ISO,TRID,XTY,ANM,NM,CF,ID? > 5,1/1/0001 12:00:00 AM,,,Transfer Fee,,,True,,,0,,,,,,,931083,,,Fee,2? > > > I do not want to have duplicate column names.? > > ? > > Any advice on other best practices that I may utilize? I am literally just learning Python now...total newbie...don't take this as the be-all-end-all...but maybe this will work for you: https://pypi.python.org/pypi/xmlutils Read the entire page. From ryanshuell at gmail.com Wed Aug 19 21:54:06 2015 From: ryanshuell at gmail.com (ryguy7272) Date: Wed, 19 Aug 2015 18:54:06 -0700 (PDT) Subject: JSON Object to CSV file In-Reply-To: References: Message-ID: <45204962-beac-401e-b529-b28720df0fcd@googlegroups.com> On Wednesday, June 17, 2015 at 11:00:24 AM UTC-4, kbtyo wrote: > I would like to have this JSON object written out to a CSV file so that the keys are header fields (for each of the columns) and the values are values that are associated with each header field. Is there a best practice for working with this? Ideally I would like to recursively iterate through the key value pairs. Thank you in advance. I am using Python 3.4 on Windows. My editor is Sublime 2. > > { > "CF": { > "A": "5", > "FEC": "1/1/0001 12:00:00 AM", > "TE": null, > "Locator": null, > "Message": "Transfer Fee", > "AT": null, > "FT": null, > "FR": "True", > "FY": null, > "FR": null, > "FG": "0", > "Comment": null, > "FUD": null, > "cID": null, > "GEO": null, > "ISO": null, > "TRID": null, > "XTY": "931083", > "ANM": null, > "NM": null > }, > "CF": "Fee", > "ID": "2" > } Please see this link. https://pypi.python.org/pypi/xmlutils I'm not sure if that will help you. I just found it toady. Also, I'm pretty new to Python. Anyway, hopefully, it gets you going in the right direction... From steve+comp.lang.python at pearwood.info Wed Aug 19 23:16:52 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 20 Aug 2015 13:16:52 +1000 Subject: Check if dictionary empty with == {} References: Message-ID: <55d546a5$0$1564$c3e8da3$5496439d@news.astraweb.com> On Thursday 20 August 2015 08:57, Anton wrote: > Probably a silly question. > Let's say I have a dictionary mydict and I need to test if a dictionary is > empty. > > I would use > > if not mydict: > """do something""" > > But I just came across a line of code like: > > if mydict == {}: > """do something""" > > which seems odd to me, but maybe there is a valid use case, thus I decided > to ask the community. It's neither good code or bad code. It looks like something a beginner or casual Python user (e.g. a sys admin) might have written, but that isn't necessarily bad. It's no more wrong than writing `if x == 0` to test for an "empty" number (or "nothing", in the numeric sense). Pros: + It's pretty short and explicit. + It allows for duck-typing: if some de facto mapping object wants to support the dict API without inheriting from dict, it can. + Even a beginner can understand it: "does mydict equal an empty dict?" Cons: - It looks a bit Python 1.5-ish. People used to more modern idioms may have an (unjustified, in my opinion) "WTF" moment when looking at it. - It *might* be a bit slow, since it takes time to create an empty dict; on the other hand, it also takes time to call isinstance(), so if you care about this, I want to see your profiling results and benchmarks. Actually, it's not a bit slow, it's *significantly* faster than an isinstance check: steve at runes:~$ python2.7 -m timeit -s "mydict = {1:2}" \ > "if mydict == {}: pass" 10000000 loops, best of 3: 0.0872 usec per loop steve at runes:~$ python2.7 -m timeit -s "mydict = {1:2}" \ > "if isinstance(mydict, dict) and not mydict: pass" 1000000 loops, best of 3: 0.257 usec per loop So maybe it's a micro-optimization? TL;DR There's nothing wrong with it. It is ever-so-subtly different from the various alternatives, so if you change it, don't be surprised if you break something. -- Steven From victorhooi at gmail.com Wed Aug 19 23:59:01 2015 From: victorhooi at gmail.com (Victor Hooi) Date: Wed, 19 Aug 2015 20:59:01 -0700 (PDT) Subject: Storing dictionary locations as a string and using eval - alternatives? Message-ID: Hi, I have a textfile with a bunch of JSON objects, one per line. I'm looking at parsing each of these, and extract some metrics from each line. I have a dict called "metrics_to_extract", containing the metrics I'm looking at extracting. In this, I store a name used to identify the metric, along with the location in the parsed JSON object. Below is my code: >>>>>>>>>>>>>>>>>>>>>>> metrics_to_extract = { 'current_connections': "server_status_json['connections']['current']", 'resident_memory': "server_status_json['mem']['resident']" } def add_point(name, value, timestamp, tags): return { "measurement": name, "tags": tags, # "time": timestamp.isoformat(), "time": timestamp, "fields": { "value": float(value) } } with open(input_file, 'r') as f: json_points = [] for line in f: if line.startswith("{"): server_status_json = json.loads(line) # pp.pprint(server_status_json) # import ipdb; ipdb.set_trace() timestamp = server_status_json['localTime'] tags = { 'project': project, 'hostname': server_status_json['host'], 'version': server_status_json['version'], 'storage_engine': server_status_json['storageEngine']['name'] } for key, value in metrics_to_extract.items(): json_points.append(add_point(key, eval(value), timestamp, tags)) # client.write_points(json_points) else: print("non matching line") >>>>>>>>>>>>>>>>>>>>>>> My question is - I'm using "eval" in the above, with the nested location (e.g. "server_status_json['mem']['resident']") stored as a string. I get the feeling this isn't particularly idiomatic or a great way of doing it - and would be keen to hear alternative suggestions? Thanks, Victor From steve+comp.lang.python at pearwood.info Thu Aug 20 00:43:55 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 20 Aug 2015 14:43:55 +1000 Subject: Storing dictionary locations as a string and using eval - alternatives? References: Message-ID: <55d55b0c$0$2736$c3e8da3$76491128@news.astraweb.com> On Thursday 20 August 2015 13:59, Victor Hooi wrote: > Hi, > > I have a textfile with a bunch of JSON objects, one per line. > > I'm looking at parsing each of these, and extract some metrics from each > line. > > I have a dict called "metrics_to_extract", containing the metrics I'm > looking at extracting. In this, I store a name used to identify the > metric, along with the location in the parsed JSON object. > > Below is my code: > >>>>>>>>>>>>>>>>>>>>>>>> > metrics_to_extract = { > 'current_connections': "server_status_json['connections']['current']", > 'resident_memory': "server_status_json['mem']['resident']" > } > > > def add_point(name, value, timestamp, tags): > return { > "measurement": name, > "tags": tags, > # "time": timestamp.isoformat(), > "time": timestamp, > "fields": { > "value": float(value) > } > } The function name is misleading and you should consider changing it. Misleading names make code harder to understand and maintain. The function doesn't "add point" at all, that implies that it should modify some data structure by adding (appending?) a point to it. Instead, it generates a dict containing (I presume) a data point. But moving on... Change metrics_to_extract above to this: metrics_to_extract = { 'current_connections': ['connections', 'current'], 'resident_memory': ['mem', 'resident'], } add this helper function: def get_nested_items(obj, *names): """Return obj[name][name2] ... [nameN] for any list of names.""" for name in names: obj = obj[name] return obj and modify the code below as shown: > with open(input_file, 'r') as f: > json_points = [] > for line in f: > if line.startswith("{"): [...] > for key, value in metrics_to_extract.items(): > json_points.append(add_point(key, eval(value), timestamp, > tags)) for key, names in metrics_to_extract.items(): value = get_nested_items(server_status_json, *names) point = add_point(key, value, timestamp, tags) json_points.append(point) -- Steven From dieter at handshake.de Thu Aug 20 01:57:57 2015 From: dieter at handshake.de (dieter) Date: Thu, 20 Aug 2015 07:57:57 +0200 Subject: Storing dictionary locations as a string and using eval - alternatives? References: Message-ID: <87r3myv6vu.fsf@handshake.de> Victor Hooi writes: > ... I did not read your message body - just your "subject". Instead of (the potentially insecure) "eval", I use "json.loads" (combined with a "json.dumps" to get the "json" representation). See the "json" module documentation. From __peter__ at web.de Thu Aug 20 03:14:31 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 20 Aug 2015 09:14:31 +0200 Subject: Storing dictionary locations as a string and using eval - alternatives? References: <87r3myv6vu.fsf@handshake.de> Message-ID: dieter wrote: > Victor Hooi writes: >> ... > I did not read your message body - just your "subject". That was a mistake ;) > Instead of (the potentially insecure) "eval", I use "json.loads" > (combined with a "json.dumps" to get the "json" representation). > See the "json" module documentation. From skip.montanaro at gmail.com Thu Aug 20 09:54:53 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 20 Aug 2015 08:54:53 -0500 Subject: Check if dictionary empty with == {} In-Reply-To: <55d546a5$0$1564$c3e8da3$5496439d@news.astraweb.com> References: <55d546a5$0$1564$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 19, 2015 at 10:16 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > So maybe it's a micro-optimization? Note, however, that the original post compared "mydict == {}" with "not mydict". In that case, it's decidedly not an optimization: firefly% python2.7 -m timeit -s "mydict = {1:2}" "if mydict == {}: pass" 10000000 loops, best of 3: 0.0508 usec per loop firefly% python2.7 -m timeit -s "mydict = {1:2}" "if not mydict: pass" 10000000 loops, best of 3: 0.0246 usec per loop Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From davros at bellaliant.net Thu Aug 20 11:12:37 2015 From: davros at bellaliant.net (John McKenzie) Date: Thu, 20 Aug 2015 15:12:37 GMT Subject: RPI.GPIO Help References: Message-ID: Thanks for the reply. Also, thanks to Laura who replied via email. Tried a bunch of things based off these comments and I always ended up with one of two situations, the channel conflict error, or an instant run and quit issue. This new version of the code runs but is unresponsive. I removed loops then put in a short sleep loop. while True: time.sleep(0.1) It could be my hardware is done up wrong, but it looks OK. Perhaps it is always sleeping. Anyone at all know about GPIO and the Pi under the Python library RPi.GPIO please feel free to advise as to what the problem is most likely to be. import atexit import time from blinkstick import blinkstick import RPi.GPIO as GPIO led = blinkstick.find_first() colour = 0 timered = 0 timeyellow = 0 timeblue = 0 timestamp = time.strftime("%H:%M:%S") GPIO.setmode(GPIO.BCM) GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) def red_button(channel): colour = 1 while colour == 1: print "Red Button pressed" timered += 1 def yellow_button(channel): colour = 2 while colour == 2: print "Yellow Button pressed" timeyellow += 1 def blue_button(channel): colour = 3 while colour == 3: print "Blue Button pressed" timeblue += 1 GPIO.add_event_detect(23, GPIO.RISING, callback=yellow_button, bouncetime=200) GPIO.add_event_detect(22, GPIO.RISING, callback=red_button, bouncetime=200) GPIO.add_event_detect(24, GPIO.RISING, callback=blue_button, bouncetime=200) while True: time.sleep(0.1) def exit_handler(): print '\033[0;41;37mRed Team:\033[0m ', timered print '\033[0;103;30mYellow Team:\033[0m ', timeyellow print '\033[0;44;37mBlue Team:\033[0m ', timeblue flog = open('flag1log.text', 'a') flog.write(timestamp + '\n' + 'Red Team: ' + str(timered) + '\n' + 'Yellow Team: ' + str(timeyellow) + '\n' + 'Blue Team: ' + str(timeblue) + '\n') flog.close() atexit.register(exit_handler) GPIO.cleanup() Thanks. From python at mrabarnett.plus.com Thu Aug 20 11:45:53 2015 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 20 Aug 2015 16:45:53 +0100 Subject: RPI.GPIO Help In-Reply-To: References: Message-ID: <55D5F631.7020901@mrabarnett.plus.com> On 2015-08-20 16:12, John McKenzie wrote: > > Thanks for the reply. Also, thanks to Laura who replied via email. > > Tried a bunch of things based off these comments and I always ended up > with one of two situations, the channel conflict error, or an instant run > and quit issue. This new version of the code runs but is unresponsive. I > removed loops then put in a short sleep loop. while True: > time.sleep(0.1) It could be my hardware is done up wrong, but it > looks OK. Perhaps it is always sleeping. > > Anyone at all know about GPIO and the Pi under the Python library > RPi.GPIO please feel free to advise as to what the problem is most likely > to be. > > > import atexit > import time > from blinkstick import blinkstick > import RPi.GPIO as GPIO > > led = blinkstick.find_first() > colour = 0 > timered = 0 > timeyellow = 0 > timeblue = 0 > timestamp = time.strftime("%H:%M:%S") > > > > GPIO.setmode(GPIO.BCM) > GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) > GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) > GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) > > > > def red_button(channel): > colour = 1 > while colour == 1: > print "Red Button pressed" > timered += 1 > > > def yellow_button(channel): > colour = 2 > while colour == 2: > print "Yellow Button pressed" > timeyellow += 1 > > > def blue_button(channel): > colour = 3 > while colour == 3: > print "Blue Button pressed" > timeblue += 1 > > GPIO.add_event_detect(23, GPIO.RISING, callback=yellow_button, > bouncetime=200) > GPIO.add_event_detect(22, GPIO.RISING, callback=red_button, > bouncetime=200) > GPIO.add_event_detect(24, GPIO.RISING, callback=blue_button, > bouncetime=200) > > while True: > time.sleep(0.1) > > def exit_handler(): > print '\033[0;41;37mRed Team:\033[0m ', timered > print '\033[0;103;30mYellow Team:\033[0m ', timeyellow > print '\033[0;44;37mBlue Team:\033[0m ', timeblue > flog = open('flag1log.text', 'a') > flog.write(timestamp + '\n' + 'Red Team: ' + str(timered) + '\n' + > 'Yellow Team: ' + str(timeyellow) + '\n' + 'Blue Team: ' + str(timeblue) > + '\n') > flog.close() > atexit.register(exit_handler) > GPIO.cleanup() > > The function 'red_button' will be called when a rising edge is detected. In that function, you're assigning to 'colour' but not changing it in the loop, so it's basically just a busy loop. However, you're trying to change 'timered', which is a global variable, but you're not declaring it as global, so that will raise UnboundLocalError. Similar remarks apply to the other two callbacks. I think you'd be better off detecting both the rising and falling edges, with a callback for each, recording when each edge occurred (duration of press = time of falling edge - time of rising edge). From alister.nospam.ware at ntlworld.com Thu Aug 20 11:54:21 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 20 Aug 2015 15:54:21 +0000 (UTC) Subject: RPI.GPIO Help References: Message-ID: On Thu, 20 Aug 2015 16:45:53 +0100, MRAB wrote: > On 2015-08-20 16:12, John McKenzie wrote: >> >> Thanks for the reply. Also, thanks to Laura who replied via email. >> >> Tried a bunch of things based off these comments and I always ended >> up >> with one of two situations, the channel conflict error, or an instant >> run and quit issue. This new version of the code runs but is >> unresponsive. I removed loops then put in a short sleep loop. while >> True: >> time.sleep(0.1) It could be my hardware is done up wrong, but it >> looks OK. Perhaps it is always sleeping. >> >> Anyone at all know about GPIO and the Pi under the Python library >> RPi.GPIO please feel free to advise as to what the problem is most >> likely to be. >> >> >> import atexit import time from blinkstick import blinkstick import >> RPi.GPIO as GPIO >> >> led = blinkstick.find_first() >> colour = 0 timered = 0 timeyellow = 0 timeblue = 0 timestamp = >> time.strftime("%H:%M:%S") >> >> >> >> GPIO.setmode(GPIO.BCM) >> GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) >> GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) >> GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) >> >> >> >> def red_button(channel): >> colour = 1 while colour == 1: >> print "Red Button pressed" timered += 1 >> >> >> def yellow_button(channel): >> colour = 2 while colour == 2: >> print "Yellow Button pressed" >> timeyellow += 1 >> >> >> def blue_button(channel): >> colour = 3 while colour == 3: >> print "Blue Button pressed" timeblue += 1 >> >> GPIO.add_event_detect(23, GPIO.RISING, callback=yellow_button, >> bouncetime=200) >> GPIO.add_event_detect(22, GPIO.RISING, callback=red_button, >> bouncetime=200) >> GPIO.add_event_detect(24, GPIO.RISING, callback=blue_button, >> bouncetime=200) >> >> while True: >> time.sleep(0.1) >> >> def exit_handler(): >> print '\033[0;41;37mRed Team:\033[0m ', timered print >> '\033[0;103;30mYellow Team:\033[0m ', timeyellow print >> '\033[0;44;37mBlue Team:\033[0m ', timeblue flog = >> open('flag1log.text', 'a') >> flog.write(timestamp + '\n' + 'Red Team: ' + str(timered) + '\n' + >> 'Yellow Team: ' + str(timeyellow) + '\n' + 'Blue Team: ' + >> str(timeblue) + '\n') >> flog.close() >> atexit.register(exit_handler) >> GPIO.cleanup() >> >> > The function 'red_button' will be called when a rising edge is detected. > > In that function, you're assigning to 'colour' but not changing it in > the loop, so it's basically just a busy loop. However, you're trying to > change 'timered', which is a global variable, but you're not declaring > it as global, so that will raise UnboundLocalError. > > Similar remarks apply to the other two callbacks. > > I think you'd be better off detecting both the rising and falling edges, > with a callback for each, recording when each edge occurred (duration of > press = time of falling edge - time of rising edge). you may also find it more useful to post this to Comp.sys.raspberry_pi the python skills may not be quite as in depth as here but they will know more about the raspberry hardware -- The easiest way to get the root password is to become system admin. -- Unknown source From laurent.pointal at free.fr Thu Aug 20 11:56:50 2015 From: laurent.pointal at free.fr (Laurent Pointal) Date: Thu, 20 Aug 2015 17:56:50 +0200 Subject: Check if dictionary empty with == {} References: Message-ID: <55d5f8c3$0$3039$426a34cc@news.free.fr> Anton wrote: > Probably a silly question. > Let's say I have a dictionary mydict and I need to test if a dictionary is > empty. > > I would use > > if not mydict: > """do something""" > > But I just came across a line of code like: > > if mydict == {}: > """do something""" > > which seems odd to me, but maybe there is a valid use case, thus I decided > to ask the community. > > Thanks. You can also use: if len(mydict) == 0: "do something" The form 'if not mydict:' is AMA the more pythonic, but it may be a source of question for beginners (what is the boolean meaning of a dictionnary?). A+ Laurent. From steve at pearwood.info Thu Aug 20 13:44:02 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 21 Aug 2015 03:44:02 +1000 Subject: Check if dictionary empty with == {} References: <55d546a5$0$1564$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55d611e1$0$1641$c3e8da3$5496439d@news.astraweb.com> On Thu, 20 Aug 2015 11:54 pm, Skip Montanaro wrote: > On Wed, Aug 19, 2015 at 10:16 PM, Steven D'Aprano < > steve+comp.lang.python at pearwood.info> wrote: > >> So maybe it's a micro-optimization? > > > Note, however, that the original post compared "mydict == {}" with "not > mydict". In that case, it's decidedly not an optimization: > > firefly% python2.7 -m timeit -s "mydict = {1:2}" "if mydict == {}: pass" > 10000000 loops, best of 3: 0.0508 usec per loop > firefly% python2.7 -m timeit -s "mydict = {1:2}" "if not mydict: pass" > 10000000 loops, best of 3: 0.0246 usec per loop I suppose it depends on whether you want to run the "if" block when mydict is None, 0, [], "", etc. Testing for "any Falsey value" and "an empty dict" are not the same, naturally they will perform differently. -- Steven From fabiofz at gmail.com Thu Aug 20 14:22:50 2015 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 20 Aug 2015 15:22:50 -0300 Subject: PyDev 4.3.0 released Message-ID: Release Highlights: ------------------------------- * Fixed parser for Python 3.x to support async and await as regular names too (PyDev-593). * The new search dialog now has a 'whole word' option which automatically adds `*` to the search * Search backend updated to Lucene 5.2.1 (instant searches on huge codebases) * When bringing up the search dialog the search text is initially selected. What is PyDev? --------------------------- PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com What is LiClipse? --------------------------- LiClipse is a PyDev standalone with goodies such as support for Multiple cursors, theming, TextMate bundles and a number of other languages such as Django Templates, Jinja2, Kivy Language, Mako Templates, Html, Javascript, etc. It's also a commercial counterpart which helps supporting the development of PyDev. Details on LiClipse: http://www.liclipse.com/ Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer LiClipse http://www.liclipse.com PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com PyVmMonitor - Python Profiler http://www.pyvmmonitor.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip.montanaro at gmail.com Thu Aug 20 14:40:31 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 20 Aug 2015 13:40:31 -0500 Subject: Check if dictionary empty with == {} In-Reply-To: <55d611e1$0$1641$c3e8da3$5496439d@news.astraweb.com> References: <55d546a5$0$1564$c3e8da3$5496439d@news.astraweb.com> <55d611e1$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Aug 20, 2015 at 12:44 PM, Steven D'Aprano wrote: > Testing for "any Falsey value" and "an empty dict" are not the same, > naturally they will perform differently. Sure, but the OP's original note explicitly said he had a dict and asked how to test if it was empty. He was used to seeing/using "not mydict", but had recently encountered "mydict == {}". Given those preconditions, the correct answer is that "not mydict" is the way to go (idiomatic Python). Using "mydict == {}" is clearly suboptimal. Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From Cecil at decebal.nl Fri Aug 21 02:11:47 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 21 Aug 2015 08:11:47 +0200 Subject: SQLite3 and web server Message-ID: <87pp2hp3vg.fsf@Equus.decebal.nl> At the moment I serve a AngularJS web application with: python3 -m http-server This only servers static html pages with the data contained in js files, like: $scope.links = [ { desc: 'Album', url: 'https://plus.google.com/collection/MuwPX' }, { desc: 'Heron Sunbathing', url: 'https://plus.google.com/+CecilWesterhof/posts/bHvSzBGobEj' }, { desc: 'Heron Fishing', url: 'https://plus.google.com/+CecilWesterhof/posts/TY3asc5oCnB' }, { desc: 'Water Lily', url: 'https://plus.google.com/+CecilWesterhof/posts/AtTwhL8SdnH' }, { desc: 'Tree at Pond', url: 'https://plus.google.com/+CecilWesterhof/posts/TyiZbUWdnrm' }, { desc: 'Fish', url: 'https://plus.google.com/+CecilWesterhof/posts/MoQ7vXs8HqP' }, { desc: 'Fountain', url: 'https://plus.google.com/+CecilWesterhof/posts/BDYkPKSMUwZ' }, { desc: 'Digitalis', url: 'https://plus.google.com/+CecilWesterhof/posts/ed3ZGNzb8kM' }, { desc: 'Sunset', url: 'https://plus.google.com/+CecilWesterhof/posts/DPbHHSFXBY4' }, { desc: 'Digitalis 2', url: 'https://plus.google.com/+CecilWesterhof/posts/ZZtSUwNb6RC' }, { desc: 'Water Lilies', url: 'https://plus.google.com/+CecilWesterhof/posts/LY62DqLEJhG' }, { desc: 'Flower', url: 'https://plus.google.com/+CecilWesterhof/posts/XFKyTcoakcy' }, { desc: 'Waterfalls', url: 'https://plus.google.com/+CecilWesterhof/posts/bfg5irDAn2T' }, { desc: 'Frogs', url: 'https://plus.google.com/+CecilWesterhof/posts/jKr5B6EQyo1' }, { desc: 'Flowers', url: 'https://plus.google.com/+CecilWesterhof/posts/iPQbBrTbcnm' }, { desc: 'Sheep', url: 'https://plus.google.com/+CecilWesterhof/posts/3a2mBo7om4H' }, { desc: 'Beetle', url: 'https://plus.google.com/+CecilWesterhof/posts/KnNtis2Gqxf' }, { desc: 'Dove', url: 'https://plus.google.com/+CecilWesterhof/posts/XA5RcC2Cxbv' }, { desc: 'City Walk', url: 'https://plus.google.com/+CecilWesterhof/posts/R9me9AKQC6n' }, { desc: 'Boar', url: 'https://plus.google.com/+CecilWesterhof/posts/9bfpBiQPYen' }, { desc: 'Bird', url: 'https://plus.google.com/+CecilWesterhof/posts/X6gFE3oxXLY' }, { desc: 'Goose', url: 'https://plus.google.com/+CecilWesterhof/posts/H4w6JvnQkcU' }, { desc: 'On mothers wings', url: 'https://plus.google.com/+CecilWesterhof/posts/PY4Nm1TASvx' }, { desc: 'Flowers', url: 'https://plus.google.com/+CecilWesterhof/posts/9o1i2NgoSfV' }, ] I would like to retrieve the information out a SQLite3 database. I did some Googling, but until now I did not find something useful. How would I implement this? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From steve at pearwood.info Fri Aug 21 02:50:29 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 21 Aug 2015 16:50:29 +1000 Subject: SQLite3 and web server References: <87pp2hp3vg.fsf@Equus.decebal.nl> Message-ID: <55d6ca35$0$1665$c3e8da3$5496439d@news.astraweb.com> On Fri, 21 Aug 2015 04:11 pm, Cecil Westerhof wrote: > At the moment I serve a AngularJS web application with: > python3 -m http-server > > This only servers static html pages with the data contained in js > files, Ah, so you're one of *them*. People who serve static content out of Javascript, instead of HTML, so that the website is broken and unusable in browsers without JS, and those with JS turned off. > I would like to retrieve the information out a SQLite3 database. I did > some Googling, but until now I did not find something useful. How > would I implement this? I feel that by answering this question, I'm in the same position as someone telling terrorists how best to build a dirty bomb. Oh well. https://docs.python.org/3/library/sqlite3.html But surely you need to find out how to access Sqlite from Javascript, not Python? This doesn't seem to be related to Python in any way. Just because the web server is written in Python doesn't mean that it's a Python problem. Your web page is generated from Javascript, not Python. Making-the-Internet-a-worse-place-one-piece-of-Javascript-at-a-time-ly y'rs, -- Steven From Cecil at decebal.nl Fri Aug 21 03:13:56 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 21 Aug 2015 09:13:56 +0200 Subject: SQLite3 and web server References: <87pp2hp3vg.fsf@Equus.decebal.nl> <55d6ca35$0$1665$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87lhd5p0zv.fsf@Equus.decebal.nl> On Friday 21 Aug 2015 08:50 CEST, Steven D'Aprano wrote: >> I would like to retrieve the information out a SQLite3 database. I >> did some Googling, but until now I did not find something useful. >> How would I implement this? > > I feel that by answering this question, I'm in the same position as > someone telling terrorists how best to build a dirty bomb. Oh well. > > https://docs.python.org/3/library/sqlite3.html > > But surely you need to find out how to access Sqlite from > Javascript, not Python? This doesn't seem to be related to Python in > any way. Just because the web server is written in Python doesn't > mean that it's a Python problem. Your web page is generated from > Javascript, not Python. I know how to work with SQLite. What I do not know how to make a python web-server that accepts a request from the JavaScript code and responds with data from the SQLite3 database. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From rosuav at gmail.com Fri Aug 21 03:27:10 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Aug 2015 17:27:10 +1000 Subject: SQLite3 and web server In-Reply-To: <87lhd5p0zv.fsf@Equus.decebal.nl> References: <87pp2hp3vg.fsf@Equus.decebal.nl> <55d6ca35$0$1665$c3e8da3$5496439d@news.astraweb.com> <87lhd5p0zv.fsf@Equus.decebal.nl> Message-ID: On Fri, Aug 21, 2015 at 5:13 PM, Cecil Westerhof wrote: > I know how to work with SQLite. What I do not know how to make a > python web-server that accepts a request from the JavaScript code and > responds with data from the SQLite3 database. The request from JS will be some sort of HTTP transaction. It'll be AJAX or similar, and to your web server, it'll simply be another page request. (You might be using a method other than GET/POST (which are the only two that regular page loads use), but it's still a standard HTTP request.) You then respond to that request with data that you got from the database. Check out this video from PyCon. Its main thrust is "here's why websockets are great, and why other technologies are insufficient", but the background info is a tidy summary of how the web works. https://www.youtube.com/watch?v=u5QT3luWx7w ChrisA From __peter__ at web.de Fri Aug 21 05:32:51 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 21 Aug 2015 11:32:51 +0200 Subject: SQLite3 and web server References: <87pp2hp3vg.fsf@Equus.decebal.nl> Message-ID: Cecil Westerhof wrote: > At the moment I serve a AngularJS web application with: > python3 -m http-server > > This only servers static html pages with the data contained in js > files, like: > $scope.links = [ > { desc: 'Album', url: > { 'https://plus.google.com/collection/MuwPX' > { }, desc: 'Heron Sunbathing', url: > I would like to retrieve the information out a SQLite3 database. I did > some Googling, but until now I did not find something useful. How > would I implement this? I like bottle for (not much) dabbling around with generated html. Assuming there is an sqlite database "links.sqlite" with a table "links" featuring columns "desc" and "url" you get a traditional html page built on the fly from the data in that table with the code shown below. Producing JSON is also demonstrated. Integrating the JSON data is a matter of the javascript framework; google found http://api.jquery.com/jquery.getjson/. $ cat serve.py #!/usr/bin/env python3 import bottle import json import sqlite3 from contextlib import contextmanager @contextmanager def open_db(): db = sqlite3.connect("links.sqlite") cs = db.cursor() try: yield cs finally: db.close() def read_links(): with open_db() as cs: return cs.execute("select desc, url from links;").fetchall() TEMPLATE = """ "Links as found in the db % for desc, url in rows: {{desc}}
% end """ @bottle.route("/links") def links_as_html(): rows = read_links() return bottle.template(TEMPLATE, rows=rows) @bottle.route("/links/data") def links_as_json(): bottle.response.content_type = "application/json" return json.dumps([ {"desc": desc, "url": url} for desc, url in read_links()], indent=4) if __name__ == "__main__": bottle.run(host="localhost", port=8080) [Instead of the following commandline gymnastics you can just invoke the script with $ python3 serve.py and then point your browser to http://localhost:8080/links] $ python3 serve.py 2>/dev/null & [1] 8418 $ curl http://localhost:8080/links 2>/dev/null | head "Links as found in the db Album
Heron Sunbathing
Heron Fishing
Water Lily
Tree at Pond
Fish
Fountain
Digitalis
Sunset
Digitalis 2
Water Lilies
Flower
Waterfalls
Frogs
$ curl http://localhost:8080/links/data 2>/dev/null | head [ { "desc": "Album", "url": "https://plus.google.com/collection/MuwPX" }, { "desc": "Heron Sunbathing", "url": "https://plus.google.com/+CecilWesterhof/posts/bHvSzBGobEj" }, { "desc": "Heron Fishing", "url": "https://plus.google.com/+CecilWesterhof/posts/TY3asc5oCnB" }, { "desc": "Water Lily", "url": "https://plus.google.com/+CecilWesterhof/posts/AtTwhL8SdnH" }, { "desc": "Tree at Pond", "url": "https://plus.google.com/+CecilWesterhof/posts/TyiZbUWdnrm" From Cecil at decebal.nl Fri Aug 21 05:44:15 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 21 Aug 2015 11:44:15 +0200 Subject: SQLite3 and web server References: <87pp2hp3vg.fsf@Equus.decebal.nl> <55d6ca35$0$1665$c3e8da3$5496439d@news.astraweb.com> <87lhd5p0zv.fsf@Equus.decebal.nl> Message-ID: <87h9ntou1c.fsf@Equus.decebal.nl> On Friday 21 Aug 2015 09:27 CEST, Chris Angelico wrote: > On Fri, Aug 21, 2015 at 5:13 PM, Cecil Westerhof wrote: >> I know how to work with SQLite. What I do not know how to make a >> python web-server that accepts a request from the JavaScript code >> and responds with data from the SQLite3 database. > > The request from JS will be some sort of HTTP transaction. It'll be > AJAX or similar, and to your web server, it'll simply be another > page request. (You might be using a method other than GET/POST > (which are the only two that regular page loads use), but it's still > a standard HTTP request.) You then respond to that request with data > that you got from the database. > > Check out this video from PyCon. Its main thrust is "here's why > websockets are great, and why other technologies are insufficient", > but the background info is a tidy summary of how the web works. > > https://www.youtube.com/watch?v=u5QT3luWx7w Interesting, but it does not help me. I need to know how to server data from SQLite instead of static files. I understood that CGI is old school and should not be used anymore, but I tried it anyway. (Because that is the only thing I found.) I use the following script: ======================================================================== #!/usr/bin/env python3 import http.server import os import socketserver import sys os.chdir(os.path.dirname(os.path.abspath(sys.argv[0]))) PORT = 8000 Handler = http.server.CGIHTTPRequestHandler httpd = socketserver.TCPServer(('', PORT), Handler) print('serving at port {0}'.format(PORT)) httpd.serve_forever() ======================================================================== In cgi-bin I have the script helloTxt.py, which contains: ======================================================================== #!/usr/bin/env python3 print('Content-type: text/plain\n\n') print ('Hello World!\n') ======================================================================== My static files are handled correctly, but when I enter: localhost:8000/cgi-bin/helloTxt.py I get: ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 49380) Traceback (most recent call last): File "/usr/lib64/python3.4/socketserver.py", line 305, in _handle_request_noblock self.process_request(request, client_address) File "/usr/lib64/python3.4/socketserver.py", line 331, in process_request self.finish_request(request, client_address) File "/usr/lib64/python3.4/socketserver.py", line 344, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/lib64/python3.4/socketserver.py", line 665, in __init__ self.handle() File "/usr/lib64/python3.4/http/server.py", line 398, in handle self.handle_one_request() File "/usr/lib64/python3.4/http/server.py", line 386, in handle_one_request method() File "/usr/lib64/python3.4/http/server.py", line 677, in do_GET f = self.send_head() File "/usr/lib64/python3.4/http/server.py", line 961, in send_head return self.run_cgi() File "/usr/lib64/python3.4/http/server.py", line 1051, in run_cgi env['SERVER_NAME'] = self.server.server_name AttributeError: 'TCPServer' object has no attribute 'server_name' ---------------------------------------- -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From torriem at gmail.com Fri Aug 21 10:19:50 2015 From: torriem at gmail.com (Michael Torrie) Date: Fri, 21 Aug 2015 08:19:50 -0600 Subject: SQLite3 and web server In-Reply-To: <87h9ntou1c.fsf@Equus.decebal.nl> References: <87pp2hp3vg.fsf@Equus.decebal.nl> <55d6ca35$0$1665$c3e8da3$5496439d@news.astraweb.com> <87lhd5p0zv.fsf@Equus.decebal.nl> <87h9ntou1c.fsf@Equus.decebal.nl> Message-ID: <55D73386.3020208@gmail.com> On 08/21/2015 03:44 AM, Cecil Westerhof wrote: > Interesting, but it does not help me. I need to know how to server > data from SQLite instead of static files. Is your program already working with data coming from your Python dict? If so, you would just replace the python dict lookups with a call to SQLite3's function to perform a query on the database. You say you already know how to work with SQLite, so I assume this is what you're doing. http://raspberrywebserver.com/sql-databases/accessing-an-sqlite-database-with-python.html As to the traceback you reported, I don't know enough about using http.server and socketserver to answer. Typically web development in Python is done via WSGI protocol, in conjunction with a web server like Apache using mod_wsgi[1], which is available in most distro's repos. But of course you can use straight CGI with Apache too. Probably this is the easiest way for you to get started. Don't try to run your own http server. That's just a waste of time and effort. Run the CGIs under Apache. Google for Apache CGI to get info on how to set up apache to execute CGI scripts (in any language). [1] https://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide From torriem at gmail.com Fri Aug 21 10:57:04 2015 From: torriem at gmail.com (Michael Torrie) Date: Fri, 21 Aug 2015 08:57:04 -0600 Subject: SQLite3 and web server In-Reply-To: <55D73386.3020208@gmail.com> References: <87pp2hp3vg.fsf@Equus.decebal.nl> <55d6ca35$0$1665$c3e8da3$5496439d@news.astraweb.com> <87lhd5p0zv.fsf@Equus.decebal.nl> <87h9ntou1c.fsf@Equus.decebal.nl> <55D73386.3020208@gmail.com> Message-ID: <55D73C40.20002@gmail.com> On 08/21/2015 08:19 AM, Michael Torrie wrote: > But of course you can use straight CGI with Apache too. Probably this > is the easiest way for you to get started. Don't try to run your own > http server. That's just a waste of time and effort. Run the CGIs under > Apache. Google for Apache CGI to get info on how to set up apache to > execute CGI scripts (in any language). On second thought, maybe your original course of action is better, though I don't know the cause of the errors you are seeing. From Cecil at decebal.nl Fri Aug 21 11:12:57 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 21 Aug 2015 17:12:57 +0200 Subject: SQLite3 and web server References: <87pp2hp3vg.fsf@Equus.decebal.nl> Message-ID: <87d1ygptdy.fsf@Equus.decebal.nl> On Friday 21 Aug 2015 11:32 CEST, Peter Otten wrote: > Cecil Westerhof wrote: > >> At the moment I serve a AngularJS web application with: >> python3 -m http-server >> >> This only servers static html pages with the data contained in js >> files, like: >> $scope.links = [ >> { desc: 'Album', url: >> { 'https://plus.google.com/collection/MuwPX' >> { }, desc: 'Heron Sunbathing', url: > >> I would like to retrieve the information out a SQLite3 database. I >> did some Googling, but until now I did not find something useful. >> How would I implement this? > > I like bottle for (not much) dabbling around with generated html. > Assuming there is an sqlite database "links.sqlite" with a table > "links" featuring columns "desc" and "url" you get a traditional > html page built on the fly from the data in that table with the code > shown below. Producing JSON is also demonstrated. Thanks. I made a first try: https://github.com/CecilWesterhof/PublishedPhotos The thing I do not like is that all my static files have to be put in /static/, but I think I can life with it. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From rambiusparkisanius at gmail.com Fri Aug 21 11:17:32 2015 From: rambiusparkisanius at gmail.com (rambius) Date: Fri, 21 Aug 2015 08:17:32 -0700 (PDT) Subject: Parametrized Unit Tests Message-ID: Hello, I am running one and the same unit tests that test some web application. I would like to execute them against different servers that may host different instances of the application. So far I have something like #!/usr/bin/env python import unittest server = "" user = "" password = "" class MyTest(unittest.TestCase): def setUp(self): global server global user global password self.conn = MyConnection(server, user, password) def test_1(self): result = run_smth_1(self.conn) verify_smth_1(result) def test_2(self): result = run_smth_2(self.conn) verify_smth_2(result) def tearDown(self): self.conn.close() if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-u', '--user', default=getpass.getuser()) parser.add_argument('-p', '--password') parser.add_argument('-s', '--server') args = parser.parse_args() server = args.server user = args.user password = args.password unittest.main() Is there a better a way to pass the server, the user and the password to the test without resolving to global variables? Although I developed these tests as unit tests they are more of integration tests. Is there an integration testing framework that supports a more convenient passing of test parameters / data? Thank you in advance for your responses. Regards Rambius From Cecil at decebal.nl Fri Aug 21 11:23:04 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 21 Aug 2015 17:23:04 +0200 Subject: SQLite3 and web server References: <87pp2hp3vg.fsf@Equus.decebal.nl> <55d6ca35$0$1665$c3e8da3$5496439d@news.astraweb.com> <87lhd5p0zv.fsf@Equus.decebal.nl> <87h9ntou1c.fsf@Equus.decebal.nl> Message-ID: <878u94psx3.fsf@Equus.decebal.nl> On Friday 21 Aug 2015 16:19 CEST, Michael Torrie wrote: > On 08/21/2015 03:44 AM, Cecil Westerhof wrote: >> Interesting, but it does not help me. I need to know how to server >> data from SQLite instead of static files. > > Is your program already working with data coming from your Python > dict? If so, you would just replace the python dict lookups with a > call to SQLite3's function to perform a query on the database. You > say you already know how to work with SQLite, so I assume this is > what you're doing. > > http://raspberrywebserver.com/sql-databases/accessing-an-sqlite-database-with-python.html > > As to the traceback you reported, I don't know enough about using > http.server and socketserver to answer. Typically web development in > Python is done via WSGI protocol, in conjunction with a web server > like Apache using mod_wsgi[1], which is available in most distro's > repos. > > But of course you can use straight CGI with Apache too. Probably > this is the easiest way for you to get started. Don't try to run > your own http server. That's just a waste of time and effort. Run > the CGIs under Apache. Google for Apache CGI to get info on how to > set up apache to execute CGI scripts (in any language). > > [1] https://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide I did manage to get something working: https://github.com/CecilWesterhof/PublishedPhotos -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From lac at openend.se Fri Aug 21 11:42:26 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 21 Aug 2015 17:42:26 +0200 Subject: Parametrized Unit Tests In-Reply-To: References: Message-ID: <201508211542.t7LFgQrQ003481@fido.openend.se> In a message of Fri, 21 Aug 2015 08:17:32 -0700, rambius writes: >Although I developed these tests as unit tests they are more of integration tests. Is there an integration testing framework that supports a more convenient passing of test parameters / data? > >Thank you in advance for your responses. > >Regards >Rambius Many. https://wiki.python.org/moin/PythonTestingToolsTaxonomy isn't a bad place to start looking, but things have been developed which aren't there. ie responses http://cramer.io/2014/05/20/mocking-requests-with-responses/ nice thing for mocking requests, if you are using the requests library ... You may get a better response if you try that question over here: http://lists.idyll.org/listinfo/testing-in-python Laura From Cecil at decebal.nl Fri Aug 21 12:39:28 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 21 Aug 2015 18:39:28 +0200 Subject: Every character of a string becomes a binding Message-ID: <871tewppdr.fsf@Equus.decebal.nl> I have the following with sqlite3: urls = c.execute('SELECT URL FROM LINKS WHERE URL = ?', url).fetchall() But this gives: Traceback (most recent call last): File "./createDB.py", line 52, in urls = c.execute('SELECT URL FROM LINKS WHERE URL = ?', url).fetchall() sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 40 supplied. The number of bindings is the length of the string. What is happening here? Why is every character of the string seen as a binding, instead of the string being the binding? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From zachary.ware+pylist at gmail.com Fri Aug 21 12:50:19 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Fri, 21 Aug 2015 11:50:19 -0500 Subject: Every character of a string becomes a binding In-Reply-To: <871tewppdr.fsf@Equus.decebal.nl> References: <871tewppdr.fsf@Equus.decebal.nl> Message-ID: On Fri, Aug 21, 2015 at 11:39 AM, Cecil Westerhof wrote: > I have the following with sqlite3: > urls = c.execute('SELECT URL FROM LINKS WHERE URL = ?', url).fetchall() > > But this gives: > Traceback (most recent call last): > File "./createDB.py", line 52, in > urls = c.execute('SELECT URL FROM LINKS WHERE URL = ?', url).fetchall() > sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 40 supplied. > > The number of bindings is the length of the string. > What is happening here? Why is every character of the string seen as a > binding, instead of the string being the binding? Because the execute method expects the bindings to be passed as a sequence, which means to pass a single binding you need to wrap it in a sequence: `c.execute('SELECT url FROM links WHERE url = ?', (url,))` -- Zach From gordon at panix.com Fri Aug 21 13:02:21 2015 From: gordon at panix.com (John Gordon) Date: Fri, 21 Aug 2015 17:02:21 +0000 (UTC) Subject: Every character of a string becomes a binding References: <871tewppdr.fsf@Equus.decebal.nl> Message-ID: In <871tewppdr.fsf at Equus.decebal.nl> Cecil Westerhof writes: > I have the following with sqlite3: > urls = c.execute('SELECT URL FROM LINKS WHERE URL = ?', url).fetchall() > But this gives: > Traceback (most recent call last): > File "./createDB.py", line 52, in > urls = c.execute('SELECT URL FROM LINKS WHERE URL = ?', url).fetchall() > sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 40 supplied. > The number of bindings is the length of the string. > What is happening here? Why is every character of the string seen as a > binding, instead of the string being the binding? The second argument to execute() is supposed to be a sequence (usually a tuple) containing the items to be used a parameters in the SQL statement. You're probably defining url like this: url = 'http://somewhere.com/something' But it should be: url = ('http://somewhere.com/something', ) In which case, I wouldn't call it "url", but rather "args" or something like that. To answer your stated question: a string *is* a sequence, so technically you're passing the correct sort of object as the second argument to execute(). But the SQL statement only asks for one parameter, so sqlite is wondering where it should put the other 39 items. -- 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 Cecil at decebal.nl Fri Aug 21 13:04:24 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 21 Aug 2015 19:04:24 +0200 Subject: Every character of a string becomes a binding References: <871tewppdr.fsf@Equus.decebal.nl> Message-ID: <87wpwoo9nr.fsf@Equus.decebal.nl> On Friday 21 Aug 2015 18:50 CEST, Zachary Ware wrote: > On Fri, Aug 21, 2015 at 11:39 AM, Cecil Westerhof wrote: >> I have the following with sqlite3: urls = c.execute('SELECT URL >> FROM LINKS WHERE URL = ?', url).fetchall() >> >> But this gives: Traceback (most recent call last): File >> "./createDB.py", line 52, in urls = c.execute('SELECT URL >> FROM LINKS WHERE URL = ?', url).fetchall() >> sqlite3.ProgrammingError: Incorrect number of bindings supplied. >> The current statement uses 1, and there are 40 supplied. >> >> The number of bindings is the length of the string. What is >> happening here? Why is every character of the string seen as a >> binding, instead of the string being the binding? > > Because the execute method expects the bindings to be passed as a > sequence, which means to pass a single binding you need to wrap it > in a sequence: `c.execute('SELECT url FROM links WHERE url = ?', > (url,))` Yeah, I found that. I solved it a little differently: urls = c.execute('SELECT URL FROM links WHERE URL = ?', [url]).fetchall() -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From alejandrogroso at hotmail.com Fri Aug 21 15:31:41 2015 From: alejandrogroso at hotmail.com (Miguel Alejandro Fernandez) Date: Fri, 21 Aug 2015 16:31:41 -0300 Subject: Bug! Message-ID: hello, python3.5rc1 when trying to install , the installer did not show the button to start installing , to click in the middle he started ; after installing I thought that everything would work fine but I could never run it, telling me ' this is not a valid Win32 application ' *use a computer with WindowsXP -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Aug 21 15:41:34 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Aug 2015 05:41:34 +1000 Subject: Bug! In-Reply-To: References: Message-ID: On Sat, Aug 22, 2015 at 5:31 AM, Miguel Alejandro Fernandez wrote: > hello, python3.5rc1 when trying to install , the installer did not show the > button to start installing , to click in the middle he started ; after > installing I thought that everything would work fine but I could never run > it, telling me ' this is not a valid Win32 application ' > > *use a computer with WindowsXP Python 3.5 does not support Windows XP. I suggest installing a better-supported operating system (or failing that, a better-supported version of your current OS). ChrisA From oscar.j.benjamin at gmail.com Fri Aug 21 16:36:57 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 21 Aug 2015 20:36:57 +0000 Subject: Bug! In-Reply-To: References: Message-ID: On Fri, 21 Aug 2015 20:43 Chris Angelico wrote: On Sat, Aug 22, 2015 at 5:31 AM, Miguel Alejandro Fernandez wrote: > > *use a computer with WindowsXP Python 3.5 does not support Windows XP. I suggest installing a better-supported operating system (or failing that, a better-supported version of your current OS). Or an older version of Python. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Aug 21 17:17:25 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 21 Aug 2015 17:17:25 -0400 Subject: Bug! In-Reply-To: References: Message-ID: On 8/21/2015 4:36 PM, Oscar Benjamin wrote: > > On Fri, 21 Aug 2015 20:43 Chris Angelico > wrote: > > On Sat, Aug 22, 2015 at 5:31 AM, Miguel Alejandro Fernandez > > wrote: > > *use a computer with WindowsXP > > Python 3.5 does not support Windows XP. I suggest installing a > better-supported operating system (or failing that, a better-supported > version of your current OS). > Or an older version of Python. In particular, 3.4. -- Terry Jan Reedy From Cecil at decebal.nl Fri Aug 21 17:22:09 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 21 Aug 2015 23:22:09 +0200 Subject: Sometimes bottle takes a lot of time Message-ID: <87si7cnxq6.fsf@Equus.decebal.nl> I created a simple application with bottle: https://github.com/CecilWesterhof/PublishedPhotos But sometimes it needs a lot of time. For example: 127.0.0.1 - - [21/Aug/2015 23:16:40] "GET / HTTP/1.1" 304 0 127.0.0.1 - - [21/Aug/2015 23:16:40] "GET /static/css/default.css HTTP/1.1" 304 0 127.0.0.1 - - [21/Aug/2015 23:16:46] "GET /static/JavaScript/angular.js HTTP/1.1" 304 0 127.0.0.1 - - [21/Aug/2015 23:16:46] "GET /static/appPublishedPhotos.js HTTP/1.1" 304 0 127.0.0.1 - - [21/Aug/2015 23:16:46] "GET /links/data HTTP/1.1" 200 2884 127.0.0.1 - - [21/Aug/2015 23:16:52] "GET /versionPython HTTP/1.1" 200 5 127.0.0.1 - - [21/Aug/2015 23:16:52] "GET /versionSQLite HTTP/1.1" 200 5 Between default.css and angular.js there are six seconds. And between /links/data and /versionPytjon is again six seconds. What is happening here? Just before everything was done in a second: 127.0.0.1 - - [21/Aug/2015 23:16:22] "GET / HTTP/1.1" 200 956 127.0.0.1 - - [21/Aug/2015 23:16:22] "GET /static/css/default.css HTTP/1.1" 304 0 127.0.0.1 - - [21/Aug/2015 23:16:22] "GET /static/appPublishedPhotos.js HTTP/1.1" 304 0 127.0.0.1 - - [21/Aug/2015 23:16:22] "GET /static/JavaScript/angular.js HTTP/1.1" 304 0 127.0.0.1 - - [21/Aug/2015 23:16:23] "GET /versionPython HTTP/1.1" 200 5 127.0.0.1 - - [21/Aug/2015 23:16:23] "GET /links/data HTTP/1.1" 200 2884 127.0.0.1 - - [21/Aug/2015 23:16:23] "GET /versionSQLite HTTP/1.1" 200 5 -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From appthought1 at gmail.com Fri Aug 21 17:26:36 2015 From: appthought1 at gmail.com (appthought1 at gmail.com) Date: Fri, 21 Aug 2015 14:26:36 -0700 (PDT) Subject: Python Developer- Houston, TX Message-ID: <0acdc603-1901-454d-b95c-b142fc6661eb@googlegroups.com> Hi, Hope you are doing well !!! My name is Siva and I'm a recruiter at TheAppliedthought , a global staffing and IT consulting company. Please find the below job description which may suits any of your consultants who are available in market or who are looking for change, please send me latest updated resume along with contact details and expected hourly rate to my email id siva at theappliedthought.com or you can reach me on 407-574-7610. Position: Python Developer Location: Houston, TX Duration: Long Term Job Description * 6+ years of experience with Linux/UNIX Systems Administration * 2+ years of Openstack Experience * Hypervisor KVM, BIOS, Firmware update * Storage Technologies (NAS, SAN & Cloud Storage) * Experience with configuration management tools (Chef expert!!) * Analytical problem-solving and conceptual skills * Strong scripting and/or development chops (Ruby, Python, Bash, Perl) * Experience with database technologies (MySQL, Percona, MongoDB) * Experience with automation (Chef etc.) and monitoring (Nagios, etc.) technologies in production setting * Experience with networking technologies including TCP/IP VPN DNS routing firewalls VLAN. * Excellent communication skills * Excellent team player Thanks & Regards Siva Executive-Talent Acquisition & Bench Sales Email: siva at theappliedthought.com IM: malladi sivaramakrishna88 Phone: 407-574-7610 Fax: 407-641-8184 From rgaddi at technologyhighland.invalid Fri Aug 21 17:32:46 2015 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Fri, 21 Aug 2015 21:32:46 +0000 (UTC) Subject: Python Developer- [LOCATION DELETED] References: <0acdc603-1901-454d-b95c-b142fc6661eb@googlegroups.com> Message-ID: On Fri, 21 Aug 2015 14:26:36 -0700, appthought1 wrote: > Hi, > Hope you are doing well !!! > My name is Siva and I'm a recruiter at TheAppliedthought , a global > staffing and IT consulting company. Siva seems to have no professional regrets about spamming people on a worldwide professional mailing list. TheAppliedthought, as a recruiting agency, therefore, is either fundamentally incompetent or completely divorced from ethics. In either case, please remember TheAppliedthought as a company that you should under no circumstances use for your recruiting needs. > expected hourly rate to my email id siva at theappliedthought.com or you > can reach me on 407-574-7610. Please feel free to send unsolicited offers for genital enlargement and 30% APR credit cards to the above addresses. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From g.starck at gmail.com Fri Aug 21 17:55:19 2015 From: g.starck at gmail.com (gst) Date: Fri, 21 Aug 2015 14:55:19 -0700 (PDT) Subject: Sometimes bottle takes a lot of time In-Reply-To: <87si7cnxq6.fsf@Equus.decebal.nl> References: <87si7cnxq6.fsf@Equus.decebal.nl> Message-ID: What if you try with all the SQLite code commented ? From hamilton at nothere.com Fri Aug 21 18:42:03 2015 From: hamilton at nothere.com (hamilton) Date: Fri, 21 Aug 2015 16:42:03 -0600 Subject: Bug! In-Reply-To: References: Message-ID: On 8/21/2015 1:41 PM, Chris Angelico wrote: > Python 3.5 does not support Windows XP. Is there a simple explanation for this ? Or is it just is. From zachary.ware+pylist at gmail.com Fri Aug 21 19:07:56 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Fri, 21 Aug 2015 18:07:56 -0500 Subject: Bug! In-Reply-To: References: Message-ID: On Fri, Aug 21, 2015 at 5:42 PM, hamilton wrote: > On 8/21/2015 1:41 PM, Chris Angelico wrote: >> >> Python 3.5 does not support Windows XP. > > > Is there a simple explanation for this ? > > Or is it just is. We don't see the need to be burdened by supporting versions of Windows that are no longer supported by Microsoft in new versions of Python. Versions of Python whose initial release occurred during the support period of a particular version of Windows will always support that version of Windows, though (for example, Python 3.4 will always support XP, Python 2.7 will always support XP and even Windows 2000). Python 3.3 dropped support for Windows 2000, Python 3.5 drops support for XP and Server 2003, and Windows Vista will be unsupported by Python 3.7. See also PEP 11. -- Zach From sohcahtoa82 at gmail.com Fri Aug 21 19:53:05 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Fri, 21 Aug 2015 16:53:05 -0700 (PDT) Subject: Bug! In-Reply-To: References: Message-ID: <2a6a9035-33bb-42a0-a034-027fbb873872@googlegroups.com> On Friday, August 21, 2015 at 3:42:36 PM UTC-7, hamilton wrote: > On 8/21/2015 1:41 PM, Chris Angelico wrote: > > Python 3.5 does not support Windows XP. > > Is there a simple explanation for this ? > > Or is it just is. I have no relationship with the Python developers, but I would say that running such an old operating system is simply irresponsible due to security issues and should be discouraged in any way possible. Windows XP is 14 years old. In the computing world, that's *ancient*. It's time to upgrade and join the modern world. From rosuav at gmail.com Fri Aug 21 21:02:32 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Aug 2015 11:02:32 +1000 Subject: Bug! In-Reply-To: <2a6a9035-33bb-42a0-a034-027fbb873872@googlegroups.com> References: <2a6a9035-33bb-42a0-a034-027fbb873872@googlegroups.com> Message-ID: On Sat, Aug 22, 2015 at 9:53 AM, wrote: > On Friday, August 21, 2015 at 3:42:36 PM UTC-7, hamilton wrote: >> On 8/21/2015 1:41 PM, Chris Angelico wrote: >> > Python 3.5 does not support Windows XP. >> >> Is there a simple explanation for this ? >> >> Or is it just is. > > I have no relationship with the Python developers, but I would say that running such an old operating system is simply irresponsible due to security issues and should be discouraged in any way possible. > > Windows XP is 14 years old. In the computing world, that's *ancient*. It's time to upgrade and join the modern world. The security concerns of XP aren't Python's problem, and Python isn't in the business of twisting people's arms to make them upgrade just for the sake of upgrading. However, every new version of Windows introduces new APIs and features, so maintaining support for an older version means ignoring all features added since then; conversely, dropping support for XP means taking advantage of anything that was added in Vista. That's why the change in support. ChrisA From rosuav at gmail.com Fri Aug 21 21:03:25 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Aug 2015 11:03:25 +1000 Subject: Every character of a string becomes a binding In-Reply-To: References: <871tewppdr.fsf@Equus.decebal.nl> Message-ID: On Sat, Aug 22, 2015 at 10:47 AM, Dennis Lee Bieber wrote: > On Fri, 21 Aug 2015 18:39:28 +0200, Cecil Westerhof > declaimed the following: > >>I have the following with sqlite3: >>urls = c.execute('SELECT URL FROM LINKS WHERE URL = ?', url).fetchall() >> > Well, for one complication... You are asking for the very information > you are providing... > > select URL field > where the URL field is equal to some value. > > What do you really expect from that? If the table has multiple records > with the same URL value, you will get multiple copies of the same URL. More likely, it's a simple question: "Do you have this URL in your links?". If you get back a single row, the answer is yes; if you get back no rows, the answer is no. ChrisA From ben+python at benfinney.id.au Fri Aug 21 21:42:50 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 22 Aug 2015 11:42:50 +1000 Subject: Parametrized Unit Tests References: Message-ID: <85wpwodrol.fsf@benfinney.id.au> rambius writes: > I am running one and the same unit tests that test some web > application. I would like to execute them against different servers > that may host different instances of the application. Those aren't unit tests, then. A unit test, by definition, tests a small unit of code; usually one true-or-false assertion about one function call. What you describe sounds more like integration tests or feature tests or acceptance tests; something where large parts of the code base are all exercised at once. > Is there a better a way to pass the server, the user and the password > to the test without resolving to global variables? The ?testscenarios? library is one way to have a set of scenarios applied at run-time to produce tests across all combinations . > Although I developed these tests as unit tests they are more of > integration tests. Is there an integration testing framework that > supports a more convenient passing of test parameters / data? You may want to look at behaviour-driven testing, e.g. using Behave . Another resource to use is the ?testing-in-python? forum where there is more focussed discussion on testing in Python. -- \ ?Repetition leads to boredom, boredom to horrifying mistakes, | `\ horrifying mistakes to God-I-wish-I-was-still-bored, and it | _o__) goes downhill from there.? ?Will Larson, 2008-11-04 | Ben Finney From rustompmody at gmail.com Sat Aug 22 00:37:46 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 21 Aug 2015 21:37:46 -0700 (PDT) Subject: Bug! In-Reply-To: References: <2a6a9035-33bb-42a0-a034-027fbb873872@googlegroups.com> Message-ID: <8d78aea8-ca82-41a5-89c0-697e4698e771@googlegroups.com> On Saturday, August 22, 2015 at 6:32:56 AM UTC+5:30, Chris Angelico wrote: > On Sat, Aug 22, 2015 at 9:53 AM, sohcahtoa82 wrote: > > On Friday, August 21, 2015 at 3:42:36 PM UTC-7, hamilton wrote: > >> On 8/21/2015 1:41 PM, Chris Angelico wrote: > >> > Python 3.5 does not support Windows XP. > >> > >> Is there a simple explanation for this ? > >> > >> Or is it just is. > > > > I have no relationship with the Python developers, but I would say that running such an old operating system is simply irresponsible due to security issues and should be discouraged in any way possible. > > > > Windows XP is 14 years old. In the computing world, that's *ancient*. It's time to upgrade and join the modern world. > > The security concerns of XP aren't Python's problem, and Python isn't > in the business of twisting people's arms to make them upgrade just > for the sake of upgrading. However, every new version of Windows > introduces new APIs and features, so maintaining support for an older > version means ignoring all features added since then; conversely, > dropping support for XP means taking advantage of anything that was > added in Vista. That's why the change in support. And it can cost a pretty penny: when someone upgrades from XP (say) to something modern like Windows 10 it almost certainly requires buying a new machine. One of the charms of linux used to be (dunno how true today) that it could run reasonably well on extremely underpowered hardware From rosuav at gmail.com Sat Aug 22 01:16:22 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Aug 2015 15:16:22 +1000 Subject: Bug! In-Reply-To: <8d78aea8-ca82-41a5-89c0-697e4698e771@googlegroups.com> References: <2a6a9035-33bb-42a0-a034-027fbb873872@googlegroups.com> <8d78aea8-ca82-41a5-89c0-697e4698e771@googlegroups.com> Message-ID: On Sat, Aug 22, 2015 at 2:37 PM, Rustom Mody wrote: > One of the charms of linux used to be (dunno how true today) that it could > run reasonably well on extremely underpowered hardware Still true, although it's not so much "Linux is better than Windows" as "Linux is more modular than Windows, so you can omit the bits you don't want". If you grab a default Ubuntu install, it'll demand a certain amount of RAM and CPU and so on; but if you're running it on a low-end system, you can kick off some of the heaviest parts (usually the pretty graphics), either manually or by grabbing a dedicated low-end-system distro like AntiX. ChrisA From hamilton at nothere.com Sat Aug 22 01:26:59 2015 From: hamilton at nothere.com (hamilton) Date: Fri, 21 Aug 2015 23:26:59 -0600 Subject: Bug! In-Reply-To: References: <2a6a9035-33bb-42a0-a034-027fbb873872@googlegroups.com> Message-ID: On 8/21/2015 7:02 PM, Chris Angelico wrote: > On Sat, Aug 22, 2015 at 9:53 AM, wrote: >> On Friday, August 21, 2015 at 3:42:36 PM UTC-7, hamilton wrote: >>> On 8/21/2015 1:41 PM, Chris Angelico wrote: >>>> Python 3.5 does not support Windows XP. >>> >>> Is there a simple explanation for this ? >>> >>> Or is it just is. >> >> I have no relationship with the Python developers, but I would say that running such an old operating system is simply irresponsible due to security issues and should be discouraged in any way possible. >> >> Windows XP is 14 years old. In the computing world, that's *ancient*. It's time to upgrade and join the modern world. > > The security concerns of XP aren't Python's problem, and Python isn't > in the business of twisting people's arms to make them upgrade just > for the sake of upgrading. However, every new version of Windows > introduces new APIs and features, so maintaining support for an older > version means ignoring all features added since then; conversely, > dropping support for XP means taking advantage of anything that was > added in Vista. That's why the change in support. > > ChrisA > Thank You ChrisA, this make the best sense. From ali_ranjbar174 at hotmail.com Sat Aug 22 02:53:21 2015 From: ali_ranjbar174 at hotmail.com (ali ranjbar) Date: Sat, 22 Aug 2015 06:53:21 +0000 Subject: Qestion Message-ID: hi dear friend I have python version 2.4.3 Which version of PIL is appropriate for me and how can I add it to my systems? Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sat Aug 22 03:49:05 2015 From: __peter__ at web.de (Peter Otten) Date: Sat, 22 Aug 2015 09:49:05 +0200 Subject: Sometimes bottle takes a lot of time References: <87si7cnxq6.fsf@Equus.decebal.nl> Message-ID: Cecil Westerhof wrote: > I created a simple application with bottle: > https://github.com/CecilWesterhof/PublishedPhotos > > But sometimes it needs a lot of time. For example: > 127.0.0.1 - - [21/Aug/2015 23:16:40] "GET / HTTP/1.1" 304 0 > 127.0.0.1 - - [21/Aug/2015 23:16:40] "GET /static/css/default.css > HTTP/1.1" 304 0 127.0.0.1 - - [21/Aug/2015 23:16:46] "GET > /static/JavaScript/angular.js HTTP/1.1" 304 0 127.0.0.1 - - [21/Aug/2015 > 23:16:46] "GET /static/appPublishedPhotos.js HTTP/1.1" 304 0 127.0.0.1 - - > [21/Aug/2015 23:16:46] "GET /links/data HTTP/1.1" 200 2884 127.0.0.1 - - > [21/Aug/2015 23:16:52] "GET /versionPython HTTP/1.1" 200 5 127.0.0.1 - - > [21/Aug/2015 23:16:52] "GET /versionSQLite HTTP/1.1" 200 5 > > Between default.css and angular.js there are six seconds. And between > /links/data and /versionPytjon is again six seconds. What is happening > here? I don't know. Is it bottle, or the browser, or something completely different that eats the extra time? > Just before everything was done in a second: > 127.0.0.1 - - [21/Aug/2015 23:16:22] "GET / HTTP/1.1" 200 956 > 127.0.0.1 - - [21/Aug/2015 23:16:22] "GET /static/css/default.css > HTTP/1.1" 304 0 127.0.0.1 - - [21/Aug/2015 23:16:22] "GET > /static/appPublishedPhotos.js HTTP/1.1" 304 0 127.0.0.1 - - [21/Aug/2015 > 23:16:22] "GET /static/JavaScript/angular.js HTTP/1.1" 304 0 127.0.0.1 - - > [21/Aug/2015 23:16:23] "GET /versionPython HTTP/1.1" 200 5 127.0.0.1 - - > [21/Aug/2015 23:16:23] "GET /links/data HTTP/1.1" 200 2884 127.0.0.1 - - > [21/Aug/2015 23:16:23] "GET /versionSQLite HTTP/1.1" 200 5 > From __peter__ at web.de Sat Aug 22 03:51:21 2015 From: __peter__ at web.de (Peter Otten) Date: Sat, 22 Aug 2015 09:51:21 +0200 Subject: SQLite3 and web server References: <87pp2hp3vg.fsf@Equus.decebal.nl> <87d1ygptdy.fsf@Equus.decebal.nl> Message-ID: Cecil Westerhof wrote: > Thanks. I made a first try: > https://github.com/CecilWesterhof/PublishedPhotos > > The thing I do not like is that all my static files have to be put in > /static/, but I think I can life with it. Is that really required by bottle? Where would you like to put the files? From dfnsonfsduifb at gmx.de Sat Aug 22 05:41:56 2015 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sat, 22 Aug 2015 11:41:56 +0200 Subject: Sometimes bottle takes a lot of time In-Reply-To: <87si7cnxq6.fsf@Equus.decebal.nl> References: <87si7cnxq6.fsf@Equus.decebal.nl> Message-ID: On 21.08.2015 23:22, Cecil Westerhof wrote: > Just before everything was done in a second: Since you're on GitHub, why don't you git bisect and find out where you screwed up instead of trying to get people to remotely debug and profile your broken code? Cheers, 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 Sat Aug 22 05:45:54 2015 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sat, 22 Aug 2015 11:45:54 +0200 Subject: Every character of a string becomes a binding In-Reply-To: <87wpwoo9nr.fsf@Equus.decebal.nl> References: <871tewppdr.fsf@Equus.decebal.nl> <87wpwoo9nr.fsf@Equus.decebal.nl> Message-ID: On 21.08.2015 19:04, Cecil Westerhof wrote: >> Because the execute method expects the bindings to be passed as a >> sequence, > > Yeah, I found that. I solved it a little differently: > urls = c.execute('SELECT URL FROM links WHERE URL = ?', [url]).fetchall() You continuously ask more than amateurish questions here and frequently, after having received dozens of helpful and quick replies you respond with "yeah, I found that" or similar. Wouldn't it be advisable to tinker with your code roughly 10 more minutes the next time you run into an amateur's problem instead of firing off a Usenet post, oh very wise Senior Software Engineer? Cheers, 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 Cecil at decebal.nl Sat Aug 22 07:28:35 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sat, 22 Aug 2015 13:28:35 +0200 Subject: Sometimes bottle takes a lot of time References: <87si7cnxq6.fsf@Equus.decebal.nl> Message-ID: <87io87o93w.fsf@Equus.decebal.nl> On Saturday 22 Aug 2015 11:41 CEST, Johannes Bauer wrote: > On 21.08.2015 23:22, Cecil Westerhof wrote: > >> Just before everything was done in a second: > > Since you're on GitHub, why don't you git bisect and find out where > you screwed up instead of trying to get people to remotely debug and > profile your broken code? Are you beaten up by your wife that you need to be this harsh? If you would have taken a little more time you would have seen that there where 20 seconds between both logs. I am fast, but not that fast. It is exactly the same code. I suppose it has to do something with bottle. Something I use since yesterday. Is it that strange to look if someone else has had the same problem and maybe a solution? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Sat Aug 22 07:34:52 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sat, 22 Aug 2015 13:34:52 +0200 Subject: Sometimes bottle takes a lot of time References: <87si7cnxq6.fsf@Equus.decebal.nl> Message-ID: <87egivo8tf.fsf@Equus.decebal.nl> On Friday 21 Aug 2015 23:55 CEST, gst wrote: > What if you try with all the SQLite code commented ? I do not think that is the problem. First of all I do not think receiving 25 records takes 6 seconds. Secondly the first part is: 127.0.0.1 - - [21/Aug/2015 23:16:40] "GET / HTTP/1.1" 304 0 127.0.0.1 - - [21/Aug/2015 23:16:40] "GET /static/css/default.css HTTP/1.1" 304 0 127.0.0.1 - - [21/Aug/2015 23:16:46] "GET /static/JavaScript/angular.js HTTP/1.1" 304 0 127.0.0.1 - - [21/Aug/2015 23:16:46] "GET /static/appPublishedPhotos.js HTTP/1.1" 304 0 There is no SQLite code at all there. Only Not Modified replies. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Sat Aug 22 07:37:32 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sat, 22 Aug 2015 13:37:32 +0200 Subject: Sometimes bottle takes a lot of time References: <87si7cnxq6.fsf@Equus.decebal.nl> Message-ID: <87a8tjo8oz.fsf@Equus.decebal.nl> On Saturday 22 Aug 2015 09:49 CEST, Peter Otten wrote: > Cecil Westerhof wrote: > >> I created a simple application with bottle: >> https://github.com/CecilWesterhof/PublishedPhotos >> >> But sometimes it needs a lot of time. For example: 127.0.0.1 - - >> [21/Aug/2015 23:16:40] "GET / HTTP/1.1" 304 0 127.0.0.1 - - >> [21/Aug/2015 23:16:40] "GET /static/css/default.css HTTP/1.1" 304 0 >> 127.0.0.1 - - [21/Aug/2015 23:16:46] "GET >> /static/JavaScript/angular.js HTTP/1.1" 304 0 127.0.0.1 - - >> [21/Aug/2015 23:16:46] "GET /static/appPublishedPhotos.js HTTP/1.1" >> 304 0 127.0.0.1 - - [21/Aug/2015 23:16:46] "GET /links/data >> HTTP/1.1" 200 2884 127.0.0.1 - - [21/Aug/2015 23:16:52] "GET >> /versionPython HTTP/1.1" 200 5 127.0.0.1 - - [21/Aug/2015 23:16:52] >> "GET /versionSQLite HTTP/1.1" 200 5 >> >> Between default.css and angular.js there are six seconds. And >> between /links/data and /versionPytjon is again six seconds. What >> is happening here? > > I don't know. Is it bottle, or the browser, or something completely > different that eats the extra time? I really do not know. I suspect bottle, but I am new to this, so I value the suspicion of someone who has more experience more. :-D >> Just before everything was done in a second: 127.0.0.1 - - >> [21/Aug/2015 23:16:22] "GET / HTTP/1.1" 200 956 127.0.0.1 - - >> [21/Aug/2015 23:16:22] "GET /static/css/default.css HTTP/1.1" 304 0 >> 127.0.0.1 - - [21/Aug/2015 23:16:22] "GET >> /static/appPublishedPhotos.js HTTP/1.1" 304 0 127.0.0.1 - - >> [21/Aug/2015 23:16:22] "GET /static/JavaScript/angular.js HTTP/1.1" >> 304 0 127.0.0.1 - - [21/Aug/2015 23:16:23] "GET /versionPython >> HTTP/1.1" 200 5 127.0.0.1 - - [21/Aug/2015 23:16:23] "GET >> /links/data HTTP/1.1" 200 2884 127.0.0.1 - - [21/Aug/2015 23:16:23] >> "GET /versionSQLite HTTP/1.1" 200 5 >> -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Sat Aug 22 07:38:42 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sat, 22 Aug 2015 13:38:42 +0200 Subject: SQLite3 and web server References: <87pp2hp3vg.fsf@Equus.decebal.nl> <55d6ca35$0$1665$c3e8da3$5496439d@news.astraweb.com> <87lhd5p0zv.fsf@Equus.decebal.nl> <87h9ntou1c.fsf@Equus.decebal.nl> <55D73386.3020208@gmail.com> Message-ID: <876147o8n1.fsf@Equus.decebal.nl> On Friday 21 Aug 2015 16:57 CEST, Michael Torrie wrote: > On 08/21/2015 08:19 AM, Michael Torrie wrote: >> But of course you can use straight CGI with Apache too. Probably >> this is the easiest way for you to get started. Don't try to run >> your own http server. That's just a waste of time and effort. Run >> the CGIs under Apache. Google for Apache CGI to get info on how to >> set up apache to execute CGI scripts (in any language). > > On second thought, maybe your original course of action is better, > though I don't know the cause of the errors you are seeing. I switched to bottle. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Sat Aug 22 07:41:20 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sat, 22 Aug 2015 13:41:20 +0200 Subject: SQLite3 and web server References: <87pp2hp3vg.fsf@Equus.decebal.nl> <87d1ygptdy.fsf@Equus.decebal.nl> Message-ID: <87y4h3mty7.fsf@Equus.decebal.nl> On Saturday 22 Aug 2015 09:51 CEST, Peter Otten wrote: > Cecil Westerhof wrote: > >> Thanks. I made a first try: >> https://github.com/CecilWesterhof/PublishedPhotos >> >> The thing I do not like is that all my static files have to be put >> in /static/, but I think I can life with it. > > Is that really required by bottle? Where would you like to put the > files? That is how I interpret this: http://bottlepy.org/docs/dev/tutorial.html#routing-static-files -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From dfnsonfsduifb at gmx.de Sat Aug 22 08:09:14 2015 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sat, 22 Aug 2015 14:09:14 +0200 Subject: Sometimes bottle takes a lot of time In-Reply-To: <87io87o93w.fsf@Equus.decebal.nl> References: <87si7cnxq6.fsf@Equus.decebal.nl> <87io87o93w.fsf@Equus.decebal.nl> Message-ID: On 22.08.2015 13:28, Cecil Westerhof wrote: > If you would have taken a little more time you would have seen that > there where 20 seconds between both logs. I am fast, but not that > fast. It is exactly the same code. I suppose it has to do something > with bottle. Something I use since yesterday. Is it that strange to > look if someone else has had the same problem and maybe a solution? So let me get your story straight: You're new to bottle and, apparently, web-programming in Python as well. You're new to sqlite. You've built some web application using both. Yesterday it worked perfectly. Today it doesn't. Obviously, you suspect bottle is at fault. Being the very wise Senior Software Engineer that you are, do you really think that mature software, programmed by people who actually know what they're doing is at fault? Or do you rather think it maybe could be the piece-of-junk demo application written by someone who has proven his utter incompetence comprehensively time and time again? Since you're the very wise Senior Software Engineer here, why don't you use an approach that every schoolkid learns in a programming class? Namely, circle the error, reproduce it reliably. Change your machine, network setup and change between your software versions. Create a minimal example that demonstrate the issue. Then, should you find one, blame bottle. Not sooner, very wise Senior Software Engineer, not sooner. Cheers, 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 __peter__ at web.de Sat Aug 22 08:23:28 2015 From: __peter__ at web.de (Peter Otten) Date: Sat, 22 Aug 2015 14:23:28 +0200 Subject: SQLite3 and web server References: <87pp2hp3vg.fsf@Equus.decebal.nl> <87d1ygptdy.fsf@Equus.decebal.nl> <87y4h3mty7.fsf@Equus.decebal.nl> Message-ID: Cecil Westerhof wrote: > On Saturday 22 Aug 2015 09:51 CEST, Peter Otten wrote: > >> Cecil Westerhof wrote: >> >>> Thanks. I made a first try: >>> https://github.com/CecilWesterhof/PublishedPhotos >>> >>> The thing I do not like is that all my static files have to be put >>> in /static/, but I think I can life with it. >> >> Is that really required by bottle? Where would you like to put the >> files? > > That is how I interpret this: > http://bottlepy.org/docs/dev/tutorial.html#routing-static-files No, /static/ is in no way special. To drive the point home here's a bogus example that gives you a random file from the ~/.thumbnails/large folder: @bottle.route("/") def random_thumbnail(path): root = os.path.expanduser("~/.thumbnails/large") name = random.choice(os.listdir(root)) return bottle.static_file(name, root=root) The path is not even taken into account. From Cecil at decebal.nl Sat Aug 22 09:09:14 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sat, 22 Aug 2015 15:09:14 +0200 Subject: Sometimes bottle takes a lot of time References: <87si7cnxq6.fsf@Equus.decebal.nl> <87io87o93w.fsf@Equus.decebal.nl> Message-ID: <87twrrmpvp.fsf@Equus.decebal.nl> On Saturday 22 Aug 2015 14:09 CEST, Johannes Bauer wrote: > On 22.08.2015 13:28, Cecil Westerhof wrote: > >> If you would have taken a little more time you would have seen that >> there where 20 seconds between both logs. I am fast, but not that >> fast. It is exactly the same code. I suppose it has to do something >> with bottle. Something I use since yesterday. Is it that strange to >> look if someone else has had the same problem and maybe a solution? > > So let me get your story straight: I wish you really meant that. You just like to bash people. I am afraid I need to ignore you. Have a happy life. Do not forget to look in the mirror. Will be painful in the short term, but very beneficial in the long term. Also: take a course in reading. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From dfnsonfsduifb at gmx.de Sat Aug 22 09:51:37 2015 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sat, 22 Aug 2015 15:51:37 +0200 Subject: Sometimes bottle takes a lot of time In-Reply-To: <87twrrmpvp.fsf@Equus.decebal.nl> References: <87si7cnxq6.fsf@Equus.decebal.nl> <87io87o93w.fsf@Equus.decebal.nl> <87twrrmpvp.fsf@Equus.decebal.nl> Message-ID: On 22.08.2015 15:09, Cecil Westerhof wrote: >> So let me get your story straight: > > I wish you really meant that. I really do, did I get it wrong at all? I really don't think that I did. > Also: take a course in reading. Maybe you, oh very wise Senior Software Engineer, should take a course in Software Engineering. You wouldn't otherwise ask embarassingly stupid questions over and over and over again. Really eats away at your seniority if you ask me. Cheers, 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 auriocus at gmx.de Sat Aug 22 10:15:18 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 22 Aug 2015 16:15:18 +0200 Subject: Sometimes bottle takes a lot of time In-Reply-To: References: <87si7cnxq6.fsf@Equus.decebal.nl> <87io87o93w.fsf@Equus.decebal.nl> <87twrrmpvp.fsf@Equus.decebal.nl> Message-ID: Am 22.08.15 um 15:51 schrieb Johannes Bauer: > On 22.08.2015 15:09, Cecil Westerhof wrote: > >>> So let me get your story straight: >> >> I wish you really meant that. > > I really do, did I get it wrong at all? I really don't think that I did. Probably yes. You should take a look at the OP again and compare the time stamps. It says that in between two consecutive calls of the same program, the request was served once in a second, and once with serious delays. Despite that the server is localhost. In between both trials there are 20 seconds. I do not see, how git bisect would help here. Note that this says nothing about the location of the bug, in can still be either in the OPs code or in the framework. Christian From torriem at gmail.com Sat Aug 22 11:33:21 2015 From: torriem at gmail.com (Michael Torrie) Date: Sat, 22 Aug 2015 09:33:21 -0600 Subject: Sometimes bottle takes a lot of time In-Reply-To: <87a8tjo8oz.fsf@Equus.decebal.nl> References: <87si7cnxq6.fsf@Equus.decebal.nl> <87a8tjo8oz.fsf@Equus.decebal.nl> Message-ID: <55D89641.9000607@gmail.com> On 08/22/2015 05:37 AM, Cecil Westerhof wrote: >> I don't know. Is it bottle, or the browser, or something completely >> different that eats the extra time? > > I really do not know. I suspect bottle, but I am new to this, so I > value the suspicion of someone who has more experience more. :-D These are requests performed from browser Javascript (ajax), right? Could you write a shell script that fetches these urls in sequence using curl or wget, simulating the web browser? This would let you check times in a controlled way, without the variable of the browser itself. While it's true this particular problem is possibly beyond the scope of this python list (and may not be python-related at all), it's too bad a couple of people have taken the time to reply to your queries to simply berate you. From rustompmody at gmail.com Sat Aug 22 12:13:31 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 22 Aug 2015 09:13:31 -0700 (PDT) Subject: Sometimes bottle takes a lot of time In-Reply-To: References: <87si7cnxq6.fsf@Equus.decebal.nl> <87a8tjo8oz.fsf@Equus.decebal.nl> Message-ID: <671e9b74-848f-47c4-92d1-192619c406c3@googlegroups.com> On Saturday, August 22, 2015 at 9:03:52 PM UTC+5:30, Michael Torrie wrote: > While it's true this particular problem is possibly beyond the scope of > this python list (and may not be python-related at all), it's too bad a > couple of people have taken the time to reply to your queries to simply > berate you. Yeah -- quite uncalled for. As for beyond scope, I believe Peter Otten recommended bottle just a few days ago. So I dont see whats improper about the question. At some point of course someone may say: "Bottle written in python doesn't mean this is a python question." If after that the questions continue and they are persistent and asinine and... then berating may be ok. Dont see that here From mail at timgolden.me.uk Sat Aug 22 13:08:28 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 22 Aug 2015 18:08:28 +0100 Subject: Bug! In-Reply-To: References: <2a6a9035-33bb-42a0-a034-027fbb873872@googlegroups.com> Message-ID: <55D8AC8C.7040307@timgolden.me.uk> On 22/08/2015 02:02, Chris Angelico wrote: > The security concerns of XP aren't Python's problem, and Python isn't > in the business of twisting people's arms to make them upgrade just > for the sake of upgrading. However, every new version of Windows > introduces new APIs and features, so maintaining support for an older > version means ignoring all features added since then; conversely, > dropping support for XP means taking advantage of anything that was > added in Vista. That's why the change in support. Thanks for saying this, Chris. Just to add, from a Python developer perspective: any system -- Microsoft or not, open or not, old or new -- which core Python supports, brings a measure of complexity to the codebase. #ifdefs, conditional LoadLibrary calls &c. From the point of view simply of the maintenance burden, less code is better. Obviously there is more to deciding on platform support than code maintenance ... This isn't some kind of political move by the Python dev team to undercut Windows users: it's entirely pragmatic. And using the Windows support calendar is a common-sense way of giving ourselves a set of cut-off dates. TJG From Cecil at decebal.nl Sat Aug 22 14:03:04 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sat, 22 Aug 2015 20:03:04 +0200 Subject: Sometimes bottle takes a lot of time References: <87si7cnxq6.fsf@Equus.decebal.nl> <87a8tjo8oz.fsf@Equus.decebal.nl> Message-ID: <87pp2fmc9z.fsf@Equus.decebal.nl> On Saturday 22 Aug 2015 17:33 CEST, Michael Torrie wrote: > On 08/22/2015 05:37 AM, Cecil Westerhof wrote: >>> I don't know. Is it bottle, or the browser, or something >>> completely different that eats the extra time? >> >> I really do not know. I suspect bottle, but I am new to this, so I >> value the suspicion of someone who has more experience more. :-D > > These are requests performed from browser Javascript (ajax), right? > Could you write a shell script that fetches these urls in sequence > using curl or wget, simulating the web browser? This would let you > check times in a controlled way, without the variable of the browser > itself. I should have thought about that myself. :-( I was already thinking about writing debug statements in the routes. By the way does anybody know what the time-stamp is: the moment the requests is received, or the moment the request is finished? I just tried it again. Two almost immediately and then a long one again. What I find very peculiarly is that every-time there is a delay, there are two delays of six seconds. > While it's true this particular problem is possibly beyond the scope > of this python list (and may not be python-related at all), it's too > bad a couple of people have taken the time to reply to your queries > to simply berate you. It could be an AngularJS problem. ;-) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From chris at cdreimer.com Sat Aug 22 15:31:18 2015 From: chris at cdreimer.com (C.D. Reimer) Date: Sat, 22 Aug 2015 12:31:18 -0700 Subject: Best strategy for testing class and subclasses in pytest? Message-ID: <55D8CE06.7030206@cdreimer.com> Greetings, I'm writing a chess engine to learn about Python classes and inheritance, and using pytest for the unit test. I've created a Piece class, which has 99% of the functionality for a chess piece, and subclass the other pieces -- Bishop, King, Knight, Pawn, Queen, Rook -- that will implement the move-specific functionality. I'm not sure what's the best strategy is for testing the class and subclasses. I initially wrote unit tests for the class and subclasses (including tests for class-only functionality). That worked well until I started refactoring code and breaking the tests. Too much copy, paste and renaming for my taste. I tried to create a separate class and/or module to import the common tests for each class and subclass. My attempts often ended in failure with the "RuntimeError: super(): no arguments" message. I couldn't find a working example on the Internet on how to do that. The pytest documentation is all over the place. Is there a way to reuse tests in pytest? Or should I test everything in the class and test only the implemented functionality in the subclasses? Thank you, Chris R. From Cecil at decebal.nl Sat Aug 22 17:06:03 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sat, 22 Aug 2015 23:06:03 +0200 Subject: Sometimes bottle takes a lot of time References: <87si7cnxq6.fsf@Equus.decebal.nl> <87a8tjo8oz.fsf@Equus.decebal.nl> <87pp2fmc9z.fsf@Equus.decebal.nl> Message-ID: <87lhd3m3t0.fsf@Equus.decebal.nl> On Saturday 22 Aug 2015 20:03 CEST, Cecil Westerhof wrote: > On Saturday 22 Aug 2015 17:33 CEST, Michael Torrie wrote: > >> On 08/22/2015 05:37 AM, Cecil Westerhof wrote: >>>> I don't know. Is it bottle, or the browser, or something >>>> completely different that eats the extra time? >>> >>> I really do not know. I suspect bottle, but I am new to this, so I >>> value the suspicion of someone who has more experience more. :-D >> >> These are requests performed from browser Javascript (ajax), right? >> Could you write a shell script that fetches these urls in sequence >> using curl or wget, simulating the web browser? This would let you >> check times in a controlled way, without the variable of the >> browser itself. > > I should have thought about that myself. :-( I used Python instead of a shell script of-course. :-P ======================================================================== #!/usr/bin/env python3 import time from urllib.request import urlopen server = 'http://localhost:8080' urls = [ '/', '/static/css/default.css', '/static/JavaScript/angular.js', '/static/appPublishedPhotos.js', '/links/data', '/versionPython', '/versionSQLite', ] for x in range(0, 10): start_time = time.time() for url in urls: print(url) urlopen(server + url).read() end_time = time.time() print('It took {0} seconds\n'.format(end_time - start_time), flush = True) time.sleep(20) ======================================================================== It is not perfect code, no error checking and the last sleep is superfluous, but for the current job good enough. I have included the output as attachment. It is clear that bottle is not the problem: fetching all the data takes at most 0.017 seconds. -------------- next part -------------- A non-text attachment was scrubbed... Name: fetch.log Type: text/x-log Size: 1656 bytes Desc: not available URL: -------------- next part -------------- So my next bet is AngularJS. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From rosuav at gmail.com Sat Aug 22 19:06:44 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Aug 2015 09:06:44 +1000 Subject: Bug! In-Reply-To: <55D8AC8C.7040307@timgolden.me.uk> References: <2a6a9035-33bb-42a0-a034-027fbb873872@googlegroups.com> <55D8AC8C.7040307@timgolden.me.uk> Message-ID: On Sun, Aug 23, 2015 at 3:08 AM, Tim Golden wrote: > On 22/08/2015 02:02, Chris Angelico wrote: >> >> The security concerns of XP aren't Python's problem, and Python isn't >> in the business of twisting people's arms to make them upgrade just >> for the sake of upgrading. However, every new version of Windows >> introduces new APIs and features, so maintaining support for an older >> version means ignoring all features added since then; conversely, >> dropping support for XP means taking advantage of anything that was >> added in Vista. That's why the change in support. > > > Thanks for saying this, Chris. Just to add, from a Python developer > perspective: any system -- Microsoft or not, open or not, old or new -- > which core Python supports, brings a measure of complexity to the codebase. > #ifdefs, conditional LoadLibrary calls &c. From the point of view simply of > the maintenance burden, less code is better. Obviously there is more to > deciding on platform support than code maintenance ... > > This isn't some kind of political move by the Python dev team to undercut > Windows users: it's entirely pragmatic. And using the Windows support > calendar is a common-sense way of giving ourselves a set of cut-off dates. > Precisely. Every time you support multiple versions of some dependency, you have to test your code on all of them, and in the common case (new features added in newer versions), you have to target the oldest and weakest version. When you're writing a Python program that has to run on CPython back as far as 2.4, there's a lot you can't do... dropping support for everything pre-2.7 lets you improve your code significantly. Does dropping support for Python 2.4 consist of "undercutting RHEL users"? Nope. It's that same pragmatism - I want a cleaner codebase. CPython 3.4 will continue to run on Windows XP. If you're still using an old Windows, you just have to keep using an old Python too. Eventually Python 3.4 will be out of support, but at that point, it's no different from the OS anyway. There's nothing stopping you from using an ancient OS, an ancient CPython, and an ancient Python application, if that's what it requires... I'm not sure what OS people are running Python 1.5 on, but if anyone complains that it doesn't install properly on Windows 10, I rather doubt that python.org will release a patch :) ChrisA From rosuav at gmail.com Sat Aug 22 19:13:14 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Aug 2015 09:13:14 +1000 Subject: Sometimes bottle takes a lot of time In-Reply-To: <87lhd3m3t0.fsf@Equus.decebal.nl> References: <87si7cnxq6.fsf@Equus.decebal.nl> <87a8tjo8oz.fsf@Equus.decebal.nl> <87pp2fmc9z.fsf@Equus.decebal.nl> <87lhd3m3t0.fsf@Equus.decebal.nl> Message-ID: On Sun, Aug 23, 2015 at 7:06 AM, Cecil Westerhof wrote: > I have included the output as attachment. It is clear that bottle is > not the problem: fetching all the data takes at most 0.017 seconds. > Something to consider: You could be running into some weird interaction of caches. Try blowing your OS and browser caches, and see what the timings are like then. Also, if you can recreate the six-second delay, I'd want to know what's happening during that time - is there an open socket between the browser and the server? Is anything pegging the CPU? Is the disk heavily active? Finding any sort of saturation would help to pin down the cause of the delay. Do you have any network mounts in your file system, and could they be delaying some stat() call somewhere? Six seconds is a lot, but I do recall running into problems occasionally when I had a NETBIOS/NETBEUI mount on one of my boxes (Linux couldn't safely cache stuff, and the remote system was misconfigured as regards caching, I think - the upshot was terrible performance in certain situations, all of it spent waiting on the network). ChrisA From breamoreboy at yahoo.co.uk Sat Aug 22 19:25:59 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 23 Aug 2015 00:25:59 +0100 Subject: Sandboxing Python Message-ID: I was always led to believe that the subject was a difficult thing to do, but here https://www.reddit.com/r/learnpython/comments/3huz4x/how_to_do_math_inside_raw_input/ is a safe solution in only 23 characters, or are there any discernable flaws in it? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Sat Aug 22 19:44:59 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Aug 2015 09:44:59 +1000 Subject: Sandboxing Python In-Reply-To: References: Message-ID: On Sun, Aug 23, 2015 at 9:25 AM, Mark Lawrence wrote: > I was always led to believe that the subject was a difficult thing to do, > but here > https://www.reddit.com/r/learnpython/comments/3huz4x/how_to_do_math_inside_raw_input/ > is a safe solution in only 23 characters, or are there any discernable flaws > in it? I'm sorry, I can't see which solution you're talking about there - maybe I just don't know how to read reddit properly. Can you paste the proposed code please? The best I can see there is "use eval but with no builtins". That's fundamentally flawed because you don't need builtins to break stuff. All you need is a literal, from which you can snag everything else via its attributes. However, for this situation, I would be recommending ast.literal_eval, which *is* safe. It's a lot more powerful than "split it into number, operator, number" as mentioned at the end, but still can't majorly break anything. ChrisA From breamoreboy at yahoo.co.uk Sat Aug 22 19:52:45 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 23 Aug 2015 00:52:45 +0100 Subject: Sandboxing Python In-Reply-To: References: Message-ID: On 23/08/2015 00:44, Chris Angelico wrote: > On Sun, Aug 23, 2015 at 9:25 AM, Mark Lawrence wrote: >> I was always led to believe that the subject was a difficult thing to do, >> but here >> https://www.reddit.com/r/learnpython/comments/3huz4x/how_to_do_math_inside_raw_input/ >> is a safe solution in only 23 characters, or are there any discernable flaws >> in it? > > > I'm sorry, I can't see which solution you're talking about there - > maybe I just don't know how to read reddit properly. Can you paste the > proposed code please? > > The best I can see there is "use eval but with no builtins". That's > fundamentally flawed because you don't need builtins to break stuff. > All you need is a literal, from which you can snag everything else via > its attributes. > > However, for this situation, I would be recommending ast.literal_eval, > which *is* safe. It's a lot more powerful than "split it into number, > operator, number" as mentioned at the end, but still can't majorly > break anything. > > ChrisA > >>> import os >>> eval("os.system('rm -rf /')", {"__builtins__":None}) Traceback (most recent call last): File "", line 1, in eval("os.system('rm -rf /')", {"__builtins__":None}) File "", line 1, in TypeError: 'NoneType' object is not subscriptable Surely I must I have missed your meaning because I needed just 23 characters and zero extra lines to create a safe sandbox for this, but you've said that the core developers have tried and failed to do this. It appears that I didn't just wipe out my entire filesystem and you've stated quite matter-of-factly that there is no safe solution... so what happened here? Why didn't my filesystem just get wiped out? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Sat Aug 22 20:04:50 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Aug 2015 10:04:50 +1000 Subject: Sandboxing Python In-Reply-To: References: Message-ID: On Sun, Aug 23, 2015 at 9:52 AM, Mark Lawrence wrote: > On 23/08/2015 00:44, Chris Angelico wrote: >> >> On Sun, Aug 23, 2015 at 9:25 AM, Mark Lawrence >> wrote: >>> >>> I was always led to believe that the subject was a difficult thing to do, >>> but here >>> >>> https://www.reddit.com/r/learnpython/comments/3huz4x/how_to_do_math_inside_raw_input/ >>> is a safe solution in only 23 characters, or are there any discernable >>> flaws >>> in it? >> >> >> >> I'm sorry, I can't see which solution you're talking about there - >> maybe I just don't know how to read reddit properly. Can you paste the >> proposed code please? >> >> The best I can see there is "use eval but with no builtins". That's >> fundamentally flawed because you don't need builtins to break stuff. >> All you need is a literal, from which you can snag everything else via >> its attributes. >> >> However, for this situation, I would be recommending ast.literal_eval, >> which *is* safe. It's a lot more powerful than "split it into number, >> operator, number" as mentioned at the end, but still can't majorly >> break anything. >> >> ChrisA >> > > >>>> import os >>>> eval("os.system('rm -rf /')", {"__builtins__":None}) > Traceback (most recent call last): > File "", line 1, in > eval("os.system('rm -rf /')", {"__builtins__":None}) > File "", line 1, in > TypeError: 'NoneType' object is not subscriptable > > > > Surely I must I have missed your meaning because I needed just 23 characters > and zero extra lines to create a safe sandbox for this, but you've said that > the core developers have tried and failed to do this. It appears that I > didn't just wipe out my entire filesystem and you've stated quite > matter-of-factly that there is no safe solution... so what happened here? > Why didn't my filesystem just get wiped out? > Got it, thanks. The answer is: It's easy to make something you can't yourself break out of. It just means you don't know all the tricks. http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html >>> cmd="""[c for c in ().__class__.__base__.__subclasses__() if c.__name__ == 'catch_warnings'][0]()._module.__builtins__["__import__"]("os").system("echo Hello")""" >>> eval(cmd,{"__builtins__":None}) Hello 0 Et voila. Arbitrary module loading, arbitrary code execution, have fun. ChrisA From Cecil at decebal.nl Sat Aug 22 20:51:55 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sun, 23 Aug 2015 02:51:55 +0200 Subject: Sometimes bottle takes a lot of time References: <87si7cnxq6.fsf@Equus.decebal.nl> <87a8tjo8oz.fsf@Equus.decebal.nl> <87pp2fmc9z.fsf@Equus.decebal.nl> <87lhd3m3t0.fsf@Equus.decebal.nl> Message-ID: <87a8tin7x0.fsf@Equus.decebal.nl> On Sunday 23 Aug 2015 01:13 CEST, Chris Angelico wrote: > On Sun, Aug 23, 2015 at 7:06 AM, Cecil Westerhof wrote: >> I have included the output as attachment. It is clear that bottle >> is not the problem: fetching all the data takes at most 0.017 >> seconds. >> > > Something to consider: You could be running into some weird > interaction of caches. Try blowing your OS and browser caches, and > see what the timings are like then. Also, if you can recreate the > six-second delay, I'd want to know what's happening during that time > - is there an open socket between the browser and the server? Is > anything pegging the CPU? Is the disk heavily active? Finding any > sort of saturation would help to pin down the cause of the delay. Do > you have any network mounts in your file system, and could they be > delaying some stat() call somewhere? Six seconds is a lot, but I do > recall running into problems occasionally when I had a > NETBIOS/NETBEUI mount on one of my boxes (Linux couldn't safely > cache stuff, and the remote system was misconfigured as regards > caching, I think - the upshot was terrible performance in certain > situations, all of it spent waiting on the network). How do I see if there is an open socket? But in principal I have found the problem. (Not the reason.) The problem is Firefox. (So it is not bottle and also not AngularJS.) When using Chrome there is no problem. Not even when I do 15 times a refresh. With Firefox there is this problem. Even when I restart it. So I have found the problem and it is certainly not a Python problem. I should post it on the Firefox, but if there will be an use-full reply ? I have been reading it for a long time. And when someone mentioned that Firefox used to much CPU or memory the replies where in my opinion not very helpful. It even happens with Firefox in safe-mode. Less often and not two times, but max one time. Well, first some sleep and then trying to get something useful from the Firefox mailing-list. ;-) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From rosuav at gmail.com Sat Aug 22 21:05:02 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Aug 2015 11:05:02 +1000 Subject: Sometimes bottle takes a lot of time In-Reply-To: <87a8tin7x0.fsf@Equus.decebal.nl> References: <87si7cnxq6.fsf@Equus.decebal.nl> <87a8tjo8oz.fsf@Equus.decebal.nl> <87pp2fmc9z.fsf@Equus.decebal.nl> <87lhd3m3t0.fsf@Equus.decebal.nl> <87a8tin7x0.fsf@Equus.decebal.nl> Message-ID: On Sun, Aug 23, 2015 at 10:51 AM, Cecil Westerhof wrote: > How do I see if there is an open socket? Depends on your OS. On Linux, I can poke around in /proc or with commands like netstat and/or lsof. It may be easier to separate client and server across two computers, which would force the socket to be a "real" network connection, rather than being optimized away. > But in principal I have found the problem. (Not the reason.) The > problem is Firefox. (So it is not bottle and also not AngularJS.) When > using Chrome there is no problem. Not even when I do 15 times a > refresh. With Firefox there is this problem. Even when I restart it. Huh, interesting. I can't help there, but I wish you the very best of luck in finding it. ChrisA From simon at bleah.co.uk Sat Aug 22 21:22:51 2015 From: simon at bleah.co.uk (Simon Ward) Date: Sun, 23 Aug 2015 02:22:51 +0100 Subject: Bug! In-Reply-To: References: <2a6a9035-33bb-42a0-a034-027fbb873872@googlegroups.com> <55D8AC8C.7040307@timgolden.me.uk> Message-ID: On 23 August 2015 00:06:44 BST, Chris Angelico wrote: >Precisely. Every time you support multiple versions of some >dependency, you have to test your code on all of them, and in the >common case (new features added in newer versions), you have to target >the oldest and weakest version. Just don't add features to older versions. They're in maintenance or bugfix mode. > When you're writing a Python program >that has to run on CPython back as far as 2.4, there's a lot you can't >do... Just deprecate then drop the stuff you don't want to support any more. This is part of the standard software lifecyle to me. If you care about your users that might not be ready to upgrade provide security fixes for the older versions. If you don't care, well I wouldn't want to use your software in production. > dropping support for everything pre-2.7 lets you improve your >code significantly. Does dropping support for Python 2.4 consist of >"undercutting RHEL users"? Nope. It's that same pragmatism - I want a >cleaner codebase. RHEL 4 might still be supported (is it? haven't paid attention) but there should be no obligation to provide new features. Have a development branch or mainline, that doesn't stop you from having "stable" rele > >CPython 3.4 will continue to run on Windows XP. If you're still using >an old Windows, you just have to keep using an old Python too. >Eventually Python 3.4 will be out of support, but at that point, it's >no different from the OS anyway. There's nothing stopping you from >using an ancient OS, an ancient CPython, and an ancient Python >application, if that's what it requires... I'm not sure what OS people >are running Python 1.5 on, but if anyone complains that it doesn't >install properly on Windows 10, I rather doubt that python.org will >release a patch :) > >ChrisA -- Sent from Kaiten Mail. Please excuse my brevity. From rosuav at gmail.com Sat Aug 22 21:35:21 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Aug 2015 11:35:21 +1000 Subject: Bug! In-Reply-To: References: <2a6a9035-33bb-42a0-a034-027fbb873872@googlegroups.com> <55D8AC8C.7040307@timgolden.me.uk> Message-ID: On Sun, Aug 23, 2015 at 11:22 AM, Simon Ward wrote: > > > On 23 August 2015 00:06:44 BST, Chris Angelico wrote: >>Precisely. Every time you support multiple versions of some >>dependency, you have to test your code on all of them, and in the >>common case (new features added in newer versions), you have to target >>the oldest and weakest version. > > Just don't add features to older versions. They're in maintenance or bugfix mode. That's not what I'm talking about... I'm talking about multiple versions of a dependency. If I write a Python script, and tell people "this requires CPython 3.6 running on Linux" because that's what I run... it's not going to be easy to use. Telling people that it requires Python 3.4 or newer cuts out a lot of people, requiring 3.3 or better is going to include a lot more. It's a tradeoff between usability and cleanliness of code. ChrisA From lac at openend.se Sat Aug 22 23:57:52 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 23 Aug 2015 05:57:52 +0200 Subject: Sandboxing Python In-Reply-To: References: Message-ID: <201508230357.t7N3vqES016963@fido.openend.se> Ned Batchelder has researched this one quite a bit, see: see: http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html http://nedbatchelder.com/blog/201302/looking_for_python_3_builtins.html http://nedbatchelder.com/blog/201302/finding_python_3_builtins.html Laura From auriocus at gmx.de Sun Aug 23 01:17:33 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 23 Aug 2015 07:17:33 +0200 Subject: Sandboxing Python In-Reply-To: References: Message-ID: Am 23.08.15 um 02:04 schrieb Chris Angelico: >> >>>>> import os >>>>> eval("os.system('rm -rf /')", {"__builtins__":None}) >> Traceback (most recent call last): >> File "", line 1, in >> eval("os.system('rm -rf /')", {"__builtins__":None}) >> File "", line 1, in >> TypeError: 'NoneType' object is not subscriptable >> > > Got it, thanks. The answer is: It's easy to make something you can't > yourself break out of. It just means you don't know all the tricks. > > http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html > >>>> cmd="""[c for c in ().__class__.__base__.__subclasses__() if c.__name__ == 'catch_warnings'][0]()._module.__builtins__["__import__"]("os").system("echo Hello")""" >>>> eval(cmd,{"__builtins__":None}) > Hello > 0 > > Et voila. Arbitrary module loading, arbitrary code execution, have fun. In one of my other favourite languages, you can create sandboxes very easily. You create them as a new slave interpreter with restrictions: interp create -safe myInterp myInterp eval $userinput In addition to removing "dangerous" functions, you can limit the mount of time spent by the eval, or alias new functions to callbacks from the main interpreter (though this may break security) This was once built into it for a browser plugin (now extinct). Would it be that difficult to get the same for Python? On the C side, the interpreter is a structure and does not use global variables (as opposed to CPython), therefore it is easy to create more than one interpreter in a single program, and also to reflect that to the scripting level. Christian From rosuav at gmail.com Sun Aug 23 01:41:48 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Aug 2015 15:41:48 +1000 Subject: Sandboxing Python In-Reply-To: References: Message-ID: On Sun, Aug 23, 2015 at 3:17 PM, Christian Gollwitzer wrote: > Would it be that difficult to get the same for Python? On the C side, the > interpreter is a structure and does not use global variables (as opposed to > CPython), therefore it is easy to create more than one interpreter in a > single program, and also to reflect that to the scripting level. There have been some explorations in that direction. However, it would be very difficult to pass objects from one interpreter to the other, so you'd be restricted to some form of serialization... at which point you may as well just use a subprocess, which you can isolate using OS facilities. ChrisA From yuzhixu.ruc at gmail.com Sun Aug 23 02:10:55 2015 From: yuzhixu.ruc at gmail.com (Yuzhi Xu) Date: Sat, 22 Aug 2015 23:10:55 -0700 (PDT) Subject: how to handle cpu cache in python ( or fastest way to call a function once) Message-ID: <2aa39ddd-bb07-4a09-a046-a011e215882a@googlegroups.com> I find out that python's VM seems to be very unfriendly with CPU-Cache. see: http://stackoverflow.com/questions/32163585/how-to-handle-cpu-cache-in-python-or-fastest-way-to-call-a-function-once http://stackoverflow.com/questions/32153178/python-functionor-a-code-block-runs-much-slower-with-a-time-interval-in-a-loop for example: ******************************************* import time a = range(500) sum(a) for i in range(1000000): #just to create a time interval, seems this disturb cpu cache? pass st = time.time() sum(a) print (time.time() - st)*1e6 ********************************************* time:> 100us another case: ********************************************* import time a = range(500) for i in range(100000): st = time.time() sum(a) print (time.time() - st)*1e6 ********************************************* time:~ 20us we can see when running frequently, the code becomes much faster. is there a solution? I feel this question is very difficult. one must has indepth unstanding about the mechanism of python virtual machine, c and cpu-cache. Do you have any suggestion about where to post this question for a possible answer? From lac at openend.se Sun Aug 23 03:28:50 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 23 Aug 2015 09:28:50 +0200 Subject: Qestion In-Reply-To: References: Message-ID: <201508230728.t7N7Sorm026966@fido.openend.se> In a message of Sat, 22 Aug 2015 06:53:21 -0000, ali ranjbar writes: >hi dear friend > >I have python version 2.4.3 > >Which version of PIL is appropriate for me and how can I add it to my systems? > >Regards > >-- >https://mail.python.org/mailman/listinfo/python-list If you really have python 2.4.3 then you badly need a newer Python. However Pillow, with a version number <2.0 is promised to work for you. https://pillow.readthedocs.org/installation.html The latest 1.x version of Pillow is https://pypi.python.org/pypi/Pillow/1.7.8 so you can get this. Or did you mean that you have python 3.4.3 ? In which case you still want Pillow but this one. https://pypi.python.org/pypi/Pillow/2.9.0 And this one may already come as a package for your system, if you don't want to use pip. Laura From cs at zip.com.au Sun Aug 23 03:46:11 2015 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 23 Aug 2015 17:46:11 +1000 Subject: Qestion In-Reply-To: <201508230728.t7N7Sorm026966@fido.openend.se> References: <201508230728.t7N7Sorm026966@fido.openend.se> Message-ID: <20150823074611.GA95584@cskk.homeip.net> On 23Aug2015 09:28, Laura Creighton wrote: >In a message of Sat, 22 Aug 2015 06:53:21 -0000, ali ranjbar writes: >>I have python version 2.4.3 >>Which version of PIL is appropriate for me and how can I add it to my systems? > >If you really have python 2.4.3 then you badly need a newer Python. If he's on RedHat Linux 5 (or CentOS 5) the system Python is 2.4.3. Cheers, Cameron Simpson "How do you know I'm Mad?" asked Alice. "You must be," said the Cat, "or you wouldn't have come here." From 4kir4.1i at gmail.com Sun Aug 23 05:32:20 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Sun, 23 Aug 2015 12:32:20 +0300 Subject: Sandboxing Python References: Message-ID: <8737zafizf.fsf@gmail.com> Mark Lawrence writes: > I was always led to believe that the subject was a difficult thing to > do, but here > https://www.reddit.com/r/learnpython/comments/3huz4x/how_to_do_math_inside_raw_input/ > is a safe solution in only 23 characters, or are there any discernable > flaws in it? Related: http://stackoverflow.com/questions/2371436/evaluating-a-mathematical-expression-in-a-string From stefan_ml at behnel.de Sun Aug 23 05:54:21 2015 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 23 Aug 2015 11:54:21 +0200 Subject: how to handle cpu cache in python ( or fastest way to call a function once) In-Reply-To: <2aa39ddd-bb07-4a09-a046-a011e215882a@googlegroups.com> References: <2aa39ddd-bb07-4a09-a046-a011e215882a@googlegroups.com> Message-ID: Yuzhi Xu schrieb am 23.08.2015 um 08:10: > I find out that python's VM seems to be very unfriendly with CPU-Cache. > see: > http://stackoverflow.com/questions/32163585/how-to-handle-cpu-cache-in-python-or-fastest-way-to-call-a-function-once > http://stackoverflow.com/questions/32153178/python-functionor-a-code-block-runs-much-slower-with-a-time-interval-in-a-loop > > for example: > ******************************************* > import time > a = range(500) > > sum(a) > > for i in range(1000000): #just to create a time interval, seems this disturb cpu cache? > pass > > > st = time.time() > sum(a) > print (time.time() - st)*1e6 > > ********************************************* > time:> 100us > > > another case: > ********************************************* > import time > a = range(500) > > for i in range(100000): > st = time.time() > sum(a) > print (time.time() - st)*1e6 > > ********************************************* > time:~ 20us > > > we can see when running frequently, the code becomes much faster. That does not seem like a straight forward deduction. Especially the interpretation that the CPU caching behaviour is to blame here seems rather far fetched. My guess is that it rather has to do with CPython's internal object caching or something at that level. However, given the absolute timings above, I wouldn't bother too much finding it out. It's unlikely to hurt real-world code. (And in fact, the more interesting case where things are happing several times in a row rather than being a negligible constant one-time effort seems to be substantially faster in your timings. Congratulations!) > is there a solution? Is there a problem? Stefan From steve at pearwood.info Sun Aug 23 07:59:27 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 23 Aug 2015 21:59:27 +1000 Subject: how to handle cpu cache in python ( or fastest way to call a function once) References: <2aa39ddd-bb07-4a09-a046-a011e215882a@googlegroups.com> Message-ID: <55d9b59e$0$1652$c3e8da3$5496439d@news.astraweb.com> On Sun, 23 Aug 2015 04:10 pm, Yuzhi Xu wrote: > I find out that python's VM seems to be very unfriendly with CPU-Cache. Possibly. More comments below. > for example: > ******************************************* > import time > a = range(500) > > sum(a) > > for i in range(1000000): #just to create a time interval, seems this > disturb cpu cache? > pass > > > st = time.time() > sum(a) > print (time.time() - st)*1e6 > > ********************************************* > time:> 100us On my machine, I get about 20-25 ?s for this: (a.py contains your code above) [steve at ando ~]$ python2.7 a.py 21.9345092773 [steve at ando ~]$ python2.7 a.py 21.9345092773 [steve at ando ~]$ python2.7 a.py 24.0802764893 [steve at ando ~]$ python2.7 a.py 23.8418579102 > another case: > ********************************************* > import time > a = range(500) > > for i in range(100000): > st = time.time() > sum(a) > print (time.time() - st)*1e6 > > ********************************************* > time:~ 20us Running this as b.py, I get times of around 15?s, a bit faster than the first version, but not a factor of five times faster as you get. [steve at ando ~]$ python2.7 b.py [...] 15.0203704834 15.0203704834 25.0339508057 16.9277191162 20.0271606445 94.8905944824 15.9740447998 15.0203704834 15.0203704834 15.0203704834 15.0203704834 14.066696167 13.8282775879 15.0203704834 Traceback (most recent call last): File "b.py", line 6, in sum(a) KeyboardInterrupt Above, you say: > for i in range(1000000): #just to create a time interval, seems this > disturb cpu cache? > pass But remember that range() is a function, and so, yes, it may disturb the CPU cache. What did you expect? But I'm not sure how the CPU cache will interact with code in a high-level language like Python. I suspect that more likely, it simply has something to do with range(1000000) building an enormous list of integers. Here's another version: [steve at ando ~]$ cat c.py import time a = range(500) sum(a) for i in range(1000000): pass sum(a) st = time.time() sum(a) print (time.time() - st)*1e6 [steve at ando ~]$ python2.7 c.py 15.9740447998 And one more: [steve at ando ~]$ cat d.py import time a = range(500) sum(a) for i in xrange(1000000): # Use xrange instead of range pass st = time.time() sum(a) print (time.time() - st)*1e6 [steve at ando ~]$ python2.7 d.py 22.1729278564 [steve at ando ~]$ python2.7 d.py 23.1266021729 So... on my machine, the difference between xrange and range makes no difference: in both cases, calling sum() takes about 22?s. But calling sum() twice speeds up the second call to about 16?s, or about 25% faster. (Not 80% faster, as you find.) One last test: [steve at ando ~]$ cat e.py import time a = range(500) # Without warm-up. st = time.time() sum(a) print (time.time() - st)*1e6 # Second time, with warm-up. st = time.time() sum(a) print (time.time() - st)*1e6 # Add a delay. for i in xrange(1000): pass st = time.time() sum(a) print (time.time() - st)*1e6 st = time.time() sum(a) print (time.time() - st)*1e6 [steve at ando ~]$ python2.7 e.py 15.0203704834 15.0203704834 10.9672546387 10.9672546387 [steve at ando ~]$ python2.7 e.py 15.9740447998 12.8746032715 12.1593475342 10.9672546387 [steve at ando ~]$ python2.7 e.py 15.9740447998 20.0271606445 15.0203704834 15.9740447998 -- Steven From kmisoft at gmail.com Sun Aug 23 08:07:26 2015 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Sun, 23 Aug 2015 08:07:26 -0400 Subject: how to handle cpu cache in python ( or fastest way to call a function once) In-Reply-To: References: <2aa39ddd-bb07-4a09-a046-a011e215882a@googlegroups.com> Message-ID: Hi, >> for i in range(1000000): #just to create a time interval, seems this disturb cpu cache? >> pass Python interpreter consumes memory quite extensively because "everything is object". So constructions like: range(1000000): _take_ memory. Additionally it will trigger garbage collecting code on deallocation time so expect even more delay. To get most out of Python - all "numbers crushing" / "pixel pushing" / "store gigabytes" code should go to low-level compiled binary libraries. Vladimir https://itunes.apple.com/us/app/python-code-samples/id1025613117 From steve at pearwood.info Sun Aug 23 08:42:56 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 23 Aug 2015 22:42:56 +1000 Subject: how to handle cpu cache in python ( or fastest way to call a function once) References: <2aa39ddd-bb07-4a09-a046-a011e215882a@googlegroups.com> Message-ID: <55d9bfcf$0$1657$c3e8da3$5496439d@news.astraweb.com> On Sun, 23 Aug 2015 10:07 pm, Vladimir Ignatov wrote: > Hi, > >>> for i in range(1000000): #just to create a time interval, seems this >>> disturb cpu cache? >>> pass > > Python interpreter consumes memory quite extensively because > "everything is object". So constructions like: > > range(1000000): > > _take_ memory. Additionally it will trigger garbage collecting code > on deallocation time so expect even more delay. Normally you would be correct, but as my timing results show, using xrange instead of range does not make any difference. Whatever is going on here, it isn't as simple as "range(1000000) builds a giant list". -- Steven From Cecil at decebal.nl Sun Aug 23 08:45:45 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sun, 23 Aug 2015 14:45:45 +0200 Subject: Sometimes bottle takes a lot of time References: <87si7cnxq6.fsf@Equus.decebal.nl> <87a8tjo8oz.fsf@Equus.decebal.nl> <87pp2fmc9z.fsf@Equus.decebal.nl> <87lhd3m3t0.fsf@Equus.decebal.nl> <87a8tin7x0.fsf@Equus.decebal.nl> Message-ID: <876146mava.fsf@Equus.decebal.nl> On Sunday 23 Aug 2015 03:05 CEST, Chris Angelico wrote: >> But in principal I have found the problem. (Not the reason.) The >> problem is Firefox. (So it is not bottle and also not AngularJS.) >> When using Chrome there is no problem. Not even when I do 15 times >> a refresh. With Firefox there is this problem. Even when I restart >> it. > > Huh, interesting. I can't help there, but I wish you the very best > of luck in finding it. It looks like it is a recent problem. I also installed it on an old AcerAspire One. The fetch takes there five times as long, but fetching through Firefox is a lot faster. Not as fast as Chromium, but the difference is a lot less. But there Ice-wasel 38.0 is used instead of Firefox 40. Mozilla wants a life version. I am trying to install it on PythonAnywhere. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Sun Aug 23 09:18:53 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sun, 23 Aug 2015 15:18:53 +0200 Subject: Is this the way to go with SQLite Message-ID: <871teum9c2.fsf@Equus.decebal.nl> I understood that with sqlite3 in Python you can not use prepared statements. Below the way I solved this. Also an URL is unique, so I need to check that if it is found, the values are the same as the ones I wanted to insert. This is my code. ======================================================================== select_url = '''SELECT year , month , description FROM LINKS WHERE URL = ?''' year = 2015 month = 8 for link in links: description = link[0] url = link[1] url_values = c.execute(select_url, [url]).fetchall() if len(url_values) == 0: print('Adding {0}'.format(link)) c.execute('''INSERT INTO links (year, month, description, URL) VALUES (?, ?, ?, ?) ''', [year, month, description, url]) else: to_insert = (year, month, description) found = url_values[0] if found != to_insert: print('For {0} found {1} instead of {2}'.format(url, found, to_insert)) ======================================================================== -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From rosuav at gmail.com Sun Aug 23 10:03:53 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Aug 2015 00:03:53 +1000 Subject: Is this the way to go with SQLite In-Reply-To: <871teum9c2.fsf@Equus.decebal.nl> References: <871teum9c2.fsf@Equus.decebal.nl> Message-ID: On Sun, Aug 23, 2015 at 11:18 PM, Cecil Westerhof wrote: > Also an URL is unique, so I need to check that if it is found, the > values are the same as the ones I wanted to insert. And if they aren't? Currently, all you do is print out a message and continue on; what happens if you get the same URL coming up more than once? > select_url = '''SELECT year > , month > , description > FROM LINKS > WHERE URL = ?''' > year = 2015 > month = 8 PEP 8 has a word or two to say about this, but carry on. Incidentally, I'd be inclined to put the SELECT query down below, same as the INSERT query is; it's not in any way different from just using a string literal there, and this separates two pieces of code (IMO) unnecessarily. > for link in links: > description = link[0] > url = link[1] for description, url in links: > url_values = c.execute(select_url, [url]).fetchall() > if len(url_values) == 0: if not url_values: > print('Adding {0}'.format(link)) > c.execute('''INSERT INTO links > (year, month, description, URL) > VALUES > (?, ?, ?, ?) > ''', > [year, month, description, url]) > else: > to_insert = (year, month, description) > found = url_values[0] > if found != to_insert: > print('For {0} found {1} instead of {2}'.format(url, found, to_insert)) Otherwise, looks reasonable. I'm normally expecting to see this kind of "query, and if it isn't there, insert" code to have an UPDATE in its other branch (which makes it into a classic upsert or merge operation - what MySQL calls "INSERT... ON DUPLICATE KEY UPDATE"), or else throw an error (in which case the cleanest way is to put a unique key on the column in question and let the database throw the error). The risk normally is of a race condition; you could execute your SELECT query, find no results, and then have someone else insert one just a moment before you do. But with SQLite, you're probably assuming no other writers anyway - an assumption which (I think) you can mandate simply by opening a transaction and holding it through the full update procedure - which would make this safe. ChrisA From dfnsonfsduifb at gmx.de Sun Aug 23 10:05:30 2015 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sun, 23 Aug 2015 16:05:30 +0200 Subject: Sometimes bottle takes a lot of time In-Reply-To: References: <87si7cnxq6.fsf@Equus.decebal.nl> <87io87o93w.fsf@Equus.decebal.nl> <87twrrmpvp.fsf@Equus.decebal.nl> Message-ID: On 22.08.2015 16:15, Christian Gollwitzer wrote: > Probably yes. You should take a look at the OP again and compare the > time stamps. It says that in between two consecutive calls of the same > program, the request was served once in a second, and once with serious > delays. Despite that the server is localhost. In between both trials > there are 20 seconds. I do not see, how git bisect would help here. I do completely understand that in two consecutive runs one time the problem occurs and the other time it doesn't. It's highly unlikely that such a bug would ever have passed the bottle QA and if it did it would affect thousands of users (who would report this issue, since it's very severe). It is much more likely the bug is somewhere within the OP's program. By git bisect he can find out where he introduced the bug. > Note that this says nothing about the location of the bug, in can still > be either in the OPs code or in the framework. Yup. Note that he has now shifted from blaming bottle to blaming Firefox. Same thing with that claim. If somehow website delivery was delayed 6 seconds reproducibly, people would have noticed. I suspect that either the OPs program is at fault or the OP's setup (name resolution or some other weird stuff going on). But instead of tackling this problem systematically, like a Software Engineer would (Wireshark, debugger, profiler) he just blames other people's software. This, in my humble opinion, is annoying as fuck. Cheers, 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 Cecil at decebal.nl Sun Aug 23 10:06:15 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sun, 23 Aug 2015 16:06:15 +0200 Subject: Good resource for pythonanywhere and WSGI Message-ID: <87wpwmksko.fsf@Equus.decebal.nl> I want to host my web application on pythonanywhere so that the people of Mozilla can investigate the problem it has with this application. I do not find documentation that is useful for me. Has anyone a good resource? The application I want to deploy on pythonanywhere: https://github.com/CecilWesterhof/PublishedPhotos -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Sun Aug 23 11:20:29 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sun, 23 Aug 2015 17:20:29 +0200 Subject: Sometimes bottle takes a lot of time References: <87si7cnxq6.fsf@Equus.decebal.nl> <87io87o93w.fsf@Equus.decebal.nl> <87twrrmpvp.fsf@Equus.decebal.nl> Message-ID: <87si7akp4y.fsf@Equus.decebal.nl> On Sunday 23 Aug 2015 16:05 CEST, Johannes Bauer wrote: > On 22.08.2015 16:15, Christian Gollwitzer wrote: > >> Probably yes. You should take a look at the OP again and compare >> the time stamps. It says that in between two consecutive calls of >> the same program, the request was served once in a second, and once >> with serious delays. Despite that the server is localhost. In >> between both trials there are 20 seconds. I do not see, how git >> bisect would help here. > > I do completely understand that in two consecutive runs one time the > problem occurs and the other time it doesn't. > > It's highly unlikely that such a bug would ever have passed the > bottle QA and if it did it would affect thousands of users (who > would report this issue, since it's very severe). It is much more > likely the bug is somewhere within the OP's program. By git bisect > he can find out where he introduced the bug. You have to explain something to me: how can I introduce a bug without changing anything? Maybe by having wrong thoughts? >> Note that this says nothing about the location of the bug, in can >> still be either in the OPs code or in the framework. > > Yup. Note that he has now shifted from blaming bottle to blaming > Firefox. Same thing with that claim. If somehow website delivery was > delayed 6 seconds reproducibly, people would have noticed. I never blamed bottle, I was asking if it could be a problem with bottle. And it is (now) clear that it has to do something with Firefox. Just fetching the URL's does not give a problem. Chromium does not have a problem. Only Firefox has a problem. Even in safemode. And with an older version of Firefox there is (almost) no problem. > I suspect that either the OPs program is at fault or the OP's setup > (name resolution or some other weird stuff going on). But instead of > tackling this problem systematically, like a Software Engineer would > (Wireshark, debugger, profiler) he just blames other people's > software. This, in my humble opinion, is annoying as fuck. Do you know what I find annoying? That you need to keep bashing me, instead of thinking: was I maybe wrong in bashing? Especially because you are the only one that thinks you were right. Being the only one who thinks something, does not necessarily make you wrong, but should make you contemplate. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From python at mrabarnett.plus.com Sun Aug 23 11:44:33 2015 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 23 Aug 2015 16:44:33 +0100 Subject: Sometimes bottle takes a lot of time In-Reply-To: <87si7akp4y.fsf@Equus.decebal.nl> References: <87si7cnxq6.fsf@Equus.decebal.nl> <87io87o93w.fsf@Equus.decebal.nl> <87twrrmpvp.fsf@Equus.decebal.nl> <87si7akp4y.fsf@Equus.decebal.nl> Message-ID: <55D9EA61.9080405@mrabarnett.plus.com> On 2015-08-23 16:20, Cecil Westerhof wrote: > On Sunday 23 Aug 2015 16:05 CEST, Johannes Bauer wrote: > >> On 22.08.2015 16:15, Christian Gollwitzer wrote: >> >>> Probably yes. You should take a look at the OP again and compare >>> the time stamps. It says that in between two consecutive calls of >>> the same program, the request was served once in a second, and once >>> with serious delays. Despite that the server is localhost. In >>> between both trials there are 20 seconds. I do not see, how git >>> bisect would help here. >> >> I do completely understand that in two consecutive runs one time the >> problem occurs and the other time it doesn't. >> >> It's highly unlikely that such a bug would ever have passed the >> bottle QA and if it did it would affect thousands of users (who >> would report this issue, since it's very severe). It is much more >> likely the bug is somewhere within the OP's program. By git bisect >> he can find out where he introduced the bug. > > You have to explain something to me: how can I introduce a bug without > changing anything? Maybe by having wrong thoughts? > > >>> Note that this says nothing about the location of the bug, in can >>> still be either in the OPs code or in the framework. >> >> Yup. Note that he has now shifted from blaming bottle to blaming >> Firefox. Same thing with that claim. If somehow website delivery was >> delayed 6 seconds reproducibly, people would have noticed. > > I never blamed bottle, I was asking if it could be a problem with > bottle. > The subject says otherwise. :-) [snip] From Cecil at decebal.nl Sun Aug 23 12:15:48 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sun, 23 Aug 2015 18:15:48 +0200 Subject: Sometimes bottle takes a lot of time References: <87si7cnxq6.fsf@Equus.decebal.nl> <87io87o93w.fsf@Equus.decebal.nl> <87twrrmpvp.fsf@Equus.decebal.nl> <87si7akp4y.fsf@Equus.decebal.nl> Message-ID: <87oahykmkr.fsf@Equus.decebal.nl> On Sunday 23 Aug 2015 17:44 CEST, MRAB wrote: >> I never blamed bottle, I was asking if it could be a problem with >> bottle. >> > The subject says otherwise. :-) Yeah, my communication skills can take some improvement. I meant: I have this problem. I think it could have to do something with bottle. Can anybody shed some light on it? I hope to be more precise next time. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From rosuav at gmail.com Sun Aug 23 12:22:33 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Aug 2015 02:22:33 +1000 Subject: Is this the way to go with SQLite In-Reply-To: References: <871teum9c2.fsf@Equus.decebal.nl> Message-ID: On Mon, Aug 24, 2015 at 2:17 AM, Dennis Lee Bieber wrote: > SQLite3 supports the non-standard > > INSERT OR REPLACE ... > > (or one can do INSERT OR IGNORE; the OR XXX has a number of values that are > allowed to control behavior... BUT the OR clause only applies if a UNIQUE > constraint would be violated by the INSERT action... So if the field is not > a unique index, no foul is detected) Sure. But that's still the same as MySQL's (equally non-standard) "ON DUPLICATE KEY UPDATE", and various others. It's a way of shoving down a level the common idiom of "do this insert, only if that doesn't work, do this update instead". But that doesn't seem to be what the original code was doing - it was more like "do this insert, but if it's a duplicate based on URL, check if the other fields are the same, and if not... uhh, print something out?", which is far from common. ChrisA From torriem at gmail.com Sun Aug 23 12:47:02 2015 From: torriem at gmail.com (Michael Torrie) Date: Sun, 23 Aug 2015 10:47:02 -0600 Subject: Sometimes bottle takes a lot of time In-Reply-To: References: <87si7cnxq6.fsf@Equus.decebal.nl> <87io87o93w.fsf@Equus.decebal.nl> <87twrrmpvp.fsf@Equus.decebal.nl> Message-ID: <55D9F906.8050002@gmail.com> On 08/23/2015 08:05 AM, Johannes Bauer wrote: > By git bisect he can find out where > he introduced the bug. Like Cecil said, this is of little help. There was no code changed from when he didn't notice the behavior until he did. >> Note that this says nothing about the location of the bug, in can still >> be either in the OPs code or in the framework. > > Yup. Note that he has now shifted from blaming bottle to blaming > Firefox. Same thing with that claim. If somehow website delivery was > delayed 6 seconds reproducibly, people would have noticed. Well it does look like the problem is indeed inside firefox. Chrome does exhibit the problem. Just fetching the urls in a script does not have the problem either. Since this is an ajax thing, I can entirely understand that Firefox introduces random delays. Practically all ajax-heavy sites I've ever used has had random slowdowns in Firefox. > I suspect that either the OPs program is at fault or the OP's setup > (name resolution or some other weird stuff going on). Name resolution could be an issue, but the script he wrote to simulate the browser requests does not show the slowdown at all. Firefox could be doing name resolution differently than the rest of the system and Chrome of course, which wouldn't surprise me as Firefox seems to more and more stupid stuff. > But instead of > tackling this problem systematically, like a Software Engineer would > (Wireshark, debugger, profiler) he just blames other people's software. > This, in my humble opinion, is annoying He is tackling the problem systematically, though perhaps not in the same way you would. Sure there are ways he can improve his process, and he is doing that slowly. But your bashing on him is inappropriate and unhelpful. And sometimes things that are obvious to you and others (such as strings being iterable in his sql binding problem) are not obvious to new users of python, even ones with a lot of experience in other languages. What is annoying to me is how you have done nothing but jump all over him this whole thread, and several other times. You seem to have made it your mission to bash him continually on this list, mocking him and saying if he were a wise Senior Software Engineer he would know such and such. In fact I can find very few of your posts to this list where you aren't bashing Cecil in recent months. This does not reflect well on the list community and drives away people who would otherwise want to learn Python. If Cecil's posts annoy you, please ignore them (I wouldn't even respond to this post of yours, but I feel like something has to be said). I for one am happy to help out, and I'm very glad to see a person come and learn python and be enthusiastic about it. Unlike many people learning Python, Cecil has made a strong attempt to learn the idiomatic ways of programming in Python, and seems to be really enjoying it. He hasn't been turned off by the sometimes toxic atmosphere of the list. He hasn't run off saying Python sux because of whitespace. From dfnsonfsduifb at gmx.de Sun Aug 23 16:55:49 2015 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sun, 23 Aug 2015 22:55:49 +0200 Subject: Sometimes bottle takes a lot of time In-Reply-To: References: <87si7cnxq6.fsf@Equus.decebal.nl> <87io87o93w.fsf@Equus.decebal.nl> <87twrrmpvp.fsf@Equus.decebal.nl> Message-ID: On 23.08.2015 18:47, Michael Torrie wrote: > Since this is an ajax thing, I can entirely > understand that Firefox introduces random delays. Practically all > ajax-heavy sites I've ever used has had random slowdowns in Firefox. This would imply that random six-second delays have somehow passed the Firefox QA effortlessly. It's something that is entirely possible, but also something that I would consider magnitudes less likely than other explanations. Six seconds is *huge* for regular web applications. > Name resolution could be an issue, but the script he wrote to simulate > the browser requests does not show the slowdown at all. Firefox could > be doing name resolution differently than the rest of the system and > Chrome of course, which wouldn't surprise me as Firefox seems to more > and more stupid stuff. Proxy settings are another thing that could influence behavior. Maybe the proxy of his Chrome is differently configured than Firefox and this is causing issues. SOCKS proxies can emulate DNS as well. So there is a plethora of possible causes; no need to shift blame before evidence is presented, no need to jump to conclusions. > But your bashing on him is inappropriate and > unhelpful. [...] > What is annoying to me is how you have done nothing but jump all over > him this whole thread, and several other times. [...] > In fact I can find very few of your posts to this list where you > aren't bashing Cecil in recent months. This does not reflect well on > the list community and drives away people who would otherwise want to > learn Python. I think you're right about this. I've had some run-in with Cecil some months ago - don't even remember what it was about. The thing I did remember was that I was particularly annoyed by the whole discussion back then. This probably led to me being a lot more agressive in my choice of tone than I should have been. You're entirely right that this kind of personal feud and immature mockery is inappropriate for a mailing list and you're also right that it does create a toxic atmosphere. Since Python is the lanauge I'm most passionate about a detrimental effect on the Python community is something that is surely the exact opposite of what I want. > If Cecil's posts annoy you, please ignore them (I wouldn't even respond > to this post of yours, but I feel like something has to be said). I'll follow your advice and thank you for your honest words. Cheers, 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 charleshixsn at earthlink.net Sun Aug 23 17:43:50 2015 From: charleshixsn at earthlink.net (Charles Hixson) Date: Sun, 23 Aug 2015 14:43:50 -0700 Subject: asyncio, coroutines, etc. and simultaneous execution Message-ID: <55DA3E96.6090703@earthlink.net> If I understand correctly asyncio, coroutines, etc. (and, of course, Threads) are not simultaneously executed, and that if one wants that one must still use multiprocessing. But I'm not sure. The note is still there at the start of threading, so I'm pretty sure about that one. The requirement that coroutines always be awaited seems to confirm this, but doesn't really say so explicitly. And the concurrent.futures can clearly be either, depending on your choices, but the chart in 18.5.3.1.3 Example: Chain coroutines is of a kind that I am more familiar with in the context of multiprocessing. (E.g., the only gap in the chart, which extends across all headings is when a result is being waited for during a sleep.) For threaded execution I would expect there to be a gap whenever processing is shifted from one column to another. If someone has authority to edit the documentation a comment like: If you want your application to make better use of the computational resources of multi-core machines, you are advised to use multiprocessing or concurrent.futures.ProcessPoolExecutor . However, threading is still an appropriate model if you want to run multiple I/O-bound tasks simultaneously. (to quote from the threading documentation) would be helpful at or very near the top of each of the appropriate modules. It would also be useful if the modules that were definitely intended to result in simultaneous execution, when feasible, were so marked quite near the top. OTOH, I may be mistaken about coroutines. I haven't been able to tell. P.S.: I do note that the threading comment was a "*CPython implementation detail:"*, and not a part of the Python specifications. But CPython is, I believe, a sufficiently dominant implementation that such details are quite important. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lucas.bertolotti at yahoo.com Sun Aug 23 18:09:15 2015 From: lucas.bertolotti at yahoo.com (lbertolotti) Date: Sun, 23 Aug 2015 15:09:15 -0700 (PDT) Subject: Canopy editor-Variables browser and help In-Reply-To: <475013a6-6dcb-414e-8b99-d3af617cd2c7@googlegroups.com> References: <475013a6-6dcb-414e-8b99-d3af617cd2c7@googlegroups.com> Message-ID: <18ad5417-a10e-4744-88ed-48aa01ede2cf@googlegroups.com> Anyone? From 4kir4.1i at gmail.com Sun Aug 23 19:28:38 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Mon, 24 Aug 2015 02:28:38 +0300 Subject: asyncio, coroutines, etc. and simultaneous execution References: <55DA3E96.6090703@earthlink.net> Message-ID: <87twrpa8k9.fsf@gmail.com> Charles Hixson writes: > If I understand correctly asyncio, coroutines, etc. (and, of course, > Threads) are not simultaneously executed, and that if one wants that > one must still use multiprocessing. But I'm not sure. The note is > still there at the start of threading, so I'm pretty sure about that > one. Due to GIL (used by CPython, Pypy, not used by Jython, IronPython, pypy-stm) only one thread executes Python bytecode at a time. GIL can be released on I/O or in a C extension such as numpy, lxml, regex. It is true for any Python module or concept you use. Unrelated: use concurrent and parallel execution instead of "simultaneously executed." Parallelism might make a program faster (it implies that hardware supports it). Concurrency is a way to structure the code. The same concurrent program can run in parallel and without parallelism. Recommended: "Concurrency is not Parallelism (it's better!)" talk by Rob Pike's talk http://stackoverflow.com/questions/1050222/concurrency-vs-parallelism-what-is-the-difference > The requirement that coroutines always be awaited seems to confirm > this, but doesn't really say so explicitly. And the concurrent.futures > can clearly be either, depending on your choices, but the chart in > 18.5.3.1.3 Example: Chain coroutines is of a kind that I am more > familiar with in the context of multiprocessing. (E.g., the only gap > in the chart, which extends across all headings is when a result is > being waited for during a sleep.) For threaded execution I would > expect there to be a gap whenever processing is shifted from one > column to another. > > If someone has authority to edit the documentation a comment like: Anybody can suggest a patch https://docs.python.org/devguide/docquality.html > If you want your application to make better use of the computational > resources of multi-core machines, you are advised to use > multiprocessing > > or concurrent.futures.ProcessPoolExecutor > . However, > threading is still an appropriate model if you want to run multiple > I/O-bound tasks simultaneously. > > (to quote from the threading documentation) would be helpful at or > very near the top of each of the appropriate modules. It would also > be useful if the modules that were definitely intended to result in > simultaneous execution, when feasible, were so marked quite near the > top. It is not necessary that multiprocessing will make your code faster on a multi-core machine. It may make it slower depending on the task. Performance optimization is a vast topic. Short remarks such as you've suggested are likely misleading. > OTOH, I may be mistaken about coroutines. I haven't been able to tell. Many cooperative multitasking implementations use a *single* thread. There is a way to offload blocking code e.g., loop.run_in_executor() in asyncio. From ben+python at benfinney.id.au Sun Aug 23 20:01:04 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 24 Aug 2015 10:01:04 +1000 Subject: Sometimes bottle takes a lot of time References: <87si7cnxq6.fsf@Equus.decebal.nl> <87io87o93w.fsf@Equus.decebal.nl> <87twrrmpvp.fsf@Equus.decebal.nl> Message-ID: <85si79eerj.fsf@benfinney.id.au> Johannes Bauer writes: > You're entirely right that this kind of personal feud and immature > mockery is inappropriate for a mailing list and you're also right that > it does create a toxic atmosphere. Since Python is the lanauge I'm > most passionate about a detrimental effect on the Python community is > something that is surely the exact opposite of what I want. [?] > I'll follow your advice and thank you for your honest words. Thank you for publicly acknowledging this, and for taking responsibility for positive change. This is essential to keeping our community healthy. -- \ ?Technology is neither good nor bad; nor is it neutral.? | `\ ?Melvin Kranzberg's First Law of Technology | _o__) | Ben Finney From breamoreboy at gmail.com Sun Aug 23 20:11:18 2015 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sun, 23 Aug 2015 17:11:18 -0700 (PDT) Subject: Canopy editor-Variables browser and help In-Reply-To: <475013a6-6dcb-414e-8b99-d3af617cd2c7@googlegroups.com> References: <475013a6-6dcb-414e-8b99-d3af617cd2c7@googlegroups.com> Message-ID: On Saturday, May 2, 2015 at 8:50:22 PM UTC+1, lbertolotti wrote: > Can I: > 1.Enable a variable browser in Canopy editor similar to the Spyder editor? > 2.Writing a function say log( gives me the function help, but I can't read the whole documentation > 3.Eclipse had a auto-complete, can I enable this in Canopy? > 4.Perhaps I should try using another editor? I was having some problems with Spyder pythonpath... What do the Canopy docs at http://docs.enthought.com/canopy/ tell you? If you've used Eclipse why not give PyDev a try? From rosuav at gmail.com Sun Aug 23 20:19:38 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Aug 2015 10:19:38 +1000 Subject: Canopy editor-Variables browser and help In-Reply-To: <18ad5417-a10e-4744-88ed-48aa01ede2cf@googlegroups.com> References: <475013a6-6dcb-414e-8b99-d3af617cd2c7@googlegroups.com> <18ad5417-a10e-4744-88ed-48aa01ede2cf@googlegroups.com> Message-ID: On Mon, Aug 24, 2015 at 8:09 AM, lbertolotti via Python-list wrote: > Anyone? When you post a follow-up like this, it helps to provide some context. Fortunately for you, I have a threaded email client, but not everyone does - and not everyone was subscribed to the list when you first posted. If you're having difficulties with Canopy, you may do better on a specific Canopy mailing list. I, for one, have no experience with it, and can't advise. ChrisA From dieter at handshake.de Mon Aug 24 01:32:12 2015 From: dieter at handshake.de (dieter) Date: Mon, 24 Aug 2015 07:32:12 +0200 Subject: Best strategy for testing class and subclasses in pytest? References: <55D8CE06.7030206@cdreimer.com> Message-ID: <87wpwltfoj.fsf@handshake.de> "C.D. Reimer" writes: > I'm writing a chess engine to learn about Python classes and inheritance, and using pytest for the unit test. I've created a Piece class, which has 99% of the functionality for a chess piece, and subclass the other pieces -- Bishop, King, Knight, Pawn, Queen, Rook -- > that will implement the move-specific functionality. I'm not sure > what's the best strategy is for testing the class and subclasses. I tend to give the tests a structure similar to the implementation, i.e. the test units correspond to the functional units. In your case, I would have tests verifying the correct functioning of the base class and tests verifying that of the subclasses. When an integration module uses the (already tested) services of another module (as your subclasses use the services of the base class), I try to avoid retesting the other modules functionality - but asume in my new tests that the other (used) modules behave as expected. This often significantly reduces the test complexity. I your setup with base class and subclasses this implies that I usually test only new and overridden methods in the subclasses. In your case, you could also inherit your subclasses' test case classes from that of your base class. This would lead to a reexecution of the base class tests as part of the tests for each subclass. I follow this route when a subclass has overridden base class methods in a potentially sensible way. From shuimulinxi at foxmail.com Mon Aug 24 01:49:49 2015 From: shuimulinxi at foxmail.com (=?ISO-8859-1?B?MzQ0Mjc2MTA1?=) Date: Mon, 24 Aug 2015 13:49:49 +0800 Subject: Exception AttributeError: "'NoneType' object has no attribute 'population'" Message-ID: Hi all, I am a python learner. I encountered a problem when i was testing the following code. What is strange is that if I replace the object name with zhang, the program would be ok. And if I replace the Person.population with self.__class__.population, it will also be ok. So what is the matter? Here is the code, #!/usr/bin/python # Filename: objvar.py class Person: population = 0 def __init__(self, name): self.name = name print '(Initializing %s...)' % self.name Person.population += 1 def __del__(self): print '%s says bye.' % self.name Person.population -= 1 if Person.population == 0: print 'I am the last one.' else: print 'There are still %d people left.' % Person.population def sayHi(self): print 'Hi, my name is %s.' % self.name def howMany(self): if Person.population == 1: print 'I am the only person here.' else: print 'We have %d persons here.' % Person.population zhangsan = Person('Swaroop') zhangsan.sayHi() zhangsan.howMany() lisi = Person('LiSi') lisi.sayHi() lisi.howMany() zhangsan.sayHi() zhangsan.howMany() -------------- next part -------------- An HTML attachment was scrubbed... URL: From Cecil at decebal.nl Mon Aug 24 05:57:32 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 24 Aug 2015 11:57:32 +0200 Subject: Update my Python library Message-ID: <87fv39knzn.fsf@Equus.decebal.nl> I updated my Python library: https://github.com/CecilWesterhof/PythonLibrary/blob/master/utilDecebal.py One of the additions is time_fetchURLs. A function to display the needed time to receive a sequence of URLs from a server. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Mon Aug 24 07:00:05 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 24 Aug 2015 13:00:05 +0200 Subject: Is this the way to go with SQLite References: <871teum9c2.fsf@Equus.decebal.nl> Message-ID: <87bndxkl3e.fsf@Equus.decebal.nl> On Sunday 23 Aug 2015 16:03 CEST, Chris Angelico wrote: > On Sun, Aug 23, 2015 at 11:18 PM, Cecil Westerhof wrote: >> Also an URL is unique, so I need to check that if it is found, the >> values are the same as the ones I wanted to insert. > > And if they aren't? Currently, all you do is print out a message and > continue on; what happens if you get the same URL coming up more > than once? That is all what I want at the moment: to get notified when an URL has two different descriptions. It is just a script to do an initial fill of the table. When run again I do not insert the URLs that are already in the database. But just skipping is not enough, when it has a different description I did something wrong and should investigate that. One thing I could do is when the only difference is case, that I use the latter definition and notify the change. >> select_url = '''SELECT year >> , month >> , description >> FROM LINKS >> WHERE URL = ?''' >> year = 2015 >> month = 8 > > PEP 8 has a word or two to say about this, but carry on. Something to read then. > Incidentally, I'd be inclined to put the SELECT query down below, > same as the INSERT query is; it's not in any way different from just > using a string literal there, and this separates two pieces of code > (IMO) unnecessarily. I am inclined to do the opposite: put the INSERT query where the SELECT is. Both will be used several times in the near future (next week) and I like DRY. Was an omission when I changed the code. I have taken care of that. >> for link in links: >> description = link[0] >> url = link[1] > > for description, url in links: > >> url_values = c.execute(select_url, [url]).fetchall() >> if len(url_values) == 0: > > if not url_values: > >> print('Adding {0}'.format(link)) c.execute('''INSERT INTO links >> (year, month, description, URL) VALUES (?, ?, ?, ?) ''', [year, >> month, description, url]) else: to_insert = (year, month, >> description) found = url_values[0] if found != to_insert: >> print('For {0} found {1} instead of {2}'.format(url, found, >> to_insert)) Implemented. > Otherwise, looks reasonable. I'm normally expecting to see this kind > of "query, and if it isn't there, insert" code to have an UPDATE in > its other branch (which makes it into a classic upsert or merge > operation - what MySQL calls "INSERT... ON DUPLICATE KEY UPDATE"), > or else throw an error (in which case the cleanest way is to put a > unique key on the column in question and let the database throw the In my case I do not want the old value changed. (Maybe with the exception if only the case is different.) I need to evaluate which value is the right one. > error). The risk normally is of a race condition; you could execute > your SELECT query, find no results, and then have someone else > insert one just a moment before you do. But with SQLite, you're > probably assuming no other writers anyway - an assumption which (I > think) you can mandate simply by opening a transaction and holding > it through the full update procedure - which would make this safe. I start with: conn = sqlite3.connect('links.sqlite') c = conn.cursor() and end with: conn.commit() conn.close() Taken from: https://docs.python.org/2/library/sqlite3.html This takes care of the transaction, or not? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From rosuav at gmail.com Mon Aug 24 07:26:43 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Aug 2015 21:26:43 +1000 Subject: Is this the way to go with SQLite In-Reply-To: <87bndxkl3e.fsf@Equus.decebal.nl> References: <871teum9c2.fsf@Equus.decebal.nl> <87bndxkl3e.fsf@Equus.decebal.nl> Message-ID: On Mon, Aug 24, 2015 at 9:00 PM, Cecil Westerhof wrote: > On Sunday 23 Aug 2015 16:03 CEST, Chris Angelico wrote: > >> On Sun, Aug 23, 2015 at 11:18 PM, Cecil Westerhof wrote: >>> Also an URL is unique, so I need to check that if it is found, the >>> values are the same as the ones I wanted to insert. >> >> And if they aren't? Currently, all you do is print out a message and >> continue on; what happens if you get the same URL coming up more >> than once? > > That is all what I want at the moment: to get notified when an URL has > two different descriptions. It is just a script to do an initial fill > of the table. When run again I do not insert the URLs that are already > in the database. But just skipping is not enough, when it has a > different description I did something wrong and should investigate > that. Sounds to me like you mostly want an error, but in some cases, you'll suppress the error (ie it's exactly the same description and datestamp). >> error). The risk normally is of a race condition; you could execute >> your SELECT query, find no results, and then have someone else >> insert one just a moment before you do. But with SQLite, you're >> probably assuming no other writers anyway - an assumption which (I >> think) you can mandate simply by opening a transaction and holding >> it through the full update procedure - which would make this safe. > > I start with: > conn = sqlite3.connect('links.sqlite') > c = conn.cursor() > > and end with: > conn.commit() > conn.close() > > Taken from: > https://docs.python.org/2/library/sqlite3.html > > This takes care of the transaction, or not? Yep, I think so. If not, you should be able to ensure transactional integrity by simply adding an explicit "BEGIN" query. ChrisA From python at mrabarnett.plus.com Mon Aug 24 07:50:05 2015 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 24 Aug 2015 12:50:05 +0100 Subject: Exception AttributeError: "'NoneType' object has no attribute 'population'" In-Reply-To: References: Message-ID: <55DB04ED.5030407@mrabarnett.plus.com> On 2015-08-24 06:49, 344276105 wrote: > Hi all, > I am a python learner. I encountered a problem when i was testing the > following code. What is strange is that if I replace the object name > with zhang, the program would be ok. And if I replace the > Person.population with self.__class__.population, it will also be ok. So > what is the matter? > Here is the code, > > #!/usr/bin/python > # Filename: objvar.py > > class Person: > population = 0 > > def __init__(self, name): > self.name = name > print '(Initializing %s...)' % self.name > > Person.population += 1 > > def __del__(self): > print '%s says bye.' % self.name > Person.population -= 1 > if Person.population == 0: > print 'I am the last one.' > else: > print 'There are still %d people left.' % Person.population > > def sayHi(self): > print 'Hi, my name is %s.' % self.name > > def howMany(self): > if Person.population == 1: > print 'I am the only person here.' > else: > print 'We have %d persons here.' % Person.population > > > zhangsan = Person('Swaroop') > zhangsan.sayHi() > zhangsan.howMany() > > lisi = Person('LiSi') > lisi.sayHi() > lisi.howMany() > > zhangsan.sayHi() > zhangsan.howMany() > The error occurs because the program has finished and Python is cleaning up. Unfortunately, it looks like when the __del__ methods run, the Person class has already been cleaned up (Person is None at that point). It looks like that behaviour was fixed in Python 3.2. By the way, it's recommended that you use the latest version of Python 3 unless you require Python 2 because of some dependency on something that doesn't (yet?) work on Python 3. From ned at nedbatchelder.com Mon Aug 24 10:40:18 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 24 Aug 2015 07:40:18 -0700 (PDT) Subject: Sandboxing Python In-Reply-To: References: Message-ID: On Saturday, August 22, 2015 at 11:58:30 PM UTC-4, Laura Creighton wrote: > Ned Batchelder has researched this one quite a bit, see: > > see: http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html > http://nedbatchelder.com/blog/201302/looking_for_python_3_builtins.html > http://nedbatchelder.com/blog/201302/finding_python_3_builtins.html > > Laura When I saw the subject line, I was going to jump in, but it looks like maybe I don't have to! :) What we use at edX for sandboxing Python is isolation of processes at the OS level, with AppArmor. We've encapsulated it in a library called CodeJail: https://github.com/edx/codejail --Ned. From jspicklemire at gmail.com Mon Aug 24 12:08:51 2015 From: jspicklemire at gmail.com (jspicklemire at gmail.com) Date: Mon, 24 Aug 2015 09:08:51 -0700 (PDT) Subject: concurrent.futures vs gevent In-Reply-To: References: Message-ID: <38fed095-8d16-47b8-b315-83d4700fd92a@googlegroups.com> Some people have tried to make a case that concurrent.futures should be adopted as a replacement wherever greenlet based algorithms are in use. However, my experience is that greenelts combined with concurrent.futures provides significant advantages. In other words, to a degree the two approaches complement each other. Specifically, 'greening' a ThreadPoolExecutor delivers the simplicity of either a context manager, or a map, depending on the use case, hadling in a few lines of simple Python what might have otherwise been a complex call-back or 'twisted' solution. Please note, this usage applies only to ThreadPool, not ProcessPool. for example: import eventlet eventlet.patcher.monkey_patch(os=False, socket=True, select=True, thread=True) futures = eventlet.import_patched('concurrent.futures') # 'greening' futures, fut_tp_exec = futures.ThreadPoolExecutor # the lines above enable even nested map / context manager 'futures' # adding the lines below enables a vast number of 'simultaneous' HTTP requests. import requests req_f_sess = eventlet.import_patched('requests_futures.sessions') # 'green' req o_rest_sess = req_f_sess.FuturesSession(executor=fut_tp_exec(max_workers=5000)) From Cecil at decebal.nl Mon Aug 24 13:13:51 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 24 Aug 2015 19:13:51 +0200 Subject: Using urlopen in Python2 and Python3 Message-ID: <877foklicw.fsf@Equus.decebal.nl> In Python2 urlopen is part of urllib, but in Python3 it is part of urllib.request. I solved this by the following code: ======================================================================== from platform import python_version if python_version()[0] < '3': from urllib import urlopen else: from urllib.request import urlopen ======================================================================== -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From ned at nedbatchelder.com Mon Aug 24 13:37:50 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 24 Aug 2015 10:37:50 -0700 (PDT) Subject: Using urlopen in Python2 and Python3 In-Reply-To: <877foklicw.fsf@Equus.decebal.nl> References: <877foklicw.fsf@Equus.decebal.nl> Message-ID: <58eadd9b-a57d-4fa0-bdcc-26416fc9a7b2@googlegroups.com> On Monday, August 24, 2015 at 1:14:20 PM UTC-4, Cecil Westerhof wrote: > In Python2 urlopen is part of urllib, but in Python3 it is part of > urllib.request. I solved this by the following code: > ======================================================================== > from platform import python_version > > if python_version()[0] < '3': > from urllib import urlopen > else: > from urllib.request import urlopen A less specific technique is: try: from urllib import urlopen except ImportError: from urllib.request import urlopen Even better, the six package, which helps with 2/3 compatibility, provides this: from six.moves.urllib.request import urlopen which works on both 2 and 3. --Ned. From Cecil at decebal.nl Mon Aug 24 14:21:21 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 24 Aug 2015 20:21:21 +0200 Subject: Using urlopen in Python2 and Python3 References: <877foklicw.fsf@Equus.decebal.nl> <58eadd9b-a57d-4fa0-bdcc-26416fc9a7b2@googlegroups.com> Message-ID: <8737z8lf8e.fsf@Equus.decebal.nl> On Monday 24 Aug 2015 19:37 CEST, Ned Batchelder wrote: > On Monday, August 24, 2015 at 1:14:20 PM UTC-4, Cecil Westerhof wrote: >> In Python2 urlopen is part of urllib, but in Python3 it is part of >> urllib.request. I solved this by the following code: >> ======================================================================== >> from platform import python_version >> >> if python_version()[0] < '3': >> from urllib import urlopen >> else: >> from urllib.request import urlopen > > A less specific technique is: > > try: > from urllib import urlopen > except ImportError: > from urllib.request import urlopen > > Even better, the six package, which helps with 2/3 compatibility, > provides this: > > from six.moves.urllib.request import urlopen > > which works on both 2 and 3. Implemented. Thanks. At the moment I also use: ======================================================================== from __future__ import division, print_function . . . # To work with Python2 the flush is a seperate statement print('It took {0:.5f} seconds'.format(end_time - start_time)) sys.stdout.flush() ======================================================================== Would it be better to use: ======================================================================== from six import print_ . . . print_('It took {0:.5f} seconds'.format(end_time - start_time), flush = true) ======================================================================== -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From davanand.bahall at gmail.com Mon Aug 24 16:14:03 2015 From: davanand.bahall at gmail.com (DBS) Date: Mon, 24 Aug 2015 13:14:03 -0700 (PDT) Subject: Python/Github Message-ID: <10ea416a-41a3-41ef-9a57-ea8770b0225a@googlegroups.com> Hello, I'm trying to retrieve the number of commits and changed files on all pull requests submitted to a branch. The call to get all the pull requests is GET /repos/:owner/:repo/pulls, but it does not return "commits" or "changed_files". The call that returns number of commits and changed files is GET /repos/:owner/:repo/pulls/:number. Any guidance on how I can modify the call below to include commits and changed files on all pull requests? #!/usr/bin/env python import json import requests import datetime import sys import codecs sys.stdout = codecs.getwriter('utf8')(sys.stdout) sys.stderr = codecs.getwriter('utf8')(sys.stderr) OAUTH_KEY = "xxxxxxxxxxxxxxxxxxx" repos = ['my-repo'] # List pull request def list_pr(): for repo in repos: r = requests.get('https://api.github.com/repos/owner/%s/pulls' % repo, auth=('token', OAUTH_KEY)) data = r.json() for i in data: print "\nUser: " + i['user']['login'] + '\n' + "Number: " + str(i['number']) + '\n' + "Time created: " + i['created_at'] + '\n' + "Title: " + i['title'] + '\n' + "Body: " + i['body'] + '\n' list_pr() From appthought1 at gmail.com Mon Aug 24 17:07:53 2015 From: appthought1 at gmail.com (appthought1 at gmail.com) Date: Mon, 24 Aug 2015 14:07:53 -0700 (PDT) Subject: Python Developer- Houston, TX Message-ID: Hi, Hope you are doing well !!! My name is Siva and I'm a recruiter at TheAppliedthought , a global staffing and IT consulting company. Please find the below job description which may suits any of your consultants who are available in market or who are looking for change, please send me latest updated resume along with contact details and expected hourly rate to my email id siva at theappliedthought.com or you can reach me on 407-574-7610. Position: Python Developer Location: Houston, TX Duration: Long Term Job Description *6+ years of experience with Linux/UNIX Systems Administration *2+ years of Openstack Experience *Hypervisor KVM, BIOS, Firmware update *Storage Technologies (NAS, SAN & Cloud Storage) *Experience with configuration management tools (Chef expert!!) *Analytical problem-solving and conceptual skills *Strong scripting and/or development chops (Ruby, Python, Bash, Perl) *Experience with database technologies (MySQL, Percona, MongoDB) *Experience with automation (Chef etc.) and monitoring (Nagios, etc.) technologies in production setting *Experience with networking technologies including TCP/IP VPN DNS routing firewalls VLAN. *Excellent communication skills *Excellent team player Thanks & Regards Siva Executive-Talent Acquisition & Bench Sales Email: siva at theappliedthought.com IM: malladi sivaramakrishna88 Phone: 407-574-7610 Fax: 407-641-8184 From clp2 at rebertia.com Mon Aug 24 17:16:37 2015 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 24 Aug 2015 14:16:37 -0700 Subject: Python/Github In-Reply-To: <10ea416a-41a3-41ef-9a57-ea8770b0225a@googlegroups.com> References: <10ea416a-41a3-41ef-9a57-ea8770b0225a@googlegroups.com> Message-ID: On Mon, Aug 24, 2015 at 1:14 PM, DBS wrote: > Hello, > > I'm trying to retrieve the number of commits and changed files on all pull requests submitted to a branch. > > The call to get all the pull requests is GET /repos/:owner/:repo/pulls, but it does not return "commits" or "changed_files". > > The call that returns number of commits and changed files is GET /repos/:owner/:repo/pulls/:number. > > Any guidance on how I can modify the call below to include commits and changed files on all pull requests? > > #!/usr/bin/env python > import json > import requests Have you considered using a GitHub API Python library such as github3.py (https://github.com/sigmavirus24/github3.py ) rather than reinventing the wheel? Cheers, Chris -- http://chrisrebert.com From davanand.bahall at gmail.com Mon Aug 24 17:28:26 2015 From: davanand.bahall at gmail.com (DBS) Date: Mon, 24 Aug 2015 14:28:26 -0700 (PDT) Subject: Python/Github In-Reply-To: References: <10ea416a-41a3-41ef-9a57-ea8770b0225a@googlegroups.com> Message-ID: On Monday, August 24, 2015 at 2:16:55 PM UTC-7, Chris Rebert wrote: > On Mon, Aug 24, 2015 at 1:14 PM, DBS wrote: > > Hello, > > > > I'm trying to retrieve the number of commits and changed files on all pull requests submitted to a branch. > > > > The call to get all the pull requests is GET /repos/:owner/:repo/pulls, but it does not return "commits" or "changed_files". > > > > The call that returns number of commits and changed files is GET /repos/:owner/:repo/pulls/:number. > > > > Any guidance on how I can modify the call below to include commits and changed files on all pull requests? > > > > #!/usr/bin/env python > > import json > > import requests > > > Have you considered using a GitHub API Python library such as > github3.py (https://github.com/sigmavirus24/github3.py ) rather than > reinventing the wheel? > > Cheers, > Chris > -- > http://chrisrebert.com Hello Chris, No I haven't. I didn't know it existed until now. I'm still in the midst of learning python. I will head over that way and read up on the documentation and give it a try. If I have any questions, I will come back and post :). Thanks again!! Thanks, DBS From srkunze at mail.de Mon Aug 24 17:35:04 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Mon, 24 Aug 2015 23:35:04 +0200 Subject: asyncio, coroutines, etc. and simultaneous execution In-Reply-To: <55DA3E96.6090703@earthlink.net> References: <55DA3E96.6090703@earthlink.net> Message-ID: <55DB8E08.7070102@mail.de> On 23.08.2015 23:43, Charles Hixson wrote: > If I understand correctly asyncio, coroutines, etc. (and, of course, > Threads) are not simultaneously executed, and that if one wants that > one must still use multiprocessing. But I'm not sure. The note is > still there at the start of threading, so I'm pretty sure about that one. > > The requirement that coroutines always be awaited seems to confirm > this, but doesn't really say so explicitly. And the concurrent.futures > can clearly be either, depending on your choices, but the chart in > 18.5.3.1.3 Example: Chain coroutines is of a kind that I am more > familiar with in the context of multiprocessing. (E.g., the only gap > in the chart, which extends across all headings is when a result is > being waited for during a sleep.) For threaded execution I would > expect there to be a gap whenever processing is shifted from one > column to another. > > If someone has authority to edit the documentation a comment like: > > If you want your application to make better use of the computational > resources of multi-core machines, you are advised to use > multiprocessing > > or concurrent.futures.ProcessPoolExecutor > . > However, threading is still an appropriate model if you want to run > multiple I/O-bound tasks simultaneously. > > (to quote from the threading documentation) would be helpful at or > very near the top of each of the appropriate modules. It would also > be useful if the modules that were definitely intended to result in > simultaneous execution, when feasible, were so marked quite near the top. > > OTOH, I may be mistaken about coroutines. I haven't been able to tell. > > P.S.: I do note that the threading comment was a "*CPython > implementation detail:"*, and not a part of the Python > specifications. But CPython is, I believe, a sufficiently dominant > implementation that such details are quite important. > > We already have a discussion on python-ideas where we collected many many aspects on this particular subject. The results so far: https://mail.python.org/pipermail/python-ideas/2015-July/034813.html I know the table is a bit screwed but you will be able to handle that. Do you have anything you want to add to it? Cheers, Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrewwang43 at gmail.com Mon Aug 24 22:12:14 2015 From: andrewwang43 at gmail.com (Andrew Wang) Date: Mon, 24 Aug 2015 19:12:14 -0700 Subject: TypeCheck vs IsInstance in C API Message-ID: Hi. I know this thread is ancient, but I would like to know the answer as well ( https://mail.python.org/pipermail/python-list/2006-May/413542.html). Thanks. Andrew -------------- next part -------------- An HTML attachment was scrubbed... URL: From helical.hdi at gmail.com Tue Aug 25 01:49:51 2015 From: helical.hdi at gmail.com (Helical Insight) Date: Mon, 24 Aug 2015 22:49:51 -0700 (PDT) Subject: Is your BI tool really intelligent ? Message-ID: <3cb7686a-e037-46f3-98c2-850aefbceaa8@googlegroups.com> Is your #BI implementation ready to scale up for ALL of your future requirements? https://lnkd.in/ezeGr9b From Jostna.Srinivas at Staples.com Tue Aug 25 04:20:06 2015 From: Jostna.Srinivas at Staples.com (Srinivas, Jostna) Date: Tue, 25 Aug 2015 08:20:06 +0000 Subject: required help with python code. Message-ID: <512EEDFFFC63EB4F87578F44F4BF5D0306D331E8@nedexmb102.staplesams.com> Hi, I am trying to write a python code to create tableau data extract using tableau API. In the process I am facing following error. Please help me to fix. I tried a lot but couldn't get over net. Its critical requirement and we need your help. [cid:image001.png at 01D0DC37.285DEAE0] r Regards, Jostna Srinivas | Staples Enterprise Reporting | m. +91.984.017.8090 | Jostna.Srinivas at Staples.com -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.png Type: image/png Size: 81058 bytes Desc: image001.png URL: From ben+python at benfinney.id.au Tue Aug 25 05:13:19 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 25 Aug 2015 19:13:19 +1000 Subject: required help with python code. References: <512EEDFFFC63EB4F87578F44F4BF5D0306D331E8@nedexmb102.staplesams.com> Message-ID: <85oahveno0.fsf@benfinney.id.au> "Srinivas, Jostna" writes: > I am trying to write a python code to create tableau data extract > using tableau API. What is that? Does it have a website? Does it have its own community of users and developers? Your questions about Python are welcome here, and we'll help if we can. That said, if the thing you're using has its own specific community, you should also try the forums of that community to get more specific help. > In the process I am facing following error. Please don't post attachments, they don't propagate correctly across this forum. Instead make a Short, Self-contained, Complete, Correct Example that we can also execute to see the behaviour. If it's not Short, you need to contrive a short example that *only* demonstrates the problem. If it's not Self-contained and Complete and Correct for demonstrating the behaviour, you need to refine it until that's the case. Otherwise we can't see the behaviour you're seeing, which is necessary to understand what the problem is. > Please help me to fix. I tried a lot but couldn't get over net. Its > critical requirement and we need your help. We can't be held to whatever critical requirements you have; but I sympathise with your position. Please help us help you, by making a SSCCE that we can run to see the behaviour. -- \ ?Good judgement comes from experience. Experience comes from | `\ bad judgement.? ?Frederick P. Brooks | _o__) | Ben Finney From rosuav at gmail.com Tue Aug 25 05:13:49 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Aug 2015 19:13:49 +1000 Subject: required help with python code. In-Reply-To: <512EEDFFFC63EB4F87578F44F4BF5D0306D331E8@nedexmb102.staplesams.com> References: <512EEDFFFC63EB4F87578F44F4BF5D0306D331E8@nedexmb102.staplesams.com> Message-ID: On Tue, Aug 25, 2015 at 6:20 PM, Srinivas, Jostna wrote: > > In the process I am facing following error. > > Please help me to fix. I tried a lot but couldn?t get over net. Its critical requirement and we need your help. > Please do two things to help us to help you: 1) Make a simple file that has as little code as possible, but still demonstrates the problem. I can't see all of your code, and I have no idea what you're importing, what else your code's doing, etc. 2) Once you've done that, copy and paste the code and the traceback as text. Thank you for posting the error and part of the code, but the screenshot makes it a lot harder to work with, and as mentioned, we don't have all of the code. Ideally, code that we can test and run on our own systems would be a big help, but by the sound of things, you're using a DB2 back end, so we may well not be able to use that. But if you're using the standard Python databasing API, we can quite possibly run your code against PostgreSQL or SQLite3 or some other database. Thanks! ChrisA From __peter__ at web.de Tue Aug 25 06:01:24 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 25 Aug 2015 12:01:24 +0200 Subject: required help with python code. References: <512EEDFFFC63EB4F87578F44F4BF5D0306D331E8@nedexmb102.staplesams.com> Message-ID: Srinivas, Jostna wrote: > I am trying to write a python code to create tableau data extract using > tableau API. > > In the process I am facing following error. > > Please help me to fix. I tried a lot but couldn't get over net. Its > critical requirement and we need your help. Posting a picture turns quoting into typing; this is not a polite way to ask. In the future please post text only. In your screenshot you use the ibm_db.fetch_both() method twice, once as row = ibm_db.fetch_both(result) while row: print row["FSC_YR"] row = ibm_db.fetch_both(result) which seems to work, and once as for i in ibm_db.fetch_both(result): ... which doesn't. Assuming everything else is correct replacing the for loop with a while loop similar to that in step 1 should help. From jeanmichel at sequans.com Tue Aug 25 07:06:16 2015 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 25 Aug 2015 13:06:16 +0200 (CEST) Subject: Best strategy for testing class and subclasses in pytest? In-Reply-To: <55D8CE06.7030206@cdreimer.com> Message-ID: <1340355561.926268.1440500776140.JavaMail.root@sequans.com> > From: "C.D. Reimer" > Greetings, > > I'm writing a chess engine to learn about Python classes and > inheritance, and using pytest for the unit test. [snip] > I tried to create a separate class and/or module to import the common > tests for each class and subclass. My attempts often ended in failure > with the "RuntimeError: super(): no arguments" message. I couldn't > find > a working example on the Internet on how to do that. The pytest > documentation is all over the place. > > Is there a way to reuse tests in pytest? > > Or should I test everything in the class and test only the > implemented > functionality in the subclasses? > > Thank you, > > Chris R. I've played a little bit with pytest, I was interested in trying since it claims to add less boilerplate than unittest. I've created 2 classes, Piece and Queen, both have the 'isPiece' and 'name' property (for the sake of demo). If you execute the code (python 2.7) with pytest, you'll see that the TestQueen class actually execute 2 tests, one inherited from its base test class TestPiece. So in the end, I'd say that you may put all common tests in TestPiece, and each specific implementation into TestQueen. import pytest class Piece(object): @property def isPiece(self): #for the sake of demo return True @property def name(self): raise NotImplementedError # Piece is a sort of abstract class class Queen(Piece): @property def name(self): return 'Queen' class TestPiece(object): cls = Piece def test_isPiece(self): assert self.cls().isPiece def test_name(self): with pytest.raises(NotImplementedError): assert self.cls().name class TestQueen(TestPiece): cls = Queen def test_name(self): assert self.cls().name == 'Queen' py.test test.py platform linux2 -- Python 2.7.3 -- py-1.4.20 -- pytest-2.5.2 4 passed in 0.01 seconds -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From ryexander at gmail.com Tue Aug 25 07:39:31 2015 From: ryexander at gmail.com (ryexander at gmail.com) Date: Tue, 25 Aug 2015 04:39:31 -0700 (PDT) Subject: Pyitect V2 support for 2.6+ and big chagnes Message-ID: A while back I posted my plugin framework module asking for feedback I only got one person to respond but that just fine, they gave me plenty to think on. I'm back to showcase my improvements. https://github.com/Ryex/pyitect The biggest change in V2 is that Python versions 2.6 and up are supported with no loss of functionality. for some reason I blanked the existence of imp I know about it but forgot for around a year, it's weird. Regardless, Python 3.3 and lower uses imp and python 3.4 and up uses importlib. The second biggest change is that the magic module PyitectConsumes is no longer used for import time component loading. one of the feedback's was that this was just too much magic going on with the import machinery. Instead, pyitect has a empty sub-module pyitect.imports . this module is populated with components during import of a plugin module so insted of from PyitectConsumes import foo you use from pyitect.imports import foo the difference may seem semantic but the difference is that where as PyitectConsumes just magically existed during import pyitect.imports always exists but is empty unless a plugin module is getting imported In pyitect that is a difference between import-time and run-time component fetching. for former makes components declared in the configuration file of the plugin available while the plugin's module is still being loaded. The latter is invoked on a plugin system instance via it's load method. Plugins MAY need to use run-time component acquisition in V1 this was possible but author of the system needed to make the plugin system instance available to the author. V2 makes this much easier by letting the instance hangout in the pyitect module build_system, get_system, and destroy_system all work with a global instance of the pyitect.System class. in V1 version postfixes was a system to provide different types of the same component. their use however was a bit arcane. In V2 the functionality of post-fixes is instead accomplished with component subtypes. if a component is names with a doted notations ie. "compa.sub1.sub2" each part represents a subtype of the part before it. so a "a.b.c" is also a "a.b" and an "a" type component. if a component type "a" is requested a "a.b" may be returned if an "a" is not available. all this behavior can of course be modified. I've also written up sphinx docs this time http://pyitect.readthedocs.org/en/latest/ I would like more feedback if anyone has the time avalible to look at it. Thanks ~ Benjamin "Ryex" Powers From AllanPfalzgraf at Eaton.com Tue Aug 25 09:03:38 2015 From: AllanPfalzgraf at Eaton.com (AllanPfalzgraf at Eaton.com) Date: Tue, 25 Aug 2015 13:03:38 +0000 Subject: Logging to a file from a C-extension In-Reply-To: References: Message-ID: <6ED6C17008BE7947AB56195C0C4B7FCF9380D653@SIMTCSMB04.napa.ad.etn.com> Stefan, You have understood my question. I'm new to Python. Could I use a Cython solution to get suggestions on just how to go about this in the C extension? Otherwise could you suggest which C-API functions I should be looking at? Thanks, Al -----Original Message----- From: Stefan Behnel [mailto:stefan_ml at behnel.de] Sent: Wednesday, August 19, 2015 2:51 PM Subject: Re: Logging to a file from a C-extension Al Pfalzgraf schrieb am 18.08.2015 um 15:07: > If a logging file is opened at the level of a Python application, how > would the log file name be communicated to a C-extension so that > logging from the extension would be sent to the same log file? Writing to the file directly (as was suggested) may not be a good idea as it would bypass the log filtering and formatting. Instead, I'd suggest sending output to a normal Python Logger object instead. This is obviously trivial in Cython (where you can just implement it in Python code), but you can do the same in C with just the usual C-API overhead. Stefan From nomail at invalid.com Tue Aug 25 10:16:17 2015 From: nomail at invalid.com (ast) Date: Tue, 25 Aug 2015 16:16:17 +0200 Subject: [a,b,c,d] = 1,2,3,4 Message-ID: <55dc78b2$0$3023$426a74cc@news.free.fr> >>> [a,b,c,d] = 1,2,3,4 >>> a 1 >>> b 2 >>> c 3 >>> d 4 I have never seen this syntax before. Is it documented. Is there a name for that ? thx From joel.goldstick at gmail.com Tue Aug 25 10:30:56 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 25 Aug 2015 10:30:56 -0400 Subject: [a,b,c,d] = 1,2,3,4 In-Reply-To: <55dc78b2$0$3023$426a74cc@news.free.fr> References: <55dc78b2$0$3023$426a74cc@news.free.fr> Message-ID: On Tue, Aug 25, 2015 at 10:16 AM, ast wrote: >>>> [a,b,c,d] = 1,2,3,4 >>>> a > > 1 >>>> >>>> b > > 2 >>>> >>>> c > > 3 >>>> >>>> d > > 4 > > I have never seen this syntax before. Is it documented. > Is there a name for that ? > > thx > -- > https://mail.python.org/mailman/listinfo/python-list its called list unpacking or packing (?) the right side is considered a tuple because of the commas >>> a = 1,2,3 >>> a (1, 2, 3) >>> a[1] 2 >>> http://www.developer.com/lang/other/article.php/630101/Learn-to-Program-using-Python-Unpacking-Tuples.htm -- Joel Goldstick http://joelgoldstick.com From random832 at fastmail.us Tue Aug 25 10:32:33 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Tue, 25 Aug 2015 10:32:33 -0400 Subject: TypeCheck vs IsInstance in C API In-Reply-To: References: Message-ID: <1440513153.3402880.365512977.5E984BE4@webmail.messagingengine.com> On Mon, Aug 24, 2015, at 22:12, Andrew Wang wrote: > Hi. > > I know this thread is ancient, but I would like to know the answer > as well > ( https://mail.python.org/pipermail/python-list/2006-May/413542.html). Of course, the answer in 2015 is actually very different from the answer in 2006, since we didn't have either Python 3 or abstract classes back then. The IsInstance (and IsSubclass) function documentation mentions that they use the methods __instancecheck__ [and __subclasscheck__], presumably to support abstract classes. The actual implementation of TypeCheck is a macro: PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *); #define PyObject_TypeCheck(ob, tp) \ (Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp))) PyType_IsSubtype (in typeobject.c) only appears to deal with the real types, not any abstract class methods. So it looks like PyObject_TypeCheck/PyType_IsSubtype was originally introduced to check for real types (and not old style classes), and continued in that niche as IsInstance/IsSubclass were repurposed to deal with PEP 3119 ABC logic. Incidentally, this made me wonder what was done before PyObject_IsInstance was added in 2.1. In 2.0, substantially the same code exists inside builtin_isinstance. Stuff I found researching this: http://comments.gmane.org/gmane.comp.python.cython.devel/2928 https://groups.google.com/forum/#!topic/comp.lang.python/z594gnaBhwY https://groups.google.com/forum/#!topic/comp.lang.python/ywqzu3JD6Nw And, now, your moment of zen: > def isa(ob, cl): > try: > raise ob > except cl: > return 1 > else: return 0 From cody.piersall at gmail.com Tue Aug 25 10:32:51 2015 From: cody.piersall at gmail.com (Cody Piersall) Date: Tue, 25 Aug 2015 09:32:51 -0500 Subject: [a,b,c,d] = 1,2,3,4 In-Reply-To: <55dc78b2$0$3023$426a74cc@news.free.fr> References: <55dc78b2$0$3023$426a74cc@news.free.fr> Message-ID: On Tue, Aug 25, 2015 at 9:16 AM, ast wrote: > [a,b,c,d] = 1,2,3,4 >>>> a >>>> >>> 1 > >> b >>>> >>> 2 > >> c >>>> >>> 3 > >> d >>>> >>> 4 > > I have never seen this syntax before. Is it documented. > Is there a name for that ? > > thx > -- > https://mail.python.org/mailman/listinfo/python-list > That's called "sequence unpacking" Cody -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Tue Aug 25 10:50:41 2015 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 25 Aug 2015 16:50:41 +0200 (CEST) Subject: [a,b,c,d] = 1,2,3,4 In-Reply-To: <55dc78b2$0$3023$426a74cc@news.free.fr> Message-ID: <458715617.954476.1440514241063.JavaMail.root@sequans.com> ----- Original Message ----- > From: "ast" > To: python-list at python.org > Sent: Tuesday, 25 August, 2015 4:16:17 PM > Subject: [a,b,c,d] = 1,2,3,4 > > >>> [a,b,c,d] = 1,2,3,4 > >>> a > 1 > >>> b > 2 > >>> c > 3 > >>> d > 4 > > I have never seen this syntax before. Is it documented. > Is there a name for that ? > > thx You probably have already seen something like: a,b,c,d = 1,2,3,4 which is the same code than yours with the list replaced by a tuple. Moreover: https://docs.python.org/2/tutorial/datastructures.html """ x, y, z = t This is called, appropriately enough, sequence unpacking and works for any sequence on the right-hand side. Sequence unpacking requires the list of variables on the left to have the same number of elements as the length of the sequence. Note that multiple assignment is really just a combination of tuple packing and sequence unpacking. """ It's slightly confusing because it mentions a "list of variable" and then a "tuple packing" while the example uses a tuple. Fortunately, lists and tuples can be used in both cases. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From jeanmichel at sequans.com Tue Aug 25 10:59:25 2015 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 25 Aug 2015 16:59:25 +0200 (CEST) Subject: [a,b,c,d] = 1,2,3,4 In-Reply-To: Message-ID: <935842626.955183.1440514765199.JavaMail.root@sequans.com> ----- Original Message ----- > From: "Joel Goldstick" > its called list unpacking or packing (?) > > the right side is considered a tuple because of the commas > >>> a = 1,2,3 > >>> a > (1, 2, 3) > >>> a[1] > 2 To add to Joel's answer, the right side can be *any* sequence, and is not restricted to lists or tuples. a, b, c = (x for x in range(3)) # a generator for instance That would be a generator unpacking combined with a tuple packing (is packing restricted to tuples and lists ? probably) JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From joel.goldstick at gmail.com Tue Aug 25 11:05:23 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 25 Aug 2015 11:05:23 -0400 Subject: [a,b,c,d] = 1,2,3,4 In-Reply-To: References: <55dc78b2$0$3023$426a74cc@news.free.fr> Message-ID: On Tue, Aug 25, 2015 at 10:32 AM, Cody Piersall wrote: > > > On Tue, Aug 25, 2015 at 9:16 AM, ast wrote: >>>>> >>>>> [a,b,c,d] = 1,2,3,4 >>>>> a >> >> 1 >>>>> >>>>> b >> >> 2 >>>>> >>>>> c >> >> 3 >>>>> >>>>> d >> >> 4 >> >> I have never seen this syntax before. Is it documented. >> Is there a name for that ? >> >> thx >> -- >> https://mail.python.org/mailman/listinfo/python-list > > > That's called "sequence unpacking" > > Cody > > -- > https://mail.python.org/mailman/listinfo/python-list > The original example is one I haven't seen in the wild. One nifty use of this feature is to exchange values like this: a, b = b, a it saves the use of a temporary name From nomail at invalid.com Tue Aug 25 11:09:46 2015 From: nomail at invalid.com (ast) Date: Tue, 25 Aug 2015 17:09:46 +0200 Subject: [a,b,c,d] = 1,2,3,4 In-Reply-To: References: <55dc78b2$0$3023$426a74cc@news.free.fr> Message-ID: <55dc853c$0$3083$426a74cc@news.free.fr> "Joel Goldstick" a ?crit dans le message de news:mailman.23.1440513059.11709.python-list at python.org... > On Tue, Aug 25, 2015 at 10:16 AM, ast wrote: >>>>> [a,b,c,d] = 1,2,3,4 >>>>> a >> >> 1 >>>>> >>>>> b >> >> 2 >>>>> >>>>> c >> >> 3 >>>>> >>>>> d >> >> 4 >> >> I have never seen this syntax before. Is it documented. >> Is there a name for that ? >> >> thx >> -- >> https://mail.python.org/mailman/listinfo/python-list > > its called list unpacking or packing (?) > > the right side is considered a tuple because of the commas >>>> a = 1,2,3 >>>> a > (1, 2, 3) >>>> a[1] > 2 >>>> > > > http://www.developer.com/lang/other/article.php/630101/Learn-to-Program-using-Python-Unpacking-Tuples.htm > > > -- > Joel Goldstick > http://joelgoldstick.com Yes you are right, it is related to tuple unpacking Here are some useful examples I found. http://svn.python.org/projects/python/branches/pep-0384/Lib/test/test_unpack_ex.py From nomail at invalid.com Tue Aug 25 11:13:44 2015 From: nomail at invalid.com (ast) Date: Tue, 25 Aug 2015 17:13:44 +0200 Subject: [a,b,c,d] = 1,2,3,4 In-Reply-To: <55dc853c$0$3083$426a74cc@news.free.fr> References: <55dc78b2$0$3023$426a74cc@news.free.fr> <55dc853c$0$3083$426a74cc@news.free.fr> Message-ID: <55dc862a$0$3351$426a74cc@news.free.fr> "ast" a ?crit dans le message de news:55dc853c$0$3083$426a74cc at news.free.fr... > > "Joel Goldstick" a ?crit dans le message de > news:mailman.23.1440513059.11709.python-list at python.org... >> On Tue, Aug 25, 2015 at 10:16 AM, ast wrote: >>>>>> [a,b,c,d] = 1,2,3,4 >>>>>> a >>> >>> 1 >>>>>> >>>>>> b >>> >>> 2 >>>>>> >>>>>> c >>> >>> 3 >>>>>> >>>>>> d >>> >>> 4 >>> >>> I have never seen this syntax before. Is it documented. >>> Is there a name for that ? >>> >>> thx >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >> >> its called list unpacking or packing (?) >> >> the right side is considered a tuple because of the commas >>>>> a = 1,2,3 >>>>> a >> (1, 2, 3) >>>>> a[1] >> 2 >>>>> >> >> >> http://www.developer.com/lang/other/article.php/630101/Learn-to-Program-using-Python-Unpacking-Tuples.htm >> >> >> -- >> Joel Goldstick >> http://joelgoldstick.com > > Yes you are right, it is related to tuple unpacking > Here are some useful examples I found. > http://svn.python.org/projects/python/branches/pep-0384/Lib/test/test_unpack_ex.py Unpack in list >>> [a, *b, c] = range(5) >>> a == 0 and b == [1, 2, 3] and c == 4 True From nomail at invalid.com Tue Aug 25 11:18:39 2015 From: nomail at invalid.com (ast) Date: Tue, 25 Aug 2015 17:18:39 +0200 Subject: [a,b,c,d] = 1,2,3,4 In-Reply-To: References: <55dc78b2$0$3023$426a74cc@news.free.fr> Message-ID: <55dc8754$0$3090$426a74cc@news.free.fr> "Joel Goldstick" a ?crit dans le message de news:mailman.27.1440515128.11709.python-list at python.org... > On Tue, Aug 25, 2015 at 10:32 AM, Cody Piersall wrote: >> >> >> On Tue, Aug 25, 2015 at 9:16 AM, ast wrote: > > The original example is one I haven't seen in the wild. I found it using matplotlib import numpy as np import matplotlib.pyplot as plt f, (ax1, ax2) = plt.subplots(2, 1, sharex=True) From harvested.address at is.invalid Tue Aug 25 11:24:23 2015 From: harvested.address at is.invalid (Jussi Piitulainen) Date: Tue, 25 Aug 2015 18:24:23 +0300 Subject: [a,b,c,d] = 1,2,3,4 References: <55dc78b2$0$3023$426a74cc@news.free.fr> Message-ID: "ast" writes: >>>> [a,b,c,d] = 1,2,3,4 >>>> a > 1 >>>> b > 2 >>>> c > 3 >>>> d > 4 > > I have never seen this syntax before. Is it documented. > Is there a name for that ? I remember being unhappy when a similar assignment with round brackets turned out to be invalid syntax. Then I learned (in this newsgroup) that square brackets would work, and so they did, and then I was happy again, though it felt a bit inconsistent. When I try it today, round brackets also work, both in 2.6.6 and 3.4.0 - no idea what version it was where they failed or if I'm imagining the whole thing. The page that Joel Goldstick cited claims that Guido van Rossum himself has called the left side of a statement like "w,x,y,z = t3" (no brackets on that page) "the list of variables" (but their link to the evidence is dead). From skip.montanaro at gmail.com Tue Aug 25 11:32:53 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 25 Aug 2015 10:32:53 -0500 Subject: [a,b,c,d] = 1,2,3,4 In-Reply-To: References: <55dc78b2$0$3023$426a74cc@news.free.fr> Message-ID: On Tue, Aug 25, 2015 at 10:24 AM, Jussi Piitulainen < harvested.address at is.invalid> wrote: > When I try it today, round brackets > also work, both in 2.6.6 and 3.4.0 - no idea what version it was where > they failed or if I'm imagining the whole thing. > You are imagining the whole thing. Either that, or you had some other problem with your tuple unpacking which kept it from working. That has been a part of the language as far back as I can remember. I started using Python around the 1.0 timeframe. Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Aug 25 11:39:02 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 25 Aug 2015 09:39:02 -0600 Subject: [a,b,c,d] = 1,2,3,4 In-Reply-To: References: <55dc78b2$0$3023$426a74cc@news.free.fr> Message-ID: On Tue, Aug 25, 2015 at 9:32 AM, Skip Montanaro wrote: > > On Tue, Aug 25, 2015 at 10:24 AM, Jussi Piitulainen > wrote: >> >> When I try it today, round brackets >> also work, both in 2.6.6 and 3.4.0 - no idea what version it was where >> they failed or if I'm imagining the whole thing. > > > You are imagining the whole thing. Either that, or you had some other > problem with your tuple unpacking which kept it from working. That has been > a part of the language as far back as I can remember. I started using Python > around the 1.0 timeframe. My guess is that Jussi was trying to unpack a sequence of a single element like this: (a) = some_sequence With the result that a is assigned the whole sequence instead of the one element, because (a) does not denote a tuple, but merely an individual parenthesized expression. Any of these would work in its place: (a,) = some_sequence a, = some_sequence [a] = some_sequence From harvested.address at is.invalid Tue Aug 25 11:57:42 2015 From: harvested.address at is.invalid (Jussi Piitulainen) Date: Tue, 25 Aug 2015 18:57:42 +0300 Subject: [a,b,c,d] = 1,2,3,4 References: <55dc78b2$0$3023$426a74cc@news.free.fr> Message-ID: Skip Montanaro writes: > On Tue, Aug 25, 2015 at 10:24 AM, Jussi Piitulainen wrote: > >> When I try it today, round brackets also work, both in 2.6.6 and >> 3.4.0 - no idea what version it was where they failed or if I'm >> imagining the whole thing. > > You are imagining the whole thing. Either that, or you had some other > problem with your tuple unpacking which kept it from working. That has > been a part of the language as far back as I can remember. I started > using Python around the 1.0 timeframe. At least they work now, and clearly are intended to work. But I just checked and I have scripts with backslash-terminated lines where I'm sure I wanted to use those brackets. Could it have been some sort of temporary regression? Well, never mind :) From harvested.address at is.invalid Tue Aug 25 12:19:44 2015 From: harvested.address at is.invalid (Jussi Piitulainen) Date: Tue, 25 Aug 2015 19:19:44 +0300 Subject: [a,b,c,d] = 1,2,3,4 References: <55dc78b2$0$3023$426a74cc@news.free.fr> Message-ID: Ian Kelly writes: > On Tue, Aug 25, 2015 at 9:32 AM, Skip Montanaro wrote: >> On Tue, Aug 25, 2015 at 10:24 AM, Jussi Piitulainen wrote: >>> >>> When I try it today, round brackets also work, both in 2.6.6 and >>> 3.4.0 - no idea what version it was where they failed or if I'm >>> imagining the whole thing. >> >> You are imagining the whole thing. Either that, or you had some other >> problem with your tuple unpacking which kept it from working. That >> has been a part of the language as far back as I can remember. I >> started using Python around the 1.0 timeframe. > > My guess is that Jussi was trying to unpack a sequence of a single > element like this: > > (a) = some_sequence [snip] It wasn't that. It was a known number of tab-separated fields that I wanted to name individually, like this: ID, FORM, LEMMA, POS, MOR, FEATS, \ HEAD, REL, DEPS, MISC \ = line.split('\t') That's from actual code but not necessarily from the place where I first tried and failed to use parentheses. It didn't occur to me to try square brackets, so I got in the habit of using backslashes as above. (That script is dated in January 2015. The something that happened happened some months before that. But it may have been a hallucination.) From tjreedy at udel.edu Tue Aug 25 12:56:49 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 25 Aug 2015 12:56:49 -0400 Subject: TypeCheck vs IsInstance in C API In-Reply-To: <1440513153.3402880.365512977.5E984BE4@webmail.messagingengine.com> References: <1440513153.3402880.365512977.5E984BE4@webmail.messagingengine.com> Message-ID: On 8/25/2015 10:32 AM, random832 at fastmail.us wrote: > On Mon, Aug 24, 2015, at 22:12, Andrew Wang wrote: [question snipped] > And, now, your moment of zen: Huh?? I fail to see the point of this buggy code. >> def isa(ob, cl): >> try: >> raise ob >> except cl: >> return 1 >> else: return 0 The extra marginal '>' quote makes it look like this buggy code was posted by Andrew, but it comes from random832. In 3.x, both ob and cl must be exceptions and isa(1, int) cannot work. In 2.7, ob must be an exception or old-style class (not documented that I see). >>> raise 1 Traceback (most recent call last): File "", line 1, in raise 1 TypeError: exceptions must be old-style classes or derived from BaseException, not int Hence, isa(1, int) raises TypeError instead of returning 1. If 'else' is changed to 'except', it returns 0 instead of 1. -- Terry Jan Reedy From laurent.pointal at free.fr Tue Aug 25 13:19:25 2015 From: laurent.pointal at free.fr (Laurent Pointal) Date: Tue, 25 Aug 2015 19:19:25 +0200 Subject: [ANN] Python TreeTagger wrapper updated to 2.2.1 Message-ID: <55dca39d$0$3315$426a34cc@news.free.fr> Hello, for natural language processing, treetaggerwrapper, the Python wrapper for language independant part-of-speech statistical tagger TreeTagger from H.Schmid is now available in version 2.2.1. It is available on PyPI: https://pypi.python.org/pypi And the doc is on Read the Docs: http://treetaggerwrapper.readthedocs.org/ The source has been globally reworked, some modifications make it partially incompatible with 1.0 module. It should be more easy to use (tries to autodetect TreeTagger installation directory). It now works with Python2 and Python3 with same source. I also added a treetaggerpoll module for use in a multiprocessing context. For important (and incompatible) modifications, see http://treetaggerwrapper.readthedocs.org/en/latest/#important-modifications-notes A+ Laurent Pointal From laurent.pointal at free.fr Tue Aug 25 13:32:38 2015 From: laurent.pointal at free.fr (Laurent Pointal) Date: Tue, 25 Aug 2015 19:32:38 +0200 Subject: [ANN] Python TreeTagger wrapper updated to 2.2.1 References: <55dca39d$0$3315$426a34cc@news.free.fr> Message-ID: <55dca6b6$0$3051$426a74cc@news.free.fr> Laurent Pointal wrote: > It is available on PyPI: ? incomplete URL? Here: https://pypi.python.org/pypi/treetaggerwrapper/ From random832 at fastmail.us Tue Aug 25 13:42:44 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Tue, 25 Aug 2015 13:42:44 -0400 Subject: TypeCheck vs IsInstance in C API In-Reply-To: References: <1440513153.3402880.365512977.5E984BE4@webmail.messagingengine.com> Message-ID: <1440524564.3447394.365753657.0BAC4922@webmail.messagingengine.com> On Tue, Aug 25, 2015, at 12:56, Terry Reedy wrote: > Huh?? I fail to see the point of this buggy code. ... > The extra marginal '>' quote makes it look like this buggy code was > posted by Andrew, but it comes from random832. Actually, it comes from one of the links I posted right above it. It was, apparently, the recommended way to do this in python up to 1.4, before isinstance existed. It only worked with [old-style, goes without saying] instance and class objects and not, say, ints, but AFAICT isinstance in 1.5 didn't support anything else either. Since these couldn't be subclassed you could simply add "if type(cl) is types.TypeType: return type(ob) is cl" to the top. From larry at hastings.org Tue Aug 25 16:16:33 2015 From: larry at hastings.org (Larry Hastings) Date: Tue, 25 Aug 2015 13:16:33 -0700 Subject: [RELEASED] Python 3.5.0rc2 is now available Message-ID: <55DCCD21.4020308@hastings.org> On behalf of the Python development community and the Python 3.5 release team, I'm relieved to announce the availability of Python 3.5.0rc2, also known as Python 3.5.0 Release Candidate 2. Python 3.5 has now entered "feature freeze". By default new features may no longer be added to Python 3.5. This is a preview release, and its use is not recommended for production settings. You can find Python 3.5.0rc2 here: https://www.python.org/downloads/release/python-350rc2/ Windows and Mac users: please read the important platform-specific "Notes on this release" section near the end of that page. Happy hacking, //arry/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From rene.heymans at gmail.com Tue Aug 25 17:19:53 2015 From: rene.heymans at gmail.com (RAH) Date: Tue, 25 Aug 2015 14:19:53 -0700 (PDT) Subject: file.write() of non-ASCII characters differs in Interpreted Python than in script run Message-ID: Dear All, I experienced an incomprehensible behavior (I've spent already many hours on this subject): the `file.write('string')` provides an error in run mode and not when interpreted at the console. The string must contain non-ASCII characters. If all ASCII, there is no error. The following example shows what I can see. I must overlook something because I cannot think Python makes a difference between interpreted and run modes and yet ... Can someone please check that subject. Thank you in advance. Ren? Code extract from WSGI application (reply.py) ============================================= request_body = environ['wsgi.input'].read(request_body_size) # bytes rb = request_body.decode() # string d = parse_qs(rb) # dict f = open('logbytes', 'ab') g = open('logstr', 'a') h = open('logdict', 'a') f.write(request_body) g.write(str(type(request_body)) + '\t' + str(type(rb)) + '\t' + str(type(d)) + '\n') h.write(str(d) + '\n') <--- line 28 of the application h.close() g.close() f.close() Tail of Apache2 error.log ========================= [Tue Aug 25 20:24:04.657933 2015] [wsgi:error] [pid 3677:tid 3029764928] [remote 192.168.1.5:27575] File "reply.py", line 28, in application [Tue Aug 25 20:24:04.658001 2015] [wsgi:error] [pid 3677:tid 3029764928] [remote 192.168.1.5:27575] h.write(str(d) + '\\n') [Tue Aug 25 20:24:04.658201 2015] [wsgi:error] [pid 3677:tid 3029764928] [remote 192.168.1.5:27575] UnicodeEncodeError: 'ascii' codec can't encode character '\\xc7' in position 15: ordinal not in range(128) Checking what has been logged ============================= rse at Alibaba:~/test$ cat logbytes userName=?a va ! <--- this was indeed the input (notice the french C + cedilla) Unicode U+00C7 ALT-0199 UTF-8 C387 Reading the logbytes file one can verify that ? is indeed represented by the 2 bytes \xC3 and \x87 rse at Alibaba:~/test$ cat logstr rse at Alibaba:~/test$ cat logdict rse at Alibaba:~/test$ <--- Obviously empty because of error Trying similar code within the Python interpreter ================================================= rse at Alibaba:~/test$ python Python 3.4.0 (default, Jun 19 2015, 14:18:46) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> di = {'userName': ['?a va !']} <--- A dictionary >>> str(di) "{'userName': ['?a va !']}" <--- and its string representation >>> type(str(di)) <--- Is a string indeed >>> fi = open('essai', 'a') >>> fi.write(str(di) + '\n') 26 <--- It works well >>> fi.close() >>> Checking what has been written ============================== rse at Alibaba:~/test$ cat essai {'userName': ['?a va !']} <--- The result is correct rse at Alibaba:~/test$ No error if all ASCII ===================== If the input is `userName=Rene` for instance then there is no error and the `logdict' does indeed then contain the text of the dictionary `{'userName': ['Rene']}` From ckaynor at zindagigames.com Tue Aug 25 17:28:36 2015 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 25 Aug 2015 14:28:36 -0700 Subject: file.write() of non-ASCII characters differs in Interpreted Python than in script run In-Reply-To: References: Message-ID: On Tue, Aug 25, 2015 at 2:19 PM, RAH wrote: > Dear All, > > I experienced an incomprehensible behavior (I've spent already many hours on this subject): the `file.write('string')` provides an error in run mode and not when interpreted at the console. The string must contain non-ASCII characters. If all ASCII, there is no error. > > The following example shows what I can see. I must overlook something because I cannot think Python makes a difference between interpreted and run modes and yet ... Can someone please check that subject. > > Thank you in advance. > Ren? > > Code extract from WSGI application (reply.py) > ============================================= > > request_body = environ['wsgi.input'].read(request_body_size) # bytes > rb = request_body.decode() # string > d = parse_qs(rb) # dict > > f = open('logbytes', 'ab') > g = open('logstr', 'a') > h = open('logdict', 'a') > > f.write(request_body) > g.write(str(type(request_body)) + '\t' + str(type(rb)) + '\t' + str(type(d)) + '\n') > h.write(str(d) + '\n') <--- line 28 of the application > > h.close() > g.close() > f.close() > > > Tail of Apache2 error.log > ========================= > > [Tue Aug 25 20:24:04.657933 2015] [wsgi:error] [pid 3677:tid 3029764928] [remote 192.168.1.5:27575] File "reply.py", line 28, in application > [Tue Aug 25 20:24:04.658001 2015] [wsgi:error] [pid 3677:tid 3029764928] [remote 192.168.1.5:27575] h.write(str(d) + '\\n') > [Tue Aug 25 20:24:04.658201 2015] [wsgi:error] [pid 3677:tid 3029764928] [remote 192.168.1.5:27575] UnicodeEncodeError: 'ascii' codec can't encode character '\\xc7' in position 15: ordinal not in range(128) > What version of Python is Apache2 using? From the looks of the error, it is probably using some version of Python2, in which case you'll need to manually encode the string and pick an encoding for the file (via an encoding argument to the open function). I'd recommend using UTF-8. You can log out the value of sys.version to find out the version number. > Trying similar code within the Python interpreter > ================================================= > > rse at Alibaba:~/test$ python > Python 3.4.0 (default, Jun 19 2015, 14:18:46) > [GCC 4.8.2] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> di = {'userName': ['?a va !']} <--- A dictionary >>>> str(di) > "{'userName': ['?a va !']}" <--- and its string representation >>>> type(str(di)) > <--- Is a string indeed >>>> fi = open('essai', 'a') >>>> fi.write(str(di) + '\n') > 26 <--- It works well >>>> fi.close() >>>> In this run, you are using Python 3.4, which defaults to UTF-8. From rosuav at gmail.com Tue Aug 25 19:16:10 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Aug 2015 09:16:10 +1000 Subject: file.write() of non-ASCII characters differs in Interpreted Python than in script run In-Reply-To: References: Message-ID: On Wed, Aug 26, 2015 at 7:19 AM, RAH wrote: > rb = request_body.decode() # string I'd recommend avoiding this operation in Python 2. As of Python 3, omitting the encoding means "UTF-8", but in Python 2 it means "use the default encoding", and that often causes problems in scripts that run in various background environments. Instead, explicitly say what encoding you're using: rb = request_body.decode("UTF-8") Conversely, if you're using Python 3 for this, the default encoding is coming from this line: > h = open('logdict', 'a') Again, if you want this to be a text file with a specific encoding, say so: h = open('logdict', 'a', encoding='UTF-8') Give that a try and see if your problems disappear. If not, this should at least poke them with a pointy stick. ChrisA From dieter at handshake.de Wed Aug 26 01:51:42 2015 From: dieter at handshake.de (dieter) Date: Wed, 26 Aug 2015 07:51:42 +0200 Subject: file.write() of non-ASCII characters differs in Interpreted Python than in script run References: Message-ID: <8737z64mxd.fsf@handshake.de> RAH writes: > I experienced an incomprehensible behavior (I've spent already many hours on this subject): the `file.write('string')` provides an error in run mode and not when interpreted at the console. Maybe, I can explain the behavior: the interactive interpreter uses magic to determine the console's encoding and automatically uses this for console output. No such magic in non-interactive interpreter use. Therefore, you can get "UnicodeEncoding" problems in non-interactive use which you do not see in interactive use. From contact at stridebird.com Wed Aug 26 03:09:11 2015 From: contact at stridebird.com (Pete Dowdell) Date: Wed, 26 Aug 2015 14:09:11 +0700 Subject: file.write() of non-ASCII characters differs in Interpreted Python than in script run In-Reply-To: References: Message-ID: <55DD6617.9080106@stridebird.com> On 26/08/15 04:19, RAH wrote: > UnicodeEncodeError: 'ascii' codec can't encode character '\\xc7' in position 15: ordinal not in range(128) (Hi all, this is my first post to the list) This can be a frustrating issue to resolve, but your issue might be solved with this environment variable: PYTHONIOENCODING=UTF-8 Regards, pd From ben+python at benfinney.id.au Wed Aug 26 03:29:50 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 26 Aug 2015 17:29:50 +1000 Subject: Please don't make unfounded legalistic demands (was: [a, b, c, d] = 1, 2, 3, 4) References: <935842626.955183.1440514765199.JavaMail.root@sequans.com> Message-ID: <85k2sieccx.fsf_-_@benfinney.id.au> Jean-Michel Pichavant writes: > -- IMPORTANT NOTICE: > > The contents of this email and any attachments are confidential and > may also be privileged. If you are not the intended recipient, please > notify the sender immediately and do not disclose the contents to any > other person, use it for any purpose, or store or copy the information > in any medium. Thank you. Misleading, intimidating, hostile nonsense. If you want to participate here, please do so from a mail system which does not make these legalistic demands. -- \ ?It's easy to play any musical instrument: all you have to do | `\ is touch the right key at the right time and the instrument | _o__) will play itself.? ?Johann Sebastian Bach | Ben Finney From jeanmichel at sequans.com Wed Aug 26 05:02:14 2015 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 26 Aug 2015 11:02:14 +0200 (CEST) Subject: Please don't make unfounded legalistic demands (was: [a, b, c, d] = 1, 2, 3, 4) In-Reply-To: <85k2sieccx.fsf_-_@benfinney.id.au> Message-ID: <143673659.1031959.1440579734203.JavaMail.root@sequans.com> ----- Original Message ----- > From: "Ben Finney" > > The contents of this email and any attachments are confidential and > > may also be privileged. If you are not the intended recipient, > > please > > notify the sender immediately and do not disclose the contents to > > any > > other person, use it for any purpose, or store or copy the > > information > > in any medium. Thank you. > > Misleading, intimidating, hostile nonsense. If you want to > participate > here, please do so from a mail system which does not make these > legalistic demands. I agree with you. Unfortunately my request for removing this nonsense has been denied by my employer. To the point where I'm restrincting myself from posting from time to time. I will probably restrict myself even more. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From rene.heymans at gmail.com Wed Aug 26 05:12:05 2015 From: rene.heymans at gmail.com (RAH) Date: Wed, 26 Aug 2015 02:12:05 -0700 (PDT) Subject: file.write() of non-ASCII characters differs in Interpreted Python than in script run In-Reply-To: References: Message-ID: Dear Chris, I can confirm it is Python 3. Here is the line from the Apache2 log: [Wed Aug 26 10:28:01.508194 2015] [mpm_worker:notice] [pid 1120:tid 3074398848] AH00292: Apache/2.4.7 (Ubuntu) OpenSSL/1.0.1f mod_wsgi/4.4.13 Python/3.4.0 configured -- resuming normal operations As a matter of fact, I connect to the same machine that runs Apache2/mod_wsgi/Python via PuTTY and when I open the Python interpreter it responds: > Python 3.4.0 (default, Jun 19 2015, 14:18:46) > [GCC 4.8.2] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> Hence exactly the same Python 3.4.0 version. By the way my whole installation is defaulted to UTF-8: HTML: Javascript: